/* ===== Tokens ===== */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e3e6ea;
  --border-strong: #cfd4da;
  --text: #1c2127;
  --text-dim: #5b6470;
  --text-faint: #8a929c;
  --accent: #2f6df0;
  --accent-soft: #e8f0fe;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .10);

  /* status */
  --st-chua: #9aa3ad;        --st-chua-bg: transparent;
  --st-xemlai: #c77d11;      --st-xemlai-bg: #fdf3e3;
  --st-ok: #1f9d57;          --st-ok-bg: #e7f7ee;
  --st-cansua: #d8443c;      --st-cansua-bg: #fdeceb;

  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1b212b;
  --border: #2a313c;
  --border-strong: #3a434f;
  --text: #e6e9ee;
  --text-dim: #a7b0bb;
  --text-faint: #6e7884;
  --accent: #5b8cff;
  --accent-soft: #1b2a4a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);

  --st-chua: #6e7884;        --st-chua-bg: transparent;
  --st-xemlai: #e0a64a;      --st-xemlai-bg: #2e2410;
  --st-ok: #43c483;          --st-ok-bg: #112a1d;
  --st-cansua: #f0726a;      --st-cansua-bg: #2e1513;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
#content-store { display: none; }

/* ===== Header ===== */
header.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
header .brand { font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
header .brand small { font-weight: 500; color: var(--text-faint); font-size: 12px; margin-left: 6px; }
header .spacer { flex: 1; }
.who { font-size: 13px; color: var(--text-dim); }
.who b { color: var(--text); }
.who .role-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; margin-left: 4px; font-size: 11px; }
.linklike { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.linklike:hover { text-decoration: underline; }
.iconbtn {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  width: 34px; height: 34px; cursor: pointer; font-size: 15px; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}
.iconbtn:hover { border-color: var(--border-strong); }

/* ===== Layout ===== */
.app { display: flex; height: calc(100vh - 55px); }
.sidebar {
  width: 320px; min-width: 240px; flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 12px 8px 40px;
}
#sidebar-resizer { width: 6px; flex-shrink: 0; cursor: col-resize; background: transparent; transition: background .12s; }
#sidebar-resizer:hover, #sidebar-resizer.dragging { background: var(--accent); }
.main { flex: 1; overflow-y: auto; min-width: 0; }
.main-inner { max-width: 920px; margin: 0 auto; padding: 18px 24px 80px; }

/* ===== Tree ===== */
#name-mode { display: flex; align-items: center; gap: 8px; padding: 4px 8px 10px; margin-bottom: 6px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
#name-mode .nm-label { font-size: 12px; color: var(--text-faint); }
.nm-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.nm-seg button { border: none; background: var(--surface); color: var(--text-dim); cursor: pointer; padding: 3px 10px; font-size: 12.5px; border-right: 1px solid var(--border); }
.nm-seg button:last-child { border-right: none; }
.nm-seg button:hover { background: var(--surface-2); }
.nm-seg button.on { background: var(--accent); color: #fff; font-weight: 600; }

.tree-grade { margin-bottom: 4px; }
.tree-grade > .row, .tree-bai > .row, .tree-node {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px; cursor: pointer; user-select: none;
}
.tree-grade > .row:hover, .tree-bai > .row:hover, .tree-node:hover { background: var(--surface-2); }
.tree-grade > .row { font-weight: 650; }
.tree-disabled > .row { cursor: default; color: var(--text-faint); }
.tree-disabled > .row:hover { background: transparent; }
.caret { width: 14px; color: var(--text-faint); transition: transform .12s; font-size: 11px; }
.collapsed .caret { transform: rotate(-90deg); }
.collapsed .children { display: none; }
.children { margin-left: 14px; border-left: 1px solid var(--border); padding-left: 6px; }
.tree-bai > .row { font-size: 14px; color: var(--text-dim); }
.tree-chuong > .row { font-size: 13px; font-weight: 650; color: var(--text-dim); }
.chuong-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-node { font-size: 14px; padding-left: 10px; }
.tree-node.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-node .num { width: 18px; text-align: center; flex-shrink: 0; }
.nlabel { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-progress { font-size: 11px; color: var(--text-faint); display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.node-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--st-chua); }
.node-dot.done { background: var(--st-ok); }
.node-dot.warn { background: var(--st-xemlai); }
.node-dot.fix { background: var(--st-cansua); }
.badge-grade { font-size: 10px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-faint); }

.special-node { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }

/* ===== Toolbar (progress) ===== */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg); padding: 14px 24px 12px;
  border-bottom: 1px solid var(--border);
}
.toolbar-inner { max-width: 920px; margin: 0 auto; }
.progress-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.progress-bar-wrap { flex: 1; min-width: 160px; height: 9px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; display: flex; }
.progress-seg { height: 100%; }
.progress-seg.ok { background: var(--st-ok); }
.progress-seg.fix { background: var(--st-cansua); }
.progress-seg.warn { background: var(--st-xemlai); }
.progress-label { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.progress-label b { color: var(--text); }
.counts { display: flex; gap: 10px; font-size: 12.5px; color: var(--text-dim); flex-wrap: wrap; }
.counts span b { color: var(--text); }
.btn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.filter-row { margin-top: 10px; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); flex-wrap: wrap; }
.chip-filter {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  border-radius: 999px; padding: 3px 11px; font-size: 12.5px; cursor: pointer;
}
.chip-filter.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ===== Node header ===== */
.node-head { margin-bottom: 8px; }
.node-head h1 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.3px; }
.node-head .crumb { font-size: 12.5px; color: var(--text-faint); }
.node-head .source { font-size: 11.5px; color: var(--text-faint); font-family: var(--mono); margin-top: 4px; word-break: break-all; }
.lvl-chip { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); margin-left: 6px; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 14px 0 4px; flex-wrap: wrap; }
.tab {
  border: none; background: none; cursor: pointer; padding: 8px 14px; font-size: 14px;
  color: var(--text-dim); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab .tcount { font-size: 11px; color: var(--text-faint); margin-left: 4px; }

/* ===== Section card ===== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--st-chua);
  border-radius: 10px; margin: 14px 0; box-shadow: var(--shadow); overflow: hidden;
}
.card.st-xem_lai { border-left-color: var(--st-xemlai); }
.card.st-ok { border-left-color: var(--st-ok); }
.card.st-can_sua { border-left-color: var(--st-cansua); }
.card.st-ok.dim { opacity: .62; }

.card-head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px 8px; }
.card-head h3 { font-size: 15.5px; margin: 0; flex: 1; line-height: 1.4; }
.kind-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; padding: 1px 7px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-faint); white-space: nowrap; }
.kind-tag.question { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.kind-tag.method { color: #7a5af5; }
.kind-tag.pitfall { color: var(--st-cansua); }
.kind-tag.sample { color: var(--st-ok); }
.kind-tag.gap { background: var(--accent); color: #fff; border-color: transparent; }
.kind-tag.dang { color: #0d9488; }

/* gap card — "Báo thiếu": viền đứt + header nền accent để nổi bật là chỗ đề xuất */
.card.gap-card { border-left-style: dashed; }
.card.gap-card .card-head { background: var(--accent-soft); }
.badge-lvl { font-size: 10px; padding: 1px 7px; border-radius: 4px; border: 1px solid var(--border); color: var(--text-dim); white-space: nowrap; }

/* status selector */
.status-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.status-seg button { border: none; background: var(--surface); color: var(--text-dim); cursor: pointer; padding: 4px 9px; font-size: 12.5px; border-right: 1px solid var(--border); }
.status-seg button:last-child { border-right: none; }
.status-seg button:hover { background: var(--surface-2); }
.status-seg button.on[data-s="xem_lai"] { background: var(--st-xemlai-bg); color: var(--st-xemlai); font-weight: 700; }
.status-seg button.on[data-s="ok"] { background: var(--st-ok-bg); color: var(--st-ok); font-weight: 700; }
.status-seg button.on[data-s="can_sua"] { background: var(--st-cansua-bg); color: var(--st-cansua); font-weight: 700; }
.status-seg button.on[data-s="chua_xem"] { background: var(--surface-2); color: var(--text); font-weight: 700; }

.coverage { padding: 0 16px 6px; font-size: 11.5px; color: var(--text-faint); display: flex; gap: 10px; }

/* body */
.md-body { padding: 4px 16px 8px; overflow-x: auto; }
.md-body p { margin: .5em 0; }
.md-body ul, .md-body ol { margin: .4em 0; padding-left: 1.4em; }
.md-body li { margin: .2em 0; }
.md-body strong { color: var(--text); }
.md-body table { border-collapse: collapse; width: 100%; font-size: 13px; margin: .4em 0; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; vertical-align: top; }
.md-body th { background: var(--surface-2); }
.md-body code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: .9em; }
.md-body blockquote { border-left: 3px solid var(--border-strong); margin: .5em 0; padding: .1em 12px; color: var(--text-dim); }
.katex-display { margin: .5em 0; overflow-x: auto; overflow-y: hidden; }

