/* ECON 5040 Universal Learning & Exam Mastery PWA — Apple 3-Device Design System */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-hover: #e8ecf1;
  --text: #1d1d1f;
  --text-secondary: #515154;
  --text-muted: #6e6e73;
  --border: #d8dce3;
  --border-strong: #bfc6d1;
  --accent: #0066cc;
  --accent-soft: #e8f2ff;
  --accent-text: #004c99;

  /* Semantic Callouts (Color + Icon + Text Label for full accessibility) */
  --concept-bg: #fffbeb;
  --concept-border: #f59e0b;
  --concept-text: #92400e;
  --formula-bg: #eff6ff;
  --formula-border: #2563eb;
  --formula-text: #1e40af;
  --trap-bg: #fef2f2;
  --trap-border: #dc2626;
  --trap-text: #991b1b;
  --example-bg: #ecfdf5;
  --example-border: #059669;
  --example-text: #065f46;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --font-base: 15px;
  --sidebar-w: 232px;
  --topbar-h: 54px;
  --bottombar-h: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #222631;
  --surface-hover: #2c3140;
  --text: #f3f4f6;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border: #2e3444;
  --border-strong: #475068;
  --accent: #4ea1ff;
  --accent-soft: rgba(78, 161, 255, 0.16);
  --accent-text: #93c5fd;

  --concept-bg: rgba(245, 158, 11, 0.12);
  --concept-border: #f59e0b;
  --concept-text: #fcd34d;
  --formula-bg: rgba(59, 130, 246, 0.14);
  --formula-border: #60a5fa;
  --formula-text: #93c5fd;
  --trap-bg: rgba(239, 68, 68, 0.14);
  --trap-border: #f87171;
  --trap-text: #fca5a5;
  --example-bg: rgba(16, 185, 129, 0.14);
  --example-border: #34d399;
  --example-text: #6ee7b7;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
}

[data-font="sm"] { --font-base: 13.5px; }
[data-font="md"] { --font-base: 15px; }
[data-font="lg"] { --font-base: 16.5px; }
[data-font="xl"] { --font-base: 18.5px; }

[data-reduced-motion="true"] *,
[data-reduced-motion="true"] *::before,
[data-reduced-motion="true"] *::after {
  animation-duration: 0.01ms !important;
  transition-duration: 0.01ms !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Segoe UI", Roboto, sans-serif;
  font-size: var(--font-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100vw;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, canvas { max-width: 100%; height: auto; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* App Shell Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

/* Desktop / iPad Landscape Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  padding: calc(12px + var(--safe-top)) 10px calc(12px + var(--safe-bottom)) calc(10px + var(--safe-left));
  overflow-y: auto;
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #003366, #0066cc);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 14px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  padding: 8px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
  min-height: 38px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.nav-item .nav-ico { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-left: auto;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
}
.nav-item.active .nav-badge { background: var(--accent); color: #fff; }

/* Main Container */
.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--topbar-h);
  padding: calc(6px + var(--safe-top)) calc(16px + var(--safe-right)) 6px 16px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
[data-theme="dark"] .topbar { background: rgba(24, 27, 34, 0.88); }

.topbar-title { font-weight: 700; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }

.search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  min-height: 36px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  max-width: 280px;
  width: 100%;
}
.search-trigger:hover { border-color: var(--accent); color: var(--text); }
.search-kbd {
  margin-left: auto;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 36px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.icon-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }

.view-container {
  flex: 1;
  padding: 16px 20px 32px;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  min-width: 0;
}

/* Official Compliance Banner */
.exam-notice-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--trap-bg);
  border: 1px solid var(--trap-border);
  color: var(--trap-text);
  font-size: 13px;
  margin-bottom: 14px;
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
  min-width: 0;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.card-title { font-size: 16px; font-weight: 700; margin: 0; }
.card-subtitle { font-size: 12.5px; color: var(--text-muted); margin: 2px 0 0; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

/* Metric Cards */
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.metric-label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; display: flex; justify-content: space-between; }
.metric-value { font-size: 22px; font-weight: 800; margin: 4px 0 2px; line-height: 1.1; }
.metric-sub { font-size: 11.5px; color: var(--text-muted); }

