/* ── CraftyTest Design System — Retool / Airtable inspired ──────────────────── */
:root {
  --header-h: 48px;

  /* Brand accent — Chapman maroon */
  --cu-maroon:    #9d1f2e;
  --cu-maroon-dk: #7a1724;
  --cu-maroon-lt: #b82232;
  --cu-gold:      #d4a12a;
  --cu-gold-lt:   #f0c95c;

  /* Neutral surfaces — light mode */
  --surface-0: #ffffff;
  --surface-1: #f4f4f5;      /* page background */
  --surface-2: #ebebec;      /* row hover, stripes */
  --surface-3: #dededf;      /* strong dividers */

  /* Text */
  --text-primary:   #111827;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;

  /* Borders */
  --border:    #e5e7eb;
  --border-dk: #d1d5db;

  /* Semantic */
  --correct: #c0392b;
  --success: #16a34a;
  --danger:  #dc2626;
  --info:    #2563eb;

  /* Radii */
  --radius-sm: 5px;
  --radius:    6px;
  --radius-lg: 10px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04), 0 0 0 1px rgba(0,0,0,.05);
  --shadow:    0 2px 6px rgba(0,0,0,.06), 0 0 0 1px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.11), 0 0 0 1px rgba(0,0,0,.06);

  --font:      Inter, 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', Consolas, monospace;
}

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

html { scrollbar-gutter: stable; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--surface-1);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
.app-header {
  background: #111827;
  height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  height: 100%;
  display: flex;
  align-items: stretch;
  gap: 0;
}
.header-brand {
  display: flex;
  align-items: center;
  padding: 0 20px 0 0;
  margin-right: 4px;
  flex-shrink: 0;
  border-right: 1px solid rgba(255,255,255,.1);
}
.header-title { font-size: 15px; font-weight: 700; color: white; letter-spacing: -.01em; }
.header-sub   { font-size: 13px; font-weight: 500; color: rgba(255,255,255,.7); }
.header-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.header-dashboard-link,
.header-signout-btn {
  display: inline-flex;
  align-items: center;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,.65);
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, color .12s;
  white-space: nowrap;
  line-height: 1.5;
}
.header-dashboard-link:hover,
.header-signout-btn:hover { background: rgba(255,255,255,.14); color: white; }

/* ── Tab nav ─────────────────────────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  align-items: stretch;
  height: 100%;
  gap: 0;
  margin-left: 8px;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-top: 2px solid transparent;
  color: rgba(255,255,255,.5);
  padding: 0 16px;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color .12s, background .12s;
  white-space: nowrap;
}
.tab-btn:hover { color: rgba(255,255,255,.85); background: rgba(255,255,255,.05); }
.tab-btn.active {
  color: white;
  border-bottom-color: #e86a7a;
  font-weight: 600;
}

/* ── Main layout ─────────────────────────────────────────────────────────────── */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
#tab-preview.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h) - 40px);
}

/* ── Toolbar ─────────────────────────────────────────────────────────────────── */
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
}
.toolbar-left  { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-shrink: 0; flex-wrap: wrap; }
.panel-heading { font-size: 14px; font-weight: 600; color: var(--text-primary); }

/* ── Bulk actions bar ────────────────────────────────────────────────────────── */
.bulk-actions-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  margin-bottom: 8px;
  background: var(--primary-light, #eef2ff);
  border: 1px solid var(--primary, #4f46e5);
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-primary);
}
.bulk-actions-bar.hidden { display: none; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--cu-maroon);
  color: white;
  border-color: var(--cu-maroon-dk);
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.btn-primary:hover:not(:disabled) { background: var(--cu-maroon-lt); }

.btn-secondary {
  background: var(--surface-0);
  color: var(--text-primary);
  border-color: var(--border-dk);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text-primary); }

.btn-danger {
  background: var(--surface-0);
  color: #dc2626;
  border-color: #fca5a5;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
  border-color: #dc2626;
  color: #b91c1c;
}

.btn-small { padding: 3px 9px; font-size: 11px; }
.link-btn { background: none; border: none; color: var(--cu-maroon); cursor: pointer; text-decoration: underline; font-family: var(--font); font-size: inherit; }

