:root {
  color-scheme: light;
  --page: #f6f6f3; --surface: #fcfcfb; --surface-2: #f1f1ed; --raised: #ffffff;
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,.10);
  --accent: #2a78d6; --accent-ink: #ffffff; --accent-soft: #e4eefb;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-ink: #006300; --critical-ink: #b42323; --warn-ink: #8a5a00;
  --good-soft: #e3f4e3; --warn-soft: #fdf1d4; --critical-soft: #fbe5e5;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 0 0 1px var(--border);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --raised: #1f1f1e;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
    --accent: #3987e5; --accent-soft: #1b2a3d;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --good-ink: #0ca30c; --critical-ink: #e66767; --warn-ink: #fab219;
    --good-soft: #13261a; --warn-soft: #2e2510; --critical-soft: #331a1a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --raised: #1f1f1e;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
  --accent: #3987e5; --accent-soft: #1b2a3d;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --good-ink: #0ca30c; --critical-ink: #e66767; --warn-ink: #fab219;
  --good-soft: #13261a; --warn-soft: #2e2510; --critical-soft: #331a1a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--page); }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); } .faint { color: var(--muted); } .small { font-size: 12px; } .xs { font-size: 11px; }
.err { color: var(--critical-ink); }
.break { word-break: break-all; white-space: normal; }

/* Shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 650; font-size: 15px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .ico { width: 18px; text-align: center; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--page); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.top h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.top .spacer { flex: 1; }
.content { padding: 20px 24px 48px; max-width: 1400px; }

/* Pills & badges */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.good { background: var(--good-soft); color: var(--good-ink); }
.pill.warn { background: var(--warn-soft); color: var(--warn-ink); }
.pill.bad { background: var(--critical-soft); color: var(--critical-ink); }
.pill.info { background: var(--accent-soft); color: var(--accent); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.answer { background: var(--accent-soft); color: var(--accent); }
.badge.code { background: var(--good-soft); color: var(--good-ink); }
.badge.flash { background: var(--warn-soft); color: var(--warn-ink); }
.badge.error { background: var(--critical-soft); color: var(--critical-ink); }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* Cards & grids */
.card { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px 0; flex-wrap: wrap; }
.card-h h2 { font-size: 16px; margin: 0; font-weight: 650; }
.card-h .sub { font-size: 12px; color: var(--muted); }
.card-b { padding: 14px 18px 18px; }
.card-b.flush { padding: 8px 0 4px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); }
.tile { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--ink-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.tile .v { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
a.tile { color: inherit; display: block; } a.tile:hover { text-decoration: none; box-shadow: 0 0 0 2px var(--accent); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.between { justify-content: space-between; }

/* Controls */
.btn { border: 0; border-radius: 8px; padding: 7px 14px; background: var(--accent); color: var(--accent-ink); cursor: pointer; font-weight: 550; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { filter: brightness(1.06); } .btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; cursor: pointer; color: var(--ink-2); font-weight: 550; font-size: 13px; }
.seg button.on { background: var(--raised); color: var(--ink); box-shadow: var(--shadow); }
input[type=text], input[type=password], input[type=search], select {
  padding: 7px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--raised); min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch { position: relative; width: 44px; height: 24px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--axis); border-radius: 999px; transition: background .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + span { opacity: .5; cursor: default; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 10px 14px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { padding: 9px 14px; border-top: 1px solid var(--grid); white-space: nowrap; vertical-align: middle; }
tbody tr:first-child td { border-top: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
td.wrap { white-space: normal; min-width: 220px; }
.r { text-align: right; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.ellip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.compact .lasterr { display: none; }
.compact th, .compact td { padding-left: 10px; padding-right: 10px; }

/* Ranked bar list */
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 44%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; border-radius: 4px; background: var(--surface-2); overflow: hidden; display: flex; gap: 2px; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--s1); min-width: 2px; }
.bar-fill.s2 { background: var(--s2); } .bar-fill.s3 { background: var(--s3); }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--ink-2); min-width: 64px; text-align: right; }

/* Charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hl { fill: var(--ink); opacity: 0; }
.chart .hl.on { opacity: .06; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--raised); color: var(--ink); box-shadow: 0 6px 24px rgba(0,0,0,.18), 0 0 0 1px var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 130px; }
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .l { display: flex; justify-content: space-between; gap: 14px; }
.tip b { font-variant-numeric: tabular-nums; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* Live feed */
.feed { font-family: var(--mono); font-size: 12px; height: min(520px, 60vh); overflow: auto; background: var(--surface-2); border-radius: 8px; padding: 6px 0; }
.feed .ln { display: grid; grid-template-columns: 70px 44px 1fr; gap: 8px; padding: 2px 12px; }
.feed .ln:hover { background: var(--accent-soft); }
.feed .lv-WARN { color: var(--warn-ink); } .feed .lv-ERROR { color: var(--critical-ink); }
.feed .attrs { color: var(--muted); }
.feed a { color: inherit; text-decoration: underline dotted; cursor: pointer; }

/* Detail drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.32); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); background: var(--surface); z-index: 31; overflow: auto; box-shadow: -8px 0 32px rgba(0,0,0,.2); }
.drawer-h { position: sticky; top: 0; background: var(--surface); padding: 14px 20px; border-bottom: 1px solid var(--grid); display: flex; align-items: center; gap: 12px; z-index: 1; flex-wrap: wrap; }
.drawer-b { padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 18px; }
.drawer h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 16px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0 0 0 6px; padding: 0 0 0 18px; border-left: 2px solid var(--grid); display: flex; flex-direction: column; gap: 12px; }
.timeline li { position: relative; }
.timeline li::before { content: ""; position: absolute; left: -25px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--surface); border: 2px solid var(--axis); }
.timeline li.good::before { border-color: var(--good); background: var(--good); }
.timeline li.info::before { border-color: var(--accent); background: var(--accent); }
.timeline li.bad::before { border-color: var(--critical); background: var(--critical); }
.timeline .when { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.quote { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin-top: 4px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Meter */
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter > div { height: 100%; background: var(--s1); border-radius: 4px; }

/* Login */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin: 0 0 6px; font-size: 20px; }
.login input { width: 100%; margin-top: 12px; }

/* SMS-codes page */
.panel { padding: 14px 16px; background: var(--surface-2); border-radius: 10px; }
.filters { display: flex; gap: 14px; flex-wrap: wrap; }
.filters > div { flex: 1 1 220px; max-width: 420px; display: flex; flex-direction: column; gap: 6px; }
.filters label { font-weight: 550; color: var(--ink-2); font-size: 13px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }
.icon-btn { border: 0; border-radius: 8px; width: 30px; height: 30px; font-size: 13px; line-height: 1; cursor: pointer; background: var(--surface-2); color: var(--ink-2); }
.icon-btn.play { background: var(--accent-soft); color: var(--accent); }
tr.detail td { background: var(--surface-2); white-space: normal; }
.spin { display: inline-block; animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .pulse, .spin { animation: none; } }

@media (max-width: 1100px) { .g-3 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; height: auto; z-index: 6; flex-direction: row; align-items: center; padding: 8px 12px; overflow-x: auto; gap: 2px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0 8px 0 0; } .brand span { display: none; }
  .nav { flex-direction: row; } .nav a { padding: 6px 10px; white-space: nowrap; } .nav .ico { display: none; }
  .side-foot { display: none; }
  .top { position: static; padding: 12px 16px; }
  .content { padding: 16px 16px 40px; }
  .g-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .feed .ln { grid-template-columns: 64px 1fr; } .feed .ln .lv { display: none; }
}
