:root {
  /* ── Glassmorphism · "Slate + Amber" ─────────────────────────────────────────
     Deep steel-black gradient behind frosted glass panels. Sky is the primary/
     brand colour, amber the warm status accent (online / rx). Green-free.
     Components consume semantic tokens only — never raw hex. */

  /* backdrop (fixed gradient + drifting blobs live on .bg-field) */
  --bg-0: #0C0F16;        /* top of gradient */
  --bg-1: #10141F;        /* mid */
  --bg-2: #171B26;        /* bottom, steel-black */

  /* glass surfaces (translucent, sit over the blurred backdrop) */
  --glass: rgba(255, 255, 255, .05);
  --glass-2: rgba(255, 255, 255, .08);   /* elevated / pressed */
  --glass-strong: rgba(18, 23, 34, .55); /* modals — denser so text stays legible */
  --glass-border: rgba(255, 255, 255, .12);
  --glass-border-soft: rgba(255, 255, 255, .07);
  --glass-hi: rgba(255, 255, 255, .16);  /* top-edge highlight */
  --blur: 18px;

  --text: #F8FAFC;
  --muted: #94A3B8;       /* slate-400, ≥3:1 on backdrop */

  --accent: #38BDF8;      /* sky — brand + primary CTA */
  --accent-2: #0EA5E9;    /* deeper sky for gradient fills */
  --accent-ink: #06121F;  /* dark ink on the bright sky button */
  --amber: #FBBF24;       /* online status + warning */
  --rx: #FBBF24;          /* download / received traffic */
  --tx: #60A5FA;          /* upload / sent traffic */
  --red: #F87171;         /* danger text / ghost */
  --danger: #E11D48;      /* destructive fill (rose-600) */

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 50px rgba(2, 6, 16, .55), 0 2px 8px rgba(2, 6, 16, .4);
  --glow: 0 0 0 1px rgba(56, 189, 248, .35), 0 8px 30px rgba(56, 189, 248, .28);
  --maxw: 640px;
  --icon-sm: 16px;
  --icon-md: 20px;
  --icon-lg: 24px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  /* dense/dashboard spacing rhythm (density 8/10) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;
}

/* Glass is a dark-only design — the palette above is the only theme; OS light
   preference is deliberately ignored so the frosted look stays consistent. */
:root { color-scheme: dark; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1200px 800px at 15% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
    radial-gradient(900px 700px at 110% 10%, color-mix(in srgb, var(--amber) 10%, transparent), transparent 55%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 45%, var(--bg-2) 100%);
  background-attachment: fixed;
}

/* ── ambient drifting blobs (behind everything) ── */
.bg-field {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .5;
  will-change: transform;
}
.blob-a { width: 42vmax; height: 42vmax; left: -12vmax; top: -10vmax;
  background: radial-gradient(circle, var(--accent), transparent 70%);
  animation: drift-a 26s ease-in-out infinite; }
.blob-b { width: 34vmax; height: 34vmax; right: -10vmax; top: 20vmax;
  background: radial-gradient(circle, var(--amber), transparent 70%);
  opacity: .38; animation: drift-b 32s ease-in-out infinite; }
.blob-c { width: 30vmax; height: 30vmax; left: 30vmax; bottom: -14vmax;
  background: radial-gradient(circle, var(--tx), transparent 70%);
  opacity: .32; animation: drift-c 30s ease-in-out infinite; }
@keyframes drift-a { 50% { transform: translate(6vmax, 8vmax) scale(1.1); } }
@keyframes drift-b { 50% { transform: translate(-7vmax, 5vmax) scale(1.08); } }
@keyframes drift-c { 50% { transform: translate(4vmax, -6vmax) scale(1.12); } }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.center { text-align: center; padding: 40px 16px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── the glass primitive ── */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border-soft);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(150%);
  backdrop-filter: blur(var(--blur)) saturate(150%);
  box-shadow: var(--shadow);
  position: relative;
}
/* top-edge light reflection */
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(180deg, var(--glass-hi), transparent 40%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* ── icons ── */
.ic {
  width: var(--icon-md); height: var(--icon-md);
  stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
  flex: 0 0 auto; vertical-align: -.15em;
}
.ic-sm { width: var(--icon-sm); height: var(--icon-sm); }
.ic-lg { width: var(--icon-lg); height: var(--icon-lg); }
#i-play, #i-stop, #i-pause { fill: currentColor; stroke: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--text);
  cursor: pointer; width: 44px; height: 44px; border-radius: 50%;
  transition: background .15s;
}
.icon-btn:hover { background: var(--glass-2); }
.icon-btn:active { background: var(--glass-2); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── layout ── */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
h1 { font-size: 24px; margin: 6px 0 18px; font-weight: 750; letter-spacing: -.2px; }
h2 { font-size: 16px; margin: 0; font-weight: 650; }
#loading { display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* ── stat grid ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  border-radius: var(--radius);
  padding: 18px 12px;
  text-align: center;
  overflow: hidden;
}
.stat-val {
  font-size: 30px; font-weight: 750; line-height: 1;
  font-variant-numeric: tabular-nums; min-height: 30px;
}
.stat-online { color: var(--amber); }
.stat-online-tile {
  background:
    radial-gradient(120% 120% at 50% -20%, color-mix(in srgb, var(--amber) 22%, transparent), transparent 60%),
    var(--glass);
}
.stat-label { font-size: 11px; color: var(--muted); margin-top: 7px; text-transform: uppercase; letter-spacing: .6px; }