/* feedback */
.fb-wrap { border-top: 1px dashed var(--border); background: var(--surface-2); padding: 10px 16px 12px; }
.fb-title { font-size: 12px; color: var(--text-faint); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .4px; }
.fb-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px; margin-bottom: 8px; }
.fb-meta { font-size: 12px; color: var(--text-faint); margin-bottom: 3px; }
.fb-meta b { color: var(--text); }
.fb-meta .role-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; font-size: 10.5px; margin-left: 4px; }
.fb-content { white-space: pre-wrap; font-size: 14px; }
.fb-empty { font-size: 13px; color: var(--text-faint); font-style: italic; margin-bottom: 8px; }
.fb-add { display: flex; gap: 8px; align-items: flex-end; }
.fb-add textarea {
  flex: 1; resize: vertical; min-height: 38px; max-height: 200px;
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px;
  font-family: var(--sans); font-size: 14px; background: var(--surface); color: var(--text);
}
.fb-add textarea:focus { outline: none; border-color: var(--accent); }

/* summary view */
.summary-block { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin: 14px 0; box-shadow: var(--shadow); }
.summary-block h3 { margin: 0 0 4px; font-size: 15px; }
.summary-block .jump { font-size: 12px; }
.empty-state { color: var(--text-faint); text-align: center; padding: 60px 20px; }

