:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --grid: #e8e7e3;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --pos: #0a7d2c;
  --neg: #c62f2f;
  --warn: #b07800;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b; --grid: #2a2a27;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #3987e5;
    --pos: #3fbf5a; --neg: #e66767; --warn: #fab219;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b; --grid: #2a2a27;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #3987e5;
  --pos: #3fbf5a; --neg: #e66767; --warn: #fab219;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.err { color: var(--neg); min-height: 1.2em; margin: 0; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 18px; }
h3 { font-size: 14px; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

.btn { font: inherit; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.btn:hover { border-color: var(--text-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.danger { color: var(--neg); }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px;
  width: 100%; max-width: 340px; display: grid; gap: 14px; }
.login-card label { display: grid; gap: 4px; color: var(--text-2); font-size: 13px; }

/* header */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 16px; }
.badge { font-size: 10px; font-weight: 700; letter-spacing: .05em; color: var(--warn); border: 1px solid var(--warn);
  border-radius: 4px; padding: 1px 5px; margin-left: 6px; vertical-align: middle; }
.tabs { display: flex; gap: 4px; }
.tab { font: inherit; background: none; border: none; color: var(--text-2); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.tab.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.tabpane { padding: 16px 20px 40px; display: grid; gap: 16px; max-width: 1600px; margin: 0 auto; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.kpi .k { color: var(--text-3); font-size: 12px; }
.kpi .v { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .s { color: var(--text-3); font-size: 12px; margin-top: 2px; }

/* terminal cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.tcard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; display: grid; gap: 10px; }
.tcard .hd { display: flex; align-items: center; gap: 8px; }
.tcard .nm { font-weight: 600; }
.tcard .meta { color: var(--text-3); font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--pos); } .dot.late { background: var(--warn); } .dot.off { background: var(--neg); }
.tcard .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tcard .grid div { display: grid; }
.tcard .grid .k { color: var(--text-3); font-size: 11px; }
.tcard .grid .v { font-variant-numeric: tabular-nums; font-weight: 600; }

/* panels & tables */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.panel-h { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 460px; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 6px 8px;
  border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
.tbl th.sortable { cursor: pointer; }
.tbl th.num { text-align: right; }
.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.tbl tr.total td { font-weight: 600; border-top: 1px solid var(--border); }
.tbl tr:hover td { background: var(--surface-2); }
.sw { flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart { width: 100%; height: 280px; }
.chart.tall { height: 380px; }
.empty { color: var(--text-3); padding: 18px 4px; text-align: center; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.fgroup { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.flabel { color: var(--text-3); font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; background: var(--surface); color: var(--text-2); border: none;
  padding: 5px 10px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent); color: #fff; }

.analysis-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.analysis-main { display: grid; gap: 16px; min-width: 0; }
.picker { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow-y: auto; }
.picker .term { margin-bottom: 10px; }
.picker .term > label { font-weight: 600; display: flex; gap: 6px; align-items: center; padding: 3px 0; }
.picker .ea { display: flex; gap: 6px; align-items: center; padding: 2px 0 2px 20px; font-size: 13px; cursor: pointer; }
.picker .ea .mg { color: var(--text-3); font-size: 11px; margin-left: auto; }
.picker .ea.inactive { opacity: .55; }

/* settings */
.group-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; display: grid; gap: 8px; }
.group-card .members { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.group-card .members label { font-size: 13px; display: flex; gap: 5px; align-items: center; }
input[type=color] { padding: 0; width: 32px; height: 24px; border: none; background: none; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 50; }

@media (max-width: 900px) {
  .analysis-layout { grid-template-columns: 1fr; }
  .picker { position: static; max-height: 300px; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .top { padding: 8px 16px; gap: 8px; }
  .tabpane { padding: 12px 16px 32px; }
  .top-right #clock { display: none; }
  .tcard .grid { grid-template-columns: repeat(2, 1fr); }
  .kpi .v { font-size: 18px; }
}