/* ── Inputs ──────────────────────────────────────────────────────────────────── */
.input-text, .input-select, .input-textarea, .input-search, .input-short {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface-0);
  border: 1px solid var(--border-dk);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  transition: border-color .12s, box-shadow .12s;
}
.input-text:focus, .input-select:focus, .input-textarea:focus,
.input-search:focus, .input-short:focus {
  outline: none;
  border-color: var(--cu-maroon);
  box-shadow: 0 0 0 2px rgba(157,31,46,.1);
}
.input-text    { width: 100%; }
.input-select  { min-width: 130px; cursor: pointer; }
.input-search  { width: 200px; }
.input-short   { width: 110px; }
.input-textarea { width: 100%; resize: vertical; }
.option-input { resize: none; overflow-y: hidden; }
.w-full { width: 100%; }

/* ── Form layout ─────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.form-row { display: flex; gap: 14px; }
.form-row-2 > * { flex: 1; }
.field-hint { font-size: 11px; color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.required { color: var(--danger); }

/* ── Sort headers ────────────────────────────────────────────────────────────── */
.sort-th { cursor: pointer; user-select: none; }
.sort-th:hover { background: var(--surface-2) !important; }
.sort-indicator { display: inline-block; font-size: 10px; color: var(--text-muted); margin-left: 3px; }

/* ── Q-ID display ────────────────────────────────────────────────────────────── */
.q-id-display {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-weight: 600;
  min-height: 34px;
  display: flex;
  align-items: center;
}

/* ── Format toolbar (B/I/U) ──────────────────────────────────────────────────── */
.fmt-toolbar { display: flex; align-items: center; gap: 3px; margin-bottom: 5px; }
.fmt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  background: var(--surface-0);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font);
  transition: background .1s;
  flex-shrink: 0;
}
.fmt-btn:hover { background: var(--surface-2); border-color: var(--border-dk); color: var(--text-primary); }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--surface-2);
  vertical-align: top;
  font-size: 13px;
}
.data-table td:last-child { white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafafa; }
.data-table tbody tr.selected-row { background: #fdf3f4; }
.col-wide { width: 38%; }

/* ── Type badges ─────────────────────────────────────────────────────────────── */
.type-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.type-mc     { background: #eff6ff; color: #1d4ed8; }
.type-tf     { background: #f0fdf4; color: #15803d; }
.type-es     { background: #fffbeb; color: #92400e; }
.type-custom { background: #f5f3ff; color: #6d28d9; }

/* ── Topic chips ─────────────────────────────────────────────────────────────── */
.topic-chip {
  display: inline-block;
  background: var(--surface-2);
  color: var(--text-secondary);
  padding: 1px 6px;
  border-radius: 99px;
  font-size: 11px;
  margin: 1px 2px 1px 0;
}

/* ── Badge count ─────────────────────────────────────────────────────────────── */
.badge-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 3px 9px;
  border-radius: 99px;
  font-weight: 500;
}

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

/* ── Editor layout ───────────────────────────────────────────────────────────── */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
  align-items: start;
}
.editor-form-col {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

/* Editor toolbar sits inside the form col — reset card styling */
.editor-form-col .panel-toolbar {
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
  padding: 0 0 14px;
  margin-bottom: 20px;
}

/* MC options */
.options-block { margin-top: 16px; }
.options-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 8px;
}
.option-row { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.option-letter {
  width: 20px;
  height: 20px;
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 5px;
}
.option-input { flex: 1; }
.correct-radio-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  transition: color .12s;
  white-space: nowrap;
  margin-top: 5px;
}
.correct-radio-label:has(.correct-radio:checked) { color: var(--success); }
.correct-radio { accent-color: var(--success); }
.tf-row { display: flex; gap: 20px; }
.tf-label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; }

/* ── Figure panel ────────────────────────────────────────────────────────────── */
.editor-figures-col {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.figures-header { margin-bottom: 12px; }
.figures-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-secondary);
}
.figures-hint { font-size: 11px; color: var(--text-muted); }

.figure-drop-zone {
  border: 2px dashed var(--border-dk);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  display: block;
}
.figure-drop-zone:hover, .figure-drop-zone.drag-over {
  background: var(--surface-1);
  border-color: var(--cu-maroon);
}
.figure-drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  pointer-events: none;
}
.figure-list { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.figure-item {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.figure-thumb { width: 100%; height: 130px; object-fit: contain; background: var(--surface-2); display: block; }
.figure-meta { padding: 8px 10px; }
.figure-caption-input {
  width: 100%;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 7px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface-0);
}
.figure-caption-input:focus { outline: none; border-color: var(--cu-maroon); }
.figure-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  float: right;
  padding: 0;
  margin-left: 6px;
}
.figure-delete-btn:hover { color: var(--danger); }
.figures-save-hint { font-size: 11px; color: var(--info); margin-top: 8px; }

