:root {
  --bg: #f1f4f6; --surface: #ffffff; --surface-2: #f6f8fa; --ink: #15212a; --muted: #5c6b77;
  --line: #d5dde3; --accent: #0e6b78; --accent-ink: #ffffff;
  --down: #0e6b78; --up: #c26a12;
  --ok: #1b7443; --ok-bg: #dcefe3; --warn: #8f5400; --warn-bg: #f6e7c8; --bad: #ad241c; --bad-bg: #f8dcd8;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f161b; --surface: #172128; --surface-2: #1d2931; --ink: #e3eaee; --muted: #94a5b0;
    --line: #2b3a44; --accent: #4cbccb; --accent-ink: #062126;
    --down: #4cbccb; --up: #f0a24e;
    --ok: #63cd8f; --ok-bg: #173526; --warn: #e8ab4f; --warn-bg: #3b2c10; --bad: #f28b83; --bad-bg: #40201d;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; }
.mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.shell { max-width: 980px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 18px; }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 1.05rem; margin-right: auto; text-decoration: none; color: inherit; }
.brand img { width: 28px; height: 28px; }
.nav { display: flex; gap: 4px; }
.nav a, .linkbtn { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); background: none; border: 0; cursor: pointer; }
.nav a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.linkbtn:hover, .nav a:hover { color: var(--ink); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid2 { display: grid; gap: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.stat { gap: 4px; }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .value { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .sub { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.down { color: var(--down); }
.up { color: var(--up); }

.banner { border-radius: var(--radius); padding: 10px 14px; background: var(--warn-bg); color: var(--warn); font-size: .9rem; overflow-wrap: anywhere; }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; opacity: .5; }
.dot.on { background: var(--ok); opacity: 1; }
.dot.blocked { background: var(--bad); opacity: 1; }

.devices { display: flex; flex-direction: column; }
.device { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 11px 4px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.device:hover { background: var(--surface-2); }
.device .who { min-width: 0; }
.device .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .meta { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .rates { text-align: right; font-variant-numeric: tabular-nums; font-size: .88rem; white-space: nowrap; }
.badges { display: inline-flex; gap: 4px; flex-wrap: wrap; vertical-align: middle; margin-left: 6px; }
.badge { font-size: .68rem; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
details > summary { cursor: pointer; color: var(--muted); padding: 10px 4px; border-top: 1px solid var(--line); list-style-position: inside; }

.chart { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .line-down { stroke: var(--down); fill: none; stroke-width: 2; }
.chart .line-up { stroke: var(--up); fill: none; stroke-width: 2; }
.chart .area-down { fill: var(--down); opacity: .12; }
.chart .bar-down { fill: var(--down); }
.chart .bar-up { fill: var(--up); }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; background: currentColor; }
.legend .down::before { background: var(--down); }
.legend .up::before { background: var(--up); }

form, .form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=time], input:not([type]) {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-width: 0; width: 100%; color: var(--ink);
}
input:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > label { flex: 1 1 140px; }
.btn { border: 1px solid var(--line); background: var(--surface-2); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: .55; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.msg { font-size: .88rem; min-height: 1.3em; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--ok); }

.access { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.access .state { font-size: 1.15rem; font-weight: 650; margin-right: auto; }
.state.ok { color: var(--ok); }
.state.bad { color: var(--bad); }

.rule { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.days { display: flex; gap: 4px; flex-wrap: wrap; grid-column: 1 / -1; }
.day { width: 38px; padding: 5px 0; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: .82rem; }
.day[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.times { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.times input { width: 7.5em; }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; font-size: .9rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.log { display: flex; flex-direction: column; }
.log .entry { display: grid; grid-template-columns: 9.5em minmax(0, 1fr); gap: 2px 14px; padding: 9px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.log .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.log .what { overflow-wrap: anywhere; }

.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth { width: min(400px, 100%); }
.qr { width: 220px; height: 220px; align-self: center; border-radius: 8px; background: #fff; padding: 6px; }
.secret { font-family: var(--mono); letter-spacing: .08em; overflow-wrap: anywhere; user-select: all; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; font-size: .9rem; }
.spinner { color: var(--muted); padding: 40px 0; text-align: center; }

@media (max-width: 760px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .stat .value { font-size: 1.2rem; }
  .log .entry { grid-template-columns: minmax(0, 1fr); }
}
