/* ═══════════════════════════════════════════════════════
   MATH207 Dataset Viewer – Stylesheet
   ═══════════════════════════════════════════════════════ */

/* ─── Reset & Tokens ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 256px;
  --topbar-h: 56px;
  --filter-h: 48px;

  /* Colour palette */
  --bg:       #0d0f14;
  --bg2:      #13161d;
  --bg3:      #1a1e28;
  --surface:  #1e2330;
  --border:   rgba(255,255,255,.07);
  --border2:  rgba(255,255,255,.12);

  --text:     #e8ecf4;
  --text-muted: #7a829a;
  --text-dim:   #4d5568;

  /* Accent palette */
  --accent:   #6c8ef5;
  --accent-h: #8ba4ff;
  --green:    #4ade80;
  --amber:    #fbbf24;
  --rose:     #f87171;
  --teal:     #2dd4bf;
  --violet:   #a78bfa;

  /* Mark colours */
  --mark-short-bg: rgba(74,222,128,.12);
  --mark-short-fg: #4ade80;
  --mark-long-bg:  rgba(168,139,250,.12);
  --mark-long-fg:  #a78bfa;
  --mark-mcq-bg:   rgba(108,142,245,.12);
  --mark-mcq-fg:   #6c8ef5;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0,0,0,.45);
}

html { font-size: 15px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(108,142,245,.35);
}

.logo-title {
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text);
}

.logo-sub {
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Search */
.sidebar-search {
  margin: 12px 12px 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  transition: border-color .2s;
}

.sidebar-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,142,245,.12);
}

.search-icon {
  font-size: 1.15rem;
  color: var(--text-muted);
  user-select: none;
  line-height: 1;
}

.sidebar-search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: .85rem;
  padding: 9px 0;
}

.sidebar-search input::placeholder { color: var(--text-dim); }

.search-clear {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: .75rem;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color .2s;
  display: none;
}

.search-clear.visible { display: flex; }
.search-clear:hover { color: var(--text-muted); }

/* Chapter nav */
.sidebar-section-label {
  font-size: .65rem;
  letter-spacing: .1em;
  font-weight: 600;
  color: var(--text-dim);
  padding: 14px 16px 6px;
}

.chapter-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface) transparent;
}

.chapter-btn {
  width: 100%;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background .18s, color .18s;
  color: var(--text-muted);
  font-family: inherit;
  font-size: .82rem;
  line-height: 1.35;
}

.chapter-btn:hover {
  background: var(--bg3);
  color: var(--text);
}

.chapter-btn.active {
  background: rgba(108,142,245,.15);
  color: var(--accent-h);
}

.chapter-btn .ch-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
  opacity: .7;
}

.chapter-btn.active .ch-icon { opacity: 1; }

.chapter-btn .ch-label { flex: 1; }

.chapter-btn .ch-count {
  background: var(--surface);
  color: var(--text-muted);
  font-size: .7rem;
  padding: 2px 7px;
  border-radius: 20px;
  font-weight: 500;
  min-width: 26px;
  text-align: center;
}

.chapter-btn.active .ch-count {
  background: rgba(108,142,245,.25);
  color: var(--accent-h);
}

/* ── Chapter accordion ── */
.chapter-group { display: flex; flex-direction: column; }

.chapter-row {
  justify-content: flex-start; /* keep consistent with chapter-btn */
}

/* Arrow indicator */
.ch-arrow {
  font-size: 1rem;
  color: var(--text-dim);
  transition: transform .22s cubic-bezier(.4,0,.2,1), color .18s;
  flex-shrink: 0;
  line-height: 1;
  margin-left: auto;
}

.chapter-row.expanded .ch-arrow {
  transform: rotate(90deg);
  color: var(--accent);
}

/* Sub-chapter list (accordion body) */
.subchapter-list {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .25s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

.subchapter-list.open {
  grid-template-rows: 1fr;
}

.subchapter-list > * {
  /* inner wrapper to allow overflow:hidden on grid trick */
  min-height: 0;
}

/* Sub-chapter buttons */
.subchapter-btn {
  width: 100%;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 7px 32px; /* indent under chapter */
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  color: var(--text-dim);
  font-family: inherit;
  font-size: .78rem;
  line-height: 1.35;
  transition: background .18s, color .18s;
}

.subchapter-btn:hover {
  background: var(--bg3);
  color: var(--text-muted);
}

.subchapter-btn.active {
  background: rgba(108,142,245,.1);
  color: var(--accent-h);
}

.sub-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background .18s;
}

.subchapter-btn:hover .sub-dot { background: var(--text-muted); }
.subchapter-btn.active .sub-dot { background: var(--accent); }

.sub-label { flex: 1; }

.sub-count {
  background: var(--surface);
  color: var(--text-dim);
  font-size: .67rem;
  padding: 1px 6px;
  border-radius: 20px;
  font-weight: 500;
  min-width: 22px;
  text-align: center;
}

.subchapter-btn.active .sub-count {
  background: rgba(108,142,245,.2);
  color: var(--accent-h);
}

