:root {
  --green-900: #063a21; --green-800: #085e37; --green-700: #0a804a; --green-600: #0f9557; --green-200: #bfe8d2; --green-100: #e3f5eb; --green-50: #f2faf6;
  --lime-600: #97c354; --lime-100: #f2f8e8; --lime-800: #648a2c;
  --ink-900: #0d1f16; --ink-800: #182b22; --ink-600: #55655c; --ink-500: #77857c; --ink-400: #9aa6a0; --ink-300: #c2cac5; --ink-200: #dfe4e1; --ink-100: #eef1ef; --ink-50: #f7f8f7;
  --info: #2563c9; --warning: #e0900a; --danger: #d83a2f; --sale: #e0350c;
  --accent-text: #0a804a; --accent-text-h: #085e37; --on-green: #085e37; --toast-bg: #0d1f16; --toast-fg: #ffffff;
  --warn-bg: #fdf1d9; --warn-fg: #6b4600; --warn-badge: #8a5a00; --danger-bg: #fbe4e1; --danger-fg: #a02a21; --info-bg: #e6eefb; --info-fg: #2563c9;
  --bg: #ffffff; --page: var(--ink-50); --card: #ffffff; --text: var(--ink-800); --strong: var(--ink-900); --muted: var(--ink-500); --border: var(--ink-200);
  --shadow-sm: 0 1px 2px rgba(13,31,22,.06), 0 1px 3px rgba(13,31,22,.06);
  --shadow-lg: 0 8px 24px rgba(13,31,22,.12);
  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink-50: #13281d; --ink-100: #1a3324; --ink-200: #26402f; --ink-300: #3a5846; --ink-400: #6b8576; --ink-500: #9aa6a0; --ink-600: #b4beb8; --ink-800: #dfe4e1; --ink-900: #f7f8f7;
    --green-50: #10301f; --green-100: #123b27; --lime-100: #1c2b12; --lime-800: #bdda8f;
    --page: #0d1f16; --card: #13281d; --text: #dfe4e1; --strong: #f7f8f7; --muted: #9aa6a0; --border: #26402f; --bg: #0d1f16;
    --accent-text: #4cc189; --accent-text-h: #86d6ac; --on-green: #bfe8d2; --toast-bg: #f7f8f7; --toast-fg: #0d1f16;
    --warn-bg: #3a2c0c; --warn-fg: #f3d189; --warn-badge: #f3d189; --danger-bg: #3d1a17; --danger-fg: #f3a8a1; --info-bg: #14284a; --info-fg: #9dbdf2;
    --shadow-sm: none; --shadow-lg: 0 8px 24px rgba(0,0,0,.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --ink-50: #13281d; --ink-100: #1a3324; --ink-200: #26402f; --ink-300: #3a5846; --ink-400: #6b8576; --ink-500: #9aa6a0; --ink-600: #b4beb8; --ink-800: #dfe4e1; --ink-900: #f7f8f7;
    --green-50: #10301f; --green-100: #123b27; --lime-100: #1c2b12; --lime-800: #bdda8f;
    --page: #0d1f16; --card: #13281d; --text: #dfe4e1; --strong: #f7f8f7; --muted: #9aa6a0; --border: #26402f; --bg: #0d1f16;
    --accent-text: #4cc189; --accent-text-h: #86d6ac; --on-green: #bfe8d2; --toast-bg: #f7f8f7; --toast-fg: #0d1f16;
    --warn-bg: #3a2c0c; --warn-fg: #f3d189; --warn-badge: #f3d189; --danger-bg: #3d1a17; --danger-fg: #f3a8a1; --info-bg: #14284a; --info-fg: #9dbdf2;
    --shadow-sm: none; --shadow-lg: 0 8px 24px rgba(0,0,0,.5); color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-family: var(--font); font-size: 15px; line-height: 1.55; color: var(--text); background: var(--page); }
h1, h2, h3, h4 { color: var(--strong); margin: 0; line-height: 1.25; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -.3px; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
a { color: var(--accent-text); text-decoration: none; } a:hover { color: var(--accent-text-h); text-decoration: underline; }
:focus-visible { outline: 3px solid rgba(15,149,87,.55); outline-offset: 1px; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 16px; } .row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 0; min-width: 0; } .spread { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }

/* Khung */
.topbar { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .in { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 8px 16px; min-height: 56px; flex-wrap: wrap; padding-block: 6px; }
.wm { font-weight: 700; font-size: 19px; letter-spacing: -.4px; color: var(--accent-text); white-space: nowrap; }
.wm .e { color: var(--lime-600); } .wm small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 8px; letter-spacing: 0; }
.nav { display: flex; gap: 4px; overflow-x: auto; order: 3; flex: 1 0 100%; scrollbar-width: none; padding-bottom: 2px; }
.topbar .in > .row { margin-left: auto; }
.nav a { display: flex; gap: 6px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--ink-600); font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--green-50); text-decoration: none; color: var(--on-green); }
.nav a.on { background: var(--green-100); color: var(--on-green); }
.main { max-width: 1280px; margin: 0 auto; padding: 24px 16px 64px; }
.pagehead { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 20px; }
.pagehead p { margin: 4px 0 0; color: var(--muted); }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Thành phần */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-sm); padding: 20px; }
.card.flat { box-shadow: none; } .card h2 { margin-bottom: 12px; }
.btn { font: inherit; font-weight: 600; display: inline-flex; gap: 8px; align-items: center; justify-content: center; padding: 9px 16px; min-height: 40px; border-radius: 8px; border: 1px solid transparent; background: var(--green-700); color: #fff; cursor: pointer; }
.btn:hover { background: var(--green-800); } .btn:active { background: var(--green-900); }
.btn.outline { background: transparent; color: var(--accent-text); border-color: var(--accent-text); } .btn.outline:hover { background: var(--green-50); }
.btn.ghost { background: transparent; color: var(--ink-600); } .btn.ghost:hover { background: var(--ink-100); }
.btn.danger { background: var(--danger); } .btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
label.f { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; color: var(--strong); min-width: 0; }
label.f .hint { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--ink-300); border-radius: 8px; padding: 9px 12px; min-height: 40px; width: 100%; }
textarea { min-height: 110px; resize: vertical; font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(15,149,87,.55); border-color: var(--green-600); }
input[type=checkbox] { width: 18px; min-height: 18px; accent-color: var(--green-700); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 9999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--ink-100); color: var(--ink-600); }
.badge.green { background: var(--green-100); color: var(--on-green); } .badge.lime { background: var(--lime-100); color: var(--lime-800); }
.badge.info { background: var(--info-bg); color: var(--info-fg); } .badge.warning { background: var(--warn-bg); color: var(--warn-badge); }
.badge.danger { background: var(--danger-bg); color: var(--danger-fg); } .badge.solid { background: var(--green-700); color: #fff; }
.alert { padding: 12px 16px; border-radius: 8px; display: flex; gap: 12px; align-items: flex-start; background: var(--warn-bg); color: var(--warn-fg); }
.alert.danger { background: var(--danger-bg); color: var(--danger-fg); } .alert.info { background: var(--green-50); color: var(--on-green); }
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: none; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--ink-50); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--ink-100); vertical-align: top; }
tr:last-child td { border-bottom: 0; } tbody tr.click { cursor: pointer; } tbody tr.click:hover { background: var(--green-50); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; color: var(--strong); letter-spacing: -.5px; line-height: 1.2; }
.kpi .l { font-size: 13px; color: var(--muted); } .kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.warn .v { color: var(--warning); } .kpi.bad .v { color: var(--danger); } .kpi.good .v { color: var(--accent-text); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 13px; font-weight: 500; padding: 5px 12px; border-radius: 9999px; border: 1px solid var(--ink-300); background: var(--card); color: var(--ink-600); cursor: pointer; }
.chip.on { background: var(--green-700); color: #fff; border-color: var(--green-700); }
.bar { height: 10px; border-radius: 5px; background: var(--ink-100); overflow: hidden; } .bar > i { display: block; height: 100%; background: var(--green-700); border-radius: 5px; }
.bar.est > i { background: var(--lime-600); }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.timeline li { display: grid; grid-template-columns: 130px 1fr; gap: 12px; font-size: 14px; }
.quote { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); cursor: pointer; }
.quote.sel { border-color: var(--green-700); box-shadow: 0 0 0 2px rgba(10,128,74,.25); }
.quote .price { font-size: 20px; font-weight: 700; color: var(--accent-text); letter-spacing: -.3px; text-align: right; }
.quote input { width: 18px; min-height: 18px; accent-color: var(--green-700); }
.suggest { border: 1px solid var(--border); border-radius: 8px; background: var(--card); max-height: 220px; overflow: auto; margin-top: 4px; }
.suggest button { display: flex; width: 100%; text-align: left; gap: 12px; padding: 8px 12px; background: none; border: 0; border-bottom: 1px solid var(--ink-100); font: inherit; color: var(--text); cursor: pointer; }
.suggest button:hover { background: var(--green-50); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #0A804A 0%, #97C354 100%); }
.login .card { width: min(400px, 100%); box-shadow: var(--shadow-lg); }
.login .wm { font-size: 24px; }
dialog { border: 1px solid var(--border); border-radius: 8px; padding: 20px; width: min(460px, calc(100vw - 32px)); background: var(--card); color: var(--text); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(13,31,22,.45); }
#toasts { position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--toast-bg); color: var(--toast-fg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); max-width: 380px; }
.toast.err { background: var(--danger); color: #fff; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
@media (max-width: 1480px) { .wm small { display: none; } }
@media (max-width: 640px) {
  .topbar .in { flex-wrap: wrap; } .nav { order: 3; flex-basis: 100%; }
  .timeline li { grid-template-columns: 1fr; gap: 0; } .quote { grid-template-columns: auto 1fr; } .quote .price { grid-column: 1 / -1; text-align: left; }
  h1 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
