/* ============================================================
   PHP-Gateway · design system
   Dark: deep charcoal + neon cyan/purple, glassmorphism, glow
   Light: white + pastel gradients, soft shadows
   No frameworks, no build step. Theme via [data-theme] on <html>.
   ============================================================ */

/* ---------- dark theme (default) ---------- */
:root,
[data-theme="dark"] {
  color-scheme: dark;

  --bg: #080a0f;
  --bg-2: #0b0e15;
  --surface: rgba(19, 23, 32, .72);
  --surface-2: rgba(28, 33, 45, .72);
  --surface-3: rgba(38, 45, 60, .8);
  --surface-solid: #131720;
  --border: rgba(255, 255, 255, .08);
  --border-2: rgba(255, 255, 255, .14);

  --text: #eaf2f7;
  --text-2: #b6c4d2;
  --muted: #7d8b9c;

  --cyan: #22e4f7;
  --cyan-2: #0fb9d6;
  --purple: #a855f7;
  --purple-2: #7c3aed;
  --primary: var(--cyan);
  --primary-ink: #04141a;
  --accent-grad: linear-gradient(135deg, #22e4f7 0%, #7c8cf8 50%, #a855f7 100%);
  --accent-grad-soft: linear-gradient(135deg, rgba(34, 228, 247, .16), rgba(168, 85, 247, .16));

  --ok: #34e5a0;
  --warn: #ffc457;
  --danger: #ff5d6c;

  --ok-soft: rgba(52, 229, 160, .13);
  --warn-soft: rgba(255, 196, 87, .13);
  --danger-soft: rgba(255, 93, 108, .13);
  --primary-soft: rgba(34, 228, 247, .12);
  --primary-line: rgba(34, 228, 247, .42);

  --glow-sm: 0 0 0 1px rgba(34, 228, 247, .18), 0 4px 18px rgba(34, 228, 247, .10);
  --glow: 0 0 26px rgba(34, 228, 247, .22);
  --shadow: 0 18px 44px rgba(0, 0, 0, .55);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, .38);
  --glass-blur: blur(14px) saturate(140%);

  --radius: 12px;
  --radius-lg: 18px;
  --sidebar-w: 252px;
  --topbar-h: 60px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}

