/* VL13D admin — one stylesheet, no inline styles (CSP style-src 'self'). */
:root {
    --bg: #f3f5fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef2f7;
    --line: #e4e8f0;
    --line-strong: #d4dae5;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --primary-ring: rgba(79, 70, 229, .22);
    --ok: #15803d;
    --ok-soft: #dcfce7;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --bad: #dc2626;
    --bad-soft: #fee2e2;
    --info: #0369a1;
    --info-soft: #e0f2fe;
    --side-bg: #0f172a;
    --side-bg-2: #131c33;
    --side-text: #a8b3c7;
    --side-text-strong: #f1f5f9;
    --side-line: rgba(148, 163, 184, .14);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 18px rgba(15, 23, 42, .06);
    --radius: 14px;
    --radius-sm: 9px;
    --sidebar-w: 252px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1020;
        --surface: #121a2b;
        --surface-2: #0f1626;
        --surface-3: #1a2336;
        --line: #222c40;
        --line-strong: #2d3a52;
        --text: #e6eaf2;
        --text-2: #c6cfdd;
        --muted: #8b97ab;
        --primary: #818cf8;
        --primary-hover: #a5b4fc;
        --primary-soft: rgba(129, 140, 248, .14);
        --primary-ring: rgba(129, 140, 248, .3);
        --ok: #4ade80;
        --ok-soft: rgba(74, 222, 128, .12);
        --warn: #fbbf24;
        --warn-soft: rgba(251, 191, 36, .12);
        --bad: #f87171;
        --bad-soft: rgba(248, 113, 113, .13);
        --info: #38bdf8;
        --info-soft: rgba(56, 189, 248, .12);
        --side-bg: #080c18;
        --side-bg-2: #0d1322;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; text-underline-offset: 2px; }
.icon { width: 18px; height: 18px; flex: none; }

/* ---------- App shell ---------- */
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 30;
    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 var(--side-line);
}
.brand, .public-brand { display: flex; align-items: center; gap: 12px; color: var(--side-text-strong); }
.brand { padding: 20px 20px 18px; border-bottom: 1px solid var(--side-line); }
.brand:hover, .public-brand:hover { text-decoration: none; color: inherit; }
.logo {
    display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 11px;
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 55%, #ec4899 100%);
    color: #fff; font-weight: 800; letter-spacing: .5px; font-size: 14px;
    box-shadow: 0 6px 16px rgba(99, 102, 241, .35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; letter-spacing: .3px; }
.brand-text small { font-size: 11.5px; color: var(--side-text); }
.nav { flex: 1; overflow-y: auto; padding: 10px 12px 16px; }
.nav-title {
    margin: 16px 10px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .09em;
    text-transform: uppercase; color: #64748b;
}
.nav a {
    position: relative; display: flex; align-items: center; gap: 11px;
    padding: 8px 10px; margin: 1px 0; border-radius: 9px;
    color: var(--side-text); font-weight: 500; transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(148, 163, 184, .1); color: var(--side-text-strong); text-decoration: none; }
.nav a.active { background: rgba(99, 102, 241, .2); color: #fff; }
.nav a.active::before {
    content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
    border-radius: 0 3px 3px 0; background: #818cf8;
}
.nav a.active .icon { color: #a5b4fc; }
.sidebar-foot {
    display: flex; align-items: center; gap: 8px; padding: 14px 14px 16px;
    border-top: 1px solid var(--side-line);
}
.sidebar-foot form { margin: 0; }
.me { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--side-text-strong); }
.me:hover { text-decoration: none; color: #fff; }
.avatar {
    display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; flex: none;
    background: rgba(129, 140, 248, .22); color: #c7d2fe; font-weight: 700;
}
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.me-text strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { font-size: 11.5px; color: var(--side-text); }
.icon-button {
    display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border-radius: 9px;
    background: transparent; border: 1px solid transparent; color: inherit; cursor: pointer;
}
.sidebar .icon-button { color: var(--side-text); }
.sidebar .icon-button:hover { background: rgba(148, 163, 184, .12); color: #fff; }
.shell { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
    height: 58px; padding: 0 28px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(160%) blur(10px); -webkit-backdrop-filter: saturate(160%) blur(10px);
    border-bottom: 1px solid var(--line);
}
.crumb { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; color: var(--muted); }
.crumb strong { color: var(--text-2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb .sep { opacity: .5; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.env-chip {
    padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
    background: var(--primary-soft); color: var(--primary);
}
.burger { display: none; color: var(--text-2); border-color: var(--line); background: var(--surface); }
.nav-scrim { display: none; }
.content { width: 100%; max-width: 1320px; padding: 26px 28px 64px; }

@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
    .nav-toggle:checked ~ .sidebar { transform: none; }
    .nav-toggle:checked ~ .nav-scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(15, 23, 42, .45); }
    .shell { margin-left: 0; }
    .burger { display: inline-grid; }
    .topbar { padding: 0 16px; }
    .content { padding: 20px 16px 48px; }
    .env-chip { display: none; }
}

/* ---------- Public pages (login, register, support) ---------- */
body.public {
    min-height: 100vh;
    background:
        radial-gradient(900px 500px at 10% -10%, rgba(99, 102, 241, .22), transparent 60%),
        radial-gradient(800px 500px at 110% 10%, rgba(236, 72, 153, .16), transparent 60%),
        var(--bg);
}
.public-main { max-width: 760px; margin: 0 auto; padding: 56px 16px 64px; }
.public-brand { justify-content: center; margin-bottom: 26px; color: var(--text); }
.public-brand .brand-text small { color: var(--muted); }
.login { max-width: 410px; margin: 0 auto; padding: 30px 30px 26px; }
.login h1 { font-size: 21px; margin-bottom: 18px; }
.login input { max-width: none; }
.login button[type=submit] { width: 100%; justify-content: center; height: 42px; margin-top: 6px; }
.narrow { max-width: 760px; margin: 0 auto; }

/* ---------- Typography ---------- */
h1 { font-size: 24px; line-height: 1.25; font-weight: 750; letter-spacing: -.015em; margin: 2px 0 20px; }
h2 { font-size: 16px; font-weight: 650; letter-spacing: -.005em; margin: 28px 0 12px; }
h1 + .muted, h1 + p.muted { margin-top: -12px; margin-bottom: 20px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
code { padding: 1px 6px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); }
pre {
    margin: 0 0 12px; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--surface-2); color: var(--text-2); overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}
pre code { padding: 0; background: none; }
details > summary { cursor: pointer; color: var(--primary); font-weight: 600; }
details[open] > summary { margin-bottom: 10px; }

/* ---------- Cards ---------- */
.panel {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.panel > h2:first-child, .panel > h1:first-child { margin-top: 0; }
.panel h2 { padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.panel h2 + * { margin-top: 0; }
.panel > :last-child { margin-bottom: 0; }
.panel.muted { color: var(--text-2); background: var(--surface-2); box-shadow: none; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; align-items: start; margin-bottom: 18px; }
.row > .panel { margin-bottom: 0; }

/* Stat tiles */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
/* Between phone and wide desktop a 2-column grid avoids a lone tile on the last row. */
@media (min-width: 641px) and (max-width: 1279px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat {
    position: relative; overflow: hidden;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 18px 15px; box-shadow: var(--shadow);
}
.stat::before {
    content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px;
    background: linear-gradient(90deg, #6366f1, #a855f7);
}
.stat:nth-child(4n+2)::before { background: linear-gradient(90deg, #16a34a, #4ade80); }
.stat:nth-child(4n+3)::before { background: linear-gradient(90deg, #d97706, #fbbf24); }
.stat:nth-child(4n+4)::before { background: linear-gradient(90deg, #0284c7, #38bdf8); }
.stat .label { position: relative; z-index: 1; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .value {
    position: relative; z-index: 1; margin-top: 6px;
    font-size: 27px; line-height: 1.15; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}

/* ---------- Tables ---------- */
.table-wrap {
    overflow-x: auto; margin-bottom: 18px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table-wrap table { background: transparent; }
:not(.table-wrap) > table { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th {
    position: sticky; top: 0; background: var(--surface-2); color: var(--muted);
    font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap;
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td form.inline { gap: 6px; }
td a { font-weight: 550; }

/* ---------- Forms ---------- */
form { margin: 0; }
label { display: block; margin: 12px 0 6px; color: var(--text-2); font-size: 12.5px; font-weight: 600; }
label:first-child { margin-top: 0; }
input, select, textarea {
    width: 100%; max-width: 460px; padding: 8px 11px; min-height: 38px;
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font: inherit;
    transition: border-color .15s, box-shadow .15s;
}
textarea { max-width: 680px; min-height: 92px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #94a3b8; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
input[type=checkbox], input[type=radio], input.check { width: auto; min-height: 0; margin: 0 6px 0 0; vertical-align: -2px; accent-color: var(--primary); box-shadow: none; }
input[type=number] { max-width: 220px; }
form.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0; }
form.inline label { margin: 0; }
form.inline input, form.inline select { width: auto; min-width: 140px; }
form.inline.panel { padding: 14px 16px; margin-bottom: 18px; }
.panel form + form { margin-top: 14px; }
p:has(> button), p:has(> .button) { margin: 16px 0 0; }

/* ---------- Buttons ---------- */
button, .button {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 38px; padding: 0 16px; border-radius: var(--radius-sm);
    border: 1px solid var(--primary); background: var(--primary); color: #fff;
    font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
    box-shadow: 0 1px 2px rgba(79, 70, 229, .25); transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
button:hover, .button:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; text-decoration: none; }
button:active, .button:active { transform: translateY(1px); }
button:focus-visible, .button:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--primary-ring); }
button.secondary, .button.secondary {
    background: var(--surface); color: var(--text-2); border-color: var(--line-strong); box-shadow: var(--shadow-sm);
}
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); }
button.danger, .button.danger { background: var(--bad); border-color: var(--bad); box-shadow: 0 1px 2px rgba(220, 38, 38, .25); }
button.danger:hover { background: #b91c1c; border-color: #b91c1c; }
button.link { min-height: 0; padding: 0; border: 0; background: none; box-shadow: none; color: var(--primary); font-weight: 600; }
button.link:hover { background: none; text-decoration: underline; color: var(--primary-hover); }
button.icon-button { min-height: 36px; box-shadow: none; }

/* ---------- Badges, alerts ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 650; line-height: 1.6; white-space: nowrap;
    background: var(--surface-3); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.flash {
    display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin-bottom: 18px;
    border-radius: 11px; border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
    background: var(--ok-soft); color: var(--ok); font-weight: 550;
}
.flash::before { content: "✓"; font-weight: 800; }
.flash.error { border-color: color-mix(in srgb, var(--bad) 30%, transparent); background: var(--bad-soft); color: var(--bad); }
.flash.error::before { content: "!"; }
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.alerts li:last-child { border-bottom: 0; padding-bottom: 0; }
ul:not(.alerts) { margin: 0 0 12px; padding-left: 18px; }
ul:not(.alerts) li { margin: 5px 0; }

/* ---------- Charts ---------- */
.spark { width: 100%; height: 96px; display: block; }
.spark polyline { fill: none; stroke: var(--primary); stroke-width: 2.4; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.bars { width: 100%; height: 130px; display: block; }
.bars rect { fill: var(--primary); opacity: .85; }
.bars rect:hover { opacity: 1; }
.bars.alt rect { fill: var(--ok); }
.meter { width: 180px; height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; display: block; }
.meter rect { fill: var(--primary); }

@media (max-width: 640px) {
    h1 { font-size: 21px; margin-bottom: 16px; }
    .panel { padding: 16px; border-radius: 12px; }
    .row { grid-template-columns: 1fr; }
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat { padding: 13px 14px 12px; border-radius: 12px; }
    .stat .label { font-size: 12px; line-height: 1.3; }
    .stat .value { font-size: 22px; }
    th, td { padding: 9px 10px; }
    .crumb .root, .crumb .sep { display: none; }
}

/* Checkbox grid, e.g. server scope pickers. */
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 16px; margin: 8px 0 4px; }
.check-grid label { margin: 0; font-weight: 400; }

/* Gain/loss bars around a centre axis (economy dashboard). */
.bars.duo { height: 170px; }
.bars.duo .gain { fill: var(--ok); opacity: .85; }
.bars.duo .loss { fill: var(--bad); opacity: .75; }
.bars.duo .axis { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
a.stat { color: inherit; text-decoration: none; }
a.stat:hover { border-color: var(--primary); }

/* Compact inputs inside table rows (live-ops page). */
td input.short { width: 96px; min-width: 0; }
table.liveops td:nth-child(2) { min-width: 190px; }
table.liveops td.days { min-width: 220px; }
table.liveops td input:not([type=checkbox]) { min-width: 130px; }
.small { font-size: 12px; }
label.day { display: inline-flex; align-items: center; margin: 0 6px 0 0; font-weight: 400; }
