:root {
  color-scheme: dark;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --page: #0b0b0b;
  --surface: #191919;
  --surface-2: #222222;
  --border: rgba(255, 255, 255, 0.10);
  --text-1: #efefef;
  --text-2: #9c9c9c;
  --grid: #303030;
  --axis: #474747;
  --accent: #338ced;
  --series-1: #338ced;
  --series-2: #e76624;
  --series-3: #00a888;
  --series-4: #d28e05;
  --good: #0aac23;
  --warning: #fbb315;
  --serious: #f18a59;
  --critical: #dc3c3d;
  --good-text: #53c556;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --page: #f9f9f9;
    --surface: #ffffff;
    --surface-2: #f2f2f2;
    --border: rgba(11, 11, 11, 0.10);
    --text-1: #191919;
    --text-2: #666666;
    --grid: #e7e7e7;
    --axis: #c2c2c2;
    --accent: #257de0;
    --series-1: #257de0;
    --series-2: #f47230;
    --series-3: #00b894;
    --series-4: #f2a600;
    --good-text: #006c10;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--text-1); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; font-weight: 600; }
h2 { font-size: 14px; margin: 0 0 10px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--text-2); }
.muted { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: 12px; }

/* layout */
.app { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.brand { font-weight: 700; padding: 4px 10px 16px; }
.brand small { display: block; font-weight: 400; color: var(--text-2); font-size: 12px; }
.side a { color: var(--text-2); padding: 7px 10px; border-radius: 6px; display: flex; justify-content: space-between; }
.side a:hover { background: var(--surface-2); color: var(--text-1); text-decoration: none; }
.side a.active { background: var(--surface-2); color: var(--text-1); font-weight: 600; }
.side .spacer { flex: 1; }
.side .who { color: var(--text-2); font-size: 12px; padding: 8px 10px; }
.count { background: var(--critical); color: #fff; border-radius: 9px; padding: 0 7px; font-size: 11px; font-weight: 700; }
main { padding: 20px 24px 40px; min-width: 0; }
.banner { background: color-mix(in srgb, var(--critical) 18%, var(--surface)); border: 1px solid var(--critical); border-radius: 8px; padding: 8px 12px; margin-bottom: 16px; }
.banner.warn { background: color-mix(in srgb, var(--warning) 14%, var(--surface)); border-color: var(--warning); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1; }

.grid { display: grid; gap: 12px; }
.tiles { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 16px; }
.charts { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); margin-bottom: 16px; }
.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.tile .label { color: var(--text-2); font-size: 12px; }
.tile .value { font-size: 24px; font-weight: 600; margin-top: 2px; }
.tile .value small { font-size: 13px; font-weight: 400; color: var(--text-2); }
.tile .sub { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.meter > div { height: 100%; background: var(--series-1); border-radius: 3px; }

/* status */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-2); }
.badge.good::before { background: var(--good); }
.badge.warning::before { background: var(--warning); }
.badge.serious::before { background: var(--serious); }
.badge.critical::before { background: var(--critical); }
.badge.info::before { background: var(--series-1); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.empty { color: var(--text-2); padding: 16px 8px; text-align: center; }
.err-text { color: var(--critical); font-size: 12px; word-break: break-word; }

/* forms */
input, select, button { font: inherit; color: var(--text-1); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { cursor: pointer; background: var(--surface-2); }
button:hover { border-color: var(--axis); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--surface); color: var(--text-2); padding: 5px 10px; }
.seg button.on { background: var(--surface-2); color: var(--text-1); font-weight: 600; }
label.chk { display: inline-flex; gap: 4px; align-items: center; color: var(--text-2); font-size: 13px; }
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; max-width: 320px; }
.form-row label { font-size: 12px; color: var(--text-2); }
.msg { font-size: 13px; margin-top: 6px; }
.msg.ok { color: var(--good-text); }
.msg.bad { color: var(--critical); }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login .card { width: 340px; padding: 24px; }
.login input, .login button { width: 100%; }

/* charts */
.chart .legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.chart .legend i, .chart .tip i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart .plot { position: relative; width: 100%; }
.chart canvas { display: block; }
.chart .tip { display: none; position: absolute; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.35); min-width: 150px; z-index: 5; }
.chart .tip .tip-t { color: var(--text-2); margin-bottom: 3px; }
.chart .tip b { float: right; margin-left: 12px; font-variant-numeric: tabular-nums; }

/* request detail */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-word; }
.hints { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.hints li { padding: 8px 10px; border-radius: 6px; background: var(--surface-2); border-left: 3px solid var(--series-1); }
.hints li.error { border-left-color: var(--critical); }
.hints li.warn { border-left-color: var(--warning); }
.timing { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; margin: 8px 0 6px; }
.timing > div { min-width: 2px; }
.timing-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); }
.timing-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.logs td { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.logs td.lv-ERROR { color: var(--critical); font-weight: 700; }
.logs td.lv-WARN { color: var(--warning); font-weight: 700; }
.logs td.lv-EVENT { color: var(--serious); font-weight: 700; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; }
  .side .spacer, .brand small { display: none; }
  .charts { grid-template-columns: 1fr; }
}
