/* KeyGlass user portal — design system.
   Strict CSP: this file and portal.js are the only style/script sources.
   Light by default, follows the system dark mode. No external fonts. */

:root {
    --bg: #f4f6fb;
    --bg-soft: #eef1f8;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #f1f4f9;
    --border: #e4e8f0;
    --border-strong: #d3d9e4;
    --text: #0f172a;
    --text-2: #475569;
    --muted: #8a94a6;
    --primary: #4f46e5;
    --primary-600: #4338ca;
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --accent: #0ea5e9;
    --success: #059669;
    --success-50: #ecfdf5;
    --warning: #b45309;
    --warning-50: #fffbeb;
    --danger: #e11d48;
    --danger-50: #fff1f2;
    --info: #0369a1;
    --info-50: #f0f9ff;
    --gradient: linear-gradient(135deg, #4f46e5 0%, #2563eb 48%, #0ea5e9 100%);
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 7px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .06);
    --shadow-lg: 0 20px 50px rgba(30, 41, 99, .14);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
        "Noto Sans CJK SC", sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --side: 248px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1020;
        --bg-soft: #0f152a;
        --surface: #121a2f;
        --surface-2: #162038;
        --surface-3: #1b2642;
        --border: #24304d;
        --border-strong: #31406a;
        --text: #e7ecf7;
        --text-2: #aab4cb;
        --muted: #7c88a5;
        --primary: #818cf8;
        --primary-600: #a5b4fc;
        --primary-50: rgba(129, 140, 248, .12);
        --primary-100: rgba(129, 140, 248, .2);
        --success: #34d399;
        --success-50: rgba(52, 211, 153, .12);
        --warning: #fbbf24;
        --warning-50: rgba(251, 191, 36, .12);
        --danger: #fb7185;
        --danger-50: rgba(251, 113, 133, .12);
        --info: #38bdf8;
        --info-50: rgba(56, 189, 248, .12);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
        --shadow-lg: 0 20px 50px rgba(0, 0, 0, .45);
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-name span { color: var(--primary); }

/* ---------- buttons ---------- */
.btn, button, input[type="submit"] {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 38px; padding: 0 16px; border-radius: var(--radius-xs);
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
    font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover, button:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-primary, button.btn-primary {
    background: var(--primary); border-color: var(--primary); color: #fff;
    box-shadow: 0 6px 14px rgba(79, 70, 229, .22);
}
.btn-primary:hover, button.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.btn-gradient { background: var(--gradient); border: 0; color: #fff; box-shadow: 0 10px 24px rgba(37, 99, 235, .28); }
.btn-gradient:hover { color: #fff; filter: brightness(1.05); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; color: var(--text); }
.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger-50); border-color: var(--danger); color: var(--danger); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn-lg { height: 46px; padding: 0 24px; font-size: 15px; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }
button:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form { display: inline; margin: 0; }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label, .label { font-weight: 550; font-size: 13px; color: var(--text-2); }
.hint { font-size: 12.5px; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"],
input:not([type]), select, textarea {
    width: 100%; height: 40px; padding: 0 12px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-xs);
    background: var(--surface); color: var(--text); font: inherit;
    transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-100);
}
.input-group { display: flex; gap: 8px; }
.input-group > input { flex: 1; }
.choice { display: flex; flex-wrap: wrap; gap: 10px; border: 0; margin: 0; padding: 0; }
.choice legend { font-weight: 550; margin-bottom: 8px; color: var(--text-2); }
.choice label {
    display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; cursor: pointer;
    border: 1px solid var(--border-strong); border-radius: var(--radius-xs); background: var(--surface);
}
.choice input { accent-color: var(--primary); }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); cursor: pointer; }
.check input { accent-color: var(--primary); width: 15px; height: 15px; }

