/* ==================== THEME VARIABLES (DARK & LIGHT) ==================== */
:root {
  --teal: #00b8a9;
  --teal-dark: #009c8f;
  --teal-deep: #007d73;
  --amber: #f59e0b;
  --red: #dc2626;
  --radius: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Times New Roman", Times, Georgia, serif;
}

/* DARK THEME */
html[data-theme="dark"] {
  --bg-app: #092023;
  --bg-sidebar: #0d2b2e;
  --bg-topbar: #0a2326;
  --bg-card: #123337;
  --bg-input: #0a2427;
  --border-dashed: rgba(0, 184, 169, 0.55);
  --border-subtle: rgba(255, 255, 255, 0.12);
  --text-main: #e6f4f3;
  --text-muted: #9bc0be;
  --text-sidebar: #dceeed;
  --paper-bg: #122225;
  --paper-text: #eaf4f4;
  --paper-border: #234247;
  --paper-divider: #1f393e;
  --home-bg: #0c1d20;
  --home-card: #132b2f;
  --home-guide-bg: #12282c;
  --home-text: #eaf4f4;
  --home-muted: #a6c4c2;
  --a4-bg: #ffffff;
  --a4-text: #111827;
}

/* LIGHT THEME */
html[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-sidebar: #ffffff;
  --bg-topbar: #ffffff;
  --bg-card: #f8fafc;
  --bg-input: #ffffff;
  --border-dashed: rgba(0, 168, 150, 0.6);
  --border-subtle: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-sidebar: #1e293b;
  --paper-bg: #ffffff;
  --paper-text: #1e293b;
  --paper-border: #e2e8f0;
  --paper-divider: #e5e7eb;
  --home-bg: #fdfaff;
  --home-card: #f8fafc;
  --home-guide-bg: #f1f3f5;
  --home-text: #1f2937;
  --home-muted: #4b5563;
  --a4-bg: #ffffff;
  --a4-text: #111827;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

svg {
  display: block;
  flex-shrink: 0;
}

.view {
  display: none;
  min-height: 100vh;
}
.view.active {
  display: block;
}

/* ==================== SHARED BUTTONS & BADGES ==================== */
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.theme-toggle-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
}
.theme-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-outline-teal {
  padding: 6px 14px;
  border: 1.5px solid var(--teal);
  background: transparent;
  color: var(--teal);
  font-weight: 700;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.footer-link {
  color: #ffffff;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.group-preamble-box {
  background: rgba(0, 184, 169, 0.06);
  border-left: 3px solid var(--teal);
  border-radius: 4px;
  padding: 8px 12px;
  margin: 8px 0 10px;
  font-size: 13.5px;
  color: var(--paper-text);
  white-space: pre-line;
}
.short-ans-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(220, 38, 38, 0.12);
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}
html[data-theme="dark"] .short-ans-pill {
  color: #f87171;
}
.essay-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(0, 184, 169, 0.12);
  color: var(--teal);
  font-size: 12.5px;
  font-weight: 600;
}
.a4-preamble {
  margin: 12px 0 8px;
  font-weight: 600;
  white-space: pre-line;
}
.btn-outline-teal:hover {
  background: var(--teal);
  color: #fff;
}

.free-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 184, 169, 0.14);
  border: 1px solid rgba(0, 184, 169, 0.45);
  color: var(--teal);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.btn-teal-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 184, 169, 0.3);
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn-teal-pill:hover {
  background: var(--teal-dark);
  transform: translateY(-1px);
}
.btn-teal-pill:active {
  transform: translateY(0);
}

/* ==================== VIEW 1: HOME PAGE ==================== */
#homeView {
  background: var(--home-bg);
  color: var(--home-text);
}

.home-header {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-topbar);
  position: sticky;
  top: 0;
  z-index: 20;
}
.home-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}
.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--teal);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.brand-name {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: var(--teal);
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.home-hero {
  text-align: center;
  padding: 36px 20px 26px;
}
.hero-title {
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--home-text);
}
.hero-subtitle {
  font-size: 16px;
  color: var(--home-muted);
}

