:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2dd;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7973;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e8e7e3;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --warning-ink: #8a5a00;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #b12a2a;
  --neutral-chip: #ebeae6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
    --text: #ffffff; --text-2: #c3c2b7; --text-3: #8f8e86;
    --accent: #3987e5; --accent-ink: #86b6ef; --series-1: #3987e5; --series-2: #d95926;
    --grid: #2a2a28; --good-ink: #5fd35f; --warning-ink: #fab219; --critical-ink: #ff8a8a;
    --neutral-chip: #2c2c2a; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #8f8e86;
  --accent: #3987e5; --accent-ink: #86b6ef; --series-1: #3987e5; --series-2: #d95926;
  --grid: #2a2a28; --good-ink: #5fd35f; --warning-ink: #fab219; --critical-ink: #ff8a8a;
  --neutral-chip: #2c2c2a; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 15px; padding: 4px 10px 16px; }
.brand small { display: block; font-weight: 500; color: var(--text-3); font-size: 12px; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 7px;
  color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 4px; }
.nav .badge { background: var(--critical); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--border);
  display: flex; gap: 12px; align-items: center; padding: 10px 24px; flex-wrap: wrap; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 160px; }
.content { padding: 20px 24px 60px; max-width: 1500px; }
.btn.menu-btn { display: none; }

.range { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.range select, .range input, .input, .btn { height: 32px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 7px; padding: 0 10px; }
.btn { cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; 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); }
.btn:disabled { opacity: .5; cursor: default; }
.sync-pill { font-size: 12px; color: var(--text-2); display: flex; gap: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; vertical-align: 1px; }
.dot.ok { background: var(--good); } .dot.warn { background: var(--warning); } .dot.err { background: var(--critical); }
.dot.off { background: var(--text-3); }

/* ---------- cards / KPIs ---------- */
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; min-width: 0; }
.kpi .label { color: var(--text-2); font-size: 12.5px; font-weight: 500; display: flex; justify-content: space-between; gap: 6px; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -.01em; }
.kpi .note { color: var(--text-3); font-size: 11.5px; margin-top: 2px; }
.kpi .value.na { font-size: 13px; font-weight: 500; color: var(--text-3); padding-top: 8px; }
.tag { font-size: 10.5px; font-weight: 600; color: var(--text-3); background: var(--surface-2); border-radius: 4px; padding: 0 5px;
  text-transform: uppercase; letter-spacing: .04em; }
.row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; margin-bottom: 12px; }
.row2e { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.card h3 small { color: var(--text-3); font-weight: 400; margin-left: 6px; }
.section-title { font-size: 15px; font-weight: 600; margin: 22px 0 10px; }
.muted { color: var(--text-3); }
.notice { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; color: var(--text-2);
  margin-bottom: 14px; font-size: 13px; }
.notice.err { border-color: var(--critical); color: var(--critical-ink); background: transparent; }
.empty { color: var(--text-3); padding: 24px; text-align: center; }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 20px;
  background: var(--neutral-chip); color: var(--text-2); white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.chip.good { color: var(--good-ink); } .chip.warn { color: var(--warning-ink); } .chip.bad { color: var(--critical-ink); }
.chip.info { color: var(--accent-ink); }
.chip.plain::before { display: none; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.fchip { border: 1px solid var(--border); background: var(--surface); border-radius: 20px; padding: 3px 11px; cursor: pointer;
  font-size: 12.5px; color: var(--text-2); }
.fchip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.fchip .c { opacity: .75; margin-left: 4px; }

/* ---------- tables ---------- */
.table-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.table-tools .input { flex: 1; min-width: 200px; max-width: 420px; }
.tbl-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); max-height: 70vh; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: 12px; color: var(--text-2); z-index: 1;
  cursor: pointer; user-select: none; }
th.r, td.r { text-align: right; }
th .arrow { opacity: .6; font-size: 10px; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.click { cursor: pointer; }
td.wrap { white-space: normal; min-width: 220px; max-width: 360px; }
tfoot td { font-weight: 600; background: var(--surface-2); position: sticky; bottom: 0; }
.na { color: var(--text-3); }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; color: var(--text-2); font-size: 13px; }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gl { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 11px; }
.chart .bar { fill: var(--series-1); }
.chart .bar.alt { fill: var(--series-2); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hl { filter: brightness(1.15); }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 9px;
  border-radius: 6px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px; z-index: 3; display: none; }
.hbars { display: grid; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar .track { background: var(--surface-2); border-radius: 4px; height: 10px; overflow: hidden; }
.hbar .fill { background: var(--series-1); height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .v { color: var(--text); font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }

/* ---------- order detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--text-3); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); }
.timeline li.good::before { border-color: var(--good); background: var(--good); }
.timeline li.bad::before { border-color: var(--critical); }
.timeline li.warn::before { border-color: var(--warning); }
.timeline .t { font-weight: 600; }
.timeline .m { color: var(--text-3); font-size: 12px; }
.back { display: inline-block; margin-bottom: 10px; }

/* ---------- health ---------- */
.health { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.health .state { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.err-text { color: var(--critical-ink); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; }

/* ---------- login ---------- */
.login { max-width: 360px; margin: 12vh auto; }
.login .card { padding: 24px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login label { display: block; font-size: 12.5px; color: var(--text-2); margin: 14px 0 4px; }
.login .input { width: 100%; }
.login .btn { width: 100%; justify-content: center; margin-top: 18px; height: 36px; }

@media (max-width: 1100px) {
  .row2, .row2e, .detail-grid, .health { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; z-index: 20; width: 240px; transform: translateX(-100%); transition: transform .2s;
    box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 60px; }
  dl.kv { grid-template-columns: 110px 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 20px; }
}