/* Progress Bars */
.prog-bar { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.prog-fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width 0.25s; }
.prog-fill.green { background: #059669; }
.prog-fill.amber { background: #d97706; }

/* Semantic Callouts (Color + Icon + Text Label) */
.callout {
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 0.95em;
}
.callout-tag {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.callout.concept { background: var(--concept-bg); border-color: var(--concept-border); }
.callout.concept .callout-tag { color: var(--concept-text); }
.callout.formula { background: var(--formula-bg); border-color: var(--formula-border); }
.callout.formula .callout-tag { color: var(--formula-text); }
.callout.trap { background: var(--trap-bg); border-color: var(--trap-border); }
.callout.trap .callout-tag { color: var(--trap-text); }
.callout.example { background: var(--example-bg); border-color: var(--example-border); }
.callout.example .callout-tag { color: var(--example-text); }

/* Buttons & Pills */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(0.92); background: var(--accent); }
.btn-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-success { background: #059669; border-color: #059669; color: #fff; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.pill-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  min-height: 32px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.tag.official { background: #dbeafe; color: #1e40af; }
.tag.mock { background: #f3e8ff; color: #6b21a8; }
.tag.trap-tag { background: #fee2e2; color: #991b1b; }
.tag.ok-tag { background: #d1fae5; color: #065f46; }
[data-theme="dark"] .tag.official { background: rgba(59,130,246,0.22); color: #93c5fd; }
[data-theme="dark"] .tag.mock { background: rgba(168,85,247,0.22); color: #d8b4fe; }
[data-theme="dark"] .tag.trap-tag { background: rgba(239,68,68,0.22); color: #fca5a5; }
[data-theme="dark"] .tag.ok-tag { background: rgba(16,185,129,0.22); color: #6ee7b7; }

/* Inputs & Tables */
.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}
.textarea { min-height: 86px; resize: vertical; }

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 10px 0; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
table.data-table th { background: var(--surface-2); font-weight: 700; }

/* 15-Step Pedagogy Accordion & Reader */
.chapter-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}
.ch-chip {
  flex-shrink: 0;
  padding: 6px 11px;
  min-height: 36px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
}
.ch-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.ch-chip.done { border-color: #059669; }

.step-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  margin-bottom: 10px;
  overflow: hidden;
}
.step-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: none;
  cursor: pointer;
  text-align: left;
  font-weight: 700;
  font-size: 14px;
}
.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  flex-shrink: 0;
}
.step-body { padding: 12px 16px; }
.step-body p { margin: 0 0 8px; }
.step-body ul, .step-body ol { margin: 4px 0 8px; padding-left: 20px; }

.slide-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.slide-thumb {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
}
.slide-thumb img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: contain; background: #fff; }
.slide-thumb-cap { padding: 5px 8px; font-size: 11.5px; color: var(--text-muted); }

/* Apple Books Textbook Mode */
.textbook-prose {
  max-width: 760px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  line-height: 1.78;
}

/* Practice & Exam MCQ Options */
.mcq-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  min-height: 46px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.mcq-option:hover { border-color: var(--accent); background: var(--accent-soft); }
.mcq-option.selected { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.mcq-option.correct { border-color: #059669; background: var(--example-bg); }
.mcq-option.wrong { border-color: #dc2626; background: var(--trap-bg); }

/* Study Desk Draggable Split Pane */
.split-desk {
  display: flex;
  gap: 0;
  height: calc(100vh - 130px);
  min-height: 540px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
}
.split-pane {
  overflow-y: auto;
  padding: 14px;
  min-width: 240px;
}
.split-divider {
  width: 10px;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: none;
}
.split-divider::after {
  content: "⋮";
  color: var(--text-muted);
  font-size: 16px;
}

/* Scratchpad Canvas */
.scratchpad-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.scratchpad-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.scratchpad-stage {
  position: relative;
  width: 100%;
  height: 360px;
  background: #ffffff;
  touch-action: none;
}
[data-theme="dark"] .scratchpad-stage { background: #141821; }
.scratchpad-stage canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-dot.active { border-color: var(--accent); transform: scale(1.15); }

/* Interactive Lab Canvas */
.lab-canvas-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  margin: 10px 0;
}
.lab-canvas-box canvas { display: block; width: 100%; border-radius: 6px; background: var(--surface); }
.slider-row {
  display: grid;
  grid-template-columns: 160px 1fr 70px;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
}

/* Open-Book Slide-Over Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 80;
  display: flex;
  justify-content: flex-end;
}
.drawer-panel {
  width: min(520px, 94vw);
  height: 100%;
  background: var(--surface);
  padding: calc(14px + var(--safe-top)) 16px calc(18px + var(--safe-bottom));
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

/* Modal (Global Search / Lightbox / Glossary Tooltip) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 95;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(36px + var(--safe-top)) 14px 20px;
  overflow-y: auto;
}
.modal-card {
  width: min(680px, 100%);
  max-height: 84vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-md);
}

/* Flashcard */
.flashcard {
  min-height: 220px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
}

/* KaTeX overflow safety on narrow iPhone screens */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
  margin: 8px 0 !important;
  max-width: 100%;
}

/* Mobile Bottom Bar & More Sheet (hidden on desktop) */
.mobile-bottom-bar { display: none; }

/* ====== RESPONSIVE BREAKPOINTS ====== */
/* iPad Portrait & Narrow Split View (<= 1024px) */
@media (max-width: 1024px) {
  .sidebar { width: 204px; }
  .main-wrap { margin-left: 204px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Narrow iPad Split View & Mobile Portrait (<= 780px) */
@media (max-width: 780px) {
  .sidebar { display: none; }
  .main-wrap { margin-left: 0; padding-bottom: calc(var(--bottombar-h) + var(--safe-bottom) + 8px); }
  .view-container { padding: 12px 12px 24px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .slider-row { grid-template-columns: 1fr; gap: 4px; }
  .textbook-prose { padding: 16px 14px; }
  .search-kbd { display: none; }
  .search-trigger { max-width: 155px; padding: 6px 10px; }

  /* Auto-collapse Split Desk into vertical tabs on narrow screens */
  .split-desk { flex-direction: column; height: auto; min-height: 0; }
  .split-divider { display: none; }
  .split-pane { width: 100% !important; min-width: 0; border-bottom: 1px solid var(--border); }

  .mobile-bottom-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 60;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + var(--safe-bottom));
    min-height: calc(var(--bottombar-h) + var(--safe-bottom));
  }
  [data-theme="dark"] .mobile-bottom-bar { background: rgba(24, 27, 34, 0.94); }
  .mob-tab {
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 11px;
    font-weight: 600;
    min-height: 48px;
    cursor: pointer;
  }
  .mob-tab .ico { font-size: 18px; line-height: 1; }
  .mob-tab.active { color: var(--accent); }
}

/* iPhone Landscape compact height */
@media (max-height: 450px) and (orientation: landscape) {
  .topbar { min-height: 44px; padding-top: 4px; padding-bottom: 4px; }
  .scratchpad-stage { height: 220px; }
}