.upload-banner {
  background: linear-gradient(135deg, #00b8a9, #00a396);
  padding: 44px 20px;
  text-align: center;
  transition: background 0.2s ease, outline 0.2s ease;
}
.upload-banner.drag-over {
  background: linear-gradient(135deg, #009c8f, #007d73);
  outline: 4px dashed rgba(255, 255, 255, 0.85);
  outline-offset: -12px;
}
.upload-banner-inner {
  max-width: 680px;
  margin: 0 auto;
}
.btn-upload-hero {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 44px;
  border-radius: 999px;
  border: none;
  background: #ffffff;
  color: #111827;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-upload-hero:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
}
.upload-hint {
  margin-top: 12px;
  color: rgba(255, 255, 255, 0.95);
  font-size: 15px;
  font-weight: 500;
}

.home-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 36px 20px 56px;
}
.section-heading {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 18px;
}
.guide-dashed-box {
  background: var(--home-guide-bg);
  border: 2px dashed var(--border-dashed);
  border-radius: 8px;
  padding: 20px 26px;
  margin-bottom: 26px;
  font-size: 14.5px;
}
.guide-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.guide-list li::before {
  content: "• ";
  font-weight: 700;
  color: var(--teal);
}
.text-red {
  color: var(--red);
}
.group-guide-intro {
  text-align: center;
  font-size: 16px;
  max-width: 680px;
  margin: 0 auto 18px;
  color: var(--home-text);
}
.group-rule {
  margin-bottom: 12px;
}
.group-rule strong {
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.group-rule-note {
  margin-top: 14px;
  margin-bottom: 0;
  padding-top: 10px;
  border-top: 1px dashed var(--border-subtle);
}

.sample-download-section {
  text-align: center;
  margin: 30px 0 42px;
}
.sample-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 14px;
}
.sample-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.sample-select {
  min-width: 300px;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1.5px solid var(--teal);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 14px;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
.feature-card {
  background: var(--home-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 24px 22px;
  text-align: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}
.feature-icon {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: rgba(0, 184, 169, 0.13);
  color: var(--teal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}
.feature-card h4 {
  font-size: 15.5px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--home-text);
}
.feature-card p {
  font-size: 13.5px;
  color: var(--home-muted);
}

.home-footer {
  background: var(--teal);
  color: #ffffff;
  text-align: center;
  padding: 22px 16px;
  font-size: 14px;
}
.home-footer .copyright {
  margin-top: 6px;
  font-size: 13px;
  opacity: 0.92;
}

/* ==================== VIEW 2: WORKSPACE (INDEPENDENT SCROLLING) ==================== */
#workspaceView.active {
  display: block;
  height: 100vh;
  overflow: hidden;
}

.ws-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-app);
}

/* LEFT SIDEBAR — independent scroll container */
.ws-sidebar {
  width: 360px;
  min-width: 335px;
  max-width: 380px;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 12px 12px 14px;
  color: var(--text-sidebar);
  flex-shrink: 0;
  min-height: 0;
}
.sidebar-top-action {
  display: flex;
  justify-content: center;
  padding-bottom: 10px;
  flex-shrink: 0;
}
.btn-upload-ws,
.btn-mix-submit {
  width: 210px;
  padding: 10px 20px;
}

.sidebar-scroll-frame {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  border: 1.5px solid var(--border-dashed);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar-scroll-frame::-webkit-scrollbar,
.ws-content-scroll::-webkit-scrollbar {
  width: 7px;
}
.sidebar-scroll-frame::-webkit-scrollbar-thumb,
.ws-content-scroll::-webkit-scrollbar-thumb {
  background: rgba(0, 184, 169, 0.45);
  border-radius: 999px;
}

.sidebar-bottom-action {
  display: flex;
  justify-content: center;
  padding-top: 12px;
  flex-shrink: 0;
}

/* IMPORTANT: flex-shrink: 0 prevents sections from ever collapsing or clipping text */
.cfg-section {
  flex-shrink: 0;
  border-radius: 8px;
  border: 1.5px dashed var(--border-dashed);
  background: rgba(0, 184, 169, 0.03);
}
.cfg-header {
  background: var(--teal);
  color: #ffffff;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  padding: 8px 10px;
  border-radius: 6px 6px 0 0;
}
.cfg-body {
  padding: 10px 12px;
  font-size: 13.5px;
}
.info-line {
  padding: 4px 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.filename-val {
  font-weight: 600;
}
.error-helper-text {
  font-size: 12.5px;
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.45;
}
.error-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
}
.err-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 12.5px;
  padding: 7px 9px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.4;
}
.err-item.ok {
  background: rgba(16, 185, 129, 0.14);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.35);
  cursor: default;
}
html[data-theme="dark"] .err-item.ok {
  color: #34d399;
}
.err-item.error {
  background: rgba(220, 38, 38, 0.14);
  color: #b91c1c;
  border: 1px solid rgba(220, 38, 38, 0.35);
}
html[data-theme="dark"] .err-item.error {
  color: #f87171;
}
.err-item.warning {
  background: rgba(245, 158, 11, 0.15);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.35);
}
html[data-theme="dark"] .err-item.warning {
  color: #fbbf24;
}

.opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.opt-row:last-of-type {
  border-bottom: none;
}
.opt-label {
  font-size: 13px;
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.35;
}

.cfg-select,
.cfg-number {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  outline: none;
  flex-shrink: 0;
}
.cfg-select:focus,
.cfg-number:focus {
  border-color: var(--teal);
}
.cfg-select-wide {
  min-width: 126px;
}
.cfg-number {
  width: 68px;
  text-align: right;
}

/* Crisp, fixed-size Toggle Switch (never stretches!) */
.switch {
  position: relative;
  display: inline-block;
  flex: 0 0 46px;
  width: 46px;
  height: 24px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: background-color 0.2s ease;
  border-radius: 999px;
}
html[data-theme="dark"] .slider {
  background-color: #334e52;
}
.slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background-color: #ffffff;
  transition: transform 0.2s ease;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}
.switch input:checked + .slider {
  background-color: var(--amber);
}
.switch input:checked + .slider::before {
  transform: translateX(22px);
}

.radio-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.radio-group-compact {
  gap: 9px;
}
.zipgrade-map-box {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(0, 184, 169, 0.08);
  border: 1px solid rgba(0, 184, 169, 0.35);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.zg-chip {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  font-weight: 700;
  font-size: 12px;
}
.radio-opt {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
}
.radio-opt input[type="radio"] {
  accent-color: var(--amber);
  cursor: pointer;
}

.btn-edit-codes {
  margin-top: 10px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border: none;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-edit-codes:hover {
  background: var(--teal-dark);
}

.meta-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.meta-field:last-child {
  border-bottom: none;
}
.meta-field label {
  width: 90px;
  font-size: 12.5px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.meta-field input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  padding: 3px 4px;
  outline: none;
}
.meta-field input:focus {
  border-bottom-color: var(--teal);
}
.meta-field input::placeholder {
  color: var(--text-muted);
  opacity: 0.62;
  font-weight: 400;
  font-style: italic;
}
.radio-opt.is-disabled {
  opacity: 0.38;
  cursor: not-allowed;
}
.radio-opt.is-disabled input {
  cursor: not-allowed;
}
.a4-body-cols-2 {
  column-count: 2;
  column-gap: 18px;
  column-rule: 1px solid #cbd5e1;
}
.a4-body-cols-2 .a4-q {
  break-inside: avoid-column;
}

/* RIGHT MAIN AREA — independent scroll container */
.ws-main {
  flex: 1 1 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-app);
}
.ws-topbar {
  height: 54px;
  padding: 0 18px;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.ws-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ws-tab {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.ws-tab:hover {
  color: var(--text-main);
  background: rgba(0, 184, 169, 0.08);
}
.ws-tab.active {
  background: rgba(0, 184, 169, 0.16);
  border-color: rgba(0, 184, 169, 0.45);
  color: var(--teal);
}
.tab-badge {
  background: var(--teal);
  color: #fff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
}
.ws-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-home-nav {
  padding: 7px 16px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  color: #0f766e;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: 0.15s;
}
.btn-home-nav:hover {
  background: #e6fffb;
}

.ws-content-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 18px 24px;
}
.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

/* SOURCE EXAM PAPER */
.source-paper {
  background: var(--paper-bg);
  color: var(--paper-text);
  border: 1px solid var(--paper-border);
  border-radius: 6px;
  padding: 18px 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}
.group-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 12px;
  border-bottom: 2px solid var(--paper-divider);
  margin-bottom: 8px;
}
.group-title {
  font-size: 16px;
  font-weight: 700;
}
.group-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 184, 169, 0.14);
  color: var(--teal);
  font-weight: 600;
}

