/* Tài Chính Nâng Cao — main.css — theo SPEC.md mục 5 */

/* ===== 5.1 Design tokens ===== */
:root, [data-theme="light"] {
  --bg: #f7f8fa; --surface: #ffffff; --surface-2: #f0f2f5; --border: #dde1e7;
  --text: #1a1f2b; --text-muted: #5b6475; --heading: #0f1420;
  --primary: #1f5eff; --primary-contrast: #ffffff; --primary-soft: #e6edff;
  --accent: #0e9f6e;
  --success: #0e9f6e; --warning: #c27803; --danger: #d92d20; --info: #1f5eff;
  --c1: #1f5eff; --c2: #0e9f6e; --c3: #d92d20; --c4: #c27803; --c5: #7c3aed; --c6: #0891b2;
  --grid: rgba(0,0,0,.08);
  --radius: 10px; --radius-sm: 6px; --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
  --maxw: 1200px; --content-maxw: 780px; --sidebar-w: 280px; --header-h: 60px;
}
[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b22; --surface-2: #1c232d; --border: #2d3643;
  --text: #d7dde6; --text-muted: #8b95a5; --heading: #f0f3f7;
  --primary: #5b8cff; --primary-contrast: #0d1117; --primary-soft: #1a2640;
  --accent: #34d399; --success: #34d399; --warning: #fbbf24; --danger: #f87171; --info: #5b8cff;
  --c1: #5b8cff; --c2: #34d399; --c3: #f87171; --c4: #fbbf24; --c5: #a78bfa; --c6: #22d3ee;
  --grid: rgba(255,255,255,.08);
  --shadow: 0 1px 3px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-sans); line-height: 1.6; font-size: 16px;
  transition: background-color .15s, color .15s;
}
h1, h2, h3, h4 { color: var(--heading); line-height: 1.25; font-weight: 700; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -48px; background: var(--primary); color: var(--primary-contrast);
  padding: 8px 14px; border-radius: var(--radius-sm); z-index: 200; transition: top .15s;
}
.skip-link:focus { top: 8px; }
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
.num, .kpi__value, .data-table td { font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* ===== Header / footer ===== */
.site-header {
  position: sticky; top: 0; z-index: 100; background: var(--surface);
  border-bottom: 1px solid var(--border); height: var(--header-h);
}
.site-header__inner {
  max-width: var(--maxw); margin: 0 auto; height: 100%; padding: 0 20px;
  display: flex; align-items: center; gap: 20px;
}
.site-header__brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--heading); }
.site-header__brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; background: var(--primary); color: var(--primary-contrast);
  font-size: 13px; font-weight: 800;
}
.brand-text { font-size: 15px; }
.site-nav { display: flex; gap: 18px; margin-left: auto; }
.site-nav a { color: var(--text); font-weight: 600; font-size: 14px; }
.theme-toggle {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; width: 36px; height: 36px; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--primary-soft); }
.site-footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 48px; }
.site-footer__inner {
  max-width: var(--maxw); margin: 0 auto; padding: 24px 20px; color: var(--text-muted);
  font-size: 13px; display: flex; flex-direction: column; gap: 6px;
}
.link-btn {
  background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0;
}
.link-btn:hover { text-decoration: underline; }

/* ===== Breadcrumb / layout / sidebar / pager ===== */
.breadcrumb { max-width: var(--maxw); margin: 16px auto 0; padding: 0 20px; }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; font-size: 13px; color: var(--text-muted); }
.breadcrumb li:not(:last-child)::after { content: "›"; margin-left: 6px; }
.breadcrumb li[aria-current="page"] { color: var(--text); font-weight: 600; }

.layout {
  max-width: var(--maxw); margin: 0 auto; padding: 20px; display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: 32px; align-items: start;
}
.sidebar {
  position: sticky; top: calc(var(--header-h) + 16px);
  max-height: calc(100vh - var(--header-h) - 32px); overflow: auto;
}
.sidebar-toggle {
  display: none; width: 100%; margin-bottom: 12px; padding: 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.toc__title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 18px 0 8px; }