/* ---------- light theme ---------- */
[data-theme="light"] {
  color-scheme: light;

  --bg: #f5f7fc;
  --bg-2: #eef2fa;
  --surface: rgba(255, 255, 255, .82);
  --surface-2: rgba(255, 255, 255, .95);
  --surface-3: #f1f5fb;
  --surface-solid: #ffffff;
  --border: rgba(15, 23, 42, .09);
  --border-2: rgba(15, 23, 42, .16);

  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;

  --cyan: #06b6d4;
  --cyan-2: #0891b2;
  --purple: #7c3aed;
  --purple-2: #6d28d9;
  --primary: var(--cyan-2);
  --primary-ink: #ffffff;
  --accent-grad: linear-gradient(135deg, #22d3ee 0%, #818cf8 50%, #a855f7 100%);
  --accent-grad-soft: linear-gradient(135deg, rgba(34, 211, 238, .16), rgba(168, 85, 247, .16));

  --ok: #059669;
  --warn: #b45309;
  --danger: #dc2626;

  --ok-soft: rgba(5, 150, 105, .10);
  --warn-soft: rgba(180, 83, 9, .10);
  --danger-soft: rgba(220, 38, 38, .09);
  --primary-soft: rgba(8, 145, 178, .10);
  --primary-line: rgba(8, 145, 178, .35);

  --glow-sm: 0 2px 10px rgba(15, 23, 42, .06);
  --glow: 0 8px 26px rgba(8, 145, 178, .16);
  --shadow: 0 18px 44px rgba(15, 23, 42, .10);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, .06);
  --glass-blur: blur(12px) saturate(130%);

  --radius: 12px;
  --radius-lg: 18px;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
/* ambient neon wash (dark) / pastel wash (light) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(34, 228, 247, .13), transparent 60%),
    radial-gradient(760px 480px at 92% 4%, rgba(168, 85, 247, .12), transparent 62%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
}
[data-theme="light"] body::before {
  background:
    radial-gradient(900px 520px at 10% -10%, rgba(34, 211, 238, .20), transparent 60%),
    radial-gradient(780px 500px at 94% 0%, rgba(168, 85, 247, .16), transparent 62%),
    linear-gradient(180deg, #fbfcff, var(--bg));
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--primary-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}
.app[data-nav="collapsed"] .sidebar { flex-basis: 70px; width: 70px; }
.app[data-nav="collapsed"] .sidebar .nav-label,
.app[data-nav="collapsed"] .sidebar .brand-text,
.app[data-nav="collapsed"] .sidebar .nav-group-title { display: none; }
.app[data-nav="collapsed"] .sidebar a { justify-content: center; padding-inline: 0; }
.app[data-nav="collapsed"] .sidebar-foot .who { display: none; }

.brand {
  display: flex; align-items: center; gap: 11px;
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent-grad);
  color: #fff; flex: 0 0 auto;
  box-shadow: var(--glow-sm);
}
.brand-text { font-weight: 700; letter-spacing: .2px; }

.nav { padding: 12px 10px 18px; overflow-y: auto; flex: 1 1 auto; }
.nav-group-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); padding: 15px 10px 7px; font-weight: 700;
}
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 11px;
  color: var(--text-2); font-weight: 500;
  transition: background .14s, color .14s, box-shadow .14s;
  position: relative;
}
.nav a + a { margin-top: 3px; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active {
  color: var(--text);
  background: var(--accent-grad-soft);
  box-shadow: inset 0 0 0 1px var(--primary-line), 0 0 18px rgba(34, 228, 247, .10);
}
.nav a.active .ic { color: var(--cyan); }
.nav a.active::before {
  content: ""; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 99px; background: var(--accent-grad);
  box-shadow: 0 0 12px var(--cyan);
}
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
  min-height: 56px;
}
.sidebar-foot .who { min-width: 0; flex: 1; }
.sidebar-foot .who b { display: block; font-size: 12.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot .who span { font-size: 11px; color: var(--muted); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 15px; font-weight: 650; letter-spacing: .1px; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-2); cursor: pointer;
  transition: border-color .14s, color .14s, box-shadow .14s;
}
.icon-btn:hover { color: var(--text); border-color: var(--primary-line); box-shadow: var(--glow-sm); }
.nav-toggle { display: none; }

.content { padding: 24px; width: 100%; max-width: 1240px; margin: 0 auto; flex: 1 1 auto; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-tight { display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }

/* ---------- status pill ---------- */
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 13px 6px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px; color: var(--text-2);
  white-space: nowrap;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.status-pill[data-state="up"] { border-color: rgba(52, 229, 160, .38); color: #9df3cf; box-shadow: 0 0 16px rgba(52, 229, 160, .14); }
.status-pill[data-state="up"] .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft), 0 0 10px var(--ok); }
.status-pill[data-state="down"] { border-color: rgba(255, 93, 108, .42); color: #ffb9c0; }
.status-pill[data-state="down"] .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft), 0 0 10px var(--danger); }
.status-pill[data-state="busy"] .dot { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- card (glass) ---------- */
.card {
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-grad-soft);
}
.card-head h2 { font-size: 13.5px; font-weight: 650; letter-spacing: .1px; }
.card-head .sub { font-size: 12px; color: var(--muted); }
.card-body { padding: 20px; }
.card-body.tight { padding: 0; }
.card-foot {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: rgba(127, 127, 127, .04);
}
.card.accent-line { position: relative; }
.card.accent-line::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 2px;
  background: var(--accent-grad); box-shadow: 0 0 16px var(--cyan);
}

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(186px, 1fr)); gap: 14px; }
.stat {
  position: relative;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  overflow: hidden;
  transition: border-color .16s, box-shadow .16s, transform .16s;
}
.stat::after {
  content: ""; position: absolute; inset: auto -30% -60% auto; width: 180px; height: 180px;
  background: radial-gradient(circle, var(--accent-grad-soft), transparent 70%);
  pointer-events: none;
}
.stat:hover { transform: translateY(-2px); border-color: var(--primary-line); box-shadow: var(--glow-sm); }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; display: flex; align-items: center; gap: 6px; font-weight: 650; }
.stat .k .ic { color: var(--cyan); }
.stat .v { font-size: 27px; font-weight: 700; letter-spacing: -.6px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat.accent .v { background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat .spark { position: absolute; right: 14px; top: 14px; opacity: .85; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  color: var(--text);
  font-weight: 550; font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s, border-color .14s, box-shadow .14s, transform .06s;
}
.btn:hover { border-color: var(--primary-line); box-shadow: var(--glow-sm); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-busy="true"] { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-primary {
  background: var(--accent-grad);
  border-color: transparent; color: var(--primary-ink);
  box-shadow: 0 4px 20px rgba(34, 228, 247, .28);
  font-weight: 650;
}
[data-theme="light"] .btn-primary { color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; border-color: rgba(255, 93, 108, .38); color: #ff9aa3; }
[data-theme="light"] .btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn-icon { padding: 6px; width: 30px; height: 30px; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 650; letter-spacing: .2px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(52, 229, 160, .3); }
.badge-off { background: var(--surface-3); color: var(--muted); border-color: var(--border-2); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(255, 93, 108, .3); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(255, 196, 87, .3); }
.badge-info { background: var(--primary-soft); color: var(--cyan); border-color: var(--primary-line); }
[data-theme="light"] .badge-info { color: var(--cyan-2); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pair-cmd {
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  padding: 9px 11px; border-radius: 8px; border: 1px dashed var(--border-2);
  background: var(--surface-3); color: var(--text); white-space: pre-wrap; word-break: break-all;
}

/* ---------- forms ---------- */
.field { margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.field > label, .label {
  display: block; font-size: 12px; font-weight: 650;
  color: var(--text-2); margin-bottom: 6px; letter-spacing: .1px;
}
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  color: var(--text);
  transition: border-color .14s, box-shadow .14s;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--primary-line); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--cyan);
  box-shadow: 0 0 0 3px var(--primary-soft), 0 0 18px rgba(34, 228, 247, .12);
}
.textarea { min-height: 88px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 17px, calc(100% - 11px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 15px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 15px; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 40px; height: 23px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border-2);
  position: relative; transition: background .16s, border-color .16s; flex: 0 0 auto;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--muted); transition: transform .16s, background .16s;
}
.switch input:checked + .track { background: var(--primary-soft); border-color: var(--cyan); box-shadow: 0 0 14px rgba(34, 228, 247, .25); }
.switch input:checked + .track::after { transform: translateX(17px); background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--primary-soft); }
.switch .switch-label { font-size: 13px; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
  padding: 11px 16px; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
  white-space: nowrap;
}
table.tbl td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tbody tr { transition: background .12s; }
table.tbl tbody tr:hover td { background: var(--accent-grad-soft); }
table.tbl tr.dim td { opacity: .48; }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.actions { text-align: right; white-space: nowrap; }
.cell-strong { font-weight: 650; }
.cell-sub { font-size: 11.5px; color: var(--muted); }
.copyable { cursor: copy; border-bottom: 1px dashed var(--border-2); }
.copyable:hover { border-bottom-color: var(--cyan); color: var(--cyan); }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(127, 127, 127, .03);
}
.toolbar .input, .toolbar .select { width: auto; min-width: 150px; }
.search { position: relative; }
.search .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 34px; }

