:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --green: #166534;
  --green-bg: #dcfce7;
  --green-bd: #86efac;
  --amber: #92400e;
  --amber-bg: #fef3c7;
  --amber-bd: #fcd34d;
  --red: #991b1b;
  --red-bg: #fee2e2;
  --red-bd: #fca5a5;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --font-sans: "LXGW WenKai Screen", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Top Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 18px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.back-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.back-link:hover {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 26px;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.seg-switch {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 4px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 7px 13px;
  border-radius: 7px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.backup-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Main Container */
.main-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 22px 64px;
}

.loading-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 48px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 16px;
}

.loading-banner[hidden] {
  display: none;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Sub-tabs inside subject */
.subtabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}

.subtab-btn {
  border: none;
  background: transparent;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.subtab-btn:hover {
  color: var(--text);
}

.subtab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Cards & Collapsibles */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 16px;
}

details.filter-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

details.filter-box > summary {
  padding: 12px 18px;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

details.filter-box > summary::-webkit-details-marker {
  display: none;
}

details.filter-box > summary::after {
  content: "▾";
  font-size: 13px;
  color: var(--text-light);
  transition: transform 0.15s ease;
}

details.filter-box[open] > summary::after {
  transform: rotate(180deg);
}

.filter-body {
  padding: 4px 18px 16px;
  border-top: 1px solid var(--surface-alt);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px 16px;
  margin-top: 10px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

select, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
}

select:focus, input:focus {
  outline: 2px solid var(--primary-border);
  border-color: var(--primary);
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 4px 11px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s ease;
}

.chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.chip-sm {
  padding: 3px 9px;
  font-size: 12px;
}

.switch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  align-items: center;
  margin-top: 12px;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.range-pair {
  display: flex;
  align-items: center;
  gap: 8px;
}

.range-pair select {
  width: auto;
  min-width: 84px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-alt);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
}

.btn-ghost {
  background: var(--surface-alt);
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-link {
  text-decoration: none;
}

/* KPI Row */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

/* Breadcrumb & Drilldown */
.breadcrumb-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 14px;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
}

.crumb-btn {
  border: none;
  background: var(--surface-alt);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.crumb-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.crumb-sep {
  color: var(--text-light);
}

.dash-split {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-box {
  width: 100%;
  height: 400px;
}

.chart-box-sm {
  width: 100%;
  height: 320px;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.chart-head h3 {
  margin: 0;
  font-size: 15px;
}

/* Breakdown Table */
.table-wrap {
  overflow-x: auto;
  max-height: 375px;
  overflow-y: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table th {
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--surface-alt);
}

table.data-table tr.clickable-row {
  cursor: pointer;
  transition: background 0.12s ease;
}

table.data-table tr.clickable-row:hover {
  background: var(--primary-soft);
}

table.data-table tr.selected-row {
  background: #dbeafe;
  font-weight: 600;
}

.num-col {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.dev-pos { color: #b91c1c; font-weight: 600; }
.dev-neg { color: #0369a1; font-weight: 600; }

/* Callout Banner */
.info-banner {
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13.5px;
  line-height: 1.7;
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

/* Progress Bar & Status Filters */
.progress-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
}

.progress-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
}

.progress-track {
  width: 100%;
  height: 9px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* Toolbar & Pagination */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  margin-bottom: 12px;
}

.toolbar-left, .toolbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.pager {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

/* Question Cards */
.q-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  margin-bottom: 12px;
}

details.q-expander {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

details.q-expander > summary {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

details.q-expander-body, .q-expander-inner {
  padding: 4px 16px 14px;
  border-top: 1px solid var(--surface-alt);
}

.q-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 14.5px;
  font-weight: 600;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-ok { background: var(--green-bg); color: var(--green); border-color: var(--green-bd); }
.status-rev { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-bd); }
.status-stk { background: var(--red-bg); color: var(--red); border-color: var(--red-bd); }
.status-todo { background: var(--surface-alt); color: var(--text-muted); border-color: var(--border-strong); }

.q-img-wrap {
  margin: 8px 0 10px;
  padding: 8px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.q-img {
  display: block;
  max-width: 100%;
  height: auto;
  cursor: zoom-in;
}

.q-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 6px 0;
}

.socratic-hint {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: #78350f;
  margin: 8px 0;
}

.readable-text {
  line-height: 1.82;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 8px 10px;
  background: #fafafa;
  border: 1px solid var(--surface-alt);
  border-radius: var(--radius-sm);
  margin: 8px 0;
}

details.inner-fold {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 8px;
  background: #fcfcfd;
}

details.inner-fold > summary {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--primary);
}

.inner-fold-body {
  padding: 6px 12px 12px;
  border-top: 1px solid var(--surface-alt);
  font-size: 13.5px;
}

.extras-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.extras-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.scan-gallery {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.scan-figure {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: #ffffff;
}

.scan-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.tb-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.tb-pager input[type="number"] {
  width: 92px;
}

/* Status Action Buttons */
.status-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.st-btn {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.st-btn:hover { background: var(--surface-alt); }
.st-btn.active-ok { background: var(--green); border-color: var(--green); color: #fff; }
.st-btn.active-rev { background: #d97706; border-color: #d97706; color: #fff; }
.st-btn.active-stk { background: #dc2626; border-color: #dc2626; color: #fff; }

.status-hint {
  font-size: 12px;
  color: var(--text-light);
}

/* Coach Export Box */
.coach-export-box {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
}

.coach-export-box .field-group {
  min-width: 140px;
}

/* Inner Sub-tabs on CPA Example Card */
.card-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.card-tab-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.card-tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* Empty State */
.empty-state {
  padding: 28px 18px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14px;
}

/* Toast */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.22);
  max-width: 340px;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox[hidden] { display: none; }

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
}

.lightbox-panel {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 94vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.lightbox-title {
  font-size: 13.5px;
  font-weight: 600;
}

.lightbox-body {
  padding: 16px;
  overflow: auto;
  background: #ffffff;
}

.lightbox-body img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Print Worksheet */
.print-sheet {
  display: none;
}

@media print {
  @page {
    size: A4;
    margin: 14mm 12mm;
  }
  body {
    background: #ffffff;
  }
  #app-shell, #toast-container, #lightbox {
    display: none !important;
  }
  .print-sheet {
    display: block !important;
    color: #000000;
  }
  .print-header {
    border-bottom: 1.5px solid #334155;
    padding-bottom: 8px;
    margin-bottom: 14px;
  }
  .print-header h2 {
    margin: 0 0 4px;
    font-size: 17pt;
  }
  .print-header p {
    margin: 0;
    font-size: 9.5pt;
    color: #475569;
  }
  .print-item {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px dashed #e2e8f0;
  }
  .print-item-meta {
    font-size: 9pt;
    font-weight: 700;
    color: #1e3a8a;
    margin-bottom: 5px;
  }
  .print-item img {
    max-width: 100%;
    height: auto;
    display: block;
  }
  .print-item-text {
    font-size: 10pt;
    line-height: 1.55;
    white-space: pre-wrap;
  }
  .print-answers-start {
    break-before: page;
    page-break-before: always;
  }
}

/* Responsive */
@media (max-width: 1024px) {
  .dash-split, .trend-grid {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 14px;
  }
  .main-container {
    padding: 12px 12px 48px;
  }
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
  .seg-btn {
    font-size: 12px;
    padding: 6px 9px;
  }
}
