/* VVN Command Centre — base styles: tokens, the app shell and shared components.
   Dark-first. Every colour is a token on :root; the light theme swaps tokens and
   nothing else. There are no inline styles anywhere, so the page runs under a
   strict CSP (style-src 'self'). */

:root {
  color-scheme: dark;
  --bg: #080b12;
  --bg-2: #0c1019;
  --surface: #10151f;
  --surface-2: #141a27;
  --surface-3: #1a2131;
  --hover: rgba(148, 163, 184, 0.07);
  --border: rgba(148, 163, 184, 0.11);
  --border-2: rgba(148, 163, 184, 0.2);
  --text: #e8ebf3;
  --text-2: #a3abc0;
  --text-3: #6b7489;
  --accent: #8b93ff;
  --accent-soft: rgba(129, 140, 248, 0.14);
  --grad: linear-gradient(135deg, #6366f1 0%, #3b82f6 52%, #22d3ee 100%);
  --ok: #34d399;   --ok-soft: rgba(52, 211, 153, 0.13);
  --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, 0.13);
  --err: #fb7185;  --err-soft: rgba(251, 113, 133, 0.13);
  --info: #60a5fa; --info-soft: rgba(96, 165, 250, 0.13);
  --r-xl: 22px; --r-lg: 18px; --r: 14px; --r-sm: 10px; --r-xs: 7px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.035) inset, 0 16px 40px -20px rgba(0, 0, 0, 0.7);
  --shadow-pop: 0 24px 60px -18px rgba(0, 0, 0, 0.75);
  --ring: 0 0 0 3px rgba(129, 140, 248, 0.35);
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, ui-monospace, Menlo, monospace;
  --sidebar-w: 260px;
  --tabbar-h: 66px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5fa; --bg-2: #eceff6; --surface: #ffffff; --surface-2: #f7f8fc; --surface-3: #eef1f7;
  --hover: rgba(15, 23, 42, 0.05); --border: rgba(15, 23, 42, 0.09); --border-2: rgba(15, 23, 42, 0.16);
  --text: #0d1424; --text-2: #4b5670; --text-3: #8a94aa;
  --accent: #4f46e5; --accent-soft: rgba(79, 70, 229, 0.1);
  --ok: #059669;   --ok-soft: rgba(5, 150, 105, 0.1);
  --warn: #b45309; --warn-soft: rgba(217, 119, 6, 0.12);
  --err: #e11d48;  --err-soft: rgba(225, 29, 72, 0.09);
  --info: #2563eb; --info-soft: rgba(37, 99, 235, 0.09);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 14px 32px -18px rgba(15, 23, 42, 0.22);
  --shadow-pop: 0 26px 56px -20px rgba(15, 23, 42, 0.3);
  --ring: 0 0 0 3px rgba(79, 70, 229, 0.25);
}

/* ---------------------------------------------------------------- reset */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1100px 600px at 8% -12%, rgba(99, 102, 241, 0.13), transparent 60%),
    radial-gradient(900px 520px at 108% 4%, rgba(34, 211, 238, 0.07), transparent 62%);
}
:root[data-theme="light"] body::before { opacity: 0.55; }
h1, h2, h3, h4, h5 { margin: 0; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: none; box-shadow: var(--ring); }
[hidden] { display: none !important; }
code, pre { font-family: var(--mono); }
::selection { background: rgba(129, 140, 248, 0.35); }

/* ---------------------------------------------------------- icons & logo */
.i { width: 20px; height: 20px; flex: none; }
.i-xs { width: 13px; height: 13px; }
.i-sm { width: 16px; height: 16px; }
.i-lg { width: 26px; height: 26px; }
.logo { display: inline-flex; flex: none; border-radius: 28%; box-shadow: 0 6px 18px -6px rgba(79, 70, 229, 0.6); }
.logo svg { width: 100%; height: 100%; display: block; }
.logo-xs { width: 22px; height: 22px; box-shadow: none; }
.logo-sm { width: 30px; height: 30px; }
.logo-md { width: 38px; height: 38px; }
.logo-lg { width: 52px; height: 52px; }

.boot { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--bg); transition: opacity 0.25s ease; }
.boot.done { opacity: 0; pointer-events: none; }
.boot-logo { width: 56px; height: 56px; border-radius: 16px; background: var(--grad); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(0.92); opacity: 0.75; } }

.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }
.center { text-align: center; }