/* segmented + tabs */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  padding: 6px 13px; border: 0; background: transparent; color: var(--muted);
  border-radius: 7px; font-size: 12.5px; font-weight: 550; cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button[aria-selected="true"] { background: var(--accent-grad-soft); color: var(--text); box-shadow: inset 0 0 0 1px var(--primary-line); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 10px; }
.tabs button {
  padding: 12px 15px; background: transparent; border: 0;
  border-bottom: 2px solid transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--cyan); box-shadow: 0 6px 18px -12px var(--cyan); }
.tab-panel[hidden] { display: none; }

/* ---------- banners ---------- */
.banner {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 13px 15px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 13px;
}
.banner .ic { flex: 0 0 auto; margin-top: 1px; }
.banner b { font-weight: 650; }
.banner-ok { background: var(--ok-soft); border-color: rgba(52, 229, 160, .3); color: #9df3cf; }
.banner-err { background: var(--danger-soft); border-color: rgba(255, 93, 108, .32); color: #ffb9c0; }
.banner-warn { background: var(--warn-soft); border-color: rgba(255, 196, 87, .3); color: #ffd894; }
.banner-info { background: var(--primary-soft); border-color: var(--primary-line); color: #a9e9f5; }
[data-theme="light"] .banner-ok { color: var(--ok); }
[data-theme="light"] .banner-err { color: var(--danger); }
[data-theme="light"] .banner-warn { color: var(--warn); }
[data-theme="light"] .banner-info { color: var(--cyan-2); }

/* ---------- empty ---------- */
.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty .ic { margin: 0 auto 12px; color: var(--border-2); }
.empty h3 { font-size: 14px; color: var(--text-2); margin-bottom: 5px; }
.empty p { font-size: 12.5px; max-width: 400px; margin: 0 auto 14px; }

/* ---------- code ---------- */
.code {
  font-family: var(--mono); font-size: 12px; line-height: 1.65;
  background: rgba(6, 10, 16, .5); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px;
  overflow-x: auto; color: var(--text-2); white-space: pre;
}
[data-theme="light"] .code { background: #f8fafc; }
.code .c { color: var(--muted); }
.kbd {
  font-family: var(--mono); font-size: 11px;
  background: var(--surface-3); border: 1px solid var(--border-2);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px;
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 240;
  background: rgba(4, 6, 12, .7);
  backdrop-filter: blur(5px);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 580px; max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--surface-solid);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); box-shadow: var(--shadow), 0 0 40px rgba(34, 228, 247, .08);
  animation: rise .16s ease-out;
}
.modal.wide { max-width: 780px; }
@keyframes rise { from { transform: translateY(12px) scale(.985); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--accent-grad-soft); }
.modal-head h3 { font-size: 14.5px; font-weight: 650; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end; background: rgba(127, 127, 127, .04); }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 9px; max-width: 380px; }
.toast { cursor: pointer;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  background: var(--surface-solid); border: 1px solid var(--border-2);
  border-left: 3px solid var(--cyan);
  border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 13px; animation: slidein .16s ease-out;
}
@keyframes slidein { from { transform: translateX(14px); opacity: 0; } }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast .ic { flex: 0 0 auto; margin-top: 1px; }
.toast.err .ic { color: var(--danger); }
.toast.ok .ic { color: var(--ok); }

/* ---------- bubbles ---------- */
/* one right-side stack: live panel + local API + console never overlap */
.bubble-stack {
  position: fixed; right: 20px; bottom: 20px; z-index: 110;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  max-width: calc(100vw - 40px);
}
.bubble { display: contents; }
.bubble-console { }
.bubble-api { }
.bubble-panel {
  width: 390px; max-width: calc(100vw - 40px);
  background: var(--surface-solid); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column;
}
.bubble-panel-head { padding: 11px 13px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 650; background: var(--accent-grad-soft); }
.bubble-panel-body { padding: 11px 13px; max-height: 270px; overflow: auto; }
/* console: live process feeder above the command output */
.console-body { max-height: 430px; }
.console-feed {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); overflow: hidden; margin-bottom: 10px;
}
.console-feed-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 9px; border-bottom: 1px solid var(--border);
  font-size: 11px; font-weight: 650; color: var(--text-2);
  background: var(--accent-grad-soft);
}
.console-feed-title { letter-spacing: .2px; }
.console-feed-list {
  max-height: 132px; overflow: auto;
  font-family: var(--mono); font-size: 11px; line-height: 1.5;
}
.console-feed-row {
  display: flex; align-items: center; gap: 8px;
  padding: 1px 9px; border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer;
}
.console-feed-row:hover { background: var(--primary-soft); }
.console-feed-row:last-child { border-bottom: 0; }
.console-feed-row.is-new { animation: feedFlash 1.4s ease-out; }
@keyframes feedFlash {
  0%   { background: var(--primary-soft); }
  100% { background: transparent; }
}
.feed-role {
  flex: 0 0 74px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .3px; color: var(--muted);
}
.feed-role.feed-manager { color: var(--cyan); }
.feed-role.feed-gateway { color: var(--ok); }
.feed-role.feed-ide { color: var(--purple-2); }
.feed-role.feed-cli { color: var(--cyan-2); }
.feed-name { flex: 0 0 auto; color: var(--text); }
.feed-pid { flex: 0 0 auto; color: var(--muted); }
.feed-detail {
  flex: 1 1 auto; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; color: var(--muted);
}