/* ── Card ────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 12px;
}
.card-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title-row .card-title { margin-bottom: 0; }

/* ── Crafter layout ──────────────────────────────────────────────────────────── */
.builder-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  align-items: start;
}
.builder-questions-col {
  position: sticky;
  top: calc(var(--header-h) + 20px);
  height: calc(100vh - var(--header-h) - 40px);
  display: flex;
  flex-direction: column;
}
.builder-questions-col > .card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.selection-filters { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.selection-table-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* Section rows */
.sections-list { display: flex; flex-direction: column; gap: 10px; }
.section-item {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  position: relative;
}
.section-item-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.section-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 14px;
  flex-shrink: 0;
  user-select: none;
  padding: 0 2px;
}
.section-drag-handle:active { cursor: grabbing; }
.section-item.drag-over { border-color: var(--cu-maroon); background: #fdf3f4; }
.section-item.drag-source { opacity: .25; pointer-events: none; }

/* Prefix picker */
.prefix-picker { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 2px; }
.prefix-picker label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-primary);
  cursor: pointer;
}
.section-title-input { flex: 1; font-weight: 600; }
.section-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  line-height: 1;
}
.section-remove-btn:hover { color: var(--danger); }
.section-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.section-fields .form-group label { font-size: 11px; }
.section-checks { display: flex; gap: 14px; margin-top: 8px; font-size: 12px; }
.section-checks label { display: flex; align-items: center; gap: 5px; cursor: pointer; }