.sidebar-footer {
  padding: 12px 16px;
  font-size: .75rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

/* ─── Main ─── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: margin-left .3s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

.main.expanded { margin-left: 0; }

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
}

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  border-radius: 6px;
}

.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: background .2s;
}

.hamburger:hover span { background: var(--text); }

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.stats-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stats-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 48px;
}

.stats-pill .pill-val {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.stats-pill .pill-label {
  font-size: .65rem;
  color: var(--text-muted);
  margin-top: 2px;
  text-align: center;
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 6px;
  padding: 10px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.filter-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: inherit;
  font-size: .8rem;
  font-weight: 500;
  padding: 5px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
}

.filter-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border2);
}

.filter-btn.active {
  background: rgba(108,142,245,.2);
  border-color: var(--accent);
  color: var(--accent-h);
}

/* Questions container */
.questions-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface) transparent;
}

/* Loading */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 20px;
  color: var(--text-muted);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--surface);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

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

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: .9rem;
}

.empty-state .empty-icon { font-size: 2.5rem; opacity: .4; }

/* ─── Question Card ─── */
.question-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s, transform .15s;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.question-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(108,142,245,.04), transparent 60%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}

.question-card:hover {
  border-color: var(--border2);
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
  transform: translateY(-1px);
}

.question-card:hover::before { opacity: 1; }

.card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.card-num {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .73rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-top: 1px;
  box-shadow: 0 2px 8px rgba(108,142,245,.3);
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.tag {
  font-size: .7rem;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

.tag-marks {
  background: var(--mark-short-bg);
  color: var(--mark-short-fg);
}

.tag-marks.long {
  background: var(--mark-long-bg);
  color: var(--mark-long-fg);
}

.tag-type {
  background: var(--mark-mcq-bg);
  color: var(--mark-mcq-fg);
}

.tag-chapter {
  background: rgba(45,212,191,.1);
  color: var(--teal);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-question {
  font-size: .92rem;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 10px;
}

.card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .75rem;
  color: var(--text-dim);
}

.card-footer-icon { opacity: .6; }

.card-cta {
  margin-left: auto;
  font-size: .75rem;
  color: var(--accent);
  font-weight: 500;
  opacity: 0;
  transition: opacity .2s;
}

.question-card:hover .card-cta { opacity: 1; }

/* Options preview */
.card-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.card-option {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: .8rem;
  color: var(--text-muted);
}

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .2s ease;
}

.modal-backdrop[hidden] { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 18px;
  width: 100%;
  max-width: 780px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: slideUp .25s cubic-bezier(.4,0,.2,1);
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-meta {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.modal-close {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .2s, color .2s;
}

.modal-close:hover { background: var(--surface); color: var(--text); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface) transparent;
}

/* Modal sections */
.modal-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.modal-section:last-child { border-bottom: none; }

.modal-section-title {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .1em;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.question-text {
  font-size: 1.02rem;
  line-height: 1.8;
  color: var(--text);
  font-weight: 400;
}

/* Options in modal */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.option-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .88rem;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  transition: border-color .2s;
}

.option-letter {
  color: var(--accent);
  font-weight: 600;
  font-size: .8rem;
  flex-shrink: 0;
  margin-top: 1px;
}

/* Answer box */
.answer-box {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: .9rem;
  line-height: 1.75;
  color: var(--text);
}

/* Guided answer */
.guided-box {
  border-left-color: var(--violet);
}

.guided-level {
  margin-bottom: 16px;
}

.guided-level-title {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.level-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .68rem;
}

.level-badge.beginner {
  background: rgba(74,222,128,.12);
  color: var(--green);
}

.level-badge.intermediate {
  background: rgba(251,191,36,.12);
  color: var(--amber);
}

.guided-level-content {
  font-size: .88rem;
  line-height: 1.8;
  color: var(--text-muted);
}

/* Exam-format question box */
.exam-f-box {
  background: rgba(45,212,191,.06);
  border: 1px solid rgba(45,212,191,.2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: .9rem;
  line-height: 1.75;
  color: var(--text);
  font-style: italic;
}

/* Guided follow-up questions */
.guided-fq-box {
  background: rgba(168,139,250,.06);
  border: 1px solid rgba(168,139,250,.2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.guided-fq-item {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
  line-height: 1.75;
  color: var(--text-muted);
}

.guided-fq-item:last-child { border-bottom: none; }

.fq-num {
  font-weight: 700;
  color: var(--violet);
  flex-shrink: 0;
  min-width: 18px;
}

/* Sub-chapter badge */
.sub-chapter-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(45,212,191,.08);
  color: var(--teal);
  border: 1px solid rgba(45,212,191,.2);
  border-radius: 20px;
  font-size: .72rem;
  padding: 3px 10px;
  font-weight: 500;
}

/* Modal footer */
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-nav {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: inherit;
  font-size: .82rem;
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}

.modal-nav:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border2);
}

.modal-nav:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.modal-counter {
  font-size: .8rem;
  color: var(--text-dim);
}

/* ─── KaTeX overrides ─── */
.katex { font-size: 1em; }
.katex-display { overflow-x: auto; padding: 4px 0; }
.katex-display > .katex { text-align: left; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .main { margin-left: 0; }

  .stats-pills { display: none; }
  .questions-container { padding: 14px; }
  .modal { border-radius: 12px; }
  .modal-body { padding: 0 16px; }
  .modal-header, .modal-footer { padding: 14px 16px; }
}