.q-block {
  padding: 12px 0;
  border-bottom: 1px solid var(--paper-divider);
}
.q-block:last-child {
  border-bottom: none;
}
.q-block.q-highlight-err {
  background: rgba(220, 38, 38, 0.08);
  padding: 12px;
  border-radius: 6px;
}
.q-stem-line {
  font-size: 14.5px;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.55;
}
.q-meta-pill {
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 4px;
  background: rgba(0, 184, 169, 0.15);
  color: var(--teal);
  vertical-align: middle;
}
.q-options-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-left: 6px;
}
.q-opt-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.q-opt-item:hover {
  background: rgba(0, 184, 169, 0.08);
}
.q-opt-marker {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.q-opt-item.is-correct .q-opt-marker {
  background: var(--red);
  color: #ffffff;
  border-radius: 3px;
}
.q-opt-text {
  flex: 1;
}
.q-pin-btn {
  opacity: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  cursor: pointer;
  transition: 0.15s;
}
.q-opt-item:hover .q-pin-btn,
.q-pin-btn.pinned {
  opacity: 1;
}
.q-pin-btn.pinned {
  border-color: var(--amber);
  color: var(--amber);
  font-weight: 700;
}

/* PREVIEW TOOLBAR & A4 PAPER */
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}
.code-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.code-pill {
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s;
}
.code-pill.active {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.btn-export-primary,
.btn-export-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
}
.btn-export-primary {
  border: none;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
}
.btn-export-primary:hover {
  background: var(--teal-dark);
}
.btn-export-secondary {
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-main);
  font-weight: 600;
}
.btn-export-secondary:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.variant-paper-wrap {
  display: flex;
  justify-content: center;
}
.print-fit-pill {
  margin-top: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  background: rgba(0, 184, 169, 0.12);
  border: 1px solid rgba(0, 184, 169, 0.35);
  color: var(--teal);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}
.print-fit-pill.is-warning,
.preview-fit-bar.preview-fit-warning {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.55);
  color: var(--amber);
}
.preview-fit-bar.preview-fit-warning {
  justify-content: flex-start;
  gap: 8px;
  font-weight: 600;
}
.btn-mix-submit:disabled {
  opacity: 0.6;
  cursor: progress;
}
.a4-sheet {
  width: 100%;
  max-width: 820px;
  background: var(--a4-bg);
  color: var(--a4-text);
  font-family: var(--font-serif);
  padding: 20px 26px;
  border-radius: 4px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  font-size: 14px;
  line-height: 1.35;
}
.a4-sheet.paper-a5 {
  max-width: 580px;
}
.a4-sheet.margin-wide {
  padding: 34px 44px;
}
.a4-sheet.paper-a5.margin-wide {
  padding: 26px 32px;
}
.a4-sheet.font-arial {
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}
.a4-header-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  text-align: center;
  margin-bottom: 4px;
  line-height: 1.2;
}
.a4-header-grid.header-bottom-border {
  padding-bottom: 5px;
  border-bottom: 1.5px solid #111827;
  margin-bottom: 8px;
}
.a4-dept { font-size: 0.88em; }
.a4-school { font-size: 0.9em; font-weight: 700; }
.a4-italic { font-style: italic; font-size: 0.82em; }
.a4-bold { font-weight: 700; font-size: 0.88em; }
.a4-student-bar {
  display: grid;
  grid-template-columns: 3fr 1.2fr 1fr;
  gap: 6px;
  padding-bottom: 4px;
  border-bottom: 1.5px solid #111827;
  margin-bottom: 10px;
  font-size: 0.92em;
}
.a4-code-box { text-align: right; font-weight: 700; }
.a4-q { margin-bottom: 5px; }
.a4-q-stem { margin-bottom: 2px; }
.a4-q-label { font-weight: 700; }
.a4-reserve-box {
  margin-top: 16px;
  min-height: 180px;
  border: 1.5px dashed #94a3b8;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  color: #64748b;
  font-family: var(--font-sans);
  font-size: 13px;
  background: #f8fafc;
}
.preview-fit-bar {
  width: 100%;
  max-width: 820px;
  margin: 0 auto 10px;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(0, 184, 169, 0.12);
  border: 1px solid rgba(0, 184, 169, 0.35);
  color: var(--text-main);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.a4-opts {
  display: grid;
  gap: 2px 16px;
  padding-left: 16px;
}
.a4-opts.cols-1 { grid-template-columns: 1fr; }
.a4-opts.cols-2 { grid-template-columns: 1fr 1fr; }
.a4-opts.cols-4 { grid-template-columns: repeat(4, 1fr); }
.a4-opt-letter { font-weight: 700; }
.a4-end {
  text-align: center;
  font-weight: 700;
  font-style: italic;
  margin-top: 22px;
}

/* ANSWERS & SMART METRICS */
.answers-container {
  background: var(--paper-bg);
  color: var(--paper-text);
  border: 1px solid var(--paper-border);
  border-radius: 10px;
  padding: 20px 24px;
}
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin: 14px 0 22px;
}
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 14px;
}
.metric-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.metric-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--teal);
}
.metric-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.matrix-table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}
.ans-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  text-align: center;
}
.ans-table th,
.ans-table td {
  border: 1px solid var(--paper-border);
  padding: 7px 10px;
}
.ans-table th {
  background: var(--teal);
  color: #ffffff;
  font-weight: 700;
}
.ans-table tr:nth-child(even) td {
  background: rgba(0, 184, 169, 0.05);
}
.ans-letter-cell {
  font-weight: 800;
  color: var(--red);
}
html[data-theme="dark"] .ans-letter-cell {
  color: #f87171;
}
.status-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: #059669;
  font-weight: 600;
}
html[data-theme="dark"] .status-inline {
  color: #34d399;
}