.toc:first-child .toc__title { margin-top: 0; }
.toc__list { list-style: none; margin: 0; padding: 0; }
.toc__item a {
  display: flex; gap: 8px; align-items: baseline; padding: 6px 10px; border-radius: var(--radius-sm);
  color: var(--text); font-size: 13.5px;
}
.toc__item a:hover { background: var(--surface-2); text-decoration: none; }
.toc__item--active a { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.toc__item--done .toc__num::after { content: "✓"; color: var(--success); margin-left: 4px; }
.toc__num { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.toc--page a { font-size: 13px; color: var(--text-muted); padding: 4px 10px; }
.toc--page a:hover { color: var(--text); }

.pager {
  max-width: var(--content-maxw); margin: 40px auto 0; display: grid;
  grid-template-columns: 1fr 1fr; gap: 16px;
}
.pager a {
  display: block; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  background: var(--surface); color: var(--text);
}
.pager a:hover { border-color: var(--primary); text-decoration: none; }
.pager__next { text-align: right; }
.pager__dir { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.pager__title { font-weight: 700; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar-toggle { display: block; }
  #course-toc { display: none; }
  .sidebar--open #course-toc { display: block; }
  #page-toc { display: none; }
}

/* ===== Home ===== */
.home { max-width: var(--maxw); margin: 0 auto; padding: 0 20px 60px; }
.hero { padding: 56px 0 32px; text-align: center; }
.hero h1 { font-size: clamp(28px, 5vw, 42px); margin: 0 0 12px; }
.hero__lead { max-width: 640px; margin: 0 auto; color: var(--text-muted); font-size: 17px; }
.hero__actions { margin-top: 24px; display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.hero__stats { margin-top: 28px; max-width: 420px; margin-inline: auto; }
.roadmap { padding: 32px 0; }
.roadmap__tiers { list-style: none; margin: 24px 0 0; padding: 0; display: grid; gap: 20px; }
.roadmap__tier { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--surface); }
.roadmap__tier-title { margin: 0 0 10px; font-size: 15px; }
.roadmap__tier ol { margin: 0; padding-left: 20px; color: var(--text-muted); font-size: 14px; }
.roadmap__tier li { margin-bottom: 4px; }
.roadmap__tier a { color: var(--text); font-weight: 600; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin: 20px 0; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 7px 16px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip--active { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.course-card {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  padding: 18px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
}
.course-card.is-hidden { display: none; }
.course-card__top { display: flex; justify-content: space-between; align-items: center; }
.course-card__num { font-size: 22px; font-weight: 800; color: var(--border); }
.course-card__title { margin: 0; font-size: 17px; }
.course-card__title a { color: var(--heading); }
.course-card__desc { color: var(--text-muted); font-size: 13.5px; margin: 0; flex-grow: 1; }
.course-card__meta { font-size: 12.5px; color: var(--text-muted); margin: 0; }

/* ===== Badges / progress / buttons ===== */
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge--level { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge--done { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); border-color: transparent; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress__bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .2s; }
.progress__label { font-size: 12px; color: var(--text-muted); margin: 6px 0 0; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border-radius: var(--radius-sm); padding: 10px 20px;
  font: inherit; font-weight: 700; font-size: 14.5px; cursor: pointer; border: 1px solid transparent;
}
.btn--primary { background: var(--primary); color: var(--primary-contrast); }
.btn--primary:hover { opacity: .9; text-decoration: none; }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-2); text-decoration: none; }
.btn--sm { padding: 6px 14px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== Course page ===== */
.course-page { max-width: var(--maxw); margin: 0 auto; padding: 0 20px 60px; }
.course-hero { padding: 28px 0; border-bottom: 1px solid var(--border); margin-bottom: 28px; }
.course-hero__eyebrow { color: var(--text-muted); font-size: 13px; margin: 0 0 6px; }
.course-hero h1 { margin: 0 0 10px; }
.course-hero__lead { color: var(--text-muted); max-width: 720px; }
.course-hero__meta { font-size: 13.5px; color: var(--text-muted); }
.course-hero .progress { max-width: 320px; margin: 14px 0 16px; }
.course-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 28px; }
.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 18px 20px; }
.card h2 { font-size: 16px; margin: 0 0 10px; }
.card ul { margin: 0; padding-left: 20px; color: var(--text-muted); font-size: 14px; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { position: relative; padding-left: 26px; margin-bottom: 8px; color: var(--text); font-size: 14px; }
.checklist li::before { content: "✓"; position: absolute; left: 0; color: var(--success); font-weight: 700; }
.lesson-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lesson-list__item a {
  display: flex; align-items: center; gap: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 14px 16px; color: var(--text);
}
.lesson-list__item a:hover { border-color: var(--primary); text-decoration: none; }
.lesson-list__item--done a { border-color: color-mix(in srgb, var(--success) 40%, var(--border)); }
.lesson-list__num { font-weight: 800; color: var(--text-muted); font-variant-numeric: tabular-nums; width: 28px; }
.lesson-list__title { flex-grow: 1; font-weight: 600; }
.lesson-list__status { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
.lesson-list__item--done .lesson-list__status { color: var(--success); font-weight: 700; }
@media (max-width: 700px) { .course-cols { grid-template-columns: 1fr; } }

/* ===== Lesson content ===== */
.content { min-width: 0; }
.lesson { max-width: var(--content-maxw); }
.lesson__header { margin-bottom: 24px; }
.lesson__eyebrow { color: var(--primary); font-weight: 700; font-size: 13px; margin: 0 0 8px; }
.lesson__header h1 { margin: 0 0 8px; font-size: clamp(24px, 4vw, 32px); }
.lesson__meta { color: var(--text-muted); font-size: 13.5px; }
.section { margin: 36px 0; scroll-margin-top: calc(var(--header-h) + 16px); }
.section h2 { font-size: 21px; border-bottom: 2px solid var(--primary-soft); padding-bottom: 8px; margin-bottom: 16px; }
.section h3 { font-size: 16.5px; margin: 20px 0 8px; }
.section p { margin: 0 0 14px; }
.term { border-bottom: 1px dotted var(--text-muted); cursor: help; }

.formula-box {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm); padding: 16px 18px; margin: 0 0 16px; overflow-x: auto;
}
.formula-box__title { font-weight: 700; font-size: 13.5px; color: var(--text-muted); margin: 0 0 8px; text-transform: uppercase; letter-spacing: .02em; }
.formula-box__legend { font-size: 13.5px; color: var(--text-muted); margin: 10px 0 0; }
.katex-display { margin: 0.6em 0; }
.katex { color: var(--text); }

.example {
  background: var(--surface-2); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px;
}
.example__title { font-weight: 700; margin: 0 0 8px; }
.example__given { margin-bottom: 10px; }
.example__steps { margin: 0 0 10px; padding-left: 20px; }
.example__steps li { margin-bottom: 6px; }
.example__result { font-weight: 700; color: var(--primary); }
.example__insight { color: var(--text-muted); font-style: italic; }

.data-table { border-collapse: collapse; width: 100%; font-size: 13.5px; min-width: 480px; }
.data-table th, .data-table td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.data-table th { background: var(--surface-2); font-weight: 700; }

.callout { border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; border: 1px solid; }
.callout ul, .callout p { margin: 0; }
.callout ul { padding-left: 20px; }
.callout li { margin-bottom: 4px; }
.callout--info { background: color-mix(in srgb, var(--info) 8%, var(--surface)); border-color: color-mix(in srgb, var(--info) 30%, var(--border)); }
.callout--tip { background: color-mix(in srgb, var(--success) 8%, var(--surface)); border-color: color-mix(in srgb, var(--success) 30%, var(--border)); }
.callout--warn { background: color-mix(in srgb, var(--warning) 10%, var(--surface)); border-color: color-mix(in srgb, var(--warning) 35%, var(--border)); }

/* ===== Calculator ===== */
.calc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.calc__intro { color: var(--text-muted); font-size: 14px; }
.calc__inputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin: 14px 0; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.field--wide { grid-column: 1 / -1; }
.field__label { font-weight: 600; color: var(--text); }
.field__hint { color: var(--text-muted); font-size: 11.5px; }
.field input, .field select, .field textarea {
  font: inherit; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); width: 100%;
}
.field textarea { resize: vertical; min-height: 46px; font-family: var(--font-mono); font-size: 12.5px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.calc__outputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin: 14px 0; }
.kpi { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.kpi__label { display: block; font-size: 11.5px; color: var(--text-muted); margin-bottom: 4px; }
.kpi__value { display: block; font-size: 19px; font-weight: 800; color: var(--heading); }
.kpi--good .kpi__value { color: var(--success); }
.kpi--bad .kpi__value { color: var(--danger); }
.kpi--neutral .kpi__value { color: var(--text); }
.calc__error {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 13.5px; margin: 10px 0;
}
.calc__note { font-size: 12.5px; color: var(--text-muted); margin-top: 10px; }
.chart-box { position: relative; height: 320px; margin-top: 14px; }
.chart-fallback { color: var(--text-muted); font-size: 13px; text-align: center; padding: 40px 0; }
.heatmap { border-collapse: collapse; width: 100%; font-size: 13px; text-align: center; }
.heatmap th, .heatmap td { border: 1px solid var(--border); padding: 8px; }
.heatmap th { background: var(--surface-2); }
.heatmap__cell--base { outline: 2px solid var(--primary); outline-offset: -2px; font-weight: 800; }

/* ===== Quiz ===== */
.quiz__score-prev { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.quiz__q {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px;
  background: var(--surface);
}
.quiz__q-title { font-weight: 700; margin-bottom: 10px; padding: 0; }
.quiz__opts { display: grid; gap: 8px; }
.quiz__opt {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); cursor: pointer; font-size: 14px;
}
.quiz__opt:hover { background: var(--surface-2); }
.quiz__opt input { margin-top: 3px; }
.quiz__opt--correct { border-color: var(--success); background: color-mix(in srgb, var(--success) 12%, var(--surface)); }
.quiz__opt--wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.quiz__explain { margin-top: 10px; font-size: 13px; color: var(--text-muted); background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius-sm); display: none; }
.quiz__q--revealed .quiz__explain { display: block; }
.quiz__actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.quiz__score { font-weight: 800; font-size: 15px; }
.quiz__score--pass { color: var(--success); }
.quiz__score--fail { color: var(--danger); }

@media print {
  .site-header, .sidebar, .pager, .theme-toggle, .quiz__actions, .calc { display: none !important; }
}
