/* =========================================================================
   Algonize Admin Console
   Design tokens → layout → components → views. No external dependencies.
   ========================================================================= */

:root {
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e6e8ef;
  --border-strong: #d5d9e3;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #8a94a6;

  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-soft: #eef2ff;
  --primary-ring: rgba(79, 70, 229, .22);

  --success: #16a34a;  --success-soft: #dcfce7;
  --warning: #d97706;  --warning-soft: #fef3c7;
  --danger: #dc2626;   --danger-soft: #fee2e2;
  --info: #0284c7;     --info-soft: #e0f2fe;
  --neutral-soft: #eef1f5;

  --c1: #6366f1; --c2: #14b8a6; --c3: #f59e0b; --c4: #f43f5e;
  --c5: #0ea5e9; --c6: #8b5cf6; --c7: #22c55e; --c8: #94a3b8;

  --side-bg: #0b1020;
  --side-bg-2: #121a30;
  --side-text: #aab4c8;
  --side-text-strong: #f1f5f9;
  --side-active: rgba(99, 102, 241, .16);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow: 0 4px 16px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .18);

  --sidebar-w: 252px;
  --topbar-h: 68px;
}

[data-theme="dark"] {
  --bg: #0a0e1a;
  --surface: #111729;
  --surface-2: #151c31;
  --surface-3: #1a2239;
  --border: #222b45;
  --border-strong: #2d3857;
  --text: #e8ecf5;
  --text-2: #a6b0c6;
  --muted: #6f7a93;

  --primary: #818cf8;
  --primary-600: #6366f1;
  --primary-soft: rgba(129, 140, 248, .14);
  --primary-ring: rgba(129, 140, 248, .3);

  --success: #4ade80;  --success-soft: rgba(74, 222, 128, .13);
  --warning: #fbbf24;  --warning-soft: rgba(251, 191, 36, .13);
  --danger: #f87171;   --danger-soft: rgba(248, 113, 113, .14);
  --info: #38bdf8;     --info-soft: rgba(56, 189, 248, .13);
  --neutral-soft: rgba(148, 163, 184, .12);

  --side-bg: #070b16;
  --side-bg-2: #0d1324;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 6px 20px rgba(0, 0, 0, .35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }
code, pre, .mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
::selection { background: var(--primary-ring); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }

/* ---------- Logo ---------- */
.logo-mark { width: 36px; height: 36px; flex: none; display: block; object-fit: contain; }
.login-wordmark { display: block; width: 232px; max-width: 100%; height: auto; margin: 0 0 26px; }
[data-theme="dark"] .login-wordmark { filter: brightness(1.35) saturate(1.1); }
.powered-by { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 11px; color: #5f6b85; }
.powered-by img { width: 104px; height: auto; filter: brightness(1.45) saturate(1.1); opacity: .9; }

/* ---------- Boot ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; align-content: center; gap: 22px; background: var(--bg); z-index: 100; }
.boot-logo .logo-mark { width: 64px; height: 64px; animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.94); opacity: .8; } }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   Login
   ========================================================================= */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-hero {
  position: relative; overflow: hidden; color: #e2e8f0;
  background: radial-gradient(1100px 600px at 10% -10%, #4338ca 0%, transparent 60%),
              radial-gradient(900px 600px at 110% 110%, #0891b2 0%, transparent 55%),
              linear-gradient(160deg, #0b1020 0%, #111a36 100%);
  display: flex; align-items: center; padding: 64px;
}
.hero-grid {
  position: absolute; inset: 0; pointer-events: none; opacity: .18;
  background-image: linear-gradient(rgba(255,255,255,.14) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.14) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 30% 40%, #000 20%, transparent 75%);
}
.login-hero-inner { position: relative; max-width: 520px; z-index: 1; }
.login-hero h1 { font-size: 38px; line-height: 1.15; color: #fff; margin: 42px 0 16px; font-weight: 700; }
.login-hero p { font-size: 16px; color: #b6c2d9; margin: 0 0 30px; }
.hero-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.hero-points li { display: flex; align-items: center; gap: 12px; font-size: 15px; color: #dbe3f1; }
.hp-dot { width: 22px; height: 22px; border-radius: 7px; background: rgba(129, 140, 248, .22); position: relative; flex: none; }
.hp-dot::after { content: ""; position: absolute; left: 7px; top: 5px; width: 5px; height: 9px; border: solid #a5b4fc; border-width: 0 2px 2px 0; transform: rotate(45deg); }

.brand { display: inline-flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand-light { color: #fff; font-size: 20px; }
.brand-light .logo-mark { width: 44px; height: 44px; }
.brand em { font-style: normal; font-weight: 500; color: #9fb1d6; }

.login-panel { display: grid; place-items: center; padding: 40px 24px; background: var(--bg); }
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 38px 36px 30px; box-shadow: var(--shadow);
}
.login-head { margin-bottom: 24px; }
.login-head h2 { font-size: 26px; margin: 6px 0 4px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); }
.login-foot { margin: 20px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

/* =========================================================================
   Form controls
   ========================================================================= */
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input, .select {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
.btn-lg ~ .input, .login-card .input { height: 44px; }
.input::placeholder { color: var(--muted); }
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
.select { appearance: none; padding-right: 32px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px; background-size: 5px 5px; background-repeat: no-repeat; }
.input-sm, .select-sm { height: 34px; font-size: 13px; }
.select-sm { background-position: calc(100% - 17px) 14px, calc(100% - 12px) 14px; }
.input-group { position: relative; display: block; }
.input-group .input { padding-right: 64px; }
.input-addon { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: var(--surface-3); color: var(--text-2);
  font: 600 12px var(--font); border-radius: 7px; padding: 6px 10px; cursor: pointer; }
.input-addon:hover { color: var(--text); }
.check { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); margin: 4px 0 22px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: 600 13px var(--font); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 6px 16px -6px var(--primary); }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-lg { height: 46px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin .7s linear infinite; }

.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; flex: none;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 12px; font-weight: 600; color: var(--text-2); }
.switch input { display: none; }
.switch-track { width: 32px; height: 18px; border-radius: 20px; background: var(--border-strong); position: relative; transition: background .2s; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--success); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border); }
.seg button { border: 0; background: transparent; color: var(--text-2); font: 600 12px var(--font); padding: 6px 11px; border-radius: 7px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Alerts */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 18px; border: 1px solid transparent; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

/* =========================================================================
   Shell
   ========================================================================= */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--side-bg) 0%, var(--side-bg-2) 100%); color: var(--side-text);
  border-right: 1px solid rgba(255,255,255,.04); z-index: 40;
}
.sidebar-backdrop { display: none; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 18px; }
.sb-title { color: var(--side-text-strong); font-weight: 700; font-size: 15px; line-height: 1.2; }
.sb-sub { font-size: 12px; color: #7d89a3; }
.nav { flex: 1; overflow-y: auto; padding: 6px 12px 16px; }
.nav-group { margin-top: 18px; }
.nav-group-title { font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: #5f6b85; padding: 0 10px 8px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 9px; color: var(--side-text);
  font-weight: 500; font-size: 14px; margin-bottom: 2px; position: relative; transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.05); color: var(--side-text-strong); text-decoration: none; }
.nav-link svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-link.active { background: var(--side-active); color: #fff; }
.nav-link.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: #818cf8; }
.nav-link.active svg { color: #a5b4fc; opacity: 1; }
.sidebar-foot { padding: 14px 16px 18px; border-top: 1px solid rgba(255,255,255,.05); }
.env-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: #8793ad; }
.env-chip b { color: #dfe6f3; font-weight: 600; }
.env-tag { padding: 2px 8px; border-radius: 20px; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.env-tag.prod { background: rgba(244, 63, 94, .16); color: #fda4af; }
.env-tag.dev { background: rgba(34, 197, 94, .15); color: #86efac; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; min-height: var(--topbar-h); display: flex; align-items: center; gap: 16px;
  padding: 12px 28px; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.page-head { min-width: 0; flex: 1; }
.page-head h1 { font-size: 20px; font-weight: 700; line-height: 1.25; }
.page-head p { margin: 1px 0 0; font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.refresh-box { display: flex; align-items: center; gap: 10px; }
.updated { font-size: 12px; min-width: 88px; }
.only-mobile { display: none; }

.profile { position: relative; }
.profile-btn { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); background: var(--surface); border-radius: 30px; padding: 3px 12px 3px 3px; cursor: pointer; color: var(--text); font: 600 13px var(--font); }
.profile-btn:hover { background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #6366f1, #06b6d4); background-size: cover; background-position: center; flex: none; }
.profile-name { max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 50; }
.menu-head { padding: 12px 12px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-name { font-weight: 700; }
.menu-mail { font-size: 12px; margin: 2px 0 8px; word-break: break-all; }
.menu-item { width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; font: 500 13px var(--font); color: var(--danger); cursor: pointer; }
.menu-item:hover { background: var(--danger-soft); }

.view { padding: 24px 28px 48px; outline: none; }
.view > * + * { margin-top: 20px; }
.view-loading { display: grid; place-items: center; min-height: 50vh; }

/* =========================================================================
   Grid & cards
   ========================================================================= */
.grid { display: grid; gap: 20px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; display: flex; flex-direction: column; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 0; }
.card-title { font-size: 15px; font-weight: 650; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-body { padding: 14px 18px 18px; flex: 1; min-width: 0; }
.card-body.flush { padding: 10px 0 0; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* KPI */
.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.kpi-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.kpi-icon svg { width: 16px; height: 16px; }
.kpi-icon.tone-success { background: var(--success-soft); color: var(--success); }
.kpi-icon.tone-warning { background: var(--warning-soft); color: var(--warning); }
.kpi-icon.tone-danger { background: var(--danger-soft); color: var(--danger); }
.kpi-icon.tone-info { background: var(--info-soft); color: var(--info); }
.kpi-value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; margin-top: 8px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.kpi-foot .meter { flex: 1 1 100%; }
.kpi-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); min-height: 18px; flex-wrap: wrap; }

.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; font-size: 12px; padding: 1px 7px; border-radius: 20px; font-variant-numeric: tabular-nums; }
.delta.good { background: var(--success-soft); color: var(--success); }
.delta.bad { background: var(--danger-soft); color: var(--danger); }
.delta.flat { background: var(--neutral-soft); color: var(--text-2); }

/* Mini stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; }
.stat { padding: 14px 18px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 650; line-height: 18px; white-space: nowrap; background: var(--neutral-soft); color: var(--text-2); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-mono { font-family: var(--mono); font-size: 11px; }
.method { font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; letter-spacing: .02em; }
.method-GET { background: var(--info-soft); color: var(--info); }
.method-POST { background: var(--success-soft); color: var(--success); }
.method-PUT, .method-PATCH { background: var(--warning-soft); color: var(--warning); }
.method-DELETE { background: var(--danger-soft); color: var(--danger); }
.method-OTHER { background: var(--neutral-soft); color: var(--text-2); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--muted); }
.dot-operational { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot-degraded { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.dot-down { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); animation: pulse 1.6s infinite; }
.dot-not_configured, .dot-disabled { background: var(--muted); box-shadow: 0 0 0 3px var(--neutral-soft); }
@keyframes pulse { 50% { opacity: .45; } }

/* Status strip */
.status-strip { display: flex; flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; }
.status-strip .overall { display: flex; align-items: center; gap: 10px; font-weight: 650; margin-right: 8px; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; font-weight: 600; color: var(--text-2); }
a.pill:hover { text-decoration: none; border-color: var(--border-strong); color: var(--text); }
.status-strip .spacer { flex: 1; }

/* =========================================================================
   Tables
   ========================================================================= */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th {
  text-align: left; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); border-top: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.table th:first-child, .table td:first-child { padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .sort-ind { display: inline-block; width: 10px; margin-left: 3px; opacity: .8; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .path { font-family: var(--mono); font-size: 12.5px; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .cell-strong { font-weight: 600; }
.table .cell-sub { font-size: 12px; color: var(--muted); }
.table-scroll { max-height: 520px; overflow: auto; }
.lat-ok { color: var(--success); }
.lat-warn { color: var(--warning); font-weight: 600; }
.lat-bad { color: var(--danger); font-weight: 700; }

.empty { display: grid; place-items: center; gap: 8px; padding: 36px 18px; text-align: center; color: var(--muted); }
.empty svg { width: 28px; height: 28px; opacity: .7; }
.empty-title { font-weight: 600; color: var(--text-2); }

.meter { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 6px; background: var(--primary); }
.meter.success > span { background: var(--success); }
.meter.warning > span { background: var(--warning); }
.meter.danger > span { background: var(--danger); }

/* Bar list */
.barlist { display: grid; gap: 12px; }
.barlist-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; }
.barlist-label { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 8px; align-items: center; }
.barlist-value { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.barlist-value small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.barlist .meter { grid-column: 1 / -1; height: 7px; }

/* =========================================================================
   Charts
   ========================================================================= */
.chart { position: relative; width: 100%; min-height: 200px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .hover-line { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-size: 12px; transform: translate(-50%, 0);
  transition: opacity .1s; opacity: 0;
}
.chart-tip.show { opacity: 1; }
.chart-tip .tip-title { font-weight: 700; margin-bottom: 6px; color: var(--text); }
.chart-tip .tip-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--text-2); line-height: 1.7; }
.chart-tip .tip-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.chart-tip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }

.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut { position: relative; flex: none; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-center b { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.donut-center span { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.donut-legend { flex: 1; min-width: 150px; display: grid; gap: 9px; }
.donut-legend-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; font-size: 13px; }
.donut-legend-row i { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend-row .val { font-weight: 650; font-variant-numeric: tabular-nums; }
.donut-legend-row .pct { color: var(--muted); font-size: 12px; width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.donut path { transition: opacity .15s; }
.donut:hover path { opacity: .55; }
.donut path:hover { opacity: 1; }

/* =========================================================================
   Filters / toolbar
   ========================================================================= */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 18px; }
.toolbar .field { margin: 0; }
.toolbar .field-label { font-size: 11.5px; margin-bottom: 4px; }
.toolbar .grow { flex: 1; min-width: 220px; }
.toolbar-actions { display: flex; gap: 8px; margin-left: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 600; }
.chip button { border: 0; background: transparent; color: inherit; cursor: pointer; padding: 0; font-size: 14px; line-height: 1; }
.pager { display: flex; align-items: center; gap: 8px; }

/* =========================================================================
   Server logs console
   ========================================================================= */
.console { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border-top: 1px solid var(--border); max-height: 640px; overflow: auto; }
.log-line { display: grid; grid-template-columns: 196px 64px minmax(0, 1fr); gap: 12px; padding: 7px 18px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: start; }
.log-line:hover { background: var(--surface-3); }
.log-line .ts { color: var(--muted); white-space: nowrap; }
.log-line .msg { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.log-line.open .msg { white-space: pre-wrap; word-break: break-word; }
.log-line.lvl-error { background: color-mix(in srgb, var(--danger-soft) 55%, transparent); }
.log-line.lvl-warn { background: color-mix(in srgb, var(--warning-soft) 45%, transparent); }
.lvl { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 5px; text-align: center; }
.lvl-b-error { background: var(--danger-soft); color: var(--danger); }
.lvl-b-warn { background: var(--warning-soft); color: var(--warning); }
.lvl-b-info { background: var(--info-soft); color: var(--info); }
.lvl-b-http { background: var(--primary-soft); color: var(--primary); }
.lvl-b-debug { background: var(--neutral-soft); color: var(--text-2); }
.log-detail { grid-column: 1 / -1; margin-top: 6px; }

/* JSON viewer */
.json { font-family: var(--mono); font-size: 12px; line-height: 1.6; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow: auto; max-height: 420px; white-space: pre; margin: 0; color: var(--text); }
.json .k { color: #7c3aed; }
.json .s { color: #0f766e; }
.json .n { color: #c2410c; }
.json .b { color: #2563eb; font-weight: 600; }
.json .z { color: var(--muted); font-style: italic; }
.json .r { color: var(--danger); font-weight: 700; }
[data-theme="dark"] .json .k { color: #c4b5fd; }
[data-theme="dark"] .json .s { color: #5eead4; }
[data-theme="dark"] .json .n { color: #fdba74; }
[data-theme="dark"] .json .b { color: #93c5fd; }
pre.stack { font-family: var(--mono); font-size: 12px; background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 12px 14px; overflow: auto; max-height: 300px; margin: 0; white-space: pre-wrap; word-break: break-word; }

/* =========================================================================
   Drawer & toast
   ========================================================================= */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 60; animation: fade .15s; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--surface); z-index: 61;
  box-shadow: var(--shadow-lg); transform: translateX(105%); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column; border-left: 1px solid var(--border);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { font-size: 17px; word-break: break-all; }
.drawer-head p { margin: 3px 0 0; font-size: 12.5px; }
.drawer-body { padding: 20px 24px 40px; overflow-y: auto; flex: 1; }
.drawer-section + .drawer-section { margin-top: 24px; }
.drawer-section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.kv > div { padding: 10px 14px; border-bottom: 1px solid var(--border); min-width: 0; }
.kv > div:nth-child(odd) { border-right: 1px solid var(--border); }
.kv dt { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.kv dd { margin: 0; font-size: 13px; word-break: break-all; }
.kv .full { grid-column: 1 / -1; border-right: 0 !important; }
@keyframes fade { from { opacity: 0; } }

.toasts { position: fixed; bottom: 22px; right: 22px; z-index: 80; display: grid; gap: 10px; }
.toast { min-width: 260px; max-width: 380px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 500; animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* Skeleton */
.skeleton { position: relative; overflow: hidden; background: var(--surface-3); border-radius: 8px; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.sk-kpi { height: 112px; border-radius: var(--radius); }
.sk-chart { height: 320px; border-radius: var(--radius); }

.error-state { padding: 40px; text-align: center; }
.error-state h3 { margin-bottom: 6px; }
.note { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: flex-start; }
.note svg { width: 14px; height: 14px; flex: none; margin-top: 2px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; margin-top: 28px !important; }

/* Services grid (health) */
.services { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.service { padding: 16px 18px; }
.service-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.service-name { font-weight: 650; display: flex; align-items: center; gap: 10px; }
.service-detail { margin-top: 8px; font-size: 12.5px; color: var(--text-2); word-break: break-word; }
.hero-status { display: flex; flex-direction: row; align-items: center; gap: 16px; padding: 18px 20px; }
.hero-status .big-dot { width: 14px; height: 14px; }
.hero-status h2 { font-size: 18px; }

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 1280px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3 > .span-2 { grid-column: span 2; }
  .updated { display: none; }
}
@media (max-width: 960px) {
  .login { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform .22s; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-backdrop.open { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 35; display: block; }
  .only-mobile { display: inline-grid; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .view { padding: 16px 16px 40px; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .span-2, .span-3, .cols-3 > .span-2 { grid-column: auto; }
  .profile-name { display: none; }
  .kv { grid-template-columns: 1fr; }
  .kv > div:nth-child(odd) { border-right: 0; }
  .log-line { grid-template-columns: 1fr; gap: 4px; }
}
@media (max-width: 560px) {
  .login-card { padding: 28px 22px; }
  .seg button { padding: 6px 8px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpi-value { font-size: 22px; }
}

/* =========================================================================
   Motion & polish layer
   Everything below is progressive: it only adds movement and refinement and
   is fully disabled for users who prefer reduced motion.
   ========================================================================= */
:root {
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --glow: 0 0 0 1px color-mix(in srgb, var(--primary) 18%, transparent), 0 10px 30px -12px color-mix(in srgb, var(--primary) 45%, transparent);
}

@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes rise-sm { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes slide-in-right { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(3px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.06); color: var(--primary); } 100% { transform: scale(1); } }
@keyframes glow-pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 45%, transparent); } 50% { box-shadow: 0 0 0 5px transparent; } }

/* ---------- Page & card entrance (staggered via --i set in JS) ---------- */
.enter { animation: rise .6s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms); }
.page-head.swap h1, .page-head.swap p { animation: rise-sm .45s var(--ease-out) both; }
.page-head.swap p { animation-delay: 60ms; }
.view-fade { animation: fade .25s ease-out both; }

/* ---------- Cards & KPIs ---------- */
.card { transition: border-color .25s, box-shadow .3s var(--ease-out), transform .3s var(--ease-out); }
.card:hover { border-color: var(--border-strong); }
.kpi { cursor: default; }
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.kpi::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; opacity: 0; transition: opacity .3s;
  background: linear-gradient(90deg, var(--primary), var(--c2));
}
.kpi:hover::after { opacity: 1; }
.kpi-icon { transition: transform .35s var(--ease-spring); }
.kpi:hover .kpi-icon { transform: scale(1.12) rotate(-6deg); }
.kpi-value.bump, .stat-value.bump { animation: bump .7s var(--ease-out); display: inline-block; }
.kpi-label-wrap { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Tooltips (pure CSS, data-tip) ---------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translate(-50%, 4px);
  width: max-content; max-width: 260px; padding: 8px 10px; border-radius: 8px; background: #0f172a; color: #e2e8f0;
  font: 500 12px/1.45 var(--font); text-transform: none; letter-spacing: 0; white-space: normal; text-align: left;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .15s, transform .2s var(--ease-out); z-index: 90;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
[data-theme="dark"] [data-tip]::after { background: #e2e8f0; color: #0f172a; }
.tip { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; color: var(--muted); cursor: help; }
.tip svg { width: 14px; height: 14px; }
.tip:hover { color: var(--primary); }

/* ---------- Buttons & controls ---------- */
.btn, .icon-btn { transition: background .2s, border-color .2s, color .2s, box-shadow .25s, transform .15s var(--ease-out); }
.btn:active, .icon-btn:active { transform: scale(.96); }
.btn-primary { background-image: linear-gradient(135deg, var(--primary) 0%, color-mix(in srgb, var(--primary) 70%, var(--c2)) 100%); }
.btn-primary:hover:not(:disabled) { box-shadow: var(--glow); transform: translateY(-1px); }
.btn .btn-arrow { width: 18px; height: 18px; transition: transform .3s var(--ease-spring); }
.btn:hover .btn-arrow { transform: translateX(4px); }
.btn.is-loading .btn-arrow { display: none; }
.btn.is-success { background: var(--success); border-color: var(--success); }
.seg button { transition: color .2s, background .25s, box-shadow .25s; }
.seg button.active { animation: pop .3s var(--ease-out); }
.switch-track { transition: background .25s; }
.switch-track::after { transition: transform .3s var(--ease-spring); }
.input, .select { transition: border-color .2s, box-shadow .25s, background .2s; }
.input:hover:not(:focus), .select:hover:not(:focus) { border-color: color-mix(in srgb, var(--primary) 35%, var(--border-strong)); }

/* Live indicator + countdown ring around the refresh button */
.switch input:checked + .switch-track { animation: glow-pulse 2.4s infinite; }
@property --p { syntax: "<number>"; inherits: false; initial-value: 0; }
.icon-btn.countdown { position: relative; }
.icon-btn.countdown::before {
  content: ""; position: absolute; inset: -3px; border-radius: 12px; padding: 2px; pointer-events: none;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), transparent 0);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  animation: countdown var(--dur, 30s) linear forwards; opacity: .75;
}
@keyframes countdown { from { --p: 0; } to { --p: 100; } }

/* Top progress bar */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 120; pointer-events: none; opacity: 0; transition: opacity .3s .15s; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--c2), var(--primary), var(--c6)); box-shadow: 0 0 10px var(--primary); border-radius: 0 3px 3px 0; }
.progress.active { opacity: 1; transition: opacity .1s; }
.progress.active span { animation: progress-run 8s cubic-bezier(.1, .8, .2, 1) forwards; }
.progress.done { opacity: 0; }
.progress.done span { width: 100% !important; animation: none; transition: width .2s ease-out; }
@keyframes progress-run { 0% { width: 0; } 10% { width: 35%; } 100% { width: 90%; } }

/* ---------- Topbar ---------- */
.search-btn {
  display: inline-flex; align-items: center; gap: 10px; height: 36px; padding: 0 8px 0 12px; min-width: 200px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font: 500 13px var(--font); cursor: pointer; transition: border-color .2s, box-shadow .25s, color .2s;
}
.search-btn svg { width: 16px; height: 16px; }
.search-btn span { flex: 1; text-align: left; }
.search-btn:hover { border-color: var(--border-strong); color: var(--text-2); box-shadow: var(--shadow-sm); }
kbd {
  font: 600 11px var(--mono); padding: 2px 6px; border-radius: 6px; border: 1px solid var(--border);
  border-bottom-width: 2px; background: var(--surface-2); color: var(--text-2); line-height: 1.3;
}
.updated::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--success); margin-right: 6px; vertical-align: 1px; animation: pulse 2s infinite; }
.updated:empty::before { display: none; }
.profile-btn { transition: background .2s, box-shadow .25s, border-color .2s; }
.profile-btn:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.menu:not([hidden]) { animation: pop .22s var(--ease-out); transform-origin: top right; }

/* ---------- Sidebar ---------- */
.shell { transition: grid-template-columns .35s var(--ease-out); }
.nav-link { transition: background .2s, color .2s, padding .3s var(--ease-out); overflow: hidden; }
.nav-link svg { transition: transform .3s var(--ease-spring), color .2s; }
.nav-link:hover svg { transform: scale(1.12); }
.nav-link.active::before { animation: indicator .35s var(--ease-out); transform-origin: center; }
@keyframes indicator { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.nav-link span, .sb-title, .sb-sub, .nav-group-title, .env-chip, .powered-by, .collapse-btn span { transition: opacity .2s; white-space: nowrap; }
.collapse-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; margin-bottom: 12px; border-radius: 9px;
  border: 0; background: transparent; color: #7d89a3; font: 500 13px var(--font); cursor: pointer; transition: background .2s, color .2s;
}
.collapse-btn:hover { background: rgba(255, 255, 255, .05); color: var(--side-text-strong); }
.collapse-btn svg { width: 18px; height: 18px; flex: none; transition: transform .35s var(--ease-out); }
.shell.collapsed { --sidebar-w: 78px; }
.shell.collapsed .collapse-btn svg { transform: rotate(180deg); }
.shell.collapsed .sidebar-brand { justify-content: center; padding-left: 12px; padding-right: 12px; }
.shell.collapsed .sidebar-brand > div,
.shell.collapsed .nav-link span,
.shell.collapsed .env-chip,
.shell.collapsed .powered-by,
.shell.collapsed .collapse-btn span { opacity: 0; width: 0; overflow: hidden; pointer-events: none; }
.shell.collapsed .powered-by, .shell.collapsed .env-chip { display: none; }
.shell.collapsed .nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
.shell.collapsed .nav-group-title { font-size: 0; height: 1px; padding: 0; margin: 4px 14px 12px; background: rgba(255, 255, 255, .07); }
.shell.collapsed .collapse-btn { justify-content: center; }
.shell.collapsed .nav-link[data-tip]::after { left: calc(100% + 14px); bottom: auto; top: 50%; transform: translate(-4px, -50%); }
.shell.collapsed .nav-link[data-tip]:hover::after { transform: translate(0, -50%); opacity: 1; }
.shell:not(.collapsed) .nav-link[data-tip]::after { display: none; }
.shell.collapsed .nav-link { overflow: visible; }

/* ---------- Command palette ---------- */
.palette { position: fixed; inset: 0; z-index: 110; display: grid; justify-items: center; align-items: start; padding: 12vh 16px 16px; background: rgba(2, 6, 23, .5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .15s; }
.palette-box { width: min(620px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden; animation: pop .25s var(--ease-out); }
.palette-search { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.palette-search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.palette-search input { flex: 1; border: 0; outline: none; background: transparent; color: var(--text); font: 500 16px var(--font); }
.palette-list { list-style: none; margin: 0; padding: 8px; max-height: 52vh; overflow-y: auto; }
.palette-group { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 10px 12px 6px; }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; cursor: pointer; color: var(--text); font-size: 14px; transition: background .12s; }
.palette-item svg { width: 18px; height: 18px; color: var(--text-2); flex: none; }
.palette-item .pi-hint { margin-left: auto; font-size: 12px; color: var(--muted); }
.palette-item.selected { background: var(--primary-soft); }
.palette-item.selected svg { color: var(--primary); }
.palette-empty { padding: 28px; text-align: center; color: var(--muted); }
.palette-foot { display: flex; gap: 18px; padding: 10px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); background: var(--surface-2); }
.palette-foot kbd { margin-right: 3px; }

/* ---------- Drawer & backdrop ---------- */
.drawer-backdrop { backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.drawer { transition: transform .45s var(--ease-out); }
.drawer.open .drawer-section { animation: rise .5s var(--ease-out) both; }
.drawer.open .drawer-section:nth-child(2) { animation-delay: 60ms; }
.drawer.open .drawer-section:nth-child(3) { animation-delay: 110ms; }
.drawer.open .drawer-section:nth-child(4) { animation-delay: 160ms; }
.drawer.open .drawer-section:nth-child(5) { animation-delay: 210ms; }

/* ---------- Toasts ---------- */
.toast {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) 20px; gap: 12px; align-items: start; position: relative; overflow: hidden;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 14px 14px 16px;
  animation: slide-in-right .4s var(--ease-out);
}
.toast.error, .toast.success { background: var(--surface); color: var(--text); }
.toast .t-icon { width: 20px; height: 20px; }
.toast.success .t-icon { color: var(--success); }
.toast.error .t-icon { color: var(--danger); }
.toast.info .t-icon { color: var(--primary); }
.toast .t-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0; font-size: 18px; line-height: 1; }
.toast .t-close:hover { color: var(--text); }
.toast .t-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; transform-origin: left; animation: toast-bar linear forwards; }
.toast.success .t-bar { background: var(--success); }
.toast.error .t-bar { background: var(--danger); }
.toast.info .t-bar { background: var(--primary); }
.toast.leaving { animation: toast-out .3s var(--ease-in-out) forwards; }
@keyframes toast-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px) scale(.96); } }

/* ---------- Tables ---------- */
.table tbody tr { transition: background .15s; }
.table tbody tr.clickable td:first-child { box-shadow: inset 3px 0 0 transparent; transition: box-shadow .2s; }
.table tbody tr.clickable:hover td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.meter > span { transition: width .9s var(--ease-out); }
.meter.grow > span { width: 0 !important; }

/* ---------- Charts ---------- */
.chart svg.animate .bar { transform-box: fill-box; transform-origin: 50% 100%; animation: bar-grow .75s var(--ease-out) both; animation-delay: calc(var(--d, 0) * 10ms + 120ms); }
.chart svg.animate .line { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.3s var(--ease-in-out) forwards .15s; }
.chart svg.animate .area { animation: fade .9s ease-out both .45s; }
.chart svg.animate .line-dashed { animation: fade .8s ease-out both .5s; }
.chart .hover-line, .chart .hover-dots { transition: transform .12s var(--ease-out); }
.chart-tip { transition: opacity .15s, left .12s var(--ease-out); }
.chart-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 500; pointer-events: none; }
.chart-empty svg { width: 26px; height: 26px; opacity: .6; }
@keyframes bar-grow { from { transform: scaleY(0); opacity: .3; } to { transform: scaleY(1); opacity: 1; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
.donut .arc { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1s var(--ease-out) forwards; animation-delay: calc(var(--d, 0) * 90ms + 100ms); }
.donut:hover .arc { opacity: .5; }
.donut .arc:hover { opacity: 1; stroke-width: calc(var(--thick) + 4px); }
.donut .arc { transition: opacity .2s, stroke-width .25s var(--ease-out); }
.donut-legend-row { animation: rise-sm .45s var(--ease-out) both; animation-delay: calc(var(--d, 0) * 60ms + 200ms); }
.barlist-row { animation: rise-sm .45s var(--ease-out) both; animation-delay: calc(var(--d, 0) * 50ms + 100ms); }

/* ---------- Welcome banner (overview) ---------- */
.welcome {
  position: relative; overflow: hidden; padding: 22px 24px; border-radius: var(--radius); color: #fff; border: 0;
  background: radial-gradient(700px 240px at 100% 0%, rgba(6, 182, 212, .35), transparent 60%),
              linear-gradient(120deg, #312e81 0%, #4338ca 45%, #0e7490 100%);
  box-shadow: 0 18px 40px -24px rgba(67, 56, 202, .8);
  display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap;
}
.welcome::before {
  content: ""; position: absolute; inset: 0; opacity: .25; pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, .5) 1px, transparent 1px); background-size: 18px 18px;
  mask-image: linear-gradient(90deg, transparent, #000 60%);
}
.welcome h2 { font-size: 21px; font-weight: 700; position: relative; }
.welcome p { margin: 4px 0 0; color: rgba(255, 255, 255, .82); font-size: 14px; position: relative; max-width: 760px; }
.welcome p b { color: #fff; }
.welcome-side { position: relative; display: flex; gap: 10px; flex-wrap: wrap; }
.welcome-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .18); font-size: 12.5px; font-weight: 600; backdrop-filter: blur(4px); }
.welcome-chip .dot { box-shadow: none; }
.welcome:hover { border: 0; }

/* ---------- Empty state ---------- */
.empty svg { animation: float 3.5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-4px); } }

/* ---------- Login ---------- */
.login-card { animation: rise .7s var(--ease-out) both .1s; position: relative; }
.login-card.shake { animation: shake .5s var(--ease-in-out); }
.login-card.success { animation: pop .3s var(--ease-out) reverse forwards; }
.login.leaving { animation: fade .35s ease-in reverse forwards; }
.shell.app-enter .sidebar { animation: slide-in-left .6s var(--ease-out) both; }
.shell.app-enter .topbar { animation: rise-sm .5s var(--ease-out) both .1s; }
@keyframes slide-in-left { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
.login-hero-inner > * { animation: rise .8s var(--ease-out) both; }
.login-hero-inner > *:nth-child(2) { animation-delay: .08s; }
.login-hero-inner > *:nth-child(3) { animation-delay: .16s; }
.login-hero-inner > *:nth-child(4) { animation-delay: .24s; }
.hero-points li { animation: rise-sm .6s var(--ease-out) both; }
.hero-points li:nth-child(1) { animation-delay: .35s; }
.hero-points li:nth-child(2) { animation-delay: .45s; }
.hero-points li:nth-child(3) { animation-delay: .55s; }
.hero-points li:nth-child(4) { animation-delay: .65s; }
.hero-grid { animation: grid-drift 24s linear infinite; }
@keyframes grid-drift { to { background-position: 44px 44px, 44px 44px; } }
.orb { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .55; pointer-events: none; will-change: transform; }
.orb-a { width: 420px; height: 420px; background: #6366f1; top: -120px; left: -100px; animation: orb-a 18s ease-in-out infinite; }
.orb-b { width: 360px; height: 360px; background: #06b6d4; bottom: -140px; right: -80px; animation: orb-b 22s ease-in-out infinite; }
.orb-c { width: 260px; height: 260px; background: #8b5cf6; top: 45%; left: 55%; opacity: .35; animation: orb-c 26s ease-in-out infinite; }
@keyframes orb-a { 50% { transform: translate(120px, 80px) scale(1.1); } }
@keyframes orb-b { 50% { transform: translate(-100px, -60px) scale(1.15); } }
@keyframes orb-c { 50% { transform: translate(-140px, 60px) scale(.9); } }
.hero-card {
  position: absolute; display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 14px; z-index: 1;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .12); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  color: #fff; box-shadow: 0 20px 40px -20px rgba(0, 0, 0, .6);
}
.hero-card b { display: block; font-size: 14px; }
.hero-card small { color: #a8b5cf; font-size: 12px; }
.hero-card-a { right: 8%; top: 16%; animation: bob 7s ease-in-out infinite, rise .9s var(--ease-out) both .8s; }
.hero-card-b { right: 18%; bottom: 14%; animation: bob 8s ease-in-out infinite 1s, rise .9s var(--ease-out) both 1s; }
@keyframes bob { 50% { transform: translateY(-10px); } }
.hc-dot { width: 10px; height: 10px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 4px rgba(74, 222, 128, .2); animation: pulse 1.8s infinite; }
.hc-spark { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #818cf8, #22d3ee); }

.input-icon { position: relative; display: block; }
.input-icon > svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); pointer-events: none; transition: color .2s; z-index: 1; }
.input-icon .input { padding-left: 40px; }
.input-icon:focus-within > svg { color: var(--primary); }
.caps-hint { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; font-weight: 600; color: var(--warning); animation: rise-sm .25s var(--ease-out); }
.caps-hint::before { content: "⇪"; font-size: 13px; }
.login-wordmark { animation: rise .7s var(--ease-out) both .2s; }

/* ---------- Boot ---------- */
.boot { transition: opacity .35s ease-out; }
.boot.hide { opacity: 0; pointer-events: none; }

@media (max-width: 960px) {
  .search-btn { min-width: 0; }
  .search-btn span, .search-btn kbd { display: none; }
  .collapse-btn { display: none; }
  .shell.collapsed { --sidebar-w: 252px; }
  .hero-card { display: none; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; animation-delay: 0ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .chart svg.animate .line, .donut .arc { stroke-dashoffset: 0 !important; }
}
