:root {
    --bg: #0f1216;
    --panel: #161b21;
    --panel-2: #1c232b;
    --line: #273039;
    --text: #d9dee4;
    --muted: #7d8894;
    --accent: #5aa9ff;
    --buy: #3fbf7f;
    --sell: #ef6461;
    --flat: #8a95a1;
    --warn: #e0b341;
    --radius: 8px;
    --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "Segoe UI", system-ui, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0; font-weight: 600; }
h1:focus { outline: none; }
h2 { font-size: 0.95rem; margin: 0; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

/* ---- shell ---- */
.shell { display: flex; min-height: 100vh; }
.side {
    width: 200px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; padding: 1rem 0.75rem; gap: 2px;
    position: sticky; top: 0; height: 100vh;
}
.side a { color: var(--text); padding: 0.45rem 0.7rem; border-radius: 6px; }
.side a:hover { background: var(--panel-2); text-decoration: none; }
.side a.active { background: var(--panel-2); color: var(--accent); }
.side .signout { margin-top: auto; color: var(--muted); }
.brand { font-weight: 700; font-size: 1.1rem; padding: 0 0.7rem 1rem; letter-spacing: 0.02em; }
.brand span { color: var(--accent); font-weight: 400; margin-left: 0.3rem; }
.content { flex: 1; min-width: 0; padding: 1.5rem 2rem 3rem; max-width: 1400px; }

@media (max-width: 760px) {
    .shell { flex-direction: column; }
    .side { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; padding: 0.5rem; }
    .brand { padding: 0.45rem 0.7rem; }
    .side .signout { margin-top: 0; }
    .content { padding: 1rem; }
}

.page-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

/* ---- cards & layout ---- */
.card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 1rem 1.25rem; margin-bottom: 1rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.grid + .card { margin-top: 1rem; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0 0 0.75rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.stats { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.stats div { display: flex; flex-direction: column; }
.stats span { color: var(--muted); font-size: 0.8rem; }
.stats b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stats small { color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.error { color: var(--sell); }
.pos { color: var(--buy); }
.neg { color: var(--sell); }
.event { margin: 0 0 0.75rem; }

/* ---- controls ---- */
.btn {
    background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
    padding: 0.4rem 0.9rem; font: inherit; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b1420; font-weight: 600; }
.btn.small { padding: 0.2rem 0.6rem; font-size: 0.82rem; }
.actions { display: flex; gap: 0.5rem; }

input, select {
    background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
    padding: 0.35rem 0.5rem; font: inherit;
}
input[type=number] { width: 5.5rem; }
input:focus, select:focus { outline: none; border-color: var(--accent); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1.2rem; }
.filters label { display: flex; align-items: center; gap: 0.45rem; color: var(--muted); }
.filters label.grow { flex: 1; min-width: 14rem; }
.filters label.grow input { flex: 1; }
.filters .push { margin-left: auto; }
.filters.inline { margin-bottom: 0.5rem; }
.presets { display: flex; gap: 0.3rem; }

.confirm {
    margin-top: 0.9rem; padding: 0.8rem 1rem; border: 1px solid var(--line); border-radius: 6px;
    background: var(--panel-2); display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
}
.confirm p { margin: 0 0 0.3rem; flex-basis: 100%; }
.confirm.danger { border-color: var(--warn); }

pre.output {
    background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0.75rem;
    font: 0.8rem/1.45 var(--mono); white-space: pre-wrap; overflow-x: auto; margin: 0.75rem 0 0;
    max-height: 32rem; overflow-y: auto;
}
pre.output.bad { border-color: var(--sell); }

/* ---- badges ---- */
.pill, .mode, .tag, .status {
    display: inline-block; border-radius: 999px; padding: 0.05rem 0.6rem; font-size: 0.78rem;
    border: 1px solid var(--line); color: var(--muted);
}
.pill.on { color: var(--buy); border-color: var(--buy); }
.pill.off { color: var(--muted); }
.mode.demo { color: var(--accent); border-color: var(--accent); }
.mode.real { color: #0b1420; background: var(--warn); border-color: var(--warn); font-weight: 600; }
.status.ok { color: var(--buy); border-color: var(--buy); }
.status.bad { color: var(--sell); border-color: var(--sell); }

.dir { font-weight: 600; text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.03em; }
.dir.buy { color: var(--buy); }
.dir.sell { color: var(--sell); }
.dir.flat { color: var(--flat); }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
    border: 1px solid var(--line); border-left-width: 3px; border-radius: 5px; padding: 0.05rem 0.5rem;
    font-size: 0.8rem; background: var(--panel-2); white-space: nowrap;
}
.chip.buy { border-left-color: var(--buy); }
.chip.sell { border-left-color: var(--sell); }
.chip.flat { border-left-color: var(--flat); color: var(--muted); }
.chip.acted { border-color: var(--accent); }
.chip .num { font-variant-numeric: tabular-nums; color: var(--muted); }
.chip .tick { color: var(--accent); }

.conf { display: inline-flex; align-items: center; gap: 0.4rem; }
.conf-track { position: relative; width: 90px; height: 6px; background: var(--bg); border-radius: 3px; }
.conf-fill { position: absolute; inset: 0 auto 0 0; background: var(--flat); border-radius: 3px; }
.conf-fill.hit { background: var(--accent); }
.conf-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--warn); }
.conf-num { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- analyses ---- */
.analysis { padding: 0; }
.analysis-head {
    width: 100%; display: flex; align-items: center; gap: 1rem; padding: 0.75rem 1.25rem;
    background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.analysis-head:hover { background: var(--panel-2); }
.analysis-head .when { display: flex; flex-direction: column; min-width: 10.5rem; }
.analysis-head .chips { flex: 1; }
.analysis-head .caret { color: var(--muted); }
.analysis-body { padding: 0.25rem 1.25rem 1rem; border-top: 1px solid var(--line); }
.analysis-body .event { margin-top: 0.75rem; }

.verdict { border-top: 1px solid var(--line); padding: 0.75rem 0; }
.verdict-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.8rem; margin-bottom: 0.4rem; }
.verdict dl { display: grid; grid-template-columns: 3rem 1fr; gap: 0.3rem 0.75rem; margin: 0; }
.verdict dt { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; padding-top: 0.1rem; }
.verdict dd { margin: 0; }

details summary { cursor: pointer; color: var(--muted); margin: 0.5rem 0; }
.headlines { margin: 0; padding-left: 1.2rem; color: var(--text); }
.headlines li { margin: 0.15rem 0; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 0.8rem; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover, tr.selected { background: var(--panel-2); }
tr.detail > td { background: var(--panel-2); padding: 0 1rem; }
tr.detail .verdict { border-top: 0; }

/* ---- log ---- */
.log { padding: 0.5rem 0; font: 0.8rem/1.5 var(--mono); }
.log .line { display: grid; grid-template-columns: 5.2rem 4.8rem 11rem 1fr; gap: 0.6rem; padding: 0.1rem 1rem; }
.log .line:hover { background: var(--panel-2); }
.log .t { color: var(--muted); }
.log .s { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log .m { white-space: pre-wrap; overflow-wrap: anywhere; }
.log .lvl-warning .l, .log .lvl-warning .m { color: var(--warn); }
.log .lvl-error .l, .log .lvl-error .m, .log .lvl-critical .l, .log .lvl-critical .m { color: var(--sell); }
.log .lvl-info .l, .log .lvl-debug .l { color: var(--muted); }
@media (max-width: 760px) {
    .log .line { grid-template-columns: 5.2rem 1fr; }
    .log .l, .log .s { display: none; }
}

/* ---- signed-in user (sidebar) ---- */
.side .who { margin-top: auto; padding: 0.75rem 0.7rem 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; align-items: flex-start; gap: 0.35rem; }
.side .who a { padding: 0; }
.side .who a:hover { background: none; text-decoration: underline; }
.linklike { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; }
.linklike:hover { color: var(--text); text-decoration: underline; }
@media (max-width: 760px) {
    .side .who { margin-top: 0; border-top: 0; padding: 0.45rem 0.7rem; flex-direction: row; align-items: center; }
}

/* ---- sign-in ---- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login { width: min(26rem, 100%); display: flex; flex-direction: column; gap: 0.6rem; }
.login .brand { padding: 0 0 0.25rem; }
.login .error { margin: 0; }
.login .btn { align-self: flex-start; }
.auth-title { font-size: 1.2rem; }
.stack { display: flex; flex-direction: column; gap: 0.5rem; }
.stack label { color: var(--muted); }
.stack label.check { display: flex; align-items: center; gap: 0.45rem; }
.stack .btn { align-self: flex-start; margin-top: 0.25rem; }
input.code { font: 1.4rem var(--mono); letter-spacing: 0.35em; width: 9.5rem; text-align: center; }
.steps { padding-left: 1.2rem; margin: 0.25rem 0; display: flex; flex-direction: column; gap: 0.6rem; }
.steps li > * { display: block; }
.qr { width: 200px; height: 200px; margin: 0.6rem 0; background: #fff; padding: 8px; border-radius: 6px; image-rendering: pixelated; }
.key { font: 0.95rem var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 0.3rem 0.5rem; margin-top: 0.25rem; word-break: break-all; }
.validation-summary-errors ul, ul.validation-errors { margin: 0; padding-left: 1.1rem; color: var(--sell); }
.validation-message { color: var(--sell); }

/* ---- Blazor framework bits ---- */
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.blazor-error-boundary::after { content: "An error has occurred."; }
