:root {
  --bg: #F4F6FA; --surface: #FFFFFF; --surface-2: #F1F4F9; --line: #E3E8F0; --text: #111827; --muted: #6B7280;
  --primary: #2563EB; --primary-soft: #DBE7FE; --purple: #7C3AED; --good: #0E9F6E; --bad: #E02D3C; --amber: #D97706; --sidebar: #0F172A; --sidebar-text: #CBD5E1;
  --r-sm: 4px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px;
  --font: 'Inter', 'IBM Plex Sans Thai', system-ui, sans-serif; --head: 'Plus Jakarta Sans', 'IBM Plex Sans Thai', system-ui, sans-serif;
}
:root[data-theme="dark"] { --bg: #0B1120; --surface: #131C2E; --surface-2: #1B2639; --line: #27344A; --text: #F1F5F9; --muted: #94A3B8; --primary: #5B8DF6; --primary-soft: #1E335C; --purple: #A78BFA; --good: #34D399; --bad: #F87171; --amber: #FBBF24; --sidebar: #070C18; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.55 var(--font); }
h1, h2, h3 { font-family: var(--head); margin: 0; letter-spacing: -.01em; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 32px; display: grid; gap: 16px; }
.login h1 { font-size: 24px; }
.login p { margin: 0; color: var(--muted); }
.login label { display: grid; gap: 4px; font-weight: 500; }
.login input { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.login button { padding: 12px; border: 0; border-radius: var(--r-md); background: var(--primary); color: #fff; font-weight: 600; }
.login button:disabled { opacity: .6; }
.err { color: var(--bad); margin: 0; }

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--sidebar); color: var(--sidebar-text); padding: 24px 16px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; }
.brand { color: #fff; font: 800 18px var(--head); padding: 0 8px; }
.brand small { display: block; font: 500 12px var(--font); color: var(--sidebar-text); }
.nav { display: grid; gap: 4px; }
.nav button { text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: var(--r-md); color: var(--sidebar-text); font-weight: 500; }
.nav button:hover { background: #ffffff14; }
.nav button.on { background: var(--primary); color: #fff; }
.side-foot { margin-top: auto; display: grid; gap: 8px; font-size: 12px; padding: 0 8px; }
.side-foot button { background: none; border: 1px solid #ffffff2e; border-radius: var(--r-md); padding: 6px 8px; color: var(--sidebar-text); }
.warn { color: #FCA5A5; }

.main { padding: 32px; min-width: 0; max-width: 1400px; }
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 24px; }
.head h1 { font-size: 26px; }
.head .sub { color: var(--muted); font-size: 13px; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.pills button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; color: var(--muted); font-weight: 500; }
.pills button.on { background: var(--primary); color: #fff; }

.grid { display: grid; gap: 16px; }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 24px; min-width: 0; }
.card h2 { font-size: 16px; margin-bottom: 16px; }
.card h2 small { font: 400 12px var(--font); color: var(--muted); margin-left: 8px; }
.kpi { display: grid; grid-template-columns: 1fr 120px; gap: 8px; align-items: end; }
.kpi .lbl { color: var(--muted); font-weight: 500; }
.kpi .val { font: 800 32px/1.2 var(--head); }
.kpi .cmp { font-size: 12px; color: var(--muted); }
.mini .val { font-size: 22px; }
.mini { display: block; padding: 16px 24px; }
.up { color: var(--good); font-weight: 600; }
.down { color: var(--bad); font-weight: 600; }

svg text { font-family: var(--font); fill: var(--text); }
svg .mut { fill: var(--muted); }
.chart, .flow { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; }

.breakdown .total { font: 800 26px var(--head); margin-bottom: 8px; }
.bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; gap: 2px; margin-bottom: 12px; }
.row { display: grid; grid-template-columns: 1fr auto 56px; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.row .pct { color: var(--muted); text-align: right; font-size: 12px; }

.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
th.r, td.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.name { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.ok { background: var(--primary-soft); color: var(--primary); }
.note { color: var(--muted); font-size: 12px; line-height: 1.7; }
.search { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); margin-bottom: 8px; }
.empty, .loading { padding: 48px; text-align: center; color: var(--muted); }

@media (max-width: 1080px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3, .g2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 12px 16px; gap: 8px; }
  .nav { grid-auto-flow: column; overflow-x: auto; }
  .nav button { white-space: nowrap; }
  .side-foot { display: none; }
  .main { padding: 16px; }
  .kpi { grid-template-columns: 1fr; }
}
