/* ==========================================================================
   Version 1.3 interface theme — app shell only.
   Worksheet, mark scheme and print styles stay in styles.css.
   Copyright © 2026 Yunfei Wang
   ========================================================================== */
:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e4e8f0;
  --line-strong: #cfd6e2;
  --canvas: #f2f4f8;
  --panel: #ffffff;
  --brand: #3b4fd8;
  --brand-600: #3040bd;
  --brand-50: #eef0fe;
  --brand-100: #dde2fd;
  --cta: #0e9f6e;
  --cta-600: #0b855c;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-md: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --header-h: 68px;
  /* Older tokens used by styles.css */
  --bg-app: var(--canvas);
  --border-color: var(--line-strong);
  --text-main: var(--ink);
  --text-muted: var(--muted);
  --primary: var(--brand);
  --primary-hover: var(--brand-600);
  --primary-light: var(--brand-50);
}

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---------- Header ---------- */
.app-header {
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  box-shadow: none;
  padding: .7rem 1.5rem;
  min-height: var(--header-h);
  align-items: center;
}
.brand-group { gap: .8rem; min-width: 0; }
.brand-mark {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #4f63ee 0%, #2f3fb8 100%);
  color: #fff;
  font: 800 1.05rem/1 Georgia, 'Times New Roman', serif;
  font-style: italic;
  box-shadow: 0 4px 12px rgba(59, 79, 216, .3);
}
.brand-title h1 { font-size: 1.05rem; font-weight: 750; letter-spacing: -.015em; color: var(--ink); }
.brand-title p { font-size: .74rem; color: var(--muted); line-height: 1.4; }
.brand-title .app-copyright { font-size: .68rem !important; color: #94a3b8; }

.header-actions { gap: .6rem; flex-wrap: wrap; justify-content: flex-end; }
.header-nav { display: flex; gap: .15rem; flex-wrap: wrap; padding-right: .5rem; margin-right: .1rem; border-right: 1px solid var(--line); }
.btn { border-radius: var(--radius-sm); font-size: .82rem; font-weight: 600; padding: .5rem .85rem; line-height: 1.2; }
.btn:focus-visible { outline: 3px solid var(--brand-100); outline-offset: 1px; }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: transparent; text-decoration: none; }
.btn-ghost:hover { background: #f1f4f9; color: var(--ink); }
#generateAllSowBtn.active { background: var(--brand-50); color: var(--brand); border-color: var(--brand-100); }
.header-export { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: #fff; box-shadow: var(--shadow-sm); }
.btn-export { background: #fff; color: var(--ink); border: 0; border-radius: 0; }
.btn-export + .btn-export { border-left: 1px solid var(--line-strong); }
.btn-export:hover { background: #f6f7fb; }
.btn-cta { background: var(--cta); color: #fff; padding: .55rem 1.1rem; box-shadow: 0 1px 2px rgba(14, 159, 110, .25), 0 4px 12px rgba(14, 159, 110, .22); }
.btn-cta:hover { background: var(--cta-600); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }

/* ---------- Layout ---------- */
.app-layout { grid-template-columns: 360px minmax(0, 1fr); gap: 1.5rem; max-width: 1560px; padding: 1.4rem 1.5rem 3rem; }

/* ---------- Sidebar ---------- */
.controls-card {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0 .35rem 1rem 0;
  gap: .85rem;
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  max-height: calc(100vh - var(--header-h) - 2rem);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #cbd2de transparent;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: .95rem 1rem 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.panel-title { display: flex; align-items: center; gap: .55rem; font-size: .86rem; font-weight: 700; color: var(--ink); letter-spacing: -.005em; margin: 0 0 .1rem; }
.step { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); font-size: .7rem; font-weight: 800; }
.panel-meta { margin-left: auto; font-size: .68rem; font-weight: 600; color: var(--muted); background: #f1f4f9; padding: .15rem .5rem; border-radius: 999px; white-space: nowrap; }
.panel .two-col-inputs { gap: .6rem; }
.align-end { display: flex; align-items: flex-end; }

.form-label { font-size: .74rem; font-weight: 600; color: var(--ink-2); margin-bottom: .3rem; }
.control-note { font-size: .74rem; color: var(--muted); line-height: 1.45; }
#topicSearchResults:empty { display: none; }
.form-select, .form-input { border-color: var(--line-strong); border-radius: var(--radius-sm); font-size: .85rem; padding: .5rem .7rem; min-height: 38px; background-color: #fff; transition: border-color .15s, box-shadow .15s; }
.form-select:hover, .form-input:hover { border-color: #b7c0d0; }
.form-select:focus, .form-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(59, 79, 216, .15); }
.form-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right .7rem center;
}
.search-field .form-input {
  padding-left: 2.1rem;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat .7rem center;
}

/* Year group: segmented control */
.year-pills { background: #f1f4f9; padding: 4px; border-radius: var(--radius-md); gap: 3px; }
.year-pill { background: transparent; border: 0; border-radius: 7px; padding: .42rem .2rem; color: var(--ink-2); }
.year-pill:hover { background: rgba(255, 255, 255, .7); border: 0; }
.year-pill.active { background: #fff; color: var(--brand); box-shadow: 0 1px 2px rgba(15, 23, 42, .1), 0 1px 6px rgba(15, 23, 42, .06); }
.year-pill .yr-ks { font-size: .62rem; color: var(--muted); opacity: 1; }

/* Switch-style checkboxes */
.toggle-row { gap: .6rem; font-size: .8rem; color: var(--ink-2); padding: .15rem 0; }
.toggle-row input[type=checkbox] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: #cfd6e2;
  position: relative;
  cursor: pointer;
  transition: background .15s;
  margin: 0;
}
.toggle-row input[type=checkbox]::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .25);
  transition: transform .15s;
}
.toggle-row input[type=checkbox]:checked { background: var(--brand); }
.toggle-row input[type=checkbox]:checked::before { transform: translateX(14px); }
.toggle-row input[type=checkbox]:focus-visible { outline: 3px solid var(--brand-100); outline-offset: 1px; }

/* Chips */
.chip-row { gap: .3rem; margin-top: .4rem; }
.chip { border-radius: 999px; background: #fff; border-color: var(--line-strong); color: var(--ink-2); font-size: .72rem; padding: .22rem .6rem; transition: all .12s; }
.chip:hover { background: #f4f6fa; color: var(--ink); border-color: #b7c0d0; }
.chip.active { background: var(--brand-50); color: var(--brand); border-color: #b9c2fa; }
.preset-label { margin: .2rem 0 0; }
.preset-row { margin-top: 0; }

/* Difficulty cards */
.diff-grid { gap: .45rem; }
.diff-btn { background: #fff; border-color: var(--line-strong); border-radius: var(--radius-md); padding: .55rem .65rem; }
.diff-btn:hover { border-color: #b7c0d0; background: #fafbfd; }
.diff-btn.active { border-color: var(--brand); background: var(--brand-50); color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.diff-btn .diff-title { font-size: .79rem; }
.diff-btn .diff-desc { font-size: .67rem; line-height: 1.35; }

.panel-help summary { cursor: pointer; font-size: .74rem; font-weight: 600; color: var(--muted); list-style: none; }
.panel-help summary::-webkit-details-marker { display: none; }
.panel-help summary::before { content: '›'; display: inline-block; margin-right: .35rem; transition: transform .15s; }
.panel-help[open] summary::before { transform: rotate(90deg); }
.panel-help[open] summary { margin-bottom: .4rem; }
.panel-help .control-note + .control-note { margin-top: .35rem; }

.topic-checklist { border-color: var(--line); border-radius: var(--radius-sm); }
.selected-topic { border-color: var(--brand-100); background: var(--brand-50); border-radius: var(--radius-sm); }
.allocation-summary { background: var(--brand-50); border-radius: var(--radius-sm); }
.saved-paper-card { border-color: var(--line); border-radius: var(--radius-sm); background: #fafbfd; }

/* ---------- Preview column ---------- */
.preview-column { gap: 1rem; }
.preview-toolbar, .shadow-toolbar, .booklet-banner, .topic-breakdown, .bank-browser {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.preview-toolbar { padding: .55rem .6rem .55rem .55rem; }
.shadow-toolbar { padding: .55rem .75rem; }
.tab-group { background: #f1f4f9; border-radius: var(--radius-md); padding: 3px; gap: 2px; flex-wrap: wrap; }
.tab-btn { border-radius: 7px; font-size: .79rem; padding: .4rem .75rem; color: var(--muted); }
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { background: #fff; color: var(--brand); box-shadow: 0 1px 2px rgba(15, 23, 42, .1), 0 1px 6px rgba(15, 23, 42, .05); }
#summaryStats { font-size: .78rem !important; font-weight: 600; color: var(--ink-2) !important; background: #f1f4f9; border-radius: 999px; padding: .3rem .75rem; }
#summaryStats:empty { display: none; }
.shadow-badge { border-radius: 999px; }
.bank-notice { font-size: .74rem; color: var(--muted); padding: 0 .3rem; }

.paper-sheet {
  border: 0;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, .06), 0 2px 4px rgba(15, 23, 42, .04), 0 16px 40px rgba(15, 23, 42, .09);
}

/* Question swap controls inside the preview */
.q-swap-controls { border-radius: var(--radius-sm); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .header-nav { border-right: 0; padding-right: 0; }
}
@media (max-width: 1024px) {
  .app-layout { grid-template-columns: minmax(0, 1fr); padding: 1rem; }
  .controls-card { position: static; max-height: none; overflow: visible; padding: 0; }
  .app-header { position: static; }
}
@media (max-width: 700px) {
  .app-header { padding: .8rem 1rem; align-items: flex-start; }
  .header-actions { justify-content: flex-start; width: 100%; }
  .header-nav { width: 100%; }
  .btn-cta { flex: 1; }
  .two-col-inputs { grid-template-columns: 1fr; }
  .paper-sheet { overflow-x: auto; position: relative; }
}
@media print {
  .app-header, .controls-card, .preview-toolbar { display: none !important; }
  body { background: #fff !important; }
  .paper-sheet { box-shadow: none !important; border-radius: 0 !important; }
}