/* live gateway stats: section inside the console popup */
.console-stats {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); overflow: hidden; margin-bottom: 10px;
}
.console-stats-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 9px; border-bottom: 1px solid var(--border);
  font-size: 11px; font-weight: 650; background: var(--accent-grad-soft);
}
.console-stats-head .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3); flex: 0 0 auto;
}
.console-stats[data-state="up"] .dot { background: var(--ok); box-shadow: 0 0 7px var(--ok-soft); }
.console-stats[data-state="down"] .dot { background: var(--danger); }
.console-stats-title { letter-spacing: .2px; }
.console-stats-model {
  font-size: 11px; color: var(--cyan);
  max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.console-stats-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px; background: var(--border);
}
.console-stats-grid > div {
  background: var(--surface-2); padding: 6px 8px;
  display: flex; flex-direction: column; gap: 1px; min-width: 0;
}
.console-stats-grid span {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted);
}
.console-stats-grid b { font-size: 12px; font-weight: 650; color: var(--text); }
.console-stats-foot {
  padding: 4px 9px; font-size: 10.5px; color: var(--muted);
  border-top: 1px solid var(--border);
}

/* draggable console popup */
.console-drag-head { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.console-drag-head .drag-grip { color: var(--muted); font-size: 12px; letter-spacing: -2px; }
#console-panel.is-dragged { position: fixed; z-index: 130; margin: 0; }
#console-panel.is-dragging { opacity: .96; box-shadow: 0 22px 52px rgba(0,0,0,.55); }
#console-panel.is-dragging .console-drag-head { cursor: grabbing; }

/* console: tabs, live clock, token chart */
.console-tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  background: var(--accent-grad-soft);
}
.console-tab {
  flex: 1 1 0; padding: 7px 10px; border: 0; cursor: pointer;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 11.5px; font-weight: 650;
  border-bottom: 2px solid transparent;
}
.console-tab.is-active { color: var(--text); border-bottom-color: var(--cyan); background: var(--surface-solid); }
.console-tab:hover { color: var(--text); }
.console-clock { font-size: 11.5px; color: var(--cyan); font-variant-numeric: tabular-nums; }

