/* ===== Màu sắc: xám than + xanh ngọc ===== */
:root {
  --bg: #f3f5f5;
  --surface: #ffffff;
  --surface-2: #f7f9f9;
  --line: #e1e6e6;
  --text: #1f2629;
  --muted: #5d6b70;
  --nav-bg: #1f2629;
  --nav-text: #c9d3d5;
  --nav-active: #2dd4bf;
  --accent: #0d9488;
  --accent-strong: #0f766e;
  --accent-soft: #ccfbf1;
  --ok: #15803d; --ok-soft: #dcfce7;
  --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2;
  --info: #1d4ed8; --info-soft: #dbeafe;
  --draft: #6b21a8; --draft-soft: #f3e8ff;
  --shadow: 0 1px 2px rgba(16, 24, 27, .06), 0 4px 14px rgba(16, 24, 27, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a1c; --surface: #1e2427; --surface-2: #232b2e; --line: #313b3f;
    --text: #e6ecec; --muted: #9fb0b4; --nav-bg: #101416; --nav-text: #b3c1c4;
    --accent: #2dd4bf; --accent-strong: #5eead4; --accent-soft: #134e4a;
    --ok: #4ade80; --ok-soft: #14532d; --warn: #fbbf24; --warn-soft: #422006;
    --bad: #f87171; --bad-soft: #450a0a; --info: #93c5fd; --info-soft: #172554;
    --draft: #d8b4fe; --draft-soft: #3b0764;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151a1c; --surface: #1e2427; --surface-2: #232b2e; --line: #313b3f;
  --text: #e6ecec; --muted: #9fb0b4; --nav-bg: #101416; --nav-text: #b3c1c4;
  --accent: #2dd4bf; --accent-strong: #5eead4; --accent-soft: #134e4a;
  --ok: #4ade80; --ok-soft: #14532d; --warn: #fbbf24; --warn-soft: #422006;
  --bad: #f87171; --bad-soft: #450a0a; --info: #93c5fd; --info-soft: #172554;
  --draft: #d8b4fe; --draft-soft: #3b0764;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }

/* ===== Khung ===== */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.nav {
  background: var(--nav-bg); color: var(--nav-text); padding: 22px 14px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px;
}
.brand { display: flex; gap: 12px; align-items: center; color: #fff; text-decoration: none; padding: 0 8px; }
.brand b { display: block; font-size: 16px; }
.brand small { display: block; color: var(--nav-text); font-size: 12px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: #2b3438; display: grid; place-items: center; }
.brand-mark svg { width: 24px; height: 24px; stroke: #2dd4bf; }
.menu { display: flex; flex-direction: column; gap: 4px; }
.menu a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--nav-text); text-decoration: none; font-weight: 500;
}
.menu a:hover { background: #2a3337; color: #fff; }
.menu a.active { background: rgba(45, 212, 191, .14); color: var(--nav-active); }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.btn-ghost {
  display: flex; align-items: center; gap: 10px; background: transparent; border: 1px solid #364145;
  color: var(--nav-text); padding: 9px 12px; border-radius: 10px; cursor: pointer;
}
.btn-ghost:hover { color: #fff; border-color: #4b585d; }
.cap-nhat { font-size: 12px; margin: 0; padding: 0 4px; }
.cap-nhat b { color: #fff; }

.main { padding: 28px 32px 48px; min-width: 0; max-width: 1280px; width: 100%; }
.view { display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.sub { margin: 4px 0 0; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12.5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ===== Ô số liệu ===== */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 4px;
  border-top: 3px solid var(--k, var(--accent));
}
.kpi:hover { border-color: var(--k, var(--accent)); }
.kpi .n { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 13px; }

/* ===== Biểu đồ ===== */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 34px; gap: 10px; align-items: center; background: none; border: 0; padding: 2px 0; text-align: left; cursor: pointer; color: inherit; }
.bar .t { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .track { height: 12px; background: var(--surface-2); border-radius: 0 6px 6px 0; overflow: hidden; }
.bar .track, .bar .fill { display: block; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 0 6px 6px 0; min-width: 3px; }
.bar:hover .fill { background: var(--accent-strong); }
.bar .v { font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; color: var(--muted); }
.cols { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 18px; overflow-x: auto; }
.col { flex: 1 0 26px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; background: none; border: 0; cursor: pointer; color: inherit; padding: 0; }
.col .fill { width: 100%; max-width: 34px; background: var(--accent); border-radius: 5px 5px 0 0; min-height: 3px; }
.col:hover .fill { background: var(--accent-strong); }
.col .v { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.col .t { font-size: 11px; color: var(--muted); }

/* ===== Mốc thời gian ===== */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { display: grid; grid-template-columns: 86px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.timeline li:last-child { border-bottom: 0; }
.timeline li:hover .tl-title { color: var(--accent); }
.tl-date { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tl-date small { display: block; font-weight: 500; }
.tl-title { font-size: 13.5px; }
.tl-title b { font-weight: 600; }

/* ===== Lưới lĩnh vực ===== */
.lv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.lv-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--surface-2); cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; color: inherit; }
.lv-card:hover { border-color: var(--accent); }
.lv-card b { font-size: 14.5px; }
.lv-card span { color: var(--muted); font-size: 12.5px; }
.lv-card .n { color: var(--accent); font-weight: 700; font-size: 13px; }

/* ===== Tìm kiếm & lọc ===== */
.quick-search, .search-big { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; }
.quick-search { min-width: 300px; }
.quick-search input, .search-big input { border: 0; outline: 0; background: transparent; padding: 11px 0; width: 100%; min-width: 0; }
.search-big { background: var(--surface-2); }
.search-big input { font-size: 16px; padding: 13px 0; }
.quick-search:focus-within, .search-big:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.quick-search svg, .search-big svg { color: var(--muted); }
.filters { display: flex; flex-direction: column; gap: 14px; }
.filter-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.filter-row label, .select-wide { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); min-width: 0; }
select { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; width: 100%; min-width: 0; color: var(--text); }
select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filter-foot { display: flex; justify-content: space-between; align-items: center; }
.count { font-weight: 600; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; }
.actions { display: flex; gap: 8px; }
.btn { display: inline-flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn svg { width: 18px; height: 18px; }

/* ===== Danh sách văn bản ===== */
.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--s, var(--accent)); border-radius: 12px; padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; text-align: left; width: 100%; color: inherit; }
.doc:hover { border-color: var(--accent); border-left-color: var(--s, var(--accent)); }
.doc-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.doc-so { font-weight: 700; font-size: 14px; }
.doc-ten { font-size: 15px; font-weight: 500; }
.doc-tom { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
mark { background: var(--warn-soft); color: inherit; border-radius: 3px; padding: 0 1px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-soft); }
.badge.bad { color: var(--bad); background: var(--bad-soft); }
.badge.soon { color: var(--info); background: var(--info-soft); }
.badge.part { color: var(--warn); background: var(--warn-soft); }
.badge.draft { color: var(--draft); background: var(--draft-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.plain { color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); }
.badge.plain::before, .badge.warn::before { display: none; }

/* ===== Hộp chi tiết ===== */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px; overflow-y: auto; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 16, .55); }
.modal-box { position: relative; background: var(--surface); border-radius: 16px; max-width: 820px; width: 100%; padding: 26px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-close { position: absolute; top: 14px; right: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; }
.md-head { display: flex; flex-direction: column; gap: 8px; padding-right: 44px; margin-bottom: 18px; }
.md-head h2 { font-size: 21px; font-weight: 700; }
.md-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 18px; }
.md-grid div { background: var(--surface-2); padding: 10px 12px; }
.md-grid dt { font-size: 12px; color: var(--muted); }
.md-grid dd { margin: 2px 0 0; font-weight: 600; font-size: 14px; }
.md-sec { margin-bottom: 16px; }
.md-sec h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.md-sec p { margin: 0; }
.dk { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.dk li { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.dk b { color: var(--accent); }
.rel { display: flex; flex-direction: column; gap: 6px; }
.rel button { text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; color: inherit; }
.rel button:hover { border-color: var(--accent); }
.rel small { color: var(--muted); display: block; font-size: 12px; }
.note { background: var(--warn-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.md-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="dark"] .btn.primary { color: #0b1f1d; }
.btn.primary:hover { background: var(--accent-strong); color: #fff; }

/* ===== Sơ đồ ===== */
.select-wide { max-width: 640px; margin-bottom: 12px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.dot.hd { background: var(--accent); } .dot.sua { background: var(--warn); } .dot.thay { background: var(--bad); }
.tree ul { list-style: none; margin: 0; padding-left: 26px; position: relative; }
.tree > ul { padding-left: 0; }
.tree li { position: relative; padding: 6px 0 6px 0; }
.tree ul ul li::before { content: ""; position: absolute; left: -16px; top: 0; bottom: 0; border-left: 2px solid var(--line); }
.tree ul ul li:last-child::before { bottom: auto; height: 26px; }
.tree ul ul li::after { content: ""; position: absolute; left: -16px; top: 26px; width: 14px; border-top: 2px solid var(--line); }
.node { display: inline-flex; flex-direction: column; gap: 3px; background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--accent)); border-radius: 10px; padding: 8px 12px; cursor: pointer; text-align: left; max-width: 100%; color: inherit; }
.node:hover { border-color: var(--accent); border-left-color: var(--c, var(--accent)); }
.node.root { --c: var(--text); background: var(--accent-soft); }
.node .k { font-size: 11.5px; font-weight: 600; color: var(--c); }
.node b { font-size: 13.5px; }
.node span { font-size: 13px; }

/* ===== Thuật ngữ ===== */
.glossary { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; margin: 0; }
.glossary div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.glossary dt { font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.glossary dd { margin: 0; font-size: 14px; }

.prose h2 { margin: 18px 0 6px; font-size: 17px; }
.prose h2:first-child { margin-top: 0; }
.prose p, .prose li { max-width: 72ch; }
.prose ul { padding-left: 20px; margin: 6px 0; }
.prose li { margin: 4px 0; }

/* ===== Máy tính bảng ===== */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .filter-row { grid-template-columns: repeat(3, 1fr); }
}
/* ===== Điện thoại ===== */
@media (max-width: 820px) {
  body { font-size: 15px; }
  .app { grid-template-columns: 1fr; }
  .nav { position: sticky; top: 0; z-index: 20; height: auto; padding: 10px 16px; flex-direction: row; align-items: center; gap: 10px; }
  .brand small { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  .menu { position: fixed; bottom: 0; left: 0; right: 0; flex-direction: row; background: var(--nav-bg); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); gap: 0; z-index: 30; border-top: 1px solid #2b3438; }
  .menu a { flex: 1; flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 11px; text-align: center; }
  .nav-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .btn-ghost span, .cap-nhat { display: none; }
  .btn-ghost { padding: 8px; }
  .main { padding: 18px 16px 96px; }
  h1 { font-size: 22px; }
  .grid-2 { grid-template-columns: 1fr; }
  .bar { grid-template-columns: 46% 1fr 26px; gap: 8px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpis .kpi:first-child { grid-column: span 2; }
  .kpi .n { font-size: 26px; }
  .quick-search { min-width: 0; width: 100%; }
  .filter-row { grid-template-columns: 1fr 1fr; }
  .md-grid { grid-template-columns: 1fr 1fr; }
  .modal { padding: 0; align-items: stretch; }
  .modal-box { border-radius: 0; min-height: 100%; padding: 20px 16px 32px; }
  .glossary { grid-template-columns: 1fr; }
  .tree ul { padding-left: 18px; }
  .tree ul ul li::before, .tree ul ul li::after { left: -12px; }
  .tree ul ul li::after { width: 10px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; justify-content: center; }
}

/* ===== In ===== */
@media print {
  .nav, .filters, .page-head .actions, .modal, .quick-search { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .doc { box-shadow: none; break-inside: avoid; border: 1px solid #999; border-left: 4px solid #555; }
  .doc-tom { -webkit-line-clamp: unset; display: block; color: #333; }
  .view:not(#v-tra-cuu) { display: none !important; }
}
