:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef0f3; --border: #e2e5ea;
  --text: #14171c; --muted: #6b7280; --accent: #2f6fed; --on-accent: #fff;
  --up: #16a34a; --up-bg: #e7f6ec; --down: #dc2626; --down-bg: #fdecec;
  --warn: #b45309; --warn-bg: #fdf3e2; --hot: #dc2626; --hot-bg: #fdecec;
  --radius: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a20; --surface-2: #1f232b; --border: #2a2f38;
    --text: #e8eaed; --muted: #8b93a1; --accent: #5b8cff; --on-accent: #fff;
    --up: #34d399; --up-bg: #11291f; --down: #f87171; --down-bg: #2c1618;
    --warn: #fbbf24; --warn-bg: #2b2311; --hot: #f87171; --hot-bg: #2c1618;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 14px; cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
input { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 12px; width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--down); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
h1 { font-size: 22px; font-weight: 600; margin: 12px 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 8px; }

.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 340px; text-align: center; }
.auth-card img { border-radius: 14px; }
.auth-card form { display: grid; gap: 10px; margin-top: 16px; }

#main { max-width: 860px; margin: 0 auto; padding: calc(var(--safe-t) + 8px) 16px calc(var(--safe-b) + 84px); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 10px; }
.brand { font-weight: 700; font-size: 20px; letter-spacing: -0.01em; }
.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live .dot { background: var(--up); }
.status.stale .dot { background: var(--warn); }
.status.bad .dot { background: var(--down); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding: 4px 4px calc(var(--safe-b) + 4px); }
.tabs button { border: 0; background: none; padding: 6px 2px; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
.tabs .ic { font-size: 18px; line-height: 1.1; }
.tabs button.on { color: var(--accent); }
.count { position: absolute; top: 2px; left: calc(50% + 8px); background: var(--down); color: #fff;
  font-size: 10px; font-weight: 600; border-radius: 9px; padding: 1px 5px; }
@media (min-width: 720px) {
  #main { padding-bottom: 32px; }
  .tabs { position: static; display: flex; gap: 4px; background: none; border: 0; border-bottom: 1px solid var(--border);
    padding: 0; margin-bottom: 12px; }
  .tabs button { flex-direction: row; font-size: 14px; padding: 10px 14px; border-bottom: 2px solid transparent;
    border-radius: 0; gap: 6px; }
  .tabs .ic { font-size: 14px; }
  .tabs button.on { border-bottom-color: var(--accent); }
  .count { position: static; }
}

.toolbar { display: flex; justify-content: space-between; margin: 4px 0 10px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius); padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; font-size: 13px; color: var(--muted); border-radius: 8px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.grid { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.grid th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 9px 10px;
  border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap; }
.grid th.sorted { color: var(--text); }
.grid th.sorted::after { content: " ↑"; }
.grid th.sorted.desc::after { content: " ↓"; }
.grid td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.num, .grid th.num { text-align: right; }
.tk { font-weight: 600; }
.sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.old { color: var(--muted); }
.dist { display: inline-block; min-width: 64px; padding: 3px 8px; border-radius: 7px; font-weight: 600; text-align: right; }
.dist.hot { background: var(--hot-bg); color: var(--hot); }
.dist.warm { background: var(--warn-bg); color: var(--warn); }
.dist.in { background: var(--accent); color: var(--on-accent); }
.arrow-up { color: var(--down); }
.arrow-down { color: var(--up); }
@media (max-width: 540px) { .hide-sm { display: none; } }
.foot { font-size: 12px; margin: 10px 2px; }

details.grp { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; }
details.grp summary { list-style: none; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; cursor: pointer; }
details.grp summary::-webkit-details-marker { display: none; }
details.grp summary .tk::before { content: "›"; display: inline-block; width: 14px; transition: transform .15s; color: var(--muted); }
details.grp[open] summary .tk::before { transform: rotate(90deg); }
.brk { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 14px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.tag.up { background: var(--up-bg); color: var(--up); }
.tag.down { background: var(--down-bg); color: var(--down); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

.ev { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 6px; }
.ev .t { font-weight: 600; }
.ev .m { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.sw { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.sw:first-child { border-top: 0; }
.sw input { width: 44px; height: 26px; appearance: none; -webkit-appearance: none; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 13px; position: relative; padding: 0; cursor: pointer; transition: background .15s; }
.sw input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s; }
.sw input:checked { background: var(--up); border-color: var(--up); }
.sw input:checked::after { left: 20px; }
@media (min-width: 541px) { .hide-lg { display: none; } }

.chart-view { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 6px) 0 var(--safe-b); }
.chart-head { display: flex; align-items: center; gap: 10px; padding: 4px 12px 8px; flex-wrap: wrap; }
.chart-title { flex: 1; min-width: 120px; font-size: 17px; }
.icon-btn { font-size: 26px; line-height: 1; padding: 2px 12px 6px; }
.chart-box { flex: 1; min-height: 0; position: relative; }
.chart-msg { position: absolute; left: 0; right: 0; top: 45%; text-align: center; pointer-events: none; margin: 0; }
#tf button { padding: 6px 9px; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:active td { background: var(--surface-2); }
.brk { cursor: pointer; }