/* ── Preview toolbar ─────────────────────────────────────────────────────────── */
.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
}
.preview-exam-title { font-size: 20px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.preview-version-name { font-size: 12px; font-style: italic; color: var(--text-muted); margin-bottom: 20px; }
.editable-inline {
  border-radius: 3px;
  padding: 1px 4px;
  outline: none;
  cursor: text;
  transition: background .15s, box-shadow .15s;
}
.editable-inline:hover { background: var(--surface-2); }
.editable-inline:focus { background: var(--surface-2); box-shadow: 0 0 0 2px var(--cu-maroon); }

/* ── Preview section cards ───────────────────────────────────────────────────── */
.preview-section-card {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.preview-section-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--cu-maroon);
}
.preview-section-header-info { flex: 1; }
.preview-sec-arrows { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.preview-sec-arrow-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 22px;
  height: 18px;
  font-size: 9px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .1s, color .1s;
}
.preview-sec-arrow-btn:hover:not(:disabled) { background: var(--cu-maroon); color: #fff; }
.preview-sec-arrow-btn:disabled { opacity: .3; cursor: default; }
.preview-section-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.preview-section-meta { font-size: 11px; font-weight: 500; color: var(--text-muted); margin-top: 2px; }
.preview-intro { font-style: italic; margin-bottom: 10px; color: var(--text-secondary); font-size: 13px; }
.preview-section-questions { padding-left: 8px; }
.preview-question { margin-bottom: 18px; position: relative; }
.btn-drag-q {
  position: absolute;
  top: 0;
  left: -18px;
  font-size: 14px;
  padding: 1px 4px;
  background: transparent;
  border: none;
  cursor: grab;
  color: var(--text-muted);
  line-height: 1;
  user-select: none;
}
.btn-drag-q:active { cursor: grabbing; }
.preview-question.dragging { opacity: .35; }
.preview-drop-indicator {
  height: 2px;
  background: var(--cu-maroon);
  border-radius: 2px;
  margin: 4px 0;
  pointer-events: none;
}
.preview-question-ghost {
  position: fixed;
  pointer-events: none;
  opacity: .88;
  background: var(--surface-0);
  border: 1px solid var(--cu-maroon);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  z-index: 999;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  max-width: 520px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-edit-q {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 11px;
  padding: 2px 8px;
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-family: var(--font);
  transition: background .1s, color .1s;
}
.btn-edit-q:hover { background: var(--surface-2); color: var(--cu-maroon); }
.preview-q-num { font-weight: 600; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px; }
.preview-q-text { font-weight: 600; margin-bottom: 8px; font-size: 13.5px; }
.preview-option { padding: 2px 0 2px 8px; font-size: 13px; }
.preview-option.correct { color: var(--correct); font-weight: 700; }
.preview-figure { max-width: 380px; margin: 10px auto; display: block; }
.preview-figure-caption { text-align: center; font-size: 11px; font-style: italic; color: var(--text-muted); }
.preview-essay-box {
  border: 1px solid var(--border-dk);
  height: 90px;
  border-radius: var(--radius-sm);
  margin-top: 6px;
  background: var(--surface-1);
}

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal.hidden { display: none; }
#modal-confirm { z-index: 210; }
.modal-box {
  background: var(--surface-0);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 540px;
  max-width: 95vw;
  box-shadow: var(--shadow-lg);
}
.modal-box-sm { width: 380px; }
.modal-box-md { width: 580px; }
.modal-title { font-size: 15px; font-weight: 700; color: var(--text-primary); margin-bottom: 12px; }
.modal-hint { font-size: 12px; color: var(--text-secondary); margin-bottom: 14px; line-height: 1.6; }
.modal-hint code { background: var(--surface-2); padding: 1px 4px; border-radius: 3px; font-family: var(--font-mono); font-size: 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ── Import/Export modal tabs ────────────────────────────────────────────────── */
.import-export-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}
.import-tab-btn {
  flex: 1;
  padding: .45rem .5rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.import-tab-btn.active { color: var(--cu-maroon); border-bottom-color: var(--cu-maroon); }
.import-tab-panel { display: none; }
.import-tab-panel.active { display: block; }
.export-tab-actions { display: flex; align-items: center; gap: 1rem; margin: 1.25rem 0; }

/* ── CSV drop zone ───────────────────────────────────────────────────────────── */
.drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border-dk);
  border-radius: var(--radius);
  padding: 28px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  transition: background .15s, border-color .15s;
  margin-bottom: 8px;
}
.drop-zone:hover, .drop-zone.drag-over { background: var(--surface-1); border-color: var(--cu-maroon); }

.import-result {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.6;
  margin-top: 10px;
}
.import-ok   { color: var(--success); }
.import-warn { color: #d97706; }
.import-err  { color: var(--danger); }

/* ── Config actions ──────────────────────────────────────────────────────────── */
.config-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #111827;
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  transition: opacity .2s;
}
.toast.hidden { display: none; }
.toast.toast-success { background: var(--success); }
.toast.toast-error   { background: var(--danger); }

/* ── Utils ───────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── ES Sub-questions ────────────────────────────────────────────────────────── */
.subq-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.subq-top-row { display: flex; align-items: center; gap: 8px; }
.subq-label { font-weight: bold; min-width: 28px; font-size: 13px; flex-shrink: 0; }
.subq-input { flex: 1; }
.subq-remove-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 18px; padding: 0 4px; line-height: 1; }
.subq-remove-btn:hover { opacity: 0.7; }
.subq-rubric { margin-left: 36px; font-size: 12px; min-height: 48px; width: calc(100% - 36px); }
.subq-pts    { width: 62px; flex-shrink: 0; font-size: 12px; padding: 4px 6px; }
.pts-row { display: flex; align-items: center; gap: 8px; }
.pts-vary-hint { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.preview-subq-label { font-weight: bold; font-size: 13px; margin: 10px 0 4px; }
.preview-rubric,
.view-rubric    { color: var(--correct); font-size: 12px; font-style: italic; padding: 4px 8px; border-left: 2px solid var(--correct); }
.preview-rubric { margin: 4px 0 10px; }

/* ── Preview layout with version panel ──────────────────────────────────────── */
.preview-layout {
  display: flex;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.preview-content-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-close-btn {
  position: absolute;
  top: 10px;
  left: 14px;
  z-index: 10;
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .1s, color .1s;
  line-height: 1;
}
.preview-close-btn:hover { background: var(--surface-2); color: var(--cu-maroon); }

/* ── Shuffle dropdown ────────────────────────────────────────────────────────── */
.shuffle-wrap { position: relative; }
.shuffle-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  min-width: 160px;
  overflow: hidden;
}
.shuffle-opt {
  display: block;
  width: 100%;
  padding: 8px 14px;
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}
.shuffle-opt:hover { background: var(--surface-1); }

/* ── Version panel ───────────────────────────────────────────────────────────── */
.version-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.version-panel-header {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: 10px 10px 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface-0);
}
.version-panel-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  flex: 1;
}
.btn-xs { font-size: .7rem; padding: .15rem .55rem; line-height: 1.4; }

.version-list { overflow-y: auto; flex: 1; padding: 6px 0; }
.version-empty { padding: 12px 14px; font-size: 12px; color: var(--text-muted); }
.version-item {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  cursor: pointer;
  transition: background .1s;
}
.version-item:hover { background: var(--surface-2); }
.version-item:last-child { border-bottom: none; }
.version-item-active {
  background: #fdf3f4 !important;
  border-left: 2px solid var(--cu-maroon);
  padding-left: 12px;
}
.version-item-name { font-weight: 600; color: var(--text-primary); margin-bottom: 2px; word-break: break-word; }
.version-item-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 5px; }
.version-item-actions { display: flex; flex-wrap: wrap; gap: 4px; }

