/* =====================================================================================================
   CRYPTO MARKET MONITOR - global dark theme (self-contained: system fonts, no CDN, no scoped CSS needed)

   DESIGN TOKENS (other pages/components should use these instead of literal colors)
     --bg            page background                 --panel / --panel-2   panel surface / raised surface
     --bg-elev       header / sticky surfaces        --border / --border-strong
     --text          primary text                    --muted / --faint     secondary / tertiary text
     --accent        brand accent (links, focus)     --accent-bg
     --up / --down   positive / negative values      --up-bg / --down-bg   tinted backgrounds
     --warn / --info amber / blue status             --warn-bg / --info-bg
     --font-sans / --font-mono                       --radius, --gap, --row-h

   UTILITY / COMPONENT CLASSES
     Layout:   .page, .page-head, .page-title, .grid-2, .stack, .toolbar, .spacer
     Panels:   .panel, .panel-major (amber edge), .panel-header, .panel-title, .panel-sub, .panel-body, .caption
     Tables:   .data-table (dense, sticky header), .table-scroll (scroll container), th.sortable, tr.detail-row,
               .clip (ellipsis cell), .row-muted
     Numbers:  .num (tabular-nums, right aligned), .up / .down / .flat (value colors; always paired with +/- sign)
     Text:     .muted, .faint, .na (DATA UNAVAILABLE), .mono, .nowrap, .empty-state, .error-text
     Badges:   .badge + .badge-up|-down|-warn|-info|-accent|-muted ; .chip (exchange status) ; .score + .score-high|-mid|-low
     Status:   .dot + .dot-live|-stale|-unavailable|-disabled
     Controls: .btn, .btn-primary, .btn-danger, .btn-sm, .link-btn, .field, .check, .filters
     A11y:     .sr-only
   ===================================================================================================== */

:root {
    color-scheme: dark;

    --bg: #0b0e11;
    --bg-elev: #12161b;
    --panel: #161a1f;
    --panel-2: #1d2229;
    --border: #262c34;
    --border-strong: #38404a;

    --text: #e6e8eb;
    --muted: #8a94a3;
    --faint: #5c6573;

    --accent: #f0b90b;
    --accent-bg: rgba(240, 185, 11, 0.12);
    --up: #18c27f;
    --up-bg: rgba(24, 194, 127, 0.13);
    --down: #f2495f;
    --down-bg: rgba(242, 73, 95, 0.13);
    --warn: #f3a32b;
    --warn-bg: rgba(243, 163, 43, 0.14);
    --info: #4aa3ff;
    --info-bg: rgba(74, 163, 255, 0.13);

    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
        "Segoe UI Emoji", "Apple Color Emoji";
    --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

    --radius: 6px;
    --gap: 12px;
    --row-h: 30px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 16px; letter-spacing: 0.02em; }
h2 { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; }
h3 { font-size: 13px; }

/* ---------- text utilities ---------- */
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
.na { color: var(--faint); font-size: 11px; letter-spacing: 0.04em; }
.caption { color: var(--muted); font-size: 11.5px; }
.empty-state { color: var(--muted); padding: 10px 2px; font-style: italic; }
.error-text { color: var(--down); }
.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;
}

/* ---------- app shell ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
    position: sticky; top: 0; z-index: 20;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
}

.app-topbar {
    display: flex; align-items: center; gap: 18px;
    padding: 6px 16px; border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; letter-spacing: 0.12em; font-size: 13px; color: var(--text); white-space: nowrap; }
.brand-mark { color: var(--accent); margin-right: 6px; }
.brand-sub { color: var(--faint); font-weight: 500; letter-spacing: 0.04em; font-size: 11px; margin-left: 8px; }

.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a {
    color: var(--muted); padding: 5px 10px; border-radius: var(--radius); font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--accent); }

.auth-area { margin-left: auto; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.auth-area form { margin: 0; }

.market-strip {
    display: flex; align-items: center; flex-wrap: wrap; gap: 6px 20px;
    padding: 6px 16px; font-size: 12.5px;
}
.strip-item { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.strip-label { color: var(--faint); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; }
.strip-value { font-weight: 600; }

.exchange-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }

.app-main { flex: 1; padding: 14px 16px 32px; min-width: 0; }

/* ---------- page ---------- */
.page { display: flex; flex-direction: column; gap: var(--gap); }
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 15px; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
@media (max-width: 1200px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* ---------- panels ---------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 0;
}
.panel-major { border-color: rgba(243, 163, 43, 0.45); box-shadow: inset 3px 0 0 var(--warn); }
.panel-header {
    display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
    padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.panel-title { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text); }