.tk-tiles {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px; background: var(--border); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; margin-bottom: 10px;
}
.tk-tile { background: var(--surface-2); padding: 7px 9px; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tk-tile span { font-size: 9.5px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); }
.tk-tile b { font-size: 13px; font-weight: 650; color: var(--text); }
.tk-chart-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.tk-chart {
  display: flex; align-items: flex-end; gap: 3px; height: 78px;
  padding: 6px 4px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); overflow-x: auto;
}
.tk-col { flex: 1 0 14px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.tk-col.is-now .tk-label { color: var(--cyan); font-weight: 700; }
.tk-req { font-size: 9px; color: var(--muted); min-height: 11px; }
.tk-bar {
  position: relative; width: 100%; min-width: 8px; border-radius: 2px;
  display: flex; flex-direction: column; justify-content: flex-end;
  background: var(--surface-3); overflow: visible;
}
.tk-seg-prompt { display: block; background: var(--cyan); width: 100%; }
.tk-seg-completion { display: block; background: var(--purple); width: 100%; }
.tk-errdot {
  position: absolute; top: -4px; right: -3px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--danger); display: block;
}
.tk-label { font-size: 8.5px; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.tk-legend { display: flex; gap: 12px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.tk-key { display: inline-flex; align-items: center; gap: 4px; }
.tk-key i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.sw-prompt { background: var(--cyan); }
.sw-completion { background: var(--purple); }
.sw-error { background: var(--danger); border-radius: 50%; }
.tk-last { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }

/* clickable errors tile (lives inside .tk-tiles) + live token line + error rows */
.tk-tile-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  min-width: 0; width: auto; margin: 0; padding: 7px 9px; cursor: pointer;
  border: 0; border-radius: 0; background: var(--surface-2);
  color: var(--text); font: inherit; text-align: left;
}
.tk-tiles .tk-tile-btn:hover { background: var(--danger-soft); }
.tk-tile-btn span { font-size: 9.5px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); }
.tk-tile-btn b { font-size: 13px; font-weight: 650; color: var(--danger); }
.console-live-token {
  margin-top: 6px; padding: 5px 8px; border-radius: 7px;
  background: var(--primary-soft); color: var(--text-2);
  font-family: var(--mono); font-size: 10.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.err-row {
  border: 1px solid var(--border); border-left: 3px solid var(--danger);
  border-radius: 8px; padding: 7px 9px; background: var(--surface-2);
  cursor: pointer;
}
/* toolbar above the error rows: count on the left, Clear errors on the right */
.err-toolbar { gap: 10px; flex-wrap: nowrap; }
.err-toolbar > .small { flex: 1 1 auto; min-width: 0; }
.err-toolbar > .btn { flex: 0 0 auto; }
.err-row:hover { background: var(--danger-soft); }
.err-row-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.err-row-msg {
  font-family: var(--mono); font-size: 11px; color: var(--text-2);
  white-space: pre-wrap; word-break: break-word; max-height: 120px; overflow: auto;
}

.console-out { font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; word-break: break-word; color: var(--text-2); max-height: 190px; overflow: auto; scroll-behavior: smooth; }
  .console-out > div { padding: 1px 0; }
  .console-out .console-ok { color: var(--ok); }
  .console-out .console-warn { color: var(--warn); }
  .console-out .console-err { color: var(--danger); }
  .console-out .console-hint { color: var(--text-3); }
.bubble-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 15px; border-radius: 999px;
  background: var(--surface); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-2);
  color: var(--text-2); font-size: 12.5px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.bubble-toggle:hover { color: var(--text); border-color: var(--cyan); box-shadow: var(--glow-sm); }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 424px;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: 22px; padding: 30px;
  box-shadow: var(--shadow), 0 0 50px rgba(34, 228, 247, .10);
}
.auth-card .brand-mark { margin: 0 auto 14px; width: 42px; height: 42px; border-radius: 13px; }
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head h1 { font-size: 19px; font-weight: 700; }
.auth-head p { color: var(--muted); font-size: 13px; margin-top: 6px; }
.auth-foot { margin-top: 18px; text-align: center; font-size: 12.5px; color: var(--muted); }
.auth-card .btn { width: 100%; margin-top: 6px; }
.check-row { display: flex; align-items: center; gap: 9px; margin-bottom: 15px; font-size: 13px; color: var(--text-2); }
.check-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--cyan); }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.help-list { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; }
.help-list li { margin: 4px 0; }