/* -------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: var(--r-sm); border: 1px solid transparent;
  background: var(--surface-3); color: var(--text); font-weight: 600; font-size: 14.5px; white-space: nowrap;
  user-select: none; transition: transform 0.12s ease, background-color 0.15s, border-color 0.15s, filter 0.15s, opacity 0.15s;
}
.btn:hover { background: color-mix(in srgb, var(--surface-3) 86%, var(--text) 8%); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 8px 22px -10px rgba(79, 70, 229, 0.8); }
.btn-primary:hover { background: var(--grad); filter: brightness(1.08); }
.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-soft:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.btn-ghost { background: transparent; border-color: var(--border-2); }
.btn-ghost:hover { background: var(--hover); }
.btn-danger { background: var(--err-soft); color: var(--err); }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 22%, transparent); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: var(--r-xs); }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-2);
  transition: background-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------------------------------------------------------------- forms */
.form { display: grid; gap: 16px; }
.field { display: grid; gap: 7px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field > span em { font-style: normal; font-weight: 400; color: var(--text-3); margin-left: 6px; }
input:not([type]), input[type="text"], input[type="password"], input[type="url"], input[type="search"], textarea, select {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--border-2); background: var(--bg-2); color: var(--text); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: var(--ring); background: var(--surface); }
.otp { font-family: var(--mono); font-size: 22px; letter-spacing: 0.45em; text-align: center; }
.form-error { color: var(--err); font-size: 13.5px; font-weight: 500; }
.input-row { display: flex; gap: 10px; }
.input-row input { flex: 1; min-width: 0; }

/* ------------------------------------------------------ cards & badges */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { display: flex; align-items: center; gap: 9px; font-size: 15.5px; }
.card-head h3 .i { color: var(--accent); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2); vertical-align: middle;
}
.badge-instant { background: var(--warn-soft); color: var(--warn); }
.badge-ai { background: var(--accent-soft); color: var(--accent); }
.badge-tile, .badge-run { background: var(--info-soft); color: var(--info); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-err { background: var(--err-soft); color: var(--err); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-2);
  background: var(--surface); color: var(--text-2); font-size: 13.5px; transition: all 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot-live { background: var(--ok); animation: live 2s infinite; }
@keyframes live {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); background: var(--info-soft); font-size: 14px; }
.notice > .i { color: var(--info); margin-top: 1px; }
.notice-error { background: var(--err-soft); }
.notice-error > .i { color: var(--err); }
.notice-warn { background: var(--warn-soft); }
.notice-warn > .i { color: var(--warn); }

/* ------------------------------------------------------------- loaders */
.spinner { display: inline-block; width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; opacity: 0.8; animation: spin 0.7s linear infinite; }
.spinner-sm { width: 13px; height: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-4px); opacity: 1; } }
.skeleton {
  height: 14px; margin: 10px 0; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
.skeleton.w60 { width: 60%; }
.skeleton.w80 { width: 80%; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty { display: grid; justify-items: center; gap: 10px; padding: 36px 20px; text-align: center; color: var(--text-2); }
.empty-ic { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 16px; background: var(--surface-3); color: var(--text-2); }
.empty h4 { color: var(--text); font-size: 15.5px; }

/* --------------------------------------------------------------- toasts */
.toasts {
  position: fixed; z-index: 90; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--r);
  background: var(--surface-3); border: 1px solid var(--border-2); box-shadow: var(--shadow-pop);
  font-size: 14px; font-weight: 500; pointer-events: auto; animation: toast-in 0.22s ease;
}
.toast-ok .i { color: var(--ok); }
.toast-error .i { color: var(--err); }
.toast-warn .i { color: var(--warn); }
.toast-info .i { color: var(--info); }
.toast.leaving { animation: toast-out 0.2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

.codebox { display: flex; align-items: flex-start; gap: 8px; padding: 12px 10px 12px 14px; border-radius: var(--r-sm); background: var(--bg-2); border: 1px solid var(--border); }
.codebox code { flex: 1; min-width: 0; font-size: 12.5px; line-height: 1.6; word-break: break-all; }

/* ----------------------------------------------------------------- auth */
.auth {
  min-height: 100dvh; display: grid; place-items: center; align-content: center; gap: 18px;
  padding: calc(32px + var(--safe-top)) 16px calc(32px + var(--safe-bottom));
}
.auth-card {
  width: min(420px, 100%); display: grid; gap: 22px; padding: 32px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-pop);
}
.auth-card.wide { width: min(560px, 100%); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12.5px; color: var(--text-3); }
.brand-lg .brand-name { font-size: 19px; }
.auth-intro h2 { font-size: 21px; margin-bottom: 4px; }
.auth-foot { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-3); }
.auth-loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 24px; color: var(--text-2); }
.step { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 14px; }
.step-n { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; }
.step-body { display: grid; gap: 12px; min-width: 0; }
.step-title { font-weight: 600; font-size: 14px; }
.totp { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.qr { width: 148px; height: 148px; padding: 8px; border-radius: 12px; background: #fff; }
.totp-side { display: grid; gap: 8px; flex: 1; min-width: 180px; }
.secret { padding: 8px 10px; border-radius: var(--r-xs); background: var(--bg-2); border: 1px dashed var(--border-2); font-size: 13.5px; letter-spacing: 0.06em; word-break: break-all; }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 22px; padding: 22px 16px;
  border-right: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 72%, transparent); backdrop-filter: blur(14px);
}
.sidebar .brand { padding: 4px 8px; }
.nav { display: grid; gap: 4px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; height: 42px; padding: 0 12px;
  border-radius: var(--r-sm); color: var(--text-2); font-weight: 550; font-size: 14.5px; transition: background-color 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--text); }