/* ---------- alerts & badges ---------- */
.alert {
    display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm);
    border: 1px solid transparent; font-size: 13.5px;
}
.alert-icon { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.alert-info { background: var(--info-50); color: var(--info); border-color: rgba(3, 105, 161, .15); }
.alert-ok { background: var(--success-50); color: var(--success); border-color: rgba(5, 150, 105, .18); }
.alert-warn { background: var(--warning-50); color: var(--warning); border-color: rgba(180, 83, 9, .18); }
.alert-danger { background: var(--danger-50); color: var(--danger); border-color: rgba(225, 29, 72, .18); }
.alert p { margin: 0; }
.stack > * + * { margin-top: 12px; }
.badge {
    display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px;
    border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
    background: var(--surface-3); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-plain::before { display: none; }
.badge-ok { background: var(--success-50); color: var(--success); }
.badge-warn { background: var(--warning-50); color: var(--warning); }
.badge-danger { background: var(--danger-50); color: var(--danger); }
.badge-info { background: var(--primary-50); color: var(--primary); }
.tag {
    display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px;
    background: var(--surface-3); color: var(--text-2); font-size: 12px;
}
.method { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--success); letter-spacing: .02em; }
.method-post { color: var(--warning); }

/* ---------- cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: 20px 22px;
}
.card + .card, .card + .grid, .grid + .card, .grid + .grid { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-head .link-more { font-size: 13px; font-weight: 550; }
.card-flat { box-shadow: none; }
.card-pad-0 { padding: 0; }
.card-pad-0 .card-head { padding: 18px 22px 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat-label { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
.stat-icon {
    width: 28px; height: 28px; border-radius: 8px; display: inline-grid; place-items: center;
    background: var(--primary-50); color: var(--primary);
}
.stat-icon svg { width: 16px; height: 16px; }
.stat-icon.ok { background: var(--success-50); color: var(--success); }
.stat-icon.warn { background: var(--warning-50); color: var(--warning); }
.stat-icon.info { background: var(--info-50); color: var(--info); }
.stat-value { margin-top: 10px; font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 13px; font-weight: 550; color: var(--muted); margin-left: 3px; }
.stat-foot { margin-top: 2px; color: var(--muted); font-size: 12.5px; }

/* ---------- key/value ---------- */
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; margin: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 550; text-align: right; font-variant-numeric: tabular-nums; }
.kv-1 { grid-template-columns: minmax(0, 1fr); }

