:root, [data-theme="dark"] {
  --bg: #0E2329; --surface: #143039; --surface-2: #1B3D47; --line: #24505B;
  --text: #E6F0EC; --muted: #8FB0AA; --sea: #0A1C21;
  --island: #5CB98A; --sand: #E3CF9A; --coral: #E07A5F; --rock: #5E7A7C;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #EEF4F1; --surface: #FFFFFF; --surface-2: #E3EDE9; --line: #CBDCD6;
  --text: #12343B; --muted: #4A6A70; --sea: #12343B;
  --island: #2F8F5B; --sand: #B08A3E; --coral: #B8432F; --rock: #9AAAA8;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--text); background: var(--bg);
  font: 15px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.error { color: var(--coral); margin: 8px 0 0; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 8px 14px; background: none; }
button:focus-visible, input:focus-visible, select:focus-visible, .switch:focus-within {
  outline: 2px solid var(--island); outline-offset: 2px;
}
.primary { background: var(--island); color: #0A1C21; font-weight: 600; }
.primary:hover { filter: brightness(1.08); }
.ghost { border-color: var(--line); color: var(--muted); }
.ghost:hover { color: var(--text); border-color: var(--muted); }
.danger { background: var(--coral); color: #fff; font-weight: 600; }
input, select {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
}

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(340px, 100%); display: grid; gap: 8px; text-align: center; }
.login-logo { width: 96px; height: 96px; margin: 0 auto 8px; }
.login h1 { font-size: 28px; margin-bottom: 16px; }
.login label { text-align: left; color: var(--muted); }
.login button { margin-top: 8px; }

/* layout */
#app { max-width: 1080px; margin: 0 auto; padding: 20px 20px 48px; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.top-logo { width: 40px; height: 40px; }
.top h1 { font-size: 22px; margin-right: auto; }
.theme { padding: 7px; line-height: 0; }
.theme svg { width: 20px; height: 20px; }

.overview {
  background: var(--surface); border-radius: 16px; padding: 20px;
  display: grid; grid-template-columns: 1fr auto; gap: 16px 24px; margin-bottom: 20px;
}
.counters { display: flex; flex-wrap: wrap; gap: 8px; align-self: start; }
.counters button {
  display: grid; justify-items: start; gap: 0; min-width: 120px; padding: 10px 16px;
  background: var(--surface-2); border: 1px solid transparent; border-radius: 12px; text-align: left;
}
.counters button:hover { border-color: var(--line); }
.counters button[aria-pressed="true"] { border-color: currentColor; }
.counters b { font-size: 28px; line-height: 1.1; }
.counters span { font-size: 13px; color: var(--muted); }
.c-online { color: var(--island); }
.c-idle { color: var(--sand); }
.c-off { color: var(--muted); }
.numbers { text-align: right; align-self: center; }
.numbers p { margin: 0; }
.speed { font-size: 20px; margin-bottom: 4px !important; }
.dl { color: var(--sand); } .ul { color: var(--island); margin-left: 12px; }
#chart { grid-column: 1 / -1; width: 100%; height: 120px; }
.chart-note { grid-column: 1 / -1; margin: -10px 0 0; font-size: 12px; }
.chart-note .ul { margin-left: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
#search { flex: 1 1 220px; }
.banner { background: var(--surface); padding: 10px 14px; border-left: 3px solid var(--coral); border-radius: 6px; }

/* list */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 16px; overflow: hidden; }
.row {
  display: grid; align-items: center; gap: 14px; padding: 12px 18px;
  grid-template-columns: 12px minmax(140px, 1.4fr) minmax(110px, 1fr) 120px auto auto;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row.disabled { opacity: .55; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rock); }
.row.online .dot { background: var(--island); box-shadow: 0 0 0 4px color-mix(in srgb, var(--island) 25%, transparent); }
.row.idle .dot { background: var(--sand); }
.who b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span, .traffic span { color: var(--muted); font-size: 13px; }
.traffic { font-size: 14px; }
.traffic .now { display: block; }
.traffic .now:empty { display: none; }
.spark { width: 120px; height: 30px; }
.tools { display: flex; gap: 2px; }
.icon { padding: 7px; color: var(--muted); border-radius: 8px; line-height: 0; }
.icon:hover { color: var(--text); background: var(--surface-2); }
.icon.del:hover { color: var(--coral); }
.icon svg { width: 18px; height: 18px; }

.switch { position: relative; width: 42px; height: 24px; border-radius: 12px; background: var(--rock); transition: background .25s; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .25s; pointer-events: none; }
.switch.on { background: var(--island); }
.switch.on::after { transform: translateX(18px); }

.empty { text-align: center; color: var(--muted); padding: 32px; background: var(--surface); border-radius: 16px; }

/* dialogs */
dialog { border: 0; border-radius: 16px; padding: 24px; background: var(--surface); color: var(--text); width: min(380px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5, 15, 18, .6); }
dialog form, .qr-box { display: grid; gap: 8px; }
dialog h2 { font-size: 19px; margin-bottom: 8px; }
dialog label { color: var(--muted); font-size: 14px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
#qrImg { width: 100%; background: #fff; border-radius: 12px; padding: 12px; }

@media (max-width: 760px) {
  #app { padding: 14px 12px 40px; }
  .overview { grid-template-columns: 1fr; }
  .numbers { text-align: left; }
  .counters button { flex: 1 1 0; min-width: 0; padding: 8px 10px; }
  .counters b { font-size: 22px; }
  .row { grid-template-columns: 12px 1fr auto; grid-template-areas: "dot who sw" ". traffic traffic" ". tools tools"; gap: 6px 12px; }
  .row .dot { grid-area: dot; } .row .who { grid-area: who; } .row .switch { grid-area: sw; }
  .row .traffic { grid-area: traffic; } .row .spark { display: none; } .row .tools { grid-area: tools; }
  .top .ghost { padding: 6px 10px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
