:root {
  --bg: #f4f5f8;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(94,234,212,.18), transparent 60%),
             radial-gradient(900px 500px at 110% 0%, rgba(129,140,248,.16), transparent 60%);
  --surface: rgba(255,255,255,.78);
  --surface-solid: #ffffff;
  --surface-2: rgba(15,23,42,.04);
  --border: rgba(15,23,42,.08);
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --accent: #0d9488;
  --accent-2: #6366f1;
  --accent-grad: linear-gradient(135deg, #14b8a6, #6366f1);
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(15,23,42,.06);
  --radius: 18px;
  --radius-sm: 12px;
  --blur: saturate(160%) blur(18px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d12;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(45,212,191,.10), transparent 60%),
               radial-gradient(900px 500px at 110% 0%, rgba(99,102,241,.13), transparent 60%);
    --surface: rgba(22,25,33,.72);
    --surface-solid: #161921;
    --surface-2: rgba(255,255,255,.04);
    --border: rgba(255,255,255,.07);
    --text: #e8eaf0;
    --text-2: #a3a9b8;
    --text-3: #6b7280;
    --accent: #2dd4bf;
    --accent-2: #818cf8;
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 12px 32px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d12;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(45,212,191,.10), transparent 60%),
             radial-gradient(900px 500px at 110% 0%, rgba(99,102,241,.13), transparent 60%);
  --surface: rgba(22,25,33,.72);
  --surface-solid: #161921;
  --surface-2: rgba(255,255,255,.04);
  --border: rgba(255,255,255,.07);
  --text: #e8eaf0;
  --text-2: #a3a9b8;
  --text-3: #6b7280;
  --accent: #2dd4bf;
  --accent-2: #818cf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 12px 32px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1, "cv11" 1;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 600; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.hidden { display: none !important; }

/* ---------- boot / spinner ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 28px 16px;
  border-right: 1px solid var(--border); background: var(--surface);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 22px; font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  color: var(--text-2); text-decoration: none; border: 0; background: none; cursor: pointer; text-align: left; width: 100%;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }
.sidebar .spacer { flex: 1; }
.main { padding: 36px 40px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

.tabbar { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: calc(env(safe-area-inset-top) + 20px) 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 26px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
    backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  }
  .tabbar .nav-item { flex-direction: column; gap: 3px; font-size: 11px; padding: 6px 0; justify-content: center; align-items: center; }
  .tabbar .nav-item.active { background: none; }
}

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.grid { display: grid; gap: 16px; }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
@media (max-width: 520px) {
  .grid.tiles { grid-template-columns: 1fr 1fr; gap: 12px; }
  .card { padding: 16px; }
}
.section { margin-top: 28px; }
.section > h2 { margin-bottom: 12px; }

/* hero status */
.hero { display: flex; align-items: center; gap: 18px; padding: 24px; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; inset: 0; background: var(--accent-grad); opacity: .07; pointer-events: none; }
.pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--ok); flex: none; position: relative; }
.pulse::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--ok); opacity: .5; animation: pulse 2s ease-out infinite; }
.pulse.bad { background: var(--danger); } .pulse.bad::after { border-color: var(--danger); }
@keyframes pulse { from { transform: scale(.6); opacity: .7; } to { transform: scale(1.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pulse::after, .spinner { animation: none; } }
.hero .title { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.hero .meta { display: flex; gap: 18px; flex-wrap: wrap; margin-left: auto; }
.hero .meta div { text-align: right; }
@media (max-width: 640px) { .hero { flex-wrap: wrap; } .hero .meta { margin-left: 0; width: 100%; justify-content: space-between; } .hero .meta div { text-align: left; } }

.tile .label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 6px; }
.tile .value small { font-size: 14px; font-weight: 500; color: var(--text-2); margin-left: 4px; }
.tile .sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.meter { height: 6px; border-radius: 6px; background: var(--surface-2); margin-top: 12px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: inherit; background: var(--accent-grad); transition: width .6s cubic-bezier(.2,.8,.2,1); }
.meter.warn > i { background: var(--warn); } .meter.danger > i { background: var(--danger); }

/* ---------- client list ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search { flex: 1; min-width: 180px; }
.list { display: grid; gap: 10px; }
.client {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 14px 16px; cursor: pointer; transition: transform .12s, border-color .15s;
}
.client:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.client:active { transform: scale(.995); }
.avatar {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; position: relative;
  background: var(--surface-2); color: var(--text-2);
}
.avatar svg { width: 22px; height: 22px; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-3); border: 2px solid var(--surface-solid); }
.avatar .dot.on { background: var(--ok); }
.client .name { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.client .info { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.client .meter { margin-top: 8px; height: 4px; }
.badge { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.empty { text-align: center; padding: 40px 20px; color: var(--text-2); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-solid); cursor: pointer; font-weight: 550; white-space: nowrap;
  transition: transform .1s, opacity .15s, background .15s;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent-grad); color: #fff; border: 0; box-shadow: 0 6px 18px rgba(99,102,241,.25); }
.btn.primary:hover { opacity: .92; }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border: 0; }
.btn.block { width: 100%; height: 46px; }
.btn.icon { width: 40px; padding: 0; }
.input, select.input, textarea.input {
  width: 100%; height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 14px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 550; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .row { grid-template-columns: 1fr; } }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--text-3); opacity: .5; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); opacity: 1; }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 380px; padding: 32px 28px; }
.login .logo { width: 56px; height: 56px; border-radius: 16px; margin-bottom: 18px; }
.login h1 { font-size: 24px; margin-bottom: 4px; }
.login p { margin: 0 0 24px; color: var(--text-2); }
.error { color: var(--danger); font-size: 13.5px; margin: -4px 0 12px; min-height: 1em; }

/* ---------- sheet (modal) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(5,8,15,.45);
  display: grid; place-items: center; padding: 20px; animation: fade .18s ease;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.sheet {
  width: 100%; max-width: 480px; max-height: calc(100vh - 40px); overflow: auto;
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: 22px;
  padding: 24px; box-shadow: 0 30px 80px rgba(0,0,0,.35); animation: rise .22s cubic-bezier(.2,.8,.2,1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.sheet .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
@media (max-width: 600px) {
  .overlay { place-items: end stretch; padding: 0; }
  .sheet { max-width: none; border-radius: 22px 22px 0 0; max-height: 92vh; padding-bottom: calc(24px + env(safe-area-inset-bottom)); animation: up .25s cubic-bezier(.2,.8,.2,1); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes up { from { transform: translateY(100%); } }
.qr { display: grid; place-items: center; background: #fff; border-radius: 18px; padding: 14px; margin: 4px auto 16px; max-width: 280px; }
.qr img { width: 100%; height: auto; display: block; image-rendering: pixelated; }
.linkbox { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 8px 8px 8px 12px; margin-bottom: 10px; }
.linkbox code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 9px; cursor: pointer; color: var(--text-2); font-weight: 550; }
.seg button.on { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; margin: 0 0 16px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; text-align: right; font-weight: 550; }
.menu { display: grid; gap: 8px; }
.note { font-size: 13px; color: var(--text-2); background: var(--surface-2); padding: 10px 12px; border-radius: 12px; margin-bottom: 14px; }
.note.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; color: var(--text-3); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 0 10px 10px; }
.table td { padding: 10px; border-top: 1px solid var(--border); vertical-align: top; }
.table-wrap { overflow-x: auto; margin: 0 -10px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); top: calc(16px + env(safe-area-inset-top)); display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface-solid); border: 1px solid var(--border); box-shadow: 0 12px 30px rgba(0,0,0,.2); border-radius: 14px; padding: 12px 16px; font-weight: 550; animation: rise .2s ease; display: flex; gap: 10px; align-items: center; }
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.toast.err::before { background: var(--danger); }

/* icon sizing */
svg { flex: none; }
.tile .label svg { width: 18px; height: 18px; color: var(--accent); }
.toolbar > .btn svg, .linkbox svg { width: 18px; height: 18px; }
@media (max-width: 600px) {
  .client { grid-template-columns: auto 1fr; }
  .client > .faint.mono { display: none; }
  .tile .value { font-size: 22px; }
}
.hero > div:nth-child(2) { flex: 1; min-width: 0; }
/* ---------- device addresses ---------- */
.iprow { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 13.5px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