/* ============================================================
   Routing node-graph (dashboard hero)
   ============================================================ */
.graph-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(34, 228, 247, .05), transparent 45%),
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(127, 127, 127, .06) 27px 28px),
    repeating-linear-gradient(90deg, transparent 0 27px, rgba(127, 127, 127, .06) 27px 28px);
}
[data-theme="light"] .graph-wrap {
  background:
    linear-gradient(180deg, rgba(34, 211, 238, .10), transparent 45%),
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(15, 23, 42, .045) 27px 28px),
    repeating-linear-gradient(90deg, transparent 0 27px, rgba(15, 23, 42, .045) 27px 28px);
}
.graph-wrap svg { width: 100%; height: 260px; display: block; }
.g-edge { fill: none; stroke: rgba(127, 127, 127, .32); stroke-width: 1.5; }
.g-edge.active { stroke: url(#gwGrad); stroke-width: 2; filter: drop-shadow(0 0 6px rgba(34, 228, 247, .55)); }
.g-packet { fill: var(--cyan); filter: drop-shadow(0 0 7px var(--cyan)); }
.g-packet.err { fill: var(--danger); filter: drop-shadow(0 0 7px var(--danger)); }
.g-node-box { fill: var(--surface-solid); stroke: var(--border-2); stroke-width: 1; }
.g-node-box.router { stroke: var(--cyan); filter: drop-shadow(0 0 12px rgba(34, 228, 247, .45)); }
.g-node-box.model { stroke: var(--purple); }
.g-node-label { fill: var(--text); font: 600 11px var(--sans); }
.g-node-sub { fill: var(--muted); font: 500 9.5px var(--mono); }
.g-node-icon { fill: var(--cyan); }
.g-title { fill: var(--muted); font: 600 10px var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.g-ring { fill: none; stroke: var(--border-2); stroke-width: 3; }
.g-ring-fill { fill: none; stroke: url(#gwGrad); stroke-width: 3; stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; }
@keyframes gdash { to { stroke-dashoffset: -24; } }
.g-edge.active { stroke-dasharray: 6 6; animation: gdash 1.1s linear infinite; }
@keyframes gmove { from { offset-distance: 0%; } to { offset-distance: 100%; } }
.graph-legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }
.graph-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; vertical-align: middle; }
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: 92px; display: block; overflow: visible; }
.chart-line { fill: none; stroke: url(#gwGrad); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: url(#gwArea); opacity: .5; }
.chart-dot { fill: var(--cyan); }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.bar-track { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--accent-grad); box-shadow: 0 0 12px rgba(34, 228, 247, .35); }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .content { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .nav-toggle { display: grid; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .app[data-nav="open"] .sidebar { transform: none; }
  .app[data-nav="open"]::after { content: ""; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .5); }
  .app[data-nav="collapsed"] .sidebar { width: var(--sidebar-w); flex-basis: var(--sidebar-w); }
  .app[data-nav="collapsed"] .sidebar .nav-label,
  .app[data-nav="collapsed"] .sidebar .brand-text { display: initial; }
  .bubble-panel { width: calc(100vw - 40px); }
}
@media (max-width: 600px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .v { font-size: 22px; }
  .topbar h1 { font-size: 14px; }
  .card-body { padding: 15px; }
  .graph-wrap svg { height: 220px; }
}