:root {
  --ink: #253044;
  --muted: #68758a;
  --paper: #fffdf7;
  --cream: #fff8e7;
  --line: #e4e7ee;
  --coral: #f36d5f;
  --coral-dark: #d84d42;
  --yellow: #f8c845;
  --yellow-light: #fff2c6;
  --sky: #5eafd1;
  --sky-light: #e6f6fc;
  --mint: #69bb91;
  --mint-light: #e6f8ef;
  --violet: #9279ca;
  --violet-light: #efeafb;
  --shadow-sm: 0 4px 12px rgba(40, 52, 70, 0.05);
  --shadow: 0 10px 25px rgba(40, 52, 70, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--cream);
  font-family: "Nunito", sans-serif;
  line-height: 1.5;
}

input, select, button, textarea {
  font-family: inherit;
  font-size: 14px;
}

h1, h2, h3 {
  margin: 0;
  font-family: "Baloo 2", sans-serif;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--coral-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
}

.admin-shell {
  width: min(100% - 36px, 1200px);
  min-height: 100vh;
  padding: 24px 0 60px;
  margin: 0 auto;
}

/* Top Navigation */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 2px solid #ecdca8;
}

.nav-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #fff;
  border: 1px solid #dcd5c0;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  transition: all .15s ease;
}
.nav-back-btn:hover {
  background: #fdf5df;
  border-color: #d1b463;
  color: var(--coral-dark);
}
.nav-back-btn svg { width: 18px; height: 18px; }

.user-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #e6f6fc;
  border: 1px solid #c2e6f4;
  border-radius: 6px;
  color: #1a7196;
  font-size: 13px;
  font-weight: 800;
}
.user-badge svg { width: 16px; height: 16px; }

.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #e1e5ea;
  border-radius: 6px;
  color: #a43e37;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  transition: all .15s ease;
}
.logout-btn:hover {
  background: #ffebe9;
  border-color: #f38f87;
}
.logout-btn svg { width: 16px; height: 16px; }

/* Login Panel */
.login-panel {
  width: min(100%, 430px);
  padding: 40px 32px;
  margin: 60px auto;
  border: 2px solid #efdca4;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow);
  text-align: center;
}

.lock-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  background: var(--yellow);
  border: 2px solid #e3af25;
  border-radius: 16px;
  color: var(--ink);
  transform: rotate(-4deg);
}
.lock-mark svg { width: 28px; height: 28px; }

.login-panel h1 { font-size: 30px; margin-bottom: 6px; }
.login-desc { color: var(--muted); font-size: 14px; font-weight: 700; margin-bottom: 24px; }

.admin-form { display: grid; gap: 16px; text-align: left; }
.admin-form label span { display: block; margin-bottom: 5px; color: #4b586d; font-size: 13px; font-weight: 800; }

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-wrap svg {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  color: #8c98a8;
  pointer-events: none;
}
.input-wrap input {
  width: 100%;
  height: 44px;
  padding: 0 12px 0 38px;
  border: 1px solid #d4dae3;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input-wrap input:focus {
  border-color: var(--sky);
  box-shadow: 0 0 0 3px rgba(94, 175, 209, 0.2);
}

.login-hint {
  margin-top: 22px;
  padding: 10px 14px;
  background: #f7f9fc;
  border: 1px dashed #d5dce5;
  border-radius: 7px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #556275;
  font-size: 12px;
  text-align: left;
}
.login-hint svg { width: 16px; height: 16px; flex: 0 0 auto; color: var(--sky); }

/* Hero Overview */
.admin-hero {
  padding: 24px 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}
.hero-text h1 { font-size: 34px; margin-bottom: 4px; }
.hero-text p:not(.eyebrow) { margin: 0; color: #625b44; font-size: 15px; font-weight: 700; }

.stats-overview { display: flex; gap: 14px; }
.stat-card {
  min-width: 140px;
  padding: 12px 18px;
  background: #fffdf8;
  border: 1.5px solid #ecdca8;
  border-radius: 8px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.03);
  text-align: center;
}
.stat-num {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  color: var(--coral-dark);
}
.stat-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.stat-label svg { width: 14px; height: 14px; }

/* Alerts / Messages */
.message {
  padding: 12px 16px;
  margin: 16px 0 22px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
}
.message svg { width: 20px; height: 20px; flex: 0 0 auto; }
.message.success { background: #e4f8ed; color: #1e6c46; border: 1px solid #b7ecd0; }
.message.success a { color: #155535; font-weight: 900; text-decoration: underline; }
.message.error { background: #feebe8; color: #b73227; border: 1px solid #f9cac4; }

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.card {
  padding: 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 20px;
  border-bottom: 1px solid #eceff4;
}
.card-header h2 { font-size: 22px; }
.header-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--yellow-light);
  border: 1px solid #f0d588;
  border-radius: 8px;
  color: #7b590e;
}
.header-icon svg { width: 22px; height: 22px; }

/* Form Styles */
.book-form { display: grid; gap: 16px; }
.form-group { display: grid; gap: 6px; }
.label-text { color: #435165; font-size: 13px; font-weight: 900; }
.label-text .req { color: var(--coral-dark); }

input[type="text"], input[type="url"], select {
  height: 42px;
  padding: 0 12px;
  border: 1px solid #d2d8e2;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  outline: none;
  transition: border-color .15s ease;
}
input[type="text"]:focus, input[type="url"]:focus, select:focus {
  border-color: var(--sky);
  box-shadow: 0 0 0 3px rgba(94, 175, 209, 0.18);
}

.form-row { display: grid; grid-template-columns: 1fr; gap: 12px; }

/* Tone Picker */
.tone-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 3px;
}
.tone-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: 2px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  background: #fff;
  border: 1px solid #e2e6ed;
  transition: all .15s ease;
}
.tone-option input { position: absolute; opacity: 0; pointer-events: none; }
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
}
.swatch svg { width: 14px; height: 14px; opacity: 0; transition: opacity .15s ease; }
.tone-name { font-size: 10px; font-weight: 800; color: #556275; text-align: center; }

.tone-sky .swatch { background: var(--sky); }
.tone-yellow .swatch { background: var(--yellow); }
.tone-coral .swatch { background: var(--coral); }
.tone-mint .swatch { background: var(--mint); }
.tone-violet .swatch { background: var(--violet); }

.tone-option:has(input:checked) {
  border-color: var(--coral);
  background: #fff8f7;
}
.tone-option:has(input:checked) .swatch svg { opacity: 1; }

/* Source Tabs & Input Boxes */
.source-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background: #edf1f7;
  border-radius: 8px;
  margin-bottom: 10px;
}
.source-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  color: #5b677a;
  cursor: pointer;
  transition: all .15s ease;
}
.source-tab input { display: none; }
.source-tab svg { width: 15px; height: 15px; }
.source-tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 5px rgba(0,0,0,0.06);
}

