:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --teal: #0f766e;
  --teal-soft: #f0fdfa;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --font-ui: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  --font-print: 'Noto Serif', 'Times New Roman', serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

.hidden { display: none !important; }

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}

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

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: linear-gradient(135deg, #1d4ed8, #0f766e);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-print);
  flex-shrink: 0;
}

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

.brand-sub {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-light);
}

.topbar-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-alt);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn svg { width: 15px; height: 15px; }
.tab-btn:hover { color: var(--text); background: rgba(255,255,255,0.7); }
.tab-btn.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.badge-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
}

.badge-accent {
  background: var(--primary);
  color: #fff;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-outline:hover { background: var(--surface-alt); border-color: #94a3b8; }
.btn-danger-outline { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-success { background: var(--teal); color: #fff; }
.btn-success:hover { background: #115e59; }
.btn-link {
  border: none;
  background: none;
  color: var(--primary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}
.btn-link:hover { text-decoration: underline; }
.icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }
.icon-btn svg { width: 15px; height: 15px; }

/* LOADING BAR */
.loading-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px;
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  color: #1e40af;
  font-size: 13px;
  font-weight: 500;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2.5px solid #bfdbfe;
  border-top-color: #1d4ed8;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* MAIN LAYOUT */
.app-main {
  max-width: 1520px;
  margin: 0 auto;
  padding: 16px 20px 36px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* BANK LAYOUT */
.bank-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 18px;
  align-items: start;
}

.filter-sidebar, .export-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  margin: 0;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.sidebar-header h2 svg { width: 16px; height: 16px; color: var(--primary); }

.filter-group { margin-bottom: 13px; }
.filter-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.input-icon-wrap { position: relative; }
.input-icon-wrap svg {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-light);
}
.input-icon-wrap input { padding-left: 31px; }

.grade-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.grade-pill {
  padding: 7px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.25;
}
.grade-pill small { font-size: 10.5px; font-weight: 500; opacity: 0.8; }
.grade-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chip {
  padding: 4px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 5px;
}
.checkbox-row.compact { margin-bottom: 0; }
.checkbox-row input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }

/* BANK TOOLBAR & CARDS */
.bank-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.result-summary { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.question-list { display: flex; flex-direction: column; gap: 12px; }

.q-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.q-card.in-cart {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.12);
}

.q-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
  flex-wrap: wrap;
}

.q-tags { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 5px;
}
.tag-id { background: #f1f5f9; color: #334155; font-family: monospace; font-size: 11.5px; }
.tag-tn { background: #dbeafe; color: #1e40af; }
.tag-ds { background: #ede9fe; color: #5b21b6; }
.tag-tln { background: #fef3c7; color: #92400e; }
.tag-tl { background: #d1fae5; color: #065f46; }
.tag-N { background: #e0f2fe; color: #0369a1; }
.tag-H { background: #dcfce7; color: #15803d; }
.tag-V { background: #ffedd5; color: #c2410c; }
.tag-C { background: #ffe4e6; color: #be123c; }
.tag-tikz { background: #fce7f3; color: #9d174d; }
.tag-custom { background: #fef9c3; color: #854d0e; }
.tag-topic { background: transparent; color: var(--text-light); font-weight: 500; padding-left: 2px; }

.q-card-actions { display: flex; align-items: center; gap: 6px; }

.q-body {
  font-size: 14px;
  line-height: 1.65;
  overflow-x: auto;
}

.q-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  margin-top: 10px;
}
.q-options.single-col { grid-template-columns: 1fr; }

.q-opt {
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 13.5px;
}
.q-opt.is-correct {
  background: #ecfdf5;
  border-color: #6ee7b7;
}
.q-opt-label {
  font-weight: 700;
  color: var(--primary);
  margin-right: 5px;
}
.q-opt.is-correct .q-opt-label { color: #047857; }
.ds-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 0 5px;
  border-radius: 4px;
  margin-left: 6px;
}
.ds-badge-t { background: #dcfce7; color: #166534; }
.ds-badge-f { background: #fee2e2; color: #991b1b; }

.q-shortans-bar {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: #fef3c7;
  color: #92400e;
  font-size: 13px;
  font-weight: 600;
}

.q-solution {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #f8fafc;
  border-left: 3px solid var(--teal);
  font-size: 13.5px;
}
.q-solution-title {
  font-weight: 700;
  color: var(--teal);
  margin-bottom: 4px;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* LATEX TABLES, LISTS, IMMINI, TIKZ */
.tex-table {
  border-collapse: collapse;
  margin: 8px auto;
  font-size: 13px;
}
.tex-table td, .tex-table th {
  border: 1px solid #64748b;
  padding: 4px 9px;
  text-align: center;
}
.tex-list { margin: 4px 0 4px 20px; padding: 0; }
.tex-list li { margin-bottom: 3px; }
.tex-itemchoice { list-style: none; margin: 4px 0; padding: 0; }
.tex-itemchoice li { margin-bottom: 4px; }
.tex-immini {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
}
.tex-immini-text { flex: 1; min-width: 0; }
.tex-immini-fig { flex: 0 0 auto; max-width: 240px; }
.tex-center { text-align: center; margin: 6px 0; }
.tikz-placeholder {
  display: inline-block;
  margin: 6px 0;
  padding: 8px 12px;
  border: 1px dashed #94a3b8;
  border-radius: 6px;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
}
.tikz-placeholder summary { cursor: pointer; font-weight: 600; color: #7c3aed; }
.tikz-placeholder pre {
  margin: 6px 0 0;
  max-height: 160px;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  padding: 8px;
  border-radius: 4px;
  font-size: 11px;
  text-align: left;
}

/* PAGINATION */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* BUILDER & MATRIX */
.builder-grid, .saved-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 18px;
  align-items: start;
}

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

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 {
  margin: 0 0 3px;
  font-size: 15.5px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.card-header h2 svg { width: 17px; height: 17px; color: var(--primary); }
.card-desc { margin: 0; font-size: 12.5px; color: var(--text-light); }
.header-btns { display: flex; gap: 6px; flex-wrap: wrap; }

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.matrix-options {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.matrix-table-wrap { overflow-x: auto; margin-bottom: 12px; }
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.matrix-table th {
  text-align: left;
  padding: 7px 6px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-weight: 600;
}
.matrix-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
.matrix-table select, .matrix-table input { padding: 5px 6px; font-size: 12.5px; }

.matrix-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.matrix-actions-right { display: flex; align-items: center; gap: 12px; }
.matrix-total-badge { font-weight: 700; color: var(--primary); font-size: 13.5px; }

.shuffle-box {
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
}
.shuffle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.field-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
}
.field-inline input { width: 64px; padding: 5px 7px; }

.cart-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 540px;
  overflow-y: auto;
}
.cart-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-alt);
}
.cart-item-main { flex: 1; min-width: 0; }
.cart-item-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; flex-wrap: wrap; }
.cart-item-snippet {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cart-item-btns { display: flex; gap: 4px; flex-shrink: 0; }

/* PREVIEW LAYOUT */
.preview-layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 20px;
  align-items: start;
}

.export-actions-top {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.btn-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

.preview-canvas-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.exam-preview-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* ==================== A4 PAPER DOCUMENT STYLING ==================== */
.a4-sheet {
  width: 210mm;
  max-width: 100%;
  min-height: 297mm;
  background: #ffffff;
  color: #111827;
  font-family: var(--font-print);
  font-size: 11pt;
  line-height: 1.5;
  padding: 15mm 15mm 16mm 16mm;
  box-shadow: 0 6px 28px rgba(15, 23, 42, 0.14);
  border-radius: 4px;
}

/* Exam Standard Header (THPT 2025) */
.exam-header-std {
  display: grid;
  grid-template-columns: 44% 56%;
  gap: 10px;
  border-bottom: 1.5px solid #111827;
  padding-bottom: 8px;
  margin-bottom: 10px;
}
.eh-left, .eh-right { text-align: center; }
.eh-dept { font-size: 10pt; font-weight: 600; text-transform: uppercase; }
.eh-school { font-size: 10.5pt; font-weight: 700; text-transform: uppercase; }
.eh-line-short { width: 90px; height: 1px; background: #111827; margin: 4px auto; }
.eh-note { font-size: 9.5pt; font-style: italic; }
.eh-title { font-size: 11.5pt; font-weight: 700; text-transform: uppercase; }
.eh-subtitle { font-size: 10.5pt; font-weight: 600; margin-top: 2px; }
.eh-duration { font-size: 9.5pt; font-style: italic; margin-top: 2px; }

.exam-student-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 10.5pt;
  margin-bottom: 12px;
}
.exam-code-box {
  border: 1.5px solid #111827;
  padding: 2px 10px;
  font-weight: 700;
  white-space: nowrap;
}

/* Leftnote Layout (BS_ToanThucTe style) */
.a4-sheet.tpl-leftnote {
  padding: 12mm 10mm 14mm 12mm;
}
.leftnote-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid #0e7490;
  padding-bottom: 6px;
  margin-bottom: 12px;
}
.leftnote-badge {
  background: #0e7490;
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 10pt;
  padding: 6px 14px;
  border-radius: 6px;
}
.leftnote-title-block { text-align: center; flex: 1; padding: 0 10px; }
.leftnote-title-block h2 { margin: 0; font-size: 13pt; color: #0e7490; text-transform: uppercase; }
.leftnote-title-block p { margin: 2px 0 0; font-size: 9.5pt; color: #475569; }
.leftnote-grid {
  display: grid;
  grid-template-columns: 1fr 52mm;
  gap: 6mm;
  align-items: stretch;
}
.leftnote-margin {
  border: 1.5px solid #0284c7;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-height: 230mm;
  overflow: hidden;
}
.leftnote-margin-title {
  text-align: center;
  font-family: var(--font-ui);
  font-size: 9.5pt;
  font-weight: 700;
  color: #b91c1c;
  padding: 5px 4px;
  border-bottom: 1px solid #0284c7;
  background: #f0f9ff;
}
.leftnote-lines {
  flex: 1;
  background-image:
    linear-gradient(to right, rgba(2, 132, 199, 0.22) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(2, 132, 199, 0.25) 1px, transparent 1px);
  background-size: 5mm 6mm;
}

/* Worksheet Header */
.worksheet-header {
  text-align: center;
  border-bottom: 2px solid #1d4ed8;
  padding-bottom: 8px;
  margin-bottom: 14px;
}
.worksheet-header h2 { margin: 0; font-size: 13.5pt; color: #1e3a8a; text-transform: uppercase; }
.worksheet-header p { margin: 3px 0 0; font-size: 10pt; color: #334155; }

/* Sections & Questions in Print/Preview */
.exam-part-title {
  font-size: 11pt;
  font-weight: 700;
  margin: 12px 0 4px;
  color: #111827;
}
.a4-sheet.tpl-leftnote .exam-part-title {
  color: #b91c1c;
  font-family: var(--font-ui);
}
.exam-part-desc {
  font-size: 10pt;
  font-style: italic;
  margin: 0 0 8px;
  color: #374151;
}

.exam-q {
  margin-bottom: 10px;
  break-inside: avoid;
  page-break-inside: avoid;
}
.exam-q-num {
  font-weight: 700;
  color: #111827;
}
.a4-sheet.tpl-leftnote .exam-q-num { color: #b91c1c; }
.exam-q-code {
  font-family: monospace;
  font-size: 8.5pt;
  color: #64748b;
  margin-right: 4px;
}

.exam-opts-grid {
  display: grid;
  gap: 3px 12px;
  margin-top: 4px;
  padding-left: 4px;
}
.exam-opts-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.exam-opts-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.exam-opts-grid.cols-1 { grid-template-columns: 1fr; }

.exam-opt-letter { font-weight: 700; margin-right: 3px; }
.exam-opt-letter.correct-hl { color: #047857; text-decoration: underline; }

.exam-sol-box {
  margin-top: 5px;
  padding: 5px 9px;
  background: #f8fafc;
  border-left: 2.5px solid #0f766e;
  font-size: 10pt;
}
.exam-sol-label { font-weight: 700; font-style: italic; color: #0f766e; margin-right: 4px; }

.exam-end-mark {
  text-align: center;
  font-weight: 700;
  margin: 16px 0 10px;
  letter-spacing: 0.05em;
}

/* Answer Table */
.ans-section {
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1.5px dashed #64748b;
  break-inside: avoid;
}
.ans-section h3 {
  margin: 0 0 8px;
  font-size: 11.5pt;
  text-align: center;
  text-transform: uppercase;
}
.ans-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9.5pt;
  margin-bottom: 10px;
}
.ans-table th, .ans-table td {
  border: 1px solid #334155;
  padding: 3px 6px;
  text-align: center;
}
.ans-table th { background: #f1f5f9; font-weight: 700; }

.exam-footer-line {
  margin-top: 14px;
  padding-top: 6px;
  border-top: 1px solid #cbd5e1;
  display: flex;
  justify-content: space-between;
  font-size: 9pt;
  color: #64748b;
}

/* SAVED EXAMS & STATS */
.saved-exams-list { display: flex; flex-direction: column; gap: 10px; }
.saved-exam-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}
.saved-exam-item h4 { margin: 0 0 3px; font-size: 14px; }
.saved-exam-item p { margin: 0; font-size: 12px; color: var(--text-light); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat-box {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
.stat-box .stat-num { font-size: 22px; font-weight: 700; color: var(--primary); }
.stat-box .stat-lbl { font-size: 12px; color: var(--text-muted); }

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 44px 24px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
}
.empty-state svg { width: 42px; height: 42px; color: var(--text-light); margin-bottom: 8px; }
.empty-state h3 { margin: 0 0 6px; }
.empty-state p { margin: 0 0 16px; color: var(--text-muted); }

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-lg { max-width: 780px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 15.5px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}

.form-row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.form-field { margin-bottom: 12px; }
.form-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.mq-opt-grid { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.mq-opt-row { display: flex; align-items: center; gap: 8px; }
.mq-opt-tag { width: 46px; font-size: 12px; font-weight: 700; color: var(--primary); }

.live-preview-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}
.live-preview-label { font-size: 11.5px; font-weight: 700; color: var(--text-light); margin-bottom: 6px; text-transform: uppercase; }

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  padding: 30px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-alt);
  transition: all 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.dropzone svg { width: 32px; height: 32px; color: var(--primary); margin-bottom: 6px; }
.import-status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 7px;
  background: #ecfdf5;
  border: 1px solid #6ee7b7;
  color: #065f46;
  font-size: 13px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.22);
}

/* RESPONSIVE */
@media (max-width: 1024px) {
  .bank-layout, .builder-grid, .preview-layout, .saved-grid {
    grid-template-columns: 1fr;
  }
  .filter-sidebar, .export-sidebar { position: static; max-height: none; }
  .form-row-4 { grid-template-columns: 1fr 1fr; }
}

/* ==================== PRINT / PDF VECTOR ENGINE ==================== */
.print-only { display: none; }

@page {
  size: A4 portrait;
  margin: 14mm 13mm 14mm 15mm;
}

@media print {
  body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  .a4-sheet {
    width: auto !important;
    max-width: none !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    page-break-after: always;
    break-after: page;
  }
  .a4-sheet:last-child {
    page-break-after: auto;
    break-after: auto;
  }
  .tikz-placeholder pre { display: none !important; }
  .tikz-placeholder {
    border-style: dashed;
    font-size: 9pt;
    padding: 4px 8px;
  }
  .leftnote-margin { min-height: 240mm; }
  .exam-q { break-inside: avoid; page-break-inside: avoid; }
  .ans-section { break-inside: avoid; page-break-inside: avoid; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