.panel-sub { color: var(--muted); font-size: 11.5px; }
.panel-header .panel-count { margin-left: auto; color: var(--faint); font-size: 11px; }
.panel-body { padding: 6px 12px 10px; }
.panel-body.flush { padding: 0; }
.panel-foot { padding: 6px 12px 8px; border-top: 1px solid var(--border); }

/* ---------- tables ---------- */
.table-scroll { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th, .data-table td {
    padding: 0 8px; height: var(--row-h); border-bottom: 1px solid var(--border);
    text-align: left; white-space: nowrap; vertical-align: middle;
}
.data-table thead th {
    position: sticky; top: 0; z-index: 2;
    background: var(--panel-2); color: var(--muted);
    font-weight: 600; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
    height: 28px; border-bottom: 1px solid var(--border-strong);
}
.data-table th.num, .data-table td.num { text-align: right; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.data-table tr.row-muted td { opacity: 0.55; }
.data-table tr.row-pinned td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.data-table tr.detail-row td { height: auto; white-space: normal; background: var(--bg-elev); padding: 8px 12px 10px; }
.data-table td.clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.data-table td.wrap { white-space: normal; }
.data-table th.sortable { cursor: pointer; user-select: none; padding: 0; }
.data-table th.sortable button {
    all: unset; box-sizing: border-box; display: block; width: 100%; height: 28px; line-height: 28px;
    padding: 0 8px; cursor: pointer; text-align: inherit;
}
.data-table th.sortable button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.data-table th.sortable:hover { color: var(--text); }
.data-table th.sorted { color: var(--accent); }
.sort-ind { display: inline-block; width: 10px; font-size: 9px; margin-left: 2px; }

.why { color: var(--muted); font-size: 11.5px; }

/* ---------- badges / chips / score ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border-strong);
    font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; line-height: 16px;
    color: var(--muted); background: var(--panel-2); white-space: nowrap;
}
.badge-up { color: var(--up); background: var(--up-bg); border-color: rgba(24, 194, 127, 0.35); }
.badge-down { color: var(--down); background: var(--down-bg); border-color: rgba(242, 73, 95, 0.35); }
.badge-warn { color: var(--warn); background: var(--warn-bg); border-color: rgba(243, 163, 43, 0.35); }
.badge-info { color: var(--info); background: var(--info-bg); border-color: rgba(74, 163, 255, 0.35); }
.badge-accent { color: var(--accent); background: var(--accent-bg); border-color: rgba(240, 185, 11, 0.35); }
.badge-muted { color: var(--faint); background: transparent; }

.chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border-strong);
    font-size: 11px; white-space: nowrap; background: var(--panel);
}
.chip-name { font-weight: 600; }
.chip-state { font-size: 10px; font-weight: 700; letter-spacing: 0.05em; }
.chip-live .chip-state { color: var(--up); }
.chip-stale .chip-state { color: var(--warn); }
.chip-unavailable .chip-state { color: var(--down); }
.chip-disabled { opacity: 0.6; }
.chip-disabled .chip-state { color: var(--faint); }
.chip-latency { color: var(--faint); font-variant-numeric: tabular-nums; }

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.dot-live { background: var(--up); box-shadow: 0 0 0 2px var(--up-bg); }
.dot-stale { background: var(--warn); }
.dot-unavailable { background: var(--down); }
.dot-disabled { background: var(--faint); }

.score {
    display: inline-block; min-width: 30px; padding: 0 5px; border-radius: 4px;
    font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; line-height: 18px;
}
.score-high { color: #0b0e11; background: var(--accent); }
.score-mid { color: var(--accent); background: var(--accent-bg); }
.score-low { color: var(--muted); background: var(--panel-2); }

.icon-flags { display: inline-flex; gap: 4px; }
.ratio-list { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; }
.ratio-item { white-space: nowrap; color: var(--muted); }
.ratio-item b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.ratio-item.leader b { color: var(--warn); }

/* ---------- attention breakdown ---------- */
.breakdown { width: 100%; max-width: 900px; border-collapse: collapse; font-size: 12px; }
.breakdown th, .breakdown td { padding: 3px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.breakdown th { color: var(--faint); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; }
.breakdown .bar { display: inline-block; height: 6px; background: var(--accent); border-radius: 3px; vertical-align: middle; }
.breakdown .bar-track { display: inline-block; width: 70px; height: 6px; background: var(--panel-2); border-radius: 3px; margin-right: 6px; vertical-align: middle; }

/* ---------- news ---------- */
.news-list { list-style: none; margin: 0; padding: 0; }
.news-list li { padding: 7px 0; border-bottom: 1px solid var(--border); display: grid; gap: 3px; }
.news-list li:last-child { border-bottom: none; }
.news-title { color: var(--text); font-weight: 500; }
.news-title:hover { color: var(--accent); }
.news-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; color: var(--muted); font-size: 11.5px; }

/* ---------- controls ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="number"], input[type="search"], input[type="password"], select, textarea {
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: 4px; padding: 4px 7px; min-height: 28px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input[type="number"] { width: 100%; }
input[type="checkbox"] { accent-color: var(--accent); }

.btn {
    display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
    padding: 4px 11px; min-height: 28px; border-radius: 4px;
    border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text); font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b0e11; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--down); border-color: rgba(242, 73, 95, 0.5); background: transparent; }
.btn-sm { padding: 1px 7px; min-height: 22px; font-size: 11.5px; }
.link-btn { all: unset; cursor: pointer; color: var(--muted); padding: 0 4px; border-radius: 3px; }
.link-btn:hover { color: var(--text); }
.link-btn:focus-visible { outline: 2px solid var(--accent); }

.field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); min-width: 0; }
.field > span { letter-spacing: 0.03em; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); cursor: pointer; white-space: nowrap; }

.filters {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 12px; align-items: end;
}
.filters .field-wide { grid-column: span 2; }
.filter-toggles { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; }
.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ---------- coins table ---------- */
.coins-scroll { max-height: calc(100vh - 330px); min-height: 320px; }
.coins-table td:first-child, .coins-table th:first-child { position: sticky; left: 0; background: var(--panel); z-index: 1; }
.coins-table thead th:first-child { z-index: 3; background: var(--panel-2); }

/* ---------- misc ---------- */
.stale-flag { color: var(--warn); font-weight: 700; font-size: 11px; letter-spacing: 0.05em; }
.collecting { padding: 28px; text-align: center; color: var(--muted); }
.collecting strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }

/* ---------- login / empty layout (static SSR) ---------- */
.empty-layout { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
    width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { letter-spacing: 0.12em; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.login-card button {
    margin-top: 6px; padding: 7px; border: none; border-radius: 4px; cursor: pointer;
    background: var(--accent); color: #0b0e11; font-weight: 600;
}
.login-card .error { color: var(--down); margin: 0; }

/* ---------- Blazor error / reconnect UI ---------- */
#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    padding: 8px 16px; background: var(--down-bg); border-top: 1px solid var(--down); color: var(--text);
    backdrop-filter: blur(4px);
}
#blazor-error-ui .reload { color: var(--accent); margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 14px; top: 6px; }
.blazor-error-boundary { padding: 12px; border: 1px solid var(--down); border-radius: var(--radius); background: var(--down-bg); }
.blazor-error-boundary::after { content: "This section failed to render. Reload the page to retry."; }
