/* ── BEPS & Pillar Two Notes — styles.css ── */

/* ─── DARK MODE (Default) ─── */
:root {
  --bg:           #09090b;
  --surface:      #111113;
  --card:         #18181b;
  --border:       #27272a;
  --border-light: #3f3f46;
  --text:         #fafafa;
  --muted:        #a1a1aa;
  --dim:          #52525b;
  --shadow:       0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.5);

  --accent:  #6366f1;
  --accent2: #818cf8;
  --accent3: #a5b4fc;
  --green:   #22c55e;
  --amber:   #f59e0b;
  --coral:   #f97316;
  --pink:    #ec4899;
  --teal:    #14b8a6;

  --radius:    4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --topbar-height: 40px;
}

/* ─── LIGHT MODE ─── */
.light, [data-theme="light"] {
  --bg:           #fafaf9;
  --surface:      #f4f4f5;
  --card:         #ffffff;
  --border:       #e4e4e7;
  --border-light: #d4d4d8;
  --text:         #09090b;
  --muted:        #52525b;
  --dim:          #a1a1aa;
  --shadow:       0 1px 3px rgba(0,0,0,0.06);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.08);
  --green-text: #15803d;
  --amber-text: #b45309;
  --coral-text: #c2410c;
  --teal-text:  #0f766e;
}

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

html { font-size: 16px; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ── Topbar ── */
.site-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.topbar-inner {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.topbar-logo-mark {
  width: 24px; height: 24px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
}

.topbar-logo-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  overflow: hidden;
}

.topbar-bc-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s;
}
.topbar-bc-link:hover { color: var(--text); }

.topbar-bc-sep {
  font-size: 12px;
  color: var(--dim);
  flex-shrink: 0;
}

.topbar-bc-current {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  transition: all .15s;
  flex-shrink: 0;
}
.topbar-theme-toggle:hover { color: var(--text); border-color: var(--border-light); }

.icon-light { display: none; }
.icon-dark  { display: inline; }
.light .icon-dark  { display: none; }
.light .icon-light { display: inline; }

.topbar-request {
  font-size: 12px;
  padding: 4px 10px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  text-decoration: none;
  white-space: nowrap;
  transition: opacity .15s;
  flex-shrink: 0;
}
.topbar-request:hover { opacity: .85; }

/* ── App layout ── */
.app-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height));
  margin-top: var(--topbar-height);
}

/* ── Sidebar ── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  height: calc(100vh - var(--topbar-height));
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-label {
  padding: 12px 14px 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#toc-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
#toc-nav::-webkit-scrollbar { width: 3px; }
#toc-nav::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }
#toc-nav::-webkit-scrollbar-track { background: transparent; }

a.toc-header, a.toc-sub { text-decoration: none; color: inherit; display: flex; }

.toc-item { border-bottom: 1px solid var(--border); }

.toc-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, background .15s;
  text-decoration: none;
}
.toc-header:hover { color: var(--text); background: rgba(255,255,255,.03); }
.light .toc-header:hover { background: rgba(0,0,0,.03); }
.toc-header.active { color: var(--accent); background: rgba(99,102,241,.07); border-left: 2px solid var(--accent); }

.toc-icon { font-size: 14px; flex-shrink: 0; }
.toc-label { flex: 1; }
.toc-chevron {
  font-size: 8px;
  color: var(--dim);
  transition: transform .2s ease;
  flex-shrink: 0;
  margin-top: 1px;
}
.toc-item.open .toc-chevron { transform: rotate(90deg); }

.toc-subs { display: none; }
.toc-item.open .toc-subs { display: block; }

.toc-sub {
  display: block;
  padding: 7px 14px 7px 36px;
  font-size: 12px;
  color: var(--dim);
  text-decoration: none;
  transition: color .15s, background .15s;
}
.toc-sub:hover { color: var(--muted); background: rgba(255,255,255,.02); }
.light .toc-sub:hover { background: rgba(0,0,0,.02); }
.toc-sub.active { color: var(--accent2); font-weight: 500; }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--dim);
  margin-bottom: 5px;
}

.progress-bar {
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width .4s ease;
}

/* ── Main content ── */
.main-content {
  flex: 1;
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  padding: 32px 48px 64px;
}

.main-header {
  padding: 0 0 0;
  max-width: 960px;
  margin: 0 auto 4px;
}