/* ── cards ── */
.card {
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.card p.muted { margin: 0 0 14px; font-size: 14px; }

.kv {
  display: grid; grid-template-columns: auto 1fr;
  gap: 8px 16px; margin: 0 0 8px; font-size: 14px;
}
.stats-meta {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 12px 0 4px; font-size: 13px;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 650; padding: 4px 11px; border-radius: 999px;
  background: var(--glass-2);
  border: 1px solid var(--glass-border-soft);
  color: var(--muted); white-space: nowrap;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.badge.up   { background: color-mix(in srgb, var(--amber) 20%, transparent); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 35%, transparent); }
.badge.down { background: color-mix(in srgb, var(--red)  20%, transparent); color: var(--red);  border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.badge.ok   { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.badge.no   { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 32%, transparent); }

/* ── buttons ── */
.btn {
  appearance: none;
  border: 1px solid var(--glass-border);
  background: var(--glass-2);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  color: var(--text);
  font-size: 14px; font-weight: 600;
  padding: 10px 16px; min-height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform .12s var(--ease), box-shadow .18s, background .15s, filter .15s;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: var(--glass-hi); border-color: var(--glass-border); }
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: default; filter: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: var(--glow); }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; box-shadow: 0 6px 18px color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-danger-ghost { color: var(--red); }
.btn-sm { padding: 7px 12px; min-height: 38px; font-size: 13px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn-row.end { justify-content: flex-end; }
.btn-row .btn { flex: 1 1 0; min-width: 0; }
.btn-row.end .btn { flex: 0 0 auto; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 26px 0 12px;
}
.section-actions { display: flex; align-items: center; gap: 4px; }
.section-actions .icon-btn { width: 38px; height: 38px; color: var(--muted); }
.section-actions .icon-btn:hover { color: var(--text); }

/* ── forms ── */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.form input {
  background: var(--glass-2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 16px; padding: 12px; min-height: 44px; width: 100%;
}
.form input::placeholder { color: var(--muted); }
.form input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

/* ── search ── */
.search-wrap { position: relative; margin-bottom: 12px; }
.search-ic {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.search-wrap input {
  background: var(--glass);
  -webkit-backdrop-filter: blur(var(--blur)); backdrop-filter: blur(var(--blur));
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 16px; padding: 12px 14px 12px 42px; min-height: 44px; width: 100%;
}
.search-wrap input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.search-wrap input::placeholder { color: var(--muted); }

.list-filter {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: -4px 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── comment block (client modal) ── */
.comment-block { border-top: 1px solid var(--glass-border-soft); margin-top: 14px; padding-top: 14px; }
.comment-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.comment-label {
  display: inline-flex; align-items: center; gap: 6px; color: var(--muted);
  font-size: 13px; text-transform: uppercase; letter-spacing: .5px;
}
.comment-view { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.comment-editor textarea {
  background: var(--glass-2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 15px; line-height: 1.4;
  padding: 10px 12px; width: 100%; resize: vertical;
}
.comment-editor textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

/* ── client list ── */
.client-list { display: flex; flex-direction: column; gap: 12px; }
.client {
  display: flex; align-items: center; gap: 12px; width: 100%;
  text-align: left; font: inherit; color: inherit;
  background: var(--glass);
  border: 1px solid var(--glass-border-soft);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
  backdrop-filter: blur(var(--blur)) saturate(140%);
  border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer;
  box-shadow: 0 8px 22px rgba(2, 6, 16, .28);
  transition: transform .16s var(--ease), border-color .15s, background .15s, box-shadow .18s;
}
.client:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 45%, var(--glass-border)); box-shadow: var(--glow); }
.client:active { transform: translateY(0) scale(.99); background: var(--glass-2); }
.client:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.client .dot {
  position: relative; width: 12px; height: 12px; border-radius: 50%;
  background: transparent; border: 2px solid var(--muted); flex: 0 0 auto;
}
/* status conveyed by shape + colour, not colour alone */
.client .dot.online {
  background: var(--amber); border-color: var(--amber);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--amber) 22%, transparent);
  animation: livepulse 2s ease-in-out infinite;
}
.client .dot.disabled { border-color: var(--muted); background: transparent; }
.client .dot.disabled::after {
  content: ""; position: absolute; inset: 2px 1px; border-top: 2px solid var(--muted);
  transform: translateY(2px);
}
.client .info { flex: 1 1 auto; min-width: 0; }
.client .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client .sub { font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.client .note { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; }
.client .note span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client .traffic { text-align: right; font-size: 12px; color: var(--muted); flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.client .traffic > div { display: flex; align-items: center; justify-content: flex-end; gap: 3px; }
.client .traffic .down { color: var(--rx); }
.client .traffic .up { color: var(--tx); }

@keyframes livepulse {
  0%, 100% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--amber) 22%, transparent); }
  50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--amber) 6%, transparent); }
}

