/* ──────────────────────────────────────────────────────────────────────────
   eLiberty — Step 1: Index Extraction panel.
   Clean editor-focused UI: tight typography, soft cards, sticky action bar,
   keyboard-friendly hit targets.
   ────────────────────────────────────────────────────────────────────────── */

:root {
  --c-bg:        #f1f4fa;
  --c-card:      #ffffff;
  --c-border:    #dde2ec;
  --c-border-d:  #c5cbd9;
  --c-text:      #1c2333;
  --c-text-2:    #4a5269;
  --c-muted:     #6c7388;
  --c-muted-2:   #97a0b8;

  --c-primary:   #3949ab;
  --c-primary-d: #1a237e;
  --c-primary-l: #e8eaf6;
  --c-success:   #2e7d32;
  --c-success-l: #e8f5e9;
  --c-warn:      #b86e00;
  --c-warn-l:    #fff4dd;
  --c-error:     #c62828;
  --c-error-l:   #fdecea;
  --c-info:      #0277bd;
  --c-info-l:    #e3f2fd;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --s-1: 6px;
  --s-2: 10px;
  --s-3: 14px;
  --s-4: 18px;
  --s-5: 24px;
  --s-6: 32px;

  --shadow-1: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-2: 0 4px 18px rgba(15, 23, 42, .08);
  --shadow-pop: 0 12px 28px rgba(15, 23, 42, .14);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top bar ───────────────────────────────────────────────────────────── */
.topbar {
  background: linear-gradient(180deg, var(--c-primary-d), #131c5c);
  color: #fff;
  padding: 12px 28px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-1);
  position: sticky; top: 0; z-index: 100;
}
.topbar .brand {
  color: #fff; font-weight: 700; letter-spacing: .2px; font-size: 15px;
}
.topbar .brand small {
  display: inline-block; margin-left: 8px;
  color: #b4baed; font-weight: 400; font-size: 12px;
}
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: #cdd2f5; padding: 6px 14px; border-radius: 6px; font-size: 13px;
  font-weight: 500;
}
.topbar nav a:hover { color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.topbar nav a.active { background: rgba(255,255,255,.15); color: #fff; }

/* ── Layout ────────────────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 28px auto; padding: 0 24px 80px; }

.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 22px 26px;
  margin-bottom: var(--s-4);
  box-shadow: var(--shadow-1);
}
.card.no-pad { padding: 0; }
.card.hero {
  background: linear-gradient(135deg, #fff, #f7f9ff);
  border-color: #d9def0;
}

h1, h2, h3, h4 { color: var(--c-text); }
h1 { font-size: 1.55rem; line-height: 1.2; font-weight: 700; }
h1 .muted-small { font-weight: 400; }
h2 { font-size: 1.1rem; line-height: 1.3; font-weight: 600; margin-bottom: 10px; }
h3 { font-size: .95rem; line-height: 1.3; font-weight: 600; margin-bottom: 6px; }
h4 {
  font-size: .72rem; color: var(--c-muted); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: .6px; font-weight: 600;
}

p { margin-bottom: var(--s-2); }
p:last-child { margin-bottom: 0; }
.muted       { color: var(--c-muted); }
.muted-small { color: var(--c-muted); font-size: .8rem; }
.text-error  { color: var(--c-error); }
code         { font-family: 'SF Mono', Menlo, Consolas, monospace;
               background: var(--c-primary-l); color: var(--c-primary-d);
               padding: 1px 6px; border-radius: 4px; font-size: .82em; }

.back {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .82rem; color: var(--c-muted-2); margin-bottom: 8px;
}
.back:hover { color: var(--c-primary); text-decoration: none; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  background: #fafbfd; color: var(--c-text);
  font: inherit; font-weight: 500; font-size: .88rem;
  cursor: pointer;
  transition: all .12s ease;
  user-select: none;
  white-space: nowrap;
}
.btn:hover { background: #eef1fa; border-color: var(--c-border-d); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn-sm { padding: 4px 10px; font-size: .78rem; }
.btn-lg { padding: 10px 22px; font-size: .95rem; }

.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover { background: var(--c-primary-d); border-color: var(--c-primary-d); }

.btn-success { background: var(--c-success); color: #fff; border-color: var(--c-success); }
.btn-success:hover { background: #1b5e20; border-color: #1b5e20; }

.btn-danger  { background: #fff; color: var(--c-error); border-color: #f3c2c2; }
.btn-danger:hover { background: var(--c-error-l); border-color: #e58e8e; }

.btn-ghost   { background: transparent; border-color: transparent; color: var(--c-muted); }
.btn-ghost:hover { background: #eef1fa; color: var(--c-text); border-color: transparent; }

.icon-btn {
  border: 1px solid var(--c-border); background: #fff;
  width: 28px; height: 28px; padding: 0; display: inline-flex;
  align-items: center; justify-content: center; border-radius: var(--r-sm);
  color: var(--c-muted); cursor: pointer; transition: all .12s ease;
}
.icon-btn:hover { background: var(--c-primary-l); color: var(--c-primary-d);
                  border-color: var(--c-primary); }
.icon-btn.danger:hover { background: var(--c-error-l); color: var(--c-error);
                         border-color: #e58e8e; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .7rem; font-weight: 600; letter-spacing: .3px;
  line-height: 1.4;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%;
                  background: currentColor; }
.badge-ok      { background: var(--c-success-l); color: var(--c-success); }
.badge-warning { background: var(--c-warn-l);    color: var(--c-warn); }
.badge-error   { background: var(--c-error-l);   color: var(--c-error); }
.badge-info    { background: var(--c-info-l);    color: var(--c-info); }
.badge-muted   { background: #eef1f6;            color: var(--c-muted); }

/* ── Tables ────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th {
  background: #f5f7fb; padding: 10px 14px; text-align: left;
  font-weight: 600; color: var(--c-muted);
  text-transform: uppercase; font-size: .7rem; letter-spacing: .5px;
  border-bottom: 1px solid var(--c-border);
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid #f0f2f7; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafbff; }

/* ── Toast / flash messages ────────────────────────────────────────────── */
.toasts {
  position: fixed; top: 70px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(420px, calc(100vw - 40px));
}
.toast {
  padding: 12px 16px;
  border-radius: var(--r-md);
  font-size: .88rem;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-2);
  display: flex; align-items: flex-start; gap: 10px;
  animation: toast-in .25s ease-out;
}
.toast-info  { border-left: 4px solid var(--c-info); }
.toast-error { border-left: 4px solid var(--c-error); }
.toast .toast-close {
  margin-left: auto; background: none; border: none; color: var(--c-muted);
  cursor: pointer; padding: 0 4px; font-size: 16px; line-height: 1;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: none; }
}