.breadcrumb {
  font-size: 12px;
  color: var(--dim);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.breadcrumb .bc-active { color: var(--muted); }

.content-container {
  max-width: 960px;
  margin: 0 auto;
  padding-top: 20px;
}

/* ── Typography ── */
h1, h2 { font-size: 26px; font-weight: 700; margin-bottom: 8px; color: var(--text); line-height: 1.3; }
h2 { font-size: 22px; }
h3 { font-size: 17px; font-weight: 600; margin: 28px 0 10px; color: var(--text); }
h4 { font-size: 14px; font-weight: 600; margin: 20px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { font-size: 15px; color: var(--muted); line-height: 1.7; margin-bottom: 14px; }
strong { color: var(--text); font-weight: 600; }
em { color: var(--accent3); font-style: italic; }

ul, ol { padding-left: 20px; margin-bottom: 14px; }
li { font-size: 15px; color: var(--muted); line-height: 1.7; margin-bottom: 4px; }
li strong { color: var(--text); }

/* ── Difficulty badges ── */
.difficulty-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  margin-bottom: 20px;
  margin-top: 4px;
}
.difficulty-badge.beginner    { background: rgba(34,197,94,.12);  color: var(--green); border: 1px solid rgba(34,197,94,.25); }
.difficulty-badge.intermediate{ background: rgba(245,158,11,.12); color: var(--amber); border: 1px solid rgba(245,158,11,.25); }
.difficulty-badge.advanced    { background: rgba(249,115,22,.12); color: var(--coral); border: 1px solid rgba(249,115,22,.25); }
.difficulty-badge.expert      { background: rgba(239,68,68,.12);  color: #ef4444;      border: 1px solid rgba(239,68,68,.25); }

/* ── Stat grid ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 24px 0;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  border-top: 3px solid var(--accent);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--sv-color, var(--accent2));
  margin-bottom: 4px;
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.stat-sub {
  font-size: 11px;
  color: var(--dim);
  margin-top: 2px;
}

/* ── Tables ── */
.table-wrapper { overflow-x: auto; margin: 20px 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
thead th {
  background: var(--surface);
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  vertical-align: top;
  line-height: 1.5;
}
tr:hover td { background: rgba(255,255,255,.02); }
.light tr:hover td { background: rgba(0,0,0,.02); }
tbody td strong { color: var(--text); }

/* ── Formula block ── */
.formula-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin: 20px 0;
}
.formula-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--dim);
  margin-bottom: 8px;
}
.formula-body {
  color: var(--text);
  font-size: 15px;
  font-style: italic;
  line-height: 1.6;
}

/* ── Callout boxes ── */
.callout {
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin: 20px 0;
  border: 1px solid;
  font-size: 14px;
  line-height: 1.6;
}
.callout-info    { background: rgba(99,102,241,.08);  border-color: rgba(99,102,241,.3);  color: var(--accent3); }
.callout-success { background: rgba(34,197,94,.08);   border-color: rgba(34,197,94,.3);   color: var(--green); }
.callout-warning { background: rgba(245,158,11,.08);  border-color: rgba(245,158,11,.3);  color: var(--amber); }
.callout-danger  { background: rgba(249,115,22,.08);  border-color: rgba(249,115,22,.3);  color: var(--coral); }
.callout strong  { font-weight: 700; display: block; margin-bottom: 4px; }
.callout p { color: inherit; margin-bottom: 0; font-size: 14px; }

/* ── Mental model box ── */
.mental-model {
  background: rgba(99,102,241,.06);
  border: 1px solid rgba(99,102,241,.25);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin: 20px 0;
}
.mental-model-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent2);
  margin-bottom: 8px;
}
.mental-model p { color: var(--muted); margin-bottom: 0; font-size: 14px; }