.source-input-box { margin-top: 2px; }

/* Drop Area */
.drop-area {
  display: block;
  padding: 24px 16px;
  border: 2px dashed #cbd4e0;
  border-radius: 8px;
  background: #fbfcfe;
  text-align: center;
  cursor: pointer;
  transition: all .15s ease;
}
.drop-area:hover {
  border-color: var(--sky);
  background: #f3faff;
}
.drop-area input { display: none; }
.drop-icon { width: 34px; height: 34px; color: var(--sky); margin: 0 auto 6px; display: block; }
.drop-title { margin: 0 0 2px; font-weight: 800; font-size: 14px; color: var(--ink); }
.drop-sub { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.chosen-filename {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 99px;
  background: #edf2f7;
  color: #637083;
  font-size: 12px;
  font-weight: 800;
}
.chosen-filename.has-file {
  background: #e3f8ec;
  color: #1d7348;
}

/* URL Input Field */
.url-input-field {
  position: relative;
  display: flex;
  align-items: center;
}
.url-input-field svg {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: #8c98a8;
}
.url-input-field input {
  width: 100%;
  padding-left: 36px;
}

.gdrive-tip {
  margin-top: 10px;
  padding: 10px 12px;
  background: #fff9e6;
  border: 1px solid #f2dfa4;
  border-radius: 6px;
  display: flex;
  gap: 9px;
  font-size: 12px;
  line-height: 1.45;
  color: #5c4f22;
}
.gdrive-tip svg { width: 17px; height: 17px; flex: 0 0 auto; color: #d09413; }

.form-note {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  background: #f7f9fc;
  border-radius: 6px;
  color: #536277;
  font-size: 12px;
  font-weight: 700;
}
.form-note svg { width: 16px; height: 16px; color: var(--coral); flex: 0 0 auto; }

.submit-btn {
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 20px;
  border: 0;
  border-radius: 7px;
  background: var(--coral);
  color: #fff;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--coral-dark);
  transition: all .15s ease;
}
.submit-btn:hover {
  background: var(--coral-dark);
  transform: translateY(-1px);
}
.submit-btn svg { width: 18px; height: 18px; }

.secondary-btn {
  background: #2a394f;
  box-shadow: 0 3px 0 #1b2635;
}
.secondary-btn:hover {
  background: #1b2635;
}

/* Book List / Table */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap svg {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: #8c98a8;
}
.search-wrap input {
  height: 36px;
  padding: 0 12px 0 32px;
  border: 1px solid #d4dae3;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-weight: 700;
  outline: none;
}
.search-wrap input:focus { border-color: var(--sky); }

.books-table-wrap {
  overflow-x: auto;
  margin-top: 4px;
}
.books-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
.books-table th {
  padding: 10px 12px;
  border-bottom: 2px solid #e4e8ef;
  color: #5d6a7d;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.books-table td {
  padding: 12px;
  border-bottom: 1px solid #eef1f6;
  vertical-align: middle;
}
.books-table tbody tr:hover {
  background: #fafcfe;
}

/* Mini Cover Thumbnail in Admin Table */
.thumb-wrap {
  position: relative;
  width: 48px;
  height: 64px;
  border-radius: 4px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #5eafd1;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  border: 1px solid rgba(0,0,0,0.08);
}
.thumb-wrap.tone-yellow { background: var(--yellow); }
.thumb-wrap.tone-coral { background: var(--coral); }
.thumb-wrap.tone-mint { background: var(--mint); }
.thumb-wrap.tone-violet { background: var(--violet); }
.thumb-wrap.tone-sky { background: var(--sky); }

.admin-cover-canvas,
.admin-cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}
.admin-cover-canvas {
  display: none;
}
.thumb-fallback { color: #fff; opacity: .8; }
.thumb-fallback svg { width: 22px; height: 22px; }

.book-row-main { display: grid; gap: 4px; }
.row-title { font-size: 15px; color: var(--ink); font-weight: 800; }
.row-meta { display: flex; align-items: center; gap: 6px; }

.meta-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 800;
}
.subject-badge { background: #fff0ed; color: var(--coral-dark); border: 1px solid #fedbd5; }

.meta-tone {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}
.tone-pill-sky { background: var(--sky-light); color: #186b8f; }
.tone-pill-yellow { background: var(--yellow-light); color: #836109; }
.tone-pill-coral { background: #ffece9; color: #a9352b; }
.tone-pill-mint { background: var(--mint-light); color: #1f764a; }
.tone-pill-violet { background: var(--violet-light); color: #5f4893; }

.source-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 800;
}
.source-tag svg { width: 13px; height: 13px; }
.default-tag { background: #e9f5fa; color: #227394; }
.gdrive-tag { background: #e8f8ef; color: #20774a; }
.upload-tag { background: #fff2ea; color: #b0551e; }

/* Table Action Buttons */
.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.action-btn {
  height: 32px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid #d8dee6;
  border-radius: 5px;
  background: #fff;
  color: #4b5768;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: all .15s ease;
}
.action-btn svg { width: 14px; height: 14px; }
.action-btn:hover { border-color: var(--sky); color: #187196; background: #f4fbfe; }

.preview-btn { color: #187196; border-color: #cde6f2; background: #f5fbfe; }
.preview-btn:hover { background: #e3f4fc; }

.edit-btn:hover { border-color: #f3b145; color: #8a5e0d; background: #fff9ed; }

.delete-btn { color: #b73429; }
.delete-btn:hover { border-color: #f79d95; color: #a0251a; background: #ffeeec; }

/* Security Panel */
.security-card {
  margin-top: 24px;
}
.password-grid-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 12px;
  align-items: end;
}
.password-grid-form .button-group { margin-bottom: 0; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(27, 36, 50, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}
.modal-box {
  width: min(100%, 540px);
  background: #fff;
  border-radius: 12px;
  padding: 26px;
  box-shadow: 0 20px 45px rgba(23, 33, 49, 0.25);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eef1f6;
}
.modal-header h3 {
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.modal-header h3 svg { width: 20px; height: 20px; color: var(--sky); }
.modal-close {
  border: 0;
  background: transparent;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}
.modal-form { display: grid; gap: 14px; }

/* Modal Source Section */
.modal-source-section {
  padding: 14px;
  background: #f7f9fd;
  border: 1px solid #e1e7f0;
  border-radius: 8px;
  display: grid;
  gap: 10px;
}
.current-file-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.cur-label { font-weight: 800; color: #627083; flex: 0 0 auto; }
.cur-path {
  display: inline-block;
  max-width: 380px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 8px;
  background: #fff;
  border: 1px solid #dbe2ec;
  border-radius: 4px;
  color: #1a6e92;
  font-family: monospace;
  font-size: 12px;
}
.edit-source-radios {
  display: grid;
  gap: 8px;
  padding: 6px 0;
}
.edit-radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
  color: #3b485a;
  cursor: pointer;
}
.edit-radio-label input {
  cursor: pointer;
  accent-color: var(--coral);
}
.edit-source-field {
  padding-top: 4px;
}
.edit-field-tip {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}
.cancel-btn { height: 42px; padding: 0 16px; }

/* Responsive Media Queries */
@media (max-width: 950px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .password-grid-form { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .admin-shell { width: min(100% - 24px, 1200px); padding-top: 16px; }
  .login-panel { padding: 30px 20px; margin: 30px auto; }
  .hero-text h1 { font-size: 28px; }
  .stats-overview { width: 100%; }
  .stat-card { flex: 1; }
  .tone-picker { grid-template-columns: repeat(3, 1fr); }
  .books-table th:nth-child(3), .books-table td:nth-child(3) { display: none; }
}