/* ── skeletons ── */
.sk {
  display: inline-block; border-radius: 6px;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--muted) 16%, transparent) 25%,
    color-mix(in srgb, var(--muted) 30%, transparent) 37%,
    color-mix(in srgb, var(--muted) 16%, transparent) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.sk-num { width: 40%; height: 28px; }
.client.skeleton { pointer-events: none; animation: none; }
.client.skeleton .sk-dot { width: 12px; height: 12px; border-radius: 50%; }
.client.skeleton .info .sk { display: block; }
.client.skeleton .sk-line1 { width: 45%; height: 12px; margin-bottom: 7px; }
.client.skeleton .sk-line2 { width: 65%; height: 10px; }
.client.skeleton .sk-tr { width: 44px; height: 24px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ── toggle switch ── */
.switch {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto; width: 46px; height: 44px; cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .slider {
  position: relative; width: 46px; height: 28px;
  background: var(--glass-2);
  border: 1px solid var(--glass-border);
  border-radius: 999px; transition: background .18s, border-color .18s;
}
.switch .slider::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--muted);
  transition: transform .18s var(--ease), background .18s;
}
.switch input:checked + .slider {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 45%, transparent);
}
.switch input:checked + .slider::before { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled { cursor: default; }
.switch input:disabled + .slider { opacity: .5; }

/* ── modal ── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(4, 8, 16, .55);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  padding: 0; animation: fade .15s ease;
}
@media (min-width: 560px) { .modal { align-items: center; padding: 16px; } }
.modal-card {
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(28px) saturate(150%); backdrop-filter: blur(28px) saturate(150%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  width: 100%; max-width: var(--maxw);
  padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  animation: slideup .26s var(--ease);
}
@media (min-width: 560px) { .modal-card { border-radius: var(--radius); animation: popin .2s var(--ease); } }
.modal-card h2 { margin-bottom: 14px; }

.qr-wrap { text-align: center; margin: 18px 0; }
.qr-wrap img {
  width: 220px; max-width: 70%;
  background: #fff; padding: 12px; border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(2, 6, 16, .4);
  image-rendering: pixelated;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
@keyframes popin { from { transform: scale(.96); opacity: .6; } to { transform: scale(1); opacity: 1; } }
@keyframes rowin { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* staggered list entrance (subtle) */
.client-list .client { animation: rowin .3s var(--ease) both; }

/* ── toast ── */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 100;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  color: var(--text); border: 1px solid var(--glass-border);
  padding: 12px 18px; border-radius: 999px; box-shadow: var(--shadow);
  font-size: 14px; max-width: 90%; animation: fade .15s ease;
}
.toast.err { border-color: var(--red); color: var(--red); }
.toast.ok  { border-color: var(--accent); }

.spin { display: inline-block; animation: rot 1s linear infinite; transform-origin: center; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ── reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .sk { animation: none; opacity: .6; }
  .blob { animation: none; }
}