.version-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.version-icon-btn:hover { background-color: var(--surface-3); color: var(--text-primary); }
.version-icon-btn svg { display: block; }

.preview-content {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px;
  background: var(--surface-0);
  font-size: 13.5px;
  line-height: 1.7;
  min-height: 0;
}

/* ── Question view modal ─────────────────────────────────────────────────────── */
.modal-box-lg {
  width: 700px;
  max-height: 88vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.modal-close-btn:hover { color: var(--text-primary); }
.view-q-body { flex: 1; overflow-y: auto; }
.view-q-text { font-weight: 600; margin-bottom: 10px; font-size: 14px; }
.view-rubric { margin: 6px 0 10px; }
.view-meta { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.view-notes { font-style: italic; }

/* ── Excluded badge ──────────────────────────────────────────────────────────── */
.excl-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 3px;
  padding: 1px 5px;
  letter-spacing: .03em;
}

/* ── Excluded toggle ─────────────────────────────────────────────────────────── */
.excl-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.excl-toggle input { cursor: pointer; accent-color: var(--danger); }
.excl-toggle:has(input:checked) { color: var(--danger); }

/* ── Permission badges ───────────────────────────────────────────────────────── */
.perm-badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  vertical-align: middle;
}
.perm-badge.view  { background: #eff6ff; color: #1d4ed8; }
.perm-badge.exam  { background: #f0fdf4; color: #15803d; }
.perm-badge.edit  { background: #fff7ed; color: #c2410c; }

/* ── Swap question button ────────────────────────────────────────────────────── */
.btn-swap-q {
  font-size: .72rem;
  padding: .15rem .45rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
}
.btn-swap-q:hover { background: var(--surface-3); }

/* ── Swap question modal ─────────────────────────────────────────────────────── */
.swap-replacing-section {
  background: var(--surface-1);
  border-radius: var(--radius-sm);
  padding: .6rem .8rem;
  margin-bottom: .9rem;
}
.swap-replacing-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .25rem;
}
.swap-replacing-text { font-size: .85rem; color: var(--text-secondary); line-height: 1.4; }
.swap-filters { display: flex; gap: .5rem; margin-bottom: .75rem; }
.swap-filters .form-input { flex: 1; }
.swap-candidate-list {
  max-height: 380px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: .9rem;
}
.swap-candidate-card {
  padding: .65rem .8rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.swap-candidate-card:last-child { border-bottom: none; }
.swap-candidate-card:hover { background: var(--surface-1); }
.swap-card-header { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .3rem; }
.swap-card-id {
  font-size: .75rem;
  background: var(--surface-2);
  padding: .1rem .35rem;
  border-radius: 3px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}
.swap-card-type {
  font-size: .67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--cu-maroon);
  color: #fff;
  padding: .1rem .35rem;
  border-radius: 3px;
}
.swap-card-topics { display: flex; flex-wrap: wrap; gap: .25rem; }
.swap-topic-tag    { font-size: .68rem; background: #eff6ff; color: #1d4ed8; padding: .1rem .3rem; border-radius: 3px; }
.swap-lecture-tag  { font-size: .68rem; background: #f5f3ff; color: #6d28d9; padding: .1rem .3rem; border-radius: 3px; font-weight: 600; }
.swap-card-text    { font-size: .82rem; color: var(--text-secondary); line-height: 1.4; }
.swap-no-results   { padding: 1.5rem; text-align: center; color: var(--text-muted); font-size: .85rem; }

/* ── Toolbar divider ─────────────────────────────────────────────────────────── */
.toolbar-divider { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; margin: 0 4px; }

/* ── Answer key toggle ───────────────────────────────────────────────────────── */
.btn-ak-on { background: var(--cu-maroon) !important; color: #fff !important; border-color: var(--cu-maroon) !important; }
.btn-ak-on:hover:not(:disabled) { background: #8b0000 !important; border-color: #8b0000 !important; }

/* ── Canvas course ID pill ───────────────────────────────────────────────────── */
.course-id-pill {
  display: inline-block;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: .02em;
  margin-top: 2px;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .editor-layout  { grid-template-columns: 1fr; }
  .builder-layout { grid-template-columns: 1fr; }
  .header-inner   { flex-wrap: wrap; padding: 8px 12px; height: auto; }
  .tab-nav        { width: 100%; overflow-x: auto; margin-left: 0; }
  .tab-btn        { flex: 1; padding: 8px 10px; font-size: 12px; }
  #tab-preview.active { height: auto; }
}