/* ---------- progress ---------- */
.meter { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--gradient); }
.meter.warn > span { background: linear-gradient(90deg, #f59e0b, #f97316); }
.meter.danger > span { background: linear-gradient(90deg, #f43f5e, #e11d48); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
    text-align: left; font-weight: 600; font-size: 12.5px; color: var(--text-2);
    background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .r { text-align: right; }
.table code { word-break: break-all; }

/* ---------- code blocks ---------- */
.code {
    position: relative; margin: 0; padding: 14px 16px; border-radius: var(--radius-sm);
    background: #0d1426; color: #dbe4ff; overflow-x: auto; line-height: 1.65;
    border: 1px solid rgba(255, 255, 255, .06); white-space: pre; font-size: 12.5px;
}
.code-wrap { position: relative; }
.code-wrap .copy-btn { position: absolute; top: 8px; right: 8px; }
.code-wrap .copy-btn {
    height: 26px; padding: 0 10px; font-size: 12px; background: rgba(255, 255, 255, .08);
    color: #c7d2fe; border-color: rgba(255, 255, 255, .14);
}
.code-wrap .copy-btn:hover { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .3); }
.prompt-text { white-space: pre-wrap; word-break: break-word; max-height: 420px; overflow: auto; }
.inline-code {
    font-family: var(--mono); font-size: 12.5px; padding: 2px 7px; border-radius: 6px;
    background: var(--surface-3); color: var(--text); word-break: break-all;
}
.copy-status { font-size: 12.5px; }
.copy-status.ok { color: var(--success); }
.copy-status.err { color: var(--danger); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs a, .tabs button {
    display: inline-flex; align-items: center; gap: 6px; height: 42px; padding: 0 14px;
    color: var(--text-2); font-weight: 550; border: 0; border-bottom: 2px solid transparent;
    background: none; border-radius: 0; white-space: nowrap; margin-bottom: -1px;
}
.tabs a:hover, .tabs button:hover { color: var(--text); text-decoration: none; border-color: transparent; }
.tabs [aria-current="page"], .tabs [aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.segmented {
    display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-3);
}
.segmented a, .segmented button {
    height: 30px; padding: 0 12px; border-radius: 8px; border: 0; background: transparent;
    color: var(--text-2); font-weight: 550; font-size: 13px; display: inline-flex; align-items: center;
}
.segmented a:hover, .segmented button:hover { text-decoration: none; color: var(--text); }
.segmented [aria-current="page"], .segmented [aria-selected="true"] {
    background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm);
}

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; margin-bottom: 8px; opacity: .7; }
.empty strong { display: block; color: var(--text-2); margin-bottom: 4px; }

/* ---------- list rows ---------- */
.rows { display: grid; grid-template-columns: minmax(0, 1fr); }
.row-item {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 2px; border-bottom: 1px solid var(--border);
}
.row-item:last-child { border-bottom: 0; }
.row-item .row-main { min-width: 0; }
.row-item .row-title { font-weight: 600; }
.row-item .row-sub { color: var(--muted); font-size: 12.5px; }
a.row-item { color: inherit; }
a.row-item:hover { text-decoration: none; }
a.row-item:hover .row-title { color: var(--primary); }
.chev { color: var(--muted); }

/* ---------- source cards ---------- */
.source {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center;
    padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.source + .source { margin-top: 12px; }
.source-logo {
    width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
    color: #fff; font-weight: 800; font-size: 15px; background: var(--gradient);
}
.source-logo.lsr { background: linear-gradient(135deg, #0f766e, #14b8a6); }
.source-logo.mcp { background: linear-gradient(135deg, #7c3aed, #c026d3); }
.source-logo.ws { background: linear-gradient(135deg, #ea580c, #f59e0b); }
.source-title { font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.source-sub { color: var(--muted); font-size: 12.5px; }
.source-meta { display: flex; gap: 22px; align-items: center; }
.source-meta .mini { text-align: right; }
.source-meta .mini b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.source-meta .mini span { color: var(--muted); font-size: 12px; }
.source-off { opacity: .72; }

/* ---------- charts (server-rendered SVG) ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 3 4; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .area { fill: url(#chartFill); }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line-err { fill: none; stroke: var(--danger); stroke-width: 1.6; stroke-dasharray: 4 3; }
.chart .dot { fill: var(--surface); stroke: var(--primary); stroke-width: 2; }
.chart .bar { fill: var(--primary); opacity: .85; }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); margin-top: 8px; }
.chart-legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.rank { display: grid; gap: 10px; }
.rank-item { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.rank-no {
    width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 12px;
    font-weight: 700; background: var(--surface-3); color: var(--text-2);
}
.rank-item:nth-child(-n+3) .rank-no { background: var(--primary-50); color: var(--primary); }
.rank-path { font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar { grid-column: 2 / 4; height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; margin-top: -6px; }
.rank-bar span { display: block; height: 100%; background: var(--gradient); }

/* =====================================================================
   Public site (landing, login, register)
   ===================================================================== */
.site { min-height: 100vh; display: flex; flex-direction: column; }
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header-inner { max-width: 1080px; margin: 0 auto; height: 60px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.site-cta { display: flex; gap: 10px; }
.container { max-width: 1080px; margin: 0 auto; padding: 0 24px; }
.site-main { width: 100%; min-width: 0; padding-top: 36px; padding-bottom: 40px; }
.site-main h1 { font-size: 24px; margin-bottom: 6px; }
.product {
    display: flex; flex-direction: column; gap: 4px; padding: 20px; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--surface);
}
.product h3 { font-size: 16px; }
.product .price { font-size: 26px; font-weight: 750; margin: 6px 0 14px; letter-spacing: -.02em; }
.product .price small { font-size: 13px; color: var(--muted); font-weight: 550; }
.product .btn, .product .form { margin-top: auto; }
.site-footer { margin-top: auto; border-top: 1px solid var(--border); padding: 22px 0; color: var(--muted); font-size: 13px; }
.site-footer .container { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 40px 20px; background: var(--bg); }
.auth-panel {
    width: 100%; max-width: 420px; padding: 32px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.auth-panel > .brand { margin-bottom: 22px; }
.auth-panel h1 { font-size: 22px; margin-bottom: 6px; }
.auth-panel .sub { color: var(--text-2); margin-bottom: 20px; }
.auth-panel .tabs { margin-bottom: 20px; }
.auth-panel .form button[type="submit"] { width: 100%; height: 42px; }
.auth-foot { margin-top: 20px; text-align: center; color: var(--text-2); }
.tab-panel + .tab-panel { margin-top: 26px; padding-top: 22px; border-top: 1px dashed var(--border); }
.js .tab-panel + .tab-panel { margin-top: 0; padding-top: 0; border-top: 0; }

/* =====================================================================
   Signed-in application shell
   ===================================================================== */
.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.side {
    position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface);
    border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column;
}
.side .brand { padding: 4px 8px 18px; }
.side-group { margin-top: 10px; }
.side-group-title { padding: 6px 10px; font-size: 11.5px; font-weight: 650; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.side-link {
    display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border-radius: 9px;
    color: var(--text-2); font-weight: 550;
}
.side-link svg { width: 18px; height: 18px; flex: none; }
.side-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.side-link[aria-current="page"] { background: var(--primary-50); color: var(--primary); }
.topbar {
    position: sticky; top: 0; z-index: 10; height: 62px; display: flex; align-items: center; gap: 14px;
    padding: 0 28px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; flex: 1; min-width: 0; }
.crumbs a { color: var(--text-2); }
.crumbs .sep { opacity: .6; }
.crumbs .here { color: var(--text); font-weight: 600; }
.userchip {
    display: inline-flex; align-items: center; gap: 9px; height: 36px; padding: 0 12px 0 6px;
    border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text);
    font-weight: 550; max-width: 260px;
}
.userchip:hover { text-decoration: none; border-color: var(--border-strong); }
.avatar {
    width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none;
    background: var(--gradient); color: #fff; font-size: 12px; font-weight: 700;
}
.userchip .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 26px 28px 48px; max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { color: var(--text-2); margin: 6px 0 0; }
.module-head { display: flex; align-items: center; gap: 14px; }
.module-head .source-logo { width: 48px; height: 48px; }
.nav-toggle, .nav-toggle-label { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
    .grid-main { grid-template-columns: minmax(0, 1fr); }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .app { grid-template-columns: minmax(0, 1fr); }
    .side {
        position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%);
        transition: transform .2s; box-shadow: var(--shadow-lg);
    }
    .nav-toggle:checked ~ .side { transform: none; }
    .nav-toggle:checked ~ .scrim { display: block; }
    .scrim { display: none; position: fixed; inset: 0; z-index: 30; background: rgba(15, 23, 42, .4); }
    .nav-toggle-label {
        display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px;
        border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text);
    }
    .nav-toggle-label svg { width: 18px; height: 18px; }
    .topbar { padding: 0 16px; }
    .content { padding: 18px 16px 40px; }
    .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
    .auth-panel { padding: 24px 20px; }
    .kv { grid-template-columns: minmax(0, 1fr); }
    .source { grid-template-columns: auto minmax(0, 1fr); }
    .source-meta { grid-column: 1 / -1; justify-content: space-between; }
}
@media (max-width: 560px) {
    .stats, .grid-4 { grid-template-columns: minmax(0, 1fr); }
    .userchip .who { display: none; }
    .card { padding: 16px; }
    .site-cta .btn-ghost { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}

.between { justify-content: space-between; }
.app-main { min-width: 0; }
.spaced { margin-top: 18px; }

/* width utilities (CSP forbids inline style attributes) */
.w0 { width: 0%; }
.w5 { width: 5%; }
.w10 { width: 10%; }
.w15 { width: 15%; }
.w20 { width: 20%; }
.w25 { width: 25%; }
.w30 { width: 30%; }
.w35 { width: 35%; }
.w40 { width: 40%; }
.w45 { width: 45%; }
.w50 { width: 50%; }
.w55 { width: 55%; }
.w60 { width: 60%; }
.w65 { width: 65%; }
.w70 { width: 70%; }
.w75 { width: 75%; }
.w80 { width: 80%; }
.w85 { width: 85%; }
.w90 { width: 90%; }
.w95 { width: 95%; }
.w100 { width: 100%; }

/* websocket tester & lists */
.ws-log {
    height: 320px; overflow: auto; padding: 12px; border-radius: var(--radius-sm); background: #0d1426;
    color: #cbd5f5; font-family: var(--mono); font-size: 12px; border: 1px solid rgba(255, 255, 255, .06);
}
.ws-log .muted { color: #7c88a5; font-family: var(--font); }
.ws-line { padding: 3px 0; border-bottom: 1px dashed rgba(255, 255, 255, .06); white-space: pre-wrap; word-break: break-all; }
.ws-line time { color: #64748b; margin-right: 8px; }
.ws-line.sys { color: #93c5fd; }
.ws-line.err { color: #fda4af; }

/* API explorer */
.explorer { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 18px; align-items: start; }
.explorer-nav { position: sticky; top: 78px; max-height: calc(100vh - 96px); overflow: auto; padding: 16px; }
.explorer-switch { display: flex; }
.explorer-switch a { flex: 1; justify-content: center; }
.explorer-groups { margin-top: 10px; }
.explorer-group + .explorer-group { margin-top: 8px; }
.explorer-item {
    display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; color: var(--text);
}
.explorer-item:hover { background: var(--surface-3); text-decoration: none; }
.explorer-item[aria-current="page"] { background: var(--primary-50); }
.explorer-item .method { margin-top: 2px; }
.explorer-item-text { display: grid; min-width: 0; }
.explorer-item-text b { font-weight: 550; font-size: 13px; }
.explorer-item-text .mono { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.explorer-main > .card + .card { margin-top: 18px; }
.endpoint-line {
    display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: var(--radius-xs);
    background: var(--surface-2); border: 1px solid var(--border); overflow-x: auto;
}
.endpoint-line code { white-space: nowrap; }
.param-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.req { color: var(--danger); }
.result-body { max-height: 520px; overflow: auto; }
@media (max-width: 1000px) {
    .explorer { grid-template-columns: minmax(0, 1fr); }
    .explorer-nav { position: static; max-height: 360px; }
    .param-grid { grid-template-columns: minmax(0, 1fr); }
}
.narrow { max-width: 420px; }

/* default icon size (specific components override below) */
.i { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.btn .i, button .i { width: 16px; height: 16px; }
.btn-sm .i { width: 14px; height: 14px; }
.card-head h2 .i { width: 18px; height: 18px; color: var(--primary); }
.copy-btn .i { width: 13px; height: 13px; }
.chev .i { width: 16px; height: 16px; }
.scrim { display: none; }
.app > .nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
@media (max-width: 900px) { .nav-toggle:checked ~ .scrim { display: block; } }
.grid > .card, .grid > div > .card:first-child { margin-top: 0; }
.grid > div > .card + .card { margin-top: 18px; }
.row-item .row-main { flex: 1; }
.row-item .badge { flex: none; }
.app { background: linear-gradient(to right, var(--surface) var(--side), var(--bg) var(--side)); }
@media (max-width: 900px) { .app { background: var(--bg); } }
.grid-main > div > p.muted { margin-top: 14px; }

/* =====================================================================
   Wallet, tickets and Keys (round 2)
   ===================================================================== */
.balance-list { display: grid; gap: 10px; }
.balance { display: flex; flex-direction: column; gap: 4px; padding: 18px 20px; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary-50), var(--info-50)); border: 1px solid var(--primary-100); }
.balance-value { font-size: 28px; font-weight: 750; letter-spacing: -.02em; color: var(--text); }
.table td.pos { color: var(--success); font-weight: 600; }
.table td.neg { color: var(--text); }
.plain-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
input.mono { letter-spacing: .06em; text-transform: uppercase; }
.thread { display: grid; gap: 14px; }
.msg { max-width: 82%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.msg-me { justify-self: end; background: var(--primary-50); border-color: var(--primary-100); }
.msg-staff { justify-self: start; }
.msg-meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.msg-body { white-space: pre-wrap; word-break: break-word; color: var(--text); }
.inline-details { display: inline-block; margin-right: 6px; text-align: left; }
.inline-details > summary { list-style: none; cursor: pointer; }
.inline-details > summary::-webkit-details-marker { display: none; }
.inline-details[open] { display: block; margin: 0 0 8px; }
.key-created { border-color: var(--warning); }
.stat-link { color: inherit; }
.stat-link:hover { text-decoration: none; }
@media (max-width: 700px) { .msg { max-width: 100%; } }

.receipt-qr { max-width: 100%; height: auto; }
