:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --card-2: #f0f2f5;
  --text: #15181d;
  --muted: #6a717d;
  --line: #e2e5ea;
  --accent: #2f6fde;
  --accent-soft: #e4edfc;
  --ok: #1f9d55;
  --warn: #d98a00;
  --bad: #d64545;
  --off: #a7adb7;
  --on: #f2a900;
  --chart: #2f6fde;
  --chart-fill: rgba(47, 111, 222, 0.12);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --card: #1a1d23;
    --card-2: #23272e;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --line: #2c3139;
    --accent: #5b8ff0;
    --accent-soft: #1f2b44;
    --ok: #3cc07a;
    --warn: #f0a92a;
    --bad: #ef6464;
    --off: #5d636d;
    --on: #ffc23d;
    --chart: #6f9cf3;
    --chart-fill: rgba(111, 156, 243, 0.16);
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --card: #1a1d23; --card-2: #23272e; --text: #e8eaee; --muted: #9aa1ad; --line: #2c3139;
  --accent: #5b8ff0; --accent-soft: #1f2b44; --ok: #3cc07a; --warn: #f0a92a; --bad: #ef6464; --off: #5d636d;
  --on: #ffc23d; --chart: #6f9cf3; --chart-fill: rgba(111, 156, 243, 0.16); --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.boot { padding: 40vh 16px; text-align: center; color: var(--muted); }

/* layout */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
header.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
header.top .wrap { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
header.top h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
header.top .agent { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
header.top .spacer { flex: 1; }
.iconbtn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  width: 36px; height: 36px; display: grid; place-items: center; padding: 0;
}
.iconbtn svg { width: 18px; height: 18px; }

.summary { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 4px; }
.chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center;
}
.chip b { color: var(--text); font-weight: 600; }

.filters { display: flex; gap: 6px; overflow-x: auto; margin: 12px 0 0; padding-bottom: 4px; scrollbar-width: none; }
.filters button {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; white-space: nowrap;
}
.filters button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

section.group { margin-top: 22px; }
section.group h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }

/* cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; display: flex; flex-direction: column; gap: 10px; text-align: left; min-width: 0;
}
.card.offline { opacity: 0.62; }
.card .row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ico {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: var(--card-2); color: var(--muted);
}
.ico svg { width: 22px; height: 22px; }
.ico.on { background: color-mix(in srgb, var(--on) 20%, transparent); color: var(--on); }
.ico.live { background: var(--accent-soft); color: var(--accent); }
.card .title { flex: 1; min-width: 0; }
.card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .open { all: unset; cursor: pointer; display: contents; }
.card .metrics { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.card .metrics b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.card .thumb { border-radius: 10px; overflow: hidden; aspect-ratio: 16/9; background: var(--card-2); display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.err { font-size: 12px; color: var(--warn); overflow-wrap: anywhere; }

/* switch */
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { appearance: none; -webkit-appearance: none; margin: 0; width: 46px; height: 28px; border-radius: 999px; background: var(--off); transition: background .15s; cursor: pointer; }
.switch input:checked { background: var(--ok); }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:disabled { opacity: .5; cursor: default; }

/* sheet */
.sheet {
  border: 0; padding: 0; background: var(--bg); color: var(--text);
  width: min(720px, 100vw); max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0 0 0 auto;
  box-shadow: -8px 0 30px rgba(0,0,0,.18);
}
.sheet::backdrop { background: rgba(10, 12, 16, 0.45); }
.sheet .head {
  position: sticky; top: 0; z-index: 2; background: var(--bg); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}
.sheet .head h3 { margin: 0; font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet .body { padding: 8px 16px calc(32px + env(safe-area-inset-bottom)); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 12px; overflow: hidden; }
.panel > h4 { margin: 0; padding: 12px 14px 4px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kv { display: grid; grid-template-columns: minmax(120px, 42%) 1fr; }
.kv > div { padding: 9px 14px; border-top: 1px solid var(--line); min-width: 0; overflow-wrap: anywhere; }
.kv > div:nth-child(-n+2) { border-top: 0; }
.kv > .k { color: var(--muted); }
.kv > .v { font-variant-numeric: tabular-nums; }
.ctl { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); min-height: 48px; }
.panel > h4 + .ctl, .panel > .ctl:first-child { border-top: 0; }
.ctl .label { flex: 1; min-width: 0; }
.ctl .label small { display: block; color: var(--muted); font-size: 12px; }
.ctl input[type="range"] { width: min(220px, 45vw); accent-color: var(--accent); }
.ctl select { background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; max-width: 55vw; }
.btn { border: 1px solid var(--line); background: var(--card-2); border-radius: 10px; padding: 8px 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }
.hue { width: min(220px, 45vw); height: 14px; border-radius: 999px; appearance: none; -webkit-appearance: none; background: linear-gradient(90deg, red, #ff0, lime, cyan, blue, #f0f, red); }
.hue::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid rgba(0,0,0,.25); }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); flex: none; }

.snap { position: relative; background: #000; aspect-ratio: 16/9; display: grid; place-items: center; color: #aaa; }
.snap img { width: 100%; height: 100%; object-fit: contain; display: block; }
.snap .when { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.snapbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.snapbar input { flex: 1; accent-color: var(--accent); }

.tabs { display: flex; gap: 4px; padding: 10px 14px 0; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: var(--card-2); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.chart { padding: 6px 8px 10px; position: relative; }
.chart svg { width: 100%; display: block; overflow: visible; touch-action: pan-y; }
.sub-h { margin: 0; padding: 12px 14px 4px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.chart .tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 3px 7px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -120%); display: none; }
.chart .empty { padding: 30px 0; text-align: center; color: var(--muted); font-size: 13px; }
.axis { fill: var(--muted); font-size: 10.5px; }
.gridline { stroke: var(--line); stroke-width: 1; }
.avail { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 10px 6px 12px; }
.avail b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.avail span { font-size: 12px; color: var(--muted); }
.strip { display: flex; height: 18px; margin: 0 14px 14px; border-radius: 5px; overflow: hidden; background: var(--card-2); }
.strip i { flex: 1; }

table.clients { width: 100%; border-collapse: collapse; font-size: 13px; }
table.clients td, table.clients th { padding: 7px 10px; border-top: 1px solid var(--line); text-align: left; }
table.clients th { color: var(--muted); font-weight: 500; }
.scroll-x { overflow-x: auto; }

.form { display: grid; gap: 8px; padding: 12px 14px; }
.form input { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; }
.form .actions { display: flex; gap: 8px; justify-content: flex-end; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .box { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; text-align: center; box-shadow: var(--shadow); }
.login img { width: 64px; height: 64px; }
.login h1 { font-size: 22px; margin: 12px 0 6px; }
.login p { color: var(--muted); margin: 0 0 18px; }
.login .btn { width: 100%; padding: 12px; font-weight: 600; }
.login .note { font-size: 13px; margin-top: 14px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; }
.muted { color: var(--muted); }
.copy { font-family: ui-monospace, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; background: var(--card-2); padding: 8px 10px; border-radius: 8px; }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  header.top .agent .long { display: none; }
  .sheet { width: 100vw; }
  .kv { grid-template-columns: 1fr 1.2fr; }
}