/* ── Diagram / Code block ── */
.diagram, .code-block {
  background: #18181b;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin: 20px 0;
  overflow-x: auto;
}
.diagram pre, .code-block code {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  color: #a1a1aa;
  white-space: pre;
  line-height: 1.6;
}
.light .diagram, .light .code-block { background: #18181b; border-color: #27272a; }
.light .diagram pre, .light .code-block code { color: #a1a1aa; }

/* ── Country tabs ── */
.country-tabs {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.country-tab-btns {
  display: flex;
  flex-wrap: wrap;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.country-tab-btn {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.country-tab-btn:hover { color: var(--text); background: rgba(255,255,255,.03); }
.light .country-tab-btn:hover { background: rgba(0,0,0,.03); }
.country-tab-btn.active { color: var(--accent); border-bottom: 2px solid var(--accent); background: rgba(99,102,241,.06); }
.country-tab-panel { display: none; padding: 16px 20px; }
.country-tab-panel.active { display: block; }
.country-tab-panel p { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.country-tab-panel ul { margin-bottom: 10px; }
.country-tab-panel li { font-size: 14px; }

/* ── Expandable ── */
.expandable {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin: 10px 0;
  overflow: hidden;
}
.expandable-trigger {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border: none;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  transition: background .15s;
}
.expandable-trigger:hover { background: rgba(255,255,255,.03); }
.light .expandable-trigger:hover { background: rgba(0,0,0,.03); }
.expandable-icon { font-size: 11px; color: var(--dim); transition: transform .2s; }
.expandable.open .expandable-icon { transform: rotate(180deg); }
.expandable-content { display: none; padding: 14px 16px; border-top: 1px solid var(--border); font-size: 14px; color: var(--muted); line-height: 1.65; }
.expandable.open .expandable-content { display: block; }

/* ── Quiz components ── */
.topic-quick-check { margin-top: 40px; padding-top: 32px; border-top: 1px solid var(--border); }
.topic-quick-check h3 { margin-bottom: 4px; }

.mini-quiz-section { margin-top: 40px; padding-top: 32px; border-top: 1px solid var(--border); }
.mini-quiz-section h3 { margin-bottom: 4px; }
.mini-quiz-block { margin-bottom: 32px; }
.mini-quiz-block h4, .knowledge-check-block h4 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-bottom: 16px;
}

.quiz-question { margin-bottom: 24px; }
.quiz-q { font-size: 15px; font-weight: 500; color: var(--text); margin-bottom: 12px; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }

.quiz-opt {
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: all .15s;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.quiz-question.answered .quiz-opt { pointer-events: none; }
.quiz-opt.correct { border-color: var(--green); background: rgba(34,197,94,.08); color: var(--green); }
.quiz-opt.wrong   { border-color: var(--coral); background: rgba(249,115,22,.08); color: var(--coral); }

.quiz-explain {
  display: none;
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(99,102,241,.06);
  border: 1px solid rgba(99,102,241,.2);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--muted);
  line-height: 1.65;
}
.quiz-question.answered .quiz-explain { display: block; }
.quiz-explain strong { color: var(--accent2); }
.quiz-explain em { color: var(--accent3); font-style: italic; }

/* Knowledge Check */
.kc-item { border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 10px; overflow: hidden; }
.kc-question {
  width: 100%; display: flex; justify-content: space-between; align-items: flex-start;
  padding: 12px 16px; background: var(--surface); border: none; cursor: pointer;
  text-align: left; gap: 12px;
}
.kc-question:hover { background: rgba(99,102,241,.05); }
.light .kc-question:hover { background: rgba(99,102,241,.04); }
.kc-q-text { font-size: 14px; color: var(--text); font-weight: 500; line-height: 1.5; }
.kc-toggle { font-size: 11px; color: var(--muted); flex-shrink: 0; margin-top: 3px; transition: transform .2s; }
.kc-item.open .kc-toggle { transform: rotate(180deg); }
.kc-answer {
  display: none; padding: 14px 16px; border-top: 1px solid var(--border);
  background: var(--bg); font-size: 14px; line-height: 1.65; color: var(--text);
}
.kc-item.open .kc-answer { display: block; }
.kc-answer p { color: var(--muted); margin-bottom: 8px; font-size: 14px; }
.kc-answer strong { color: var(--text); }

/* ── Subtopic navigation ── */
.subtopic-nav {
  margin-top: 36px;
  padding: 14px 0 10px;
  border-top: 1px solid var(--border);
}
.subtopic-nav-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 8px;
}
.subtopic-nav-links { display: flex; flex-wrap: wrap; gap: 6px; }
.subtopic-nav-link {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: color .15s, border-color .15s;
}
.subtopic-nav-link:hover { color: var(--text); border-color: var(--accent); }
.subtopic-nav-link.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(99,102,241,.07);
  font-weight: 500;
  pointer-events: none;
}

.topic-nav-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}
.topic-nav-prev, .topic-nav-next {
  font-size: 13px;
  color: var(--accent2);
  text-decoration: none;
  transition: color .15s;
}
.topic-nav-prev:hover, .topic-nav-next:hover { color: var(--accent); }
.topic-nav-next { margin-left: auto; }

/* ── Cheatsheet sections ── */
.cheatsheet-section {
  margin-bottom: 36px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.cheatsheet-section h3 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent2);
  margin-bottom: 16px;
}

/* ── Related topics ── */
.related-topics { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border); }
.related-topics h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); margin-bottom: 10px; }
.related-list { display: flex; flex-wrap: wrap; gap: 8px; }
.related-link {
  display: inline-block;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--accent2);
  text-decoration: none;
  transition: all .15s;
}
.related-link:hover { border-color: var(--accent); color: var(--accent); }

/* ── Mobile ── */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: calc(var(--topbar-height) + 12px);
  right: 0;
  z-index: 90;
  background: var(--surface);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 20px 0 0 20px;
  padding: 8px 10px 8px 12px;
  cursor: pointer;
  color: var(--accent);
}
.mobile-nav-icon { width: 18px; height: 18px; display: block; }

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 80;
  top: var(--topbar-height);
}
#sidebar-overlay.active { display: block; }

@media (max-width: 767px) {
  .mobile-nav-toggle { display: flex; align-items: center; }

  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: -260px;
    bottom: 0;
    z-index: 85;
    transition: left .25s ease;
  }
  .sidebar.open { left: 0; }

  .main-content { padding: 20px 18px 80px; }
  .main-header { padding: 0; }

  .topbar-breadcrumb { display: none; }

  .stat-grid { grid-template-columns: 1fr 1fr; }

  .topic-nav-footer { flex-direction: column; }
  .topic-nav-prev, .topic-nav-next {
    display: block;
    width: 100%;
    text-align: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    margin-left: 0;
  }
}