.ws-footer {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--bg-topbar);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-backdrop[hidden] {
  display: none;
}
.modal-card {
  width: 100%;
  max-width: 560px;
  background: var(--bg-sidebar);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.38);
}
.modal-codes-clean {
  padding: 10px 6px 6px;
}
.modal-body {
  padding: 20px 24px 16px;
}
.codes-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px 16px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 24px;
}
.code-edit-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.code-edit-cell label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
}
.code-edit-cell input {
  width: 100%;
  padding: 6px 2px;
  border: none;
  border-bottom: 1.5px solid var(--border-subtle);
  background: transparent;
  color: var(--text-main);
  font-size: 15px;
  font-weight: 600;
  outline: none;
  transition: border-color 0.15s;
}
.code-edit-cell input:focus {
  border-bottom-color: var(--teal);
}
.modal-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
}
.modal-quick-btns {
  display: flex;
  gap: 8px;
}
.btn-link-subtle {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-link-subtle:hover {
  border-color: var(--teal);
  color: var(--teal);
}
.modal-dialog-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}
.btn-modal-cancel {
  background: transparent;
  border: none;
  color: #e11d48;
  font-size: 15px;
  font-weight: 700;
  padding: 6px 10px;
  cursor: pointer;
}
.btn-modal-cancel:hover {
  opacity: 0.8;
}
.btn-modal-save {
  background: transparent;
  border: none;
  color: var(--teal);
  font-size: 15px;
  font-weight: 700;
  padding: 6px 10px;
  cursor: pointer;
}
.btn-modal-save:hover {
  opacity: 0.8;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #fff;
  border-left: 4px solid var(--teal);
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  z-index: 200;
}

/* RESPONSIVE */
@media (max-width: 900px) {
  #workspaceView.active,
  .ws-shell,
  .ws-sidebar,
  .ws-main {
    height: auto;
    overflow: visible;
  }
  .ws-shell {
    flex-direction: column;
  }
  .ws-sidebar {
    width: 100%;
    max-width: none;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
  .features-grid {
    grid-template-columns: 1fr;
  }
}

/* PRINT STYLES */
@media print {
  .ws-sidebar, .ws-topbar, .preview-toolbar, .ws-footer, #homeView {
    display: none !important;
  }
  #workspaceView.active, .ws-shell, .ws-main, .ws-content-scroll {
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    background: #fff !important;
  }
  .a4-sheet {
    box-shadow: none !important;
    padding: 12mm 15mm !important;
    max-width: none !important;
  }
}