/* ── Empty state ───────────────────────────────────────────────────────── */
.empty {
  text-align: center; padding: 40px 20px;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .35; }
.empty h3 { color: var(--c-text-2); margin-bottom: 6px; }
.empty p  { color: var(--c-muted); margin-bottom: 14px; }

/* ── Stats grid ────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: var(--s-4);
}
.stat-card {
  background: var(--c-card); border: 1px solid var(--c-border);
  border-radius: var(--r-md); padding: 14px 16px;
  box-shadow: var(--shadow-1);
}
.stat-card .label {
  font-size: .72rem; color: var(--c-muted); text-transform: uppercase;
  letter-spacing: .5px; font-weight: 600;
}
.stat-card .value {
  font-size: 1.7rem; font-weight: 700; color: var(--c-text); line-height: 1.2;
  margin-top: 4px;
}
.stat-card .value .sub {
  font-size: .85rem; color: var(--c-muted); font-weight: 400; margin-left: 4px;
}

/* ── Upload page ───────────────────────────────────────────────────────── */
.upload-form { display: flex; flex-direction: column; gap: var(--s-3); }

.dropzone {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed var(--c-border-d);
  border-radius: var(--r-lg);
  padding: 50px 24px;
  text-align: center; background: #fafbff;
  cursor: pointer; transition: all .15s ease;
}
.dropzone:hover, .dropzone.dragover {
  background: var(--c-primary-l); border-color: var(--c-primary);
}
.dropzone.dragover { border-style: solid; }
.dropzone input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.dropzone .dz-icon { font-size: 36px; color: var(--c-primary); margin-bottom: 6px; }
.dropzone .dz-title { font-weight: 600; font-size: 1rem; color: var(--c-text); }
.dropzone .dz-sub   { font-size: .82rem; color: var(--c-muted); margin-top: 4px; }
.dropzone.has-file { background: var(--c-success-l); border-color: var(--c-success);
                     border-style: solid; }
.dropzone.has-file .dz-icon { color: var(--c-success); }