.nav-item.active .i { color: var(--accent); }
.nav-item.active::before { content: ""; position: absolute; left: -16px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--grad); }
.sidebar-foot { margin-top: auto; display: grid; gap: 12px; }
.device-pill {
  display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 10px 12px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--border); font-size: 12.5px; color: var(--text-3);
}
.device-pill:hover { text-decoration: none; border-color: var(--border-2); }
.device-pill b { display: block; color: var(--text); font-weight: 600; font-size: 13.5px; }
.sidebar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px; }
.user-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-3); min-width: 0; }
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 64px; padding: 0 32px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(14px);
}
.topbar h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mobile-brand, .mobile-only { display: none; }
.status-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); white-space: nowrap;
}
.status-chip:hover { text-decoration: none; color: var(--text); }
.status-chip select { min-height: 0; height: 30px; padding: 0 4px; border: 0; background: transparent; box-shadow: none; font-size: 13px; width: auto; }
.view { flex: 1; width: 100%; min-width: 0; max-width: 1180px; margin: 0 auto; padding: 28px 32px 48px; }
.tabbar { display: none; }

@media (max-width: 959px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { height: calc(58px + var(--safe-top)); padding: var(--safe-top) 16px 0; }
  .topbar h1 { font-size: 17px; }
  .mobile-brand { display: inline-flex; }
  .mobile-only { display: inline-grid; }
  .view { padding: 18px 16px calc(var(--tabbar-h) + 28px + var(--safe-bottom)); }
  .tabbar {
    position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
    height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
    border-top: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(18px);
  }
  .tab { display: grid; place-items: center; align-content: center; gap: 3px; color: var(--text-3); font-size: 11px; font-weight: 600; }
  .tab:hover { text-decoration: none; }
  .tab.active { color: var(--text); }
  .tab.active .i { color: var(--accent); }
  .toasts { bottom: calc(var(--tabbar-h) + 16px + var(--safe-bottom)); }
  .auth-card { padding: 24px 20px; }
}

/* ------------------------------------------- markdown (brief results) */
.doc { font-size: 14.5px; line-height: 1.7; overflow-wrap: anywhere; }
.doc > * + * { margin-top: 12px; }
.doc h2 { font-size: 20px; margin-top: 22px; }
.doc h3 { font-size: 17px; margin-top: 20px; }
.doc h4, .doc h5 { font-size: 15px; margin-top: 16px; }
.doc ul, .doc ol { margin: 0; padding-left: 22px; }
.doc li + li { margin-top: 4px; }
.doc code { padding: 2px 6px; border-radius: 6px; background: var(--surface-3); font-size: 12.5px; }
.doc pre { padding: 14px; border-radius: var(--r-sm); background: var(--bg-2); border: 1px solid var(--border); overflow-x: auto; }
.doc pre code { padding: 0; background: none; }
.doc hr { border: 0; border-top: 1px solid var(--border); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-sm); }
.doc table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.doc th, .doc td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.doc th { background: var(--surface-2); color: var(--text-2); font-weight: 650; }
.doc tr:last-child td { border-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