/* ===== Modal ===== */
.modal-bg { position: fixed; inset: 0; background: rgba(10,14,20,.55); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px 24px; width: min(420px, 92vw); box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: var(--text-dim); font-size: 13.5px; }
.modal label { font-size: 12.5px; color: var(--text-dim); display: block; margin-bottom: 4px; }
.modal input { width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 14px; margin-bottom: 12px; background: var(--surface); color: var(--text); }
.modal input:focus { outline: none; border-color: var(--accent); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ===== Toast ===== */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #21262e; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.3); opacity: 0; transform: translateY(8px); transition: all .2s; }
.toast.show { opacity: 1; transform: translateY(0); }

/* ===== Resume banner ===== */
.resume-banner { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.resume-banner .rb-text { flex: 1; color: var(--text); }
.resume-banner button.close { margin-left: 4px; }

/* section highlight on jump */
.card.flash { animation: flash 1.4s ease; }
@keyframes flash { 0%,100% { box-shadow: var(--shadow); } 25% { box-shadow: 0 0 0 3px var(--accent); } }

@media (max-width: 720px) {
  .sidebar { position: fixed; left: 0; top: 55px; bottom: 0; z-index: 25; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .main-inner, .toolbar-inner { padding-left: 14px; padding-right: 14px; }
  #menu-toggle { display: inline-flex; }
  #sidebar-resizer { display: none; }
}
#menu-toggle { display: none; }