.upload-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.upload-options label {
  display: flex; flex-direction: column;
  font-size: .82rem; color: var(--c-text-2); font-weight: 500;
}
.upload-options input,
.upload-options select {
  margin-top: 4px; padding: 8px 12px;
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  font: inherit; background: #fff; color: var(--c-text);
  min-height: 38px;
}
.upload-options select { cursor: pointer; }
.upload-options input:focus,
.upload-options select:focus { outline: 2px solid var(--c-primary); outline-offset: -1px;
                              border-color: var(--c-primary); }

/* ── Review screen ─────────────────────────────────────────────────────── */
.review-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: var(--s-4);
}
.review-header .meta-line {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  font-size: .82rem; color: var(--c-muted); margin-top: 6px;
}

.text-input {
  padding: 8px 12px; border: 1px solid var(--c-border);
  border-radius: var(--r-sm); font: inherit; width: 100%;
  background: #fff; transition: border-color .12s ease;
}
.text-input:focus {
  outline: 2px solid var(--c-primary); outline-offset: -1px;
  border-color: var(--c-primary);
}

.book-meta-grid {
  display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px;
  align-items: center; margin-bottom: var(--s-4);
}
.book-meta-grid label { color: var(--c-muted); font-size: .82rem; font-weight: 500; }

.editor-toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 10px 0 14px;
  border-bottom: 1px solid var(--c-border); margin-bottom: var(--s-3);
}
.editor-toolbar .spacer { flex: 1; }
.editor-toolbar .live-count {
  font-size: .82rem; color: var(--c-muted);
  display: inline-flex; gap: 14px;
}
.editor-toolbar .live-count strong { color: var(--c-text); font-weight: 600; }

/* ── Chapter rows ──────────────────────────────────────────────────────── */
.chapters-list { display: flex; flex-direction: column; gap: 12px; }

.chapter-row {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow: hidden;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.chapter-row:hover { box-shadow: var(--shadow-1); }
.chapter-row.collapsed .chapter-body { display: none; }

.chapter-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #fafbff, #f3f5fc);
  border-bottom: 1px solid var(--c-border);
  flex-wrap: wrap;
}
.chapter-row.collapsed .chapter-header { border-bottom-color: transparent; }
.collapse-toggle {
  background: none; border: none; cursor: pointer; padding: 2px 4px;
  color: var(--c-muted-2); transition: transform .15s ease;
  font-size: 16px; line-height: 1;
}
.chapter-row.collapsed .collapse-toggle { transform: rotate(-90deg); }
.collapse-toggle:hover { color: var(--c-primary); }

.chapter-number {
  background: var(--c-primary-l); color: var(--c-primary-d);
  font-weight: 700; font-size: .8rem;
  padding: 4px 8px; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; gap: 4px;
}
.chapter-number input {
  width: 40px; padding: 0 4px; border: none; background: transparent;
  font: inherit; color: var(--c-primary-d); text-align: center; font-weight: 700;
}
.chapter-number input:focus { outline: 1px solid var(--c-primary); border-radius: 3px; }

.chapter-title-input {
  flex: 1; min-width: 240px;
  padding: 6px 10px; border: 1px solid transparent;
  background: transparent; border-radius: var(--r-sm);
  font: inherit; font-size: .95rem; font-weight: 600; color: var(--c-text);
  /* Same multi-script chain as sections-table for chapter titles. */
  font-family:
    "Hind Vadodara", "Mukta Vaani", "Anek Gujarati", "Shruti",
    "B Bharati AlokTwo", "B Bharati TitleTwo", "B Bharati TitleLightTwo",
    "Mangal", "Mukta",
    -apple-system, BlinkMacSystemFont, "Times New Roman", serif;
}
.chapter-title-input:hover { border-color: var(--c-border); }
.chapter-title-input:focus {
  background: #fff; outline: 2px solid var(--c-primary); outline-offset: -1px;
  border-color: var(--c-primary);
}

.page-input {
  width: 70px; padding: 4px 8px;
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  font: inherit; font-size: .82rem; text-align: center; color: var(--c-muted);
}
.page-input::placeholder { color: var(--c-muted-2); }

.chapter-actions { display: flex; gap: 4px; margin-left: auto; }

.chapter-body { padding: 8px 14px 14px; }

/* ── Sections table ────────────────────────────────────────────────────── */
.sections-table {
  width: 100%; border-collapse: collapse; font-size: .88rem;
  /* Multi-script fallback chain.  Unicode Gujarati first so modern
     Biology / Hind-Vadodara content renders crisply; then legacy
     non-Unicode Gujarati (B-Bharati family) for older publications;
     then Mukta / Mangal for Hindi; then Latin / system fonts. */
  font-family:
    "Hind Vadodara", "Mukta Vaani", "Anek Gujarati", "Shruti",
    "B Bharati AlokTwo", "B Bharati TitleTwo", "B Bharati TitleLightTwo",
    "Mangal", "Mukta",
    -apple-system, BlinkMacSystemFont, "Times New Roman", serif;
}
.sections-table th {
  background: #f6f8fc; padding: 6px 10px; text-align: left;
  font-size: .68rem; color: var(--c-muted); text-transform: uppercase;
  letter-spacing: .5px; font-weight: 600;
  border-bottom: 1px solid var(--c-border);
}
.sections-table td {
  padding: 4px 6px; border-bottom: 1px solid #f1f3f8;
  vertical-align: middle;
}
.sections-table tbody tr:last-child td { border-bottom: none; }
.sections-table tbody tr:hover { background: #fafbff; }
.sections-table input {
  width: 100%; padding: 6px 10px;
  border: 1px solid transparent; background: transparent;
  border-radius: var(--r-sm); font: inherit;
  transition: border-color .12s ease;
}
.sections-table input:hover { border-color: var(--c-border); }
.sections-table input:focus {
  outline: 2px solid var(--c-primary); outline-offset: -1px;
  border-color: var(--c-primary); background: #fff;
}
.sections-table .sec-label-cell { width: 90px; }
.sections-table .sec-page-cell  { width: 80px; }
.sections-table .sec-actions    { width: 64px; text-align: right; }

.sections-empty {
  padding: 14px;
  font-size: .82rem; color: var(--c-muted-2); font-style: italic;
  text-align: center; border: 1px dashed var(--c-border);
  border-radius: var(--r-sm); margin: 6px 0;
}

/* OCR-sourced section rows — slightly tinted to signal "needs verification" */
.section-row[data-source="ocr"] {
  background: #fffbf2;
}
.section-row[data-source="ocr"]:hover { background: #fff5e4; }
.sec-source-row {
  display: flex; align-items: center; gap: 6px;
  margin-top: 4px;
}
.ocr-badge {
  display: inline-flex; align-items: center;
  padding: 1px 7px;
  background: var(--c-warn-l); color: var(--c-warn);
  border-radius: 999px;
  font-size: .65rem; font-weight: 700; letter-spacing: .4px;
  cursor: help;
}
.ocr-thumb-link {
  display: inline-block; line-height: 0;
}
.ocr-thumb {
  height: 28px; width: auto; max-width: 220px;
  border: 1px solid var(--c-border);
  border-radius: 4px; background: #fff;
  transition: transform .15s ease, box-shadow .15s ease;
}
.ocr-thumb:hover {
  transform: scale(1.04);
  box-shadow: var(--shadow-2);
  border-color: var(--c-primary);
}

.add-section-btn { margin-top: 8px; }

/* ── Sticky action bar ─────────────────────────────────────────────────── */
.sticky-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(255, 255, 255, .97); backdrop-filter: blur(8px);
  border-top: 1px solid var(--c-border);
  padding: 12px 0;
  box-shadow: 0 -4px 18px rgba(15, 23, 42, .08);
  z-index: 50;
}
.sticky-bar .inner {
  max-width: 1200px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; gap: 14px;
}
.sticky-bar .unsaved-pill {
  display: none; padding: 4px 10px;
  background: var(--c-warn-l); color: var(--c-warn);
  border-radius: var(--r-sm); font-size: .78rem; font-weight: 600;
}
.sticky-bar.has-unsaved .unsaved-pill { display: inline-flex; }
.sticky-bar .spacer { flex: 1; }

/* ── Confirm + delete card ─────────────────────────────────────────────── */
.actions-card { background: #fff; }
.actions-card .row {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}

/* ── Empty section placeholder ─────────────────────────────────────────── */
.section-row[data-empty="1"] { opacity: .6; }

/* ── Source info row ───────────────────────────────────────────────────── */
.source-info {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: #f3f5fc;
  border: 1px solid var(--c-border);
  border-radius: 999px;
  font-size: .78rem; color: var(--c-muted);
}
.source-info code {
  background: transparent; color: var(--c-text-2); padding: 0;
  font-size: .82em;
}

/* ── Diagnostics ───────────────────────────────────────────────────────── */
.rule-list { padding-left: 20px; font-size: .85rem; color: var(--c-muted); }

/* ── Step 2: chapters stepper ──────────────────────────────────────────── */
.stepper { list-style: none; margin: 0; padding: 0; }
.stepper-row {
  display: flex; gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--c-border);
  transition: background .12s ease;
}
.stepper-row:last-child { border-bottom: none; }
.stepper-row:hover { background: #fafbff; }
.stepper-row.stepper-confirmed { background: linear-gradient(90deg, #f0f9f1 0%, transparent 30%); }
.stepper-row.stepper-draft     { background: linear-gradient(90deg, #f0f6fc 0%, transparent 30%); }

.stepper-num {
  flex: 0 0 44px; height: 44px;
  background: var(--c-primary-l); color: var(--c-primary-d);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.05rem;
}
.stepper-confirmed .stepper-num { background: var(--c-success-l); color: var(--c-success); }
.stepper-body { flex: 1; min-width: 0; }
.stepper-title-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 6px;
}
.stepper-title {
  font-size: 1rem; line-height: 1.3; margin: 0;
  font-family:
    "Hind Vadodara", "Mukta Vaani", "Anek Gujarati",
    "B Bharati AlokTwo", "B Bharati TitleTwo",
    -apple-system, BlinkMacSystemFont, "Times New Roman", serif;
}

.stepper-sections {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 6px 0 10px;
}
.section-chip {
  font-size: .72rem;
  padding: 3px 9px;
  background: #f1f4fa; color: var(--c-text-2);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  display: inline-flex; align-items: center; gap: 4px;
  max-width: 260px;
  white-space: nowrap; text-overflow: ellipsis; overflow: hidden;
}
.section-chip code {
  background: transparent; padding: 0; color: var(--c-muted);
  font-size: .72em;
}

.stepper-actions {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.chapter-upload-label { position: relative; cursor: pointer; }
.chapter-upload-label input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}

/* ── Step 2: chapter review ──────────────────────────────────────────── */
.qa-list { display: flex; flex-direction: column; gap: 12px; }
.qa-card {
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 12px 16px;
  background: #fff;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.qa-card[data-uncertain="1"] { border-left: 4px solid var(--c-warn); }
.qa-card:hover { box-shadow: var(--shadow-1); }

.qa-meta {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 6px;
}
.qa-seq {
  background: var(--c-primary-l); color: var(--c-primary-d);
  padding: 2px 8px; border-radius: 4px;
  font-weight: 700; font-size: .78rem;
}
.qa-meta select {
  padding: 4px 8px; border: 1px solid var(--c-border);
  border-radius: 5px; font: inherit; font-size: .82rem;
}

.qa-textarea {
  display: block; width: 100%;
  font-family:
    "Hind Vadodara", "Mukta Vaani", "Anek Gujarati",
    "B Bharati AlokTwo", "B Bharati TitleTwo",
    -apple-system, "Times New Roman", serif;
  font-size: 13px; line-height: 1.5;
  padding: 8px 10px;
  border: 1px solid var(--c-border); border-radius: 6px;
  margin-bottom: 6px;
  resize: vertical; background: #fff;
}
.qa-textarea:focus {
  outline: 2px solid var(--c-primary); outline-offset: -1px;
  border-color: var(--c-primary);
}

/* Contenteditable editor — used in chapter-review Edit mode.  Lets
   per-span fonts (loaded via the publisher's scoped CSS) apply to
   `<span class="CharOverride-N">` content the same way as in preview,
   so legacy Gujarati bytes render as Gujarati glyphs instead of as
   Latin-1 fallbacks from a Unicode font. */
.qa-editor {
  display: block; width: 100%;
  font-size: 13px; line-height: 1.6;
  padding: 8px 10px;
  border: 1px solid var(--c-border); border-radius: 6px;
  margin-bottom: 6px;
  background: #fff;
  min-height: 2.6em;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.qa-editor:focus {
  outline: 2px solid var(--c-primary); outline-offset: -1px;
  border-color: var(--c-primary);
}
.qa-editor img { max-width: 100%; height: auto; vertical-align: middle; }
.qa-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--c-text-3);
}

.q-options { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.q-options .opt-row {
  display: flex; gap: 8px; align-items: flex-start;
}
.q-options .opt-label {
  flex: 0 0 28px; padding-top: 9px;
  font-family: 'SF Mono', Menlo, monospace; font-weight: 600;
  font-size: .78rem; color: var(--c-text-2);
}
.q-options .qa-textarea { margin-bottom: 0; }
.correct-option-row {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 0; font-size: .82rem;
}
.correct-option-row select {
  padding: 4px 8px; border: 1px solid var(--c-border);
  border-radius: 5px; font: inherit;
}

/* ── Preview blocks inside Q cards ──────────────────────────────────── */
.qa-card.preview-mode .qa-edit-btn { background: #fff; color: var(--c-primary); }
.qa-card.edit-mode    .qa-edit-btn { background: var(--c-error-l); color: var(--c-error); }
.qa-card.edit-mode    { border-color: var(--c-primary); background: #fafbff; }

.qa-preview-block {
  padding: 8px 10px;
  background: #fafbfd;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  margin-bottom: 8px;
  white-space: normal;
  word-break: break-word;
}
.qa-preview-block img { max-width: 100%; height: auto; vertical-align: middle; }

.qa-preview ol.opts {
  /* The explicit <strong>(A)</strong> label is the data-driven option key
     (matches "Correct: (X)" and edit mode), so suppress the <ol type="A">
     auto-marker — otherwise every option reads "A. (A) …" (labelled twice). */
  list-style: none;
  padding-left: 0;
  margin: 4px 0 6px;
}
.qa-preview ol.opts li { padding: 4px 6px; margin-bottom: 2px; border-radius: 4px; }
.qa-preview ol.opts li.correct {
  background: var(--c-success-l);
  border-left: 3px solid var(--c-success);
}
.qa-preview ol.opts li img { max-width: 100%; height: auto; vertical-align: middle; }

.qa-table-wrap {
  padding: 8px 10px;
  background: #fafbfd;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  margin-bottom: 8px;
  overflow-x: auto;
}
.qa-table-wrap .qa-table-pos { display: block; margin-bottom: 4px; }
.qa-table-wrap table {
  border-collapse: collapse;
  width: auto; min-width: 240px;
  font-size: 12.5px;
}
.qa-table-wrap td, .qa-table-wrap th {
  border: 1px solid var(--c-border);
  padding: 4px 8px; vertical-align: top;
}
.qa-table-wrap th { background: #f1f4fa; font-weight: 600; }
.qa-table-wrap img { max-width: 100%; height: auto; }

/* ── Image sizing override ──────────────────────────────────────────────
   The publisher's scoped CSS sets per-image dimensions via classes
   like `img._idGenObjectAttribute-N { width:…; height:…; min-width:100% }`.
   Pixel-width rules are fine — they reproduce the source figure size.
   But a few rules use percentage-based sizing (intended for the
   InDesign viewer's container) which forces small images to stretch to
   100% of our differently-sized review container, breaking aspect ratio.

   To keep source widths intact while preventing the stretch, we use
   `!important` to force aspect-preserving height and a safety cap on
   width.  Specificity-wise the publisher's `.qa-card ._idGenObjectAttribute-N`
   (0,2,0) would otherwise win over our (0,1,1) override.  `width: auto`
   lets the publisher's explicit `width: 252px` still apply because
   `width:auto` only takes effect when no other `width` is set. */
.qa-card img {
  height: auto !important;
  max-width: 100% !important;
  min-width: 0 !important;
  object-fit: contain;
}

/* Multi-script font chain — applied to every preview block holding
   Q/A/option/table HTML.  Unicode Gujarati first so modern content
   wins; then legacy non-Unicode for older publications; then Hindi
   Devanagari; then Latin / system. */
.multi-lang,
.qa-preview-block,
.qa-preview ol.opts li,
.qa-table-wrap {
  font-family:
    "Hind Vadodara", "Mukta Vaani", "Anek Gujarati", "Shruti",
    "B Bharati AlokTwo", "B Bharati TitleTwo", "B Bharati TitleLightTwo",
    "Mangal", "Mukta",
    -apple-system, BlinkMacSystemFont, "Times New Roman", serif;
  /* Readable base size for Q/A/option text (Issue 3 defense-in-depth).  The
     publisher's per-class px sizes are scaled up in css_scope; this floor keeps
     any UN-classed / inherited text comfortable too.  Not !important, so the
     scaled publisher classes still win where they apply. */
  font-size: 15px;
  line-height: 1.65;
}

/* Section header in review = `chapter-header` reused */
fieldset.chapter-row .sec-id {
  width: 64px; padding: 0 4px; border: none; background: transparent;
  font: inherit; color: var(--c-primary-d); text-align: center; font-weight: 700;
}
fieldset.chapter-row .sec-id:focus { outline: 1px solid var(--c-primary); border-radius: 3px; }
fieldset.chapter-row .sec-title { /* reuses chapter-title-input styles */ }
fieldset.chapter-row .sec-type {
  padding: 4px 8px; border: 1px solid var(--c-border);
  border-radius: 5px; font: inherit; font-size: .82rem;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .container { padding: 0 16px 100px; margin-top: 16px; }
  .card { padding: 16px 18px; }
  .upload-options { grid-template-columns: 1fr; }
  .review-header { flex-direction: column; }
  .chapter-header { gap: 6px; }
  .chapter-title-input { min-width: 100%; flex: 0 0 100%; order: 2; }
}

/* ── Upload progress overlay ────────────────────────────────────────────
   Shown on chapter ZIP upload to block user interaction while the
   server is parsing + OCR-ing the file (can take 1-2 minutes for a
   chapter with many callout images).  Pure CSS — no framework. */
.upload-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(13, 17, 23, 0.78);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.upload-overlay[hidden] { display: none; }
.upload-overlay-card {
  background: #fff;
  padding: 32px 36px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  max-width: 520px;
  text-align: center;
}
.upload-overlay-title {
  margin: 16px 0 6px;
  font-size: 1.25rem;
  color: var(--c-text-1);
}
.upload-overlay-subtitle {
  margin: 0 0 16px;
  font-size: 0.95rem;
  color: var(--c-text-2);
  font-weight: 600;
}
.upload-overlay-steps {
  text-align: left;
  margin: 16px 0;
  padding-left: 22px;
  color: var(--c-text-2);
  font-size: 0.88rem;
  line-height: 1.6;
}
.upload-overlay-steps li { margin-bottom: 4px; }
.upload-overlay-warn {
  font-size: 0.82rem;
  color: var(--c-warn);
  font-weight: 600;
  margin: 12px 0 0;
}
.upload-spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  margin: 0 auto;
  animation: uploadSpin 0.9s linear infinite;
}
@keyframes uploadSpin { to { transform: rotate(360deg); } }

/* ── Dashboard list toolbar ───────────────────────────────────────────── */
.list-toolbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--c-border);
  background: #f8f9fc;
  border-top-left-radius: var(--r-lg);
  border-top-right-radius: var(--r-lg);
  flex-wrap: wrap;
}
.list-toolbar-field {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.82rem; color: var(--c-text-2); font-weight: 500;
}
.list-toolbar-field select {
  padding: 5px 8px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: #fff;
  font: inherit; font-size: 0.85rem;
  color: var(--c-text);
  cursor: pointer;
}
.list-toolbar-field select:focus-visible {
  outline: 2px solid var(--c-primary); outline-offset: 1px;
}

/* ── Confirmation modal (reused for delete) ───────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(13, 17, 23, 0.65);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
  background: #fff;
  padding: 28px 32px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  max-width: 480px;
  width: 90%;
}
.modal-title {
  margin: 0 0 12px;
  font-size: 1.15rem;
  color: var(--c-text);
}
.modal-body {
  margin: 0 0 20px;
  color: var(--c-text-2);
  font-size: 0.92rem;
  line-height: 1.55;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Log-error modal form fields ───────────────────────────────────────── */
.le-field { display: block; margin-bottom: 14px; }
.le-label {
  display: block; margin-bottom: 5px;
  font-size: .85rem; font-weight: 600; color: var(--c-text);
}
#logErrorModal textarea {
  display: block; width: 100%; box-sizing: border-box;
  padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 6px;
  font: inherit; font-size: .9rem; resize: vertical; min-height: 84px;
}
#logErrorModal textarea:focus {
  outline: 2px solid var(--c-primary); outline-offset: 0; border-color: var(--c-primary);
}
#logErrorModal input[type="file"] { display: block; font-size: .85rem; max-width: 100%; }
.le-error { margin: -8px 0 12px; font-size: .82rem; font-weight: 600; }
.le-preview { margin-top: 4px; }
.le-preview img {
  display: block; max-width: 100%; max-height: 220px;
  border: 1px solid var(--c-border); border-radius: 6px;
}
