/* ── Design tokens — light (warm paper) ─────────────────────── */
:root {
  /* Surfaces */
  --bg-base:      #f4f3f0;
  --bg-surface:   #ffffff;
  --bg-inset:     #f8f8f6;
  --bg-hover:     #f1f0ed;

  /* Legacy aliases — inline styles depend on these names */
  --bg-primary:   var(--bg-surface);
  --bg-secondary: var(--bg-inset);
  --bg-tertiary:  var(--bg-base);

  /* Text */
  --text-primary:   #1b1b1f;
  --text-secondary: #5f5f66;
  --text-tertiary:  #97979e;
  --text-muted:     var(--text-secondary);   /* fixes 314 undefined usages */

  /* Hairlines */
  --border-light:  rgba(20, 20, 25, 0.08);
  --border-medium: rgba(20, 20, 25, 0.16);
  --border:        var(--border-light);      /* fixes 91 undefined usages */

  /* Accent */
  --accent-primary:    #2563eb;
  --accent-primary-bg: rgba(37, 99, 235, 0.08);
  --accent-ring:       rgba(37, 99, 235, 0.35);
  --accent-contrast:   #ffffff;

  /* Semantic — direction (match hexes hardcoded in page builders) */
  --up:       #16a34a;
  --down:     #dc2626;
  --warn:     #d97706;
  --up-bg:    rgba(22, 163, 74, 0.10);
  --down-bg:  rgba(220, 38, 38, 0.10);
  --warn-bg:  rgba(217, 119, 6, 0.12);

  /* Elevation — light mode: shadow; dark mode: surface lightness */
  --shadow-card:  0 1px 2px rgba(20,20,25,.04), 0 2px 8px rgba(20,20,25,.04);
  --shadow-pop:   0 4px 12px rgba(20,20,25,.08), 0 12px 32px rgba(20,20,25,.10);
  --shadow-hover: 0 2px 6px rgba(20,20,25,.07), 0 6px 16px rgba(20,20,25,.06);

  /* Shape & type */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable",
          "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono",
               Menlo, Consolas, monospace;

  /* Chart palette (read by JS via getComputedStyle) */
  --chart-1: #2563eb;
  --chart-2: #d97706;
  --chart-3: #16a34a;
  --chart-4: #dc2626;
  --chart-5: #7c3aed;
  --chart-6: #64748b;
  --chart-grid: rgba(20, 20, 25, 0.07);
}

/* ── Dark theme — auto (prefers-color-scheme) ────────────────── */
/* Mirror of :root[data-theme="dark"] below — keep byte-identical */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-base:      #101114;
    --bg-surface:   #17181c;
    --bg-inset:     #1e2026;
    --bg-hover:     #22242b;

    --text-primary:   #e7e7ea;
    --text-secondary: #9b9ba3;
    --text-tertiary:  #5e5e66;

    --border-light:  rgba(255, 255, 255, 0.07);
    --border-medium: rgba(255, 255, 255, 0.14);

    --accent-primary:    #6ea0ff;
    --accent-primary-bg: rgba(110, 160, 255, 0.10);
    --accent-ring:       rgba(110, 160, 255, 0.35);
    --accent-contrast:   #0d1220;

    --up:      #34c373;
    --down:    #f0564f;
    --warn:    #e8a13c;
    --up-bg:   rgba(52, 195, 115, 0.12);
    --down-bg: rgba(240, 86, 79, 0.12);
    --warn-bg: rgba(232, 161, 60, 0.13);

    --shadow-card:  0 0 0 0.5px var(--border-light);
    --shadow-pop:   0 0 0 0.5px var(--border-medium), 0 16px 40px rgba(0,0,0,.45);
    --shadow-hover: 0 0 0 0.5px var(--border-medium);

    --chart-1: #6ea0ff;
    --chart-2: #e8a13c;
    --chart-3: #34c373;
    --chart-4: #f0564f;
    --chart-5: #a78bfa;
    --chart-6: #8a8f9c;
    --chart-grid: rgba(255, 255, 255, 0.06);
  }
}

/* ── Dark theme — manual override (Phase D data-theme="dark") ── */
/* Keep byte-identical to the media block above */
:root[data-theme="dark"] {
  --bg-base:      #101114;
  --bg-surface:   #17181c;
  --bg-inset:     #1e2026;
  --bg-hover:     #22242b;

  --text-primary:   #e7e7ea;
  --text-secondary: #9b9ba3;
  --text-tertiary:  #5e5e66;

  --border-light:  rgba(255, 255, 255, 0.07);
  --border-medium: rgba(255, 255, 255, 0.14);

  --accent-primary:    #6ea0ff;
  --accent-primary-bg: rgba(110, 160, 255, 0.10);
  --accent-ring:       rgba(110, 160, 255, 0.35);
  --accent-contrast:   #0d1220;

  --up:      #34c373;
  --down:    #f0564f;
  --warn:    #e8a13c;
  --up-bg:   rgba(52, 195, 115, 0.12);
  --down-bg: rgba(240, 86, 79, 0.12);
  --warn-bg: rgba(232, 161, 60, 0.13);

  --shadow-card:  0 0 0 0.5px var(--border-light);
  --shadow-pop:   0 0 0 0.5px var(--border-medium), 0 16px 40px rgba(0,0,0,.45);
  --shadow-hover: 0 0 0 0.5px var(--border-medium);

  --chart-1: #6ea0ff;
  --chart-2: #e8a13c;
  --chart-3: #34c373;
  --chart-4: #f0564f;
  --chart-5: #a78bfa;
  --chart-6: #8a8f9c;
  --chart-grid: rgba(255, 255, 255, 0.06);
}

/* ── Terminal theme — Forven-inspired Bloomberg-style monochrome dark ──────
   Forven_UIUX_Adoption.md §1/§1.5. A SELECTABLE theme value (gotcha #40:
   applied via data-theme attribute + _applyTheme(), never a body class),
   additive — does not replace or modify the light/dark blocks above.
   §1.5 superseded the values below: the original §1 pass was built from the
   GitHub repo's app.css (approximate/inferred colors, no real font). These
   are verified against the live production site's served CSS instead —
   warmer near-black (not pure #000), 2px corners (not 0px), and a real
   self-hosted JetBrains Mono webfont (static/fonts/, SIL OFL 1.1). */
:root[data-theme="terminal"] {
  --bg-base:      #0a0b0d;
  --bg-surface:   #101214;
  --bg-inset:     #0d0f11;
  --bg-hover:     #1c1e20;

  --text-primary:   #fafafa;
  --text-secondary: #9a9793;
  --text-tertiary:  #737373;

  --border-light:  #171717;
  --border-medium: #262626;

  /* Brand accent (orange) — the live site's actual brand color, used
     sparingly: sidebar logo dot, the active-nav-item indicator bar
     (.nav-item.active::before already reads --accent-primary), and primary
     CTA buttons (.btn-primary already reads --accent-primary). Aliased onto
     --accent-primary rather than introduced as a separate one-off color, so
     every existing --accent-primary consumer picks it up automatically —
     never used as a background fill. */
  --accent-brand:       #ff6b1a;
  --accent-brand-hover: #ff8a3d;
  --accent-primary:    var(--accent-brand);
  --accent-primary-bg: rgba(255, 107, 26, 0.10);
  --accent-ring:       rgba(255, 107, 26, 0.35);
  --accent-contrast:   #000000;

  --up:      #46d08a;
  --down:    #f5736f;
  --warn:    #eab308;
  --up-bg:   rgba(70, 208, 138, 0.12);
  --down-bg: rgba(245, 115, 111, 0.12);
  --warn-bg: rgba(234, 179, 8, 0.13);

  /* Reuse the dark-theme hairline-shadow approach (no third shadow system) */
  --shadow-card:  0 0 0 0.5px var(--border-light);
  --shadow-pop:   0 0 0 0.5px var(--border-medium), 0 16px 40px rgba(0,0,0,.6);
  --shadow-hover: 0 0 0 0.5px var(--border-medium);

  --chart-1: #ff6b1a;
  --chart-2: #eab308;
  --chart-3: #46d08a;
  --chart-4: #f5736f;
  --chart-5: #a78bfa;
  --chart-6: #9a9793;
  --chart-grid: rgba(255, 255, 255, 0.08);

  /* §1.5: 2px (not 0px) — the live site is NOT uniformly rounded-none; 2px is
     its most common button/input radius. Overriding the radius TOKENS (not
     every individual selector) means every existing var(--radius-*) consumer
     picks this up automatically. Pill/circular elements (.badge, status dots,
     toggle knobs) are unaffected either way — verified they all use hardcoded
     border-radius:99px/50% throughout this file, never these tokens, so no
     separate pill-radius token was needed. */
  --radius-sm: 2px;
  --radius-md: 2px;
  --radius-lg: 2px;

  /* Real font first, then the metric-matched fallback (prevents layout
     reflow on swap — see @font-face below), then the existing system stack. */
  --font-mono-terminal: "JetBrains Mono", "JetBrains Mono Fallback", var(--font-mono);
}

/* §1.5: real, self-hosted JetBrains Mono v2.304 (official GitHub release,
   github.com/JetBrains/JetBrainsMono, SIL OFL 1.1 — license copy alongside
   at static/fonts/JetBrainsMono-OFL.txt). file:// / offline-safe, no CDN.
   If these files are ever removed, --font-mono-terminal's fallback chain
   still resolves cleanly — never a broken-rendering failure mode. */
@font-face {
  font-family: "JetBrains Mono";
  src: url("static/fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("static/fonts/JetBrainsMono-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
/* Metric-matched fallback (mirrors the live site's own technique exactly) —
   sized/spaced to occupy the same line-height/character-width as JetBrains
   Mono, so text doesn't reflow when the real webfont swaps in after
   font-display:swap. Bridges the gap between "system mono renders
   immediately" and "real font arrives a moment later". */
@font-face {
  font-family: "JetBrains Mono Fallback";
  src: local("Arial");
  ascent-override: 75.79%;
  descent-override: 22.29%;
  line-gap-override: 0%;
  size-adjust: 134.59%;
}

[data-theme="terminal"] body {
  font-family: var(--font-mono-terminal);
  font-size: 14px;
  line-height: 1.4;
}
[data-theme="terminal"] .btn {
  font-family: var(--font-mono-terminal);
  text-transform: uppercase;
  /* §1.5: live-site uppercase micro-labels use .12em-.18em positive tracking;
     0.05em was tighter than verified — bumped into range. */
  letter-spacing: 0.14em;
  font-weight: 700;
  background: transparent;
  transition: background-color .1s ease, color .1s ease, border-color .1s ease;
}
/* Hover-invert (transparent border -> filled bg/contrasting text) instead of
   color-tinting — Forven's terminal-button pattern. */
[data-theme="terminal"] .btn:hover {
  background: var(--text-primary);
  color: var(--bg-base);
  border-color: var(--text-primary);
}
[data-theme="terminal"] .btn-primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--accent-contrast);
  box-shadow: none;
}
[data-theme="terminal"] .btn-primary:hover {
  background: transparent;
  color: var(--accent-primary);
  border-color: var(--accent-primary);
  filter: none;
}
[data-theme="terminal"] .nav-label {
  font-family: var(--font-mono-terminal);
  letter-spacing: 0.14em;
}
/* §1.5: extend the same .12em-.18em uppercase-micro-label tracking to the
   other uppercase micro-labels (.card-title, table headers) — these only had
   a px-based default (0.6-0.7px, designed for the light/dark sans-serif
   themes) with no terminal-specific override before. */
[data-theme="terminal"] .card-title,
[data-theme="terminal"] th {
  font-family: var(--font-mono-terminal);
  letter-spacing: 0.14em;
}

/* Sidebar logo: small accent square + lowercase wordmark, restyling the
   existing element only — no DOM/structure changes. */
[data-theme="terminal"] .sidebar-logo h1 {
  font-family: var(--font-mono-terminal);
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
[data-theme="terminal"] .sidebar-logo h1::before {
  content: "■ ";
  color: var(--accent-primary);
}
[data-theme="terminal"] .sidebar-logo p {
  font-family: var(--font-mono-terminal);
  text-transform: lowercase;
}

/* Minimal square scrollbars (6px, no rounding) */
[data-theme="terminal"] ::-webkit-scrollbar { width: 6px; height: 6px; }
[data-theme="terminal"] ::-webkit-scrollbar-track { background: var(--bg-base); }
[data-theme="terminal"] ::-webkit-scrollbar-thumb { background: var(--border-medium); }
[data-theme="terminal"] ::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ── Motion guard — state changes only ──────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ── Reset ───────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* Disable mobile "font boosting" — without this, browsers auto-enlarge text
   inside multi-line blocks (e.g. a Learning Loop detail row that wraps to
   2+ lines once expanded) to improve perceived legibility, which reads as
   the font size randomly changing on expand/collapse. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Tabular numerals — data reads like a terminal */
table, .metric-value, .metric-sub, .ind-val, .sr-level, .conf-bar + span,
.schedule-pill, .notif-time, code, .badge {
  font-variant-numeric: tabular-nums;
}

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* Global keyboard focus */
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
  border-radius: var(--radius-sm);
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: 228px; flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 0.5px solid var(--border-light);
  display: flex; flex-direction: column;
  padding: 1.25rem 0; overflow-y: auto;
}
.sidebar-logo { padding: 0 1.25rem 1.5rem; border-bottom: 0.5px solid var(--border-light); margin-bottom: 1rem; }
.sidebar-logo h1 { font-size: 14px; font-weight: 700; letter-spacing: -0.2px; }
.sidebar-logo h1::before { content: "◳ "; color: var(--accent-primary); }
.sidebar-logo p { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }
.nav-section { padding: 0 0.75rem; margin-bottom: 0.75rem; }
.nav-label {
  font-size: 10px; font-weight: 600; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 1px;
  padding: 0 0.5rem; margin-bottom: 4px;
}
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px 7px 14px;
  border-radius: var(--radius-md);
  cursor: pointer; font-size: 13px;
  color: var(--text-secondary);
  transition: background .12s ease, color .12s ease;
  margin-bottom: 1px; border: none; background: none;
  width: 100%; text-align: left; font-family: var(--font);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-primary-bg);
  color: var(--accent-primary);
  font-weight: 600;
}
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 2.5px; border-radius: 2px; background: var(--accent-primary);
}
.nav-icon { font-size: 13px; width: 18px; text-align: center; opacity: 0.75; }
.nav-item.active .nav-icon { opacity: 1; }
.server-indicator { margin: auto 1.25rem 0; padding-top: 1rem; border-top: 0.5px solid var(--border-light); }
.server-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.server-dot.ok { background: #22c55e; }
.server-dot.err { background: #ef4444; }
.server-dot.checking { background: #f59e0b; animation: pulse 1s infinite; }

/* ── Main ────────────────────────────────────────────────────── */
.main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.875rem 1.5rem;
  background: color-mix(in srgb, var(--bg-surface) 82%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 0.5px solid var(--border-light);
  flex-shrink: 0; gap: 12px;
}
@supports not (backdrop-filter: blur(12px)) {
  .topbar { background: var(--bg-surface); }
}
.topbar h2 { font-size: 15px; font-weight: 650; letter-spacing: -0.2px; }
.market-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 4px 10px; border-radius: 20px;
  background: var(--bg-inset);
  color: var(--text-secondary); white-space: nowrap;
}
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: #22c55e; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
.content { padding: 1.5rem; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 0.5px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
}
.card-title {
  font-size: 11px; font-weight: 600;
  color: var(--text-tertiary);
  margin-bottom: 0.875rem;
  text-transform: uppercase; letter-spacing: 0.7px;
}

/* ── Metrics ─────────────────────────────────────────────────── */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 1.25rem; }
.metric-card { background: var(--bg-inset); border-radius: var(--radius-md); padding: 1rem; }
.metric-card .metric-value.up   { color: var(--up); }
.metric-card .metric-value.down { color: var(--down); }
.metric-label { font-size: 11px; font-weight: 500; color: var(--text-secondary); margin-bottom: 4px; }
.metric-value { font-size: 24px; font-weight: 650; line-height: 1.2; letter-spacing: -0.5px; }
.metric-sub { font-size: 11px; color: var(--text-tertiary); margin-top: 3px; }

/* ── Grid layouts ────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } .grid-3 { grid-template-columns: 1fr 1fr; } .grid-4 { grid-template-columns: 1fr 1fr; } }

/* ── Tables ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 8px 12px;
  font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-tertiary);
  border-bottom: 0.5px solid var(--border-light); white-space: nowrap;
}
td { padding: 9px 12px; border-bottom: 0.5px solid var(--border-light); }
tr { transition: background .1s ease; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }

/* ── Badges — tint+dot, fully token-driven ───────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.2px;
}
.badge::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; opacity: .8; flex-shrink: 0;
}
.badge-buy                           { background: var(--up-bg);           color: var(--up); }
.badge-topup                         { background: var(--up-bg);           color: var(--up); }
.badge-sell                          { background: var(--down-bg);         color: var(--down); }
.badge-trim, .badge-hold, .badge-pending
                                     { background: var(--warn-bg);         color: var(--warn); }
.badge-executed, .badge-open         { background: var(--accent-primary-bg); color: var(--accent-primary); }
.badge-drp                           { background: rgba(124,58,237,.10);   color: #7c3aed; }
.badge-skipped, .badge-closed, .badge-neutral
                                     { background: var(--bg-inset);        color: var(--text-secondary); }
.badge-skipped::before, .badge-neutral::before { opacity: .5; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-md);
  border: 0.5px solid var(--border-medium);
  background: var(--bg-surface);
  color: var(--text-primary); font-size: 13px;
  cursor: pointer; font-family: var(--font); white-space: nowrap; font-weight: 500;
  transition: background .12s ease, border-color .12s ease,
              box-shadow .12s ease, transform .05s ease;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-medium); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent-primary); border-color: var(--accent-primary);
  color: var(--accent-contrast);
  box-shadow: 0 1px 2px rgba(37,99,235,.25);
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent-primary); opacity: 1; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger  { border-color: transparent; background: var(--down-bg); color: var(--down); }
.btn-danger:hover  { background: var(--down-bg); filter: brightness(.96); }
.btn-success { border-color: transparent; background: var(--up-bg); color: var(--up); }
.btn-success:hover { filter: brightness(.96); }

/* ── Bars ────────────────────────────────────────────────────── */
.conf-bar { width: 80px; height: 5px; border-radius: 3px; background: var(--bg-inset); overflow: hidden; display: inline-block; vertical-align: middle; }
.conf-fill { height: 100%; border-radius: 3px; }
.gauge-bar { height: 8px; border-radius: 4px; background: var(--bg-inset); overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 4px; transition: width 0.4s; }

/* ── Indicator panel ─────────────────────────────────────────── */
.ind-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ind-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 0.5px solid var(--border-light); font-size: 12px; }
.ind-row:last-child { border-bottom: none; }
.ind-label { color: var(--text-secondary); }
.ind-val { font-weight: 600; font-size: 12px; }

/* ── Signal chips — token-driven ────────────────────────────── */
.signal-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 12px; font-size: 11px; font-weight: 500; margin: 2px; }
.chip-buy  { background: var(--up-bg);   color: var(--up); }
.chip-sell { background: var(--down-bg); color: var(--down); }

/* ── Critical Alert Banner ───────────────────────────────────── */
.critical-alert-banner { display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px; border-radius: var(--radius-md); border: 1.5px solid #ef4444; background: #fff1f1; color: #7f1d1d; margin-bottom: 8px; }
.critical-alert-banner .alert-icon { font-size: 18px; flex-shrink: 0; line-height: 1; margin-top: 1px; }
.critical-alert-banner .alert-body { flex: 1; min-width: 0; }
.critical-alert-banner .alert-title { font-size: 13px; font-weight: 700; letter-spacing: -0.2px; }
.critical-alert-banner .alert-desc  { font-size: 12px; margin-top: 2px; opacity: 0.85; }
.critical-alert-banner .alert-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
@media (prefers-color-scheme: dark) {
  /* :not() guard — a manual Light theme must keep the light banner even on a dark OS */
  :root:not([data-theme="light"]) .critical-alert-banner { background: rgba(239,68,68,0.12); color: #fca5a5; border-color: rgba(239,68,68,0.5); }
}
:root[data-theme="dark"] .critical-alert-banner { background: rgba(239,68,68,0.12); color: #fca5a5; border-color: rgba(239,68,68,0.5); }

/* ── SR levels — token-driven ────────────────────────────────── */
.sr-level { display: flex; justify-content: space-between; padding: 4px 8px; border-radius: 4px; font-size: 12px; margin-bottom: 3px; }
.sr-r { background: var(--down-bg); color: var(--down); }
.sr-s { background: var(--up-bg);   color: var(--up); }
.sr-p { background: var(--bg-inset); color: var(--text-secondary); border: 0.5px solid var(--border-medium); }

/* ── Mini chart canvas ───────────────────────────────────────── */
canvas.sparkline { width: 100%; height: 60px; }
.chart-container { position: relative; width: 100%; height: 180px; }
canvas.price-chart { width: 100%; height: 180px; }

/* ── Chat ────────────────────────────────────────────────────── */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 200px); height: calc(100dvh - 200px); min-height: 400px; }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 0 12px; }
.msg { max-width: 88%; padding: 9px 13px; border-radius: 10px; font-size: 13px; line-height: 1.6; }
.msg-user { align-self: flex-end; background: var(--text-primary); color: var(--bg-surface); border-radius: 10px 10px 2px 10px; }
.msg-ai { align-self: flex-start; background: var(--bg-inset); border: 0.5px solid var(--border-light); border-radius: 10px 10px 10px 2px; white-space: pre-wrap; }
.chat-input-row { display: flex; gap: 8px; padding-top: 10px; border-top: 0.5px solid var(--border-light); margin-top: auto; }
.chat-input-row input { flex: 1; }

/* ── Loading ─────────────────────────────────────────────────── */
.loading-dots { display: inline-flex; gap: 4px; align-items: center; }
.loading-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-secondary); animation: bounce 1.2s infinite; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100%{transform:scale(0.7);opacity:0.4} 40%{transform:scale(1);opacity:1} }

/* ── Forms ───────────────────────────────────────────────────── */
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 1rem; }
.form-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
input[type="text"], input[type="number"], input[type="password"], textarea, select {
  padding: 7px 10px; border-radius: var(--radius-md);
  border: 0.5px solid var(--border-light);
  background: var(--bg-inset); color: var(--text-primary);
  font-family: var(--font); font-size: 13px; width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
textarea { resize: vertical; }

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; margin-bottom: 1.25rem; border-bottom: 0.5px solid var(--border-light); }
.tab {
  padding: 8px 18px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  transition: color .15s, border-color .15s, background .15s;
  background: transparent; font-family: var(--font);
  margin-bottom: -0.5px; border-radius: 6px 6px 0 0; white-space: nowrap;
}
.tab.active { color: var(--accent-primary); border-bottom-color: var(--accent-primary); font-weight: 700; background: var(--accent-primary-bg); }
.tab:hover:not(.active) { color: var(--text-primary); background: var(--bg-hover); }

/* ── Signal row ──────────────────────────────────────────────── */
.signal-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; border-bottom: 0.5px solid var(--border-light); font-size: 13px; }
.signal-row:last-child { border-bottom: none; }
.sentiment-bar { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.sentiment-track { flex: 1; height: 5px; border-radius: 3px; background: var(--bg-inset); overflow: hidden; }
.sentiment-fill { height: 100%; border-radius: 3px; }

/* ── Toast ───────────────────────────────────────────────────── */
#toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 0.5px solid var(--border-light);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  font-size: 13px; pointer-events: all;
  animation: slideIn .18s cubic-bezier(.2,.8,.3,1);
  max-width: 300px;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ── Rec card ────────────────────────────────────────────────── */
.rec-card {
  background: var(--bg-surface);
  border: 0.5px solid var(--border-light);
  border-radius: var(--radius-lg); padding: 1rem 1.25rem; margin-bottom: 10px;
  box-shadow: var(--shadow-card);
  transition: box-shadow .15s ease, border-color .15s ease;
}
.rec-card:hover { box-shadow: var(--shadow-hover); border-color: var(--border-medium); }
.rec-card.executed-card { border-left: 3px solid #3b82f6; }
.rec-card.skipped-card { border-left: 3px solid var(--border-medium); opacity: 0.65; }

/* ── Detail card ─────────────────────────────────────────────── */
.detail-section { margin-bottom: 1.25rem; }
.detail-section:last-child { margin-bottom: 0; }

/* ── Color utilities ─────────────────────────────────────────── */
.up { color: var(--up); } .down { color: var(--down); }
.text-success { color: var(--up); } .text-danger { color: var(--down); }
.text-warn { color: var(--warn); }
.text-muted { color: var(--text-secondary); }
.text-xs { font-size: 11px; color: var(--text-tertiary); }
.text-sm { font-size: 13px; }

/* ── Layout utils ────────────────────────────────────────────── */
.flex-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.flex-between { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; }
.section-gap { margin-bottom: 1.25rem; }
.divider { border: none; border-top: 0.5px solid var(--border-light); margin: 1rem 0; }
code { font-family: var(--font-mono); font-size: 12px; background: var(--bg-inset); padding: 2px 6px; border-radius: 4px; }
pre.code-block { font-family: var(--font-mono); font-size: 12px; background: var(--bg-inset); padding: 12px; border-radius: var(--radius-md); color: var(--text-secondary); line-height: 1.6; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-medium); border-radius: 99px;
  border: 2px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--text-tertiary); }
* { scrollbar-width: thin; scrollbar-color: var(--border-medium) transparent; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 2rem; }
.empty-icon { font-size: 36px; margin-bottom: 1rem; opacity: .25; filter: grayscale(1); }
.empty-state p { color: var(--text-secondary); font-size: 14px; }
.empty-state .sub { font-size: 12px; color: var(--text-tertiary); margin-top: 6px; }

/* ── Schedule pills — token-driven ──────────────────────────── */
.schedule-pill { padding: 5px 12px; border-radius: var(--radius-md); font-size: 12px; border: 0.5px solid var(--border-light); color: var(--text-secondary); white-space: nowrap; }
.schedule-pill.past    { border-color: var(--up);   color: var(--up);   background: var(--up-bg); }
.schedule-pill.current { border-color: var(--accent-primary); color: var(--accent-primary); background: var(--accent-primary-bg); }

/* ── Info banner — token-driven ──────────────────────────────── */
.info-banner { background: var(--warn-bg); border: 0.5px solid var(--warn); border-radius: var(--radius-md); padding: 10px 14px; font-size: 12px; color: var(--warn); margin-bottom: 1rem; }

/* ── Progress ring ───────────────────────────────────────────── */
.progress-ring { display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 56px; border-radius: 50%; border: 3px solid var(--border-light); position: relative; font-size: 13px; font-weight: 700; }

/* ── Dialog / modal ──────────────────────────────────────────── */
dialog::backdrop { background: rgba(10, 10, 14, 0.45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
dialog { box-shadow: var(--shadow-pop); border-radius: var(--radius-lg) !important; max-height: 90vh; max-height: 90dvh; overflow-y: auto; }

/* ── Skeleton shimmer (CSS ready; JS opts in by adding .skeleton) */
.skeleton {
  background: linear-gradient(90deg, var(--bg-inset) 25%, var(--bg-hover) 50%, var(--bg-inset) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
  color: transparent !important;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Delta chip (utility for future use) ─────────────────────── */
.delta-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 7px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.delta-chip.up   { background: var(--up-bg);   color: var(--up); }
.delta-chip.down { background: var(--down-bg); color: var(--down); }

/* ── Compact / density mode — PRESERVED ─────────────────────── */
body.compact .card { padding: 0.75rem; }
body.compact .metric-card { padding: 0.6rem 0.75rem; }
body.compact .rec-card { padding: 0.6rem 0.875rem; margin-bottom: 6px; }
body.compact th { padding: 5px 10px; font-size: 10px; }
body.compact td { padding: 5px 10px; font-size: 12px; }
body.compact .card-title { font-size: 11px; margin-bottom: 8px; }
body.compact .section-gap { margin-bottom: 8px; }
body.compact .btn { padding: 5px 10px; font-size: 12px; }
body.compact .ind-row { padding: 3px 0; font-size: 11px; }
body.compact .signal-row { padding: 4px 0; font-size: 12px; }

/* ── Mobile / responsive layout (≤768px) — PRESERVED ────────── */
.mobile-menu-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-medium);
  background: none; cursor: pointer;
  color: var(--text-primary); font-size: 18px;
  line-height: 1;
}
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
}
@media (max-width: 768px) {
  .mobile-menu-btn { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: 240px;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
  }
  .sidebar-overlay.mobile-open { display: block; }
  .content { padding: 0.875rem; }
  .grid-2 { grid-template-columns: 1fr !important; }
  .grid-3 { grid-template-columns: 1fr !important; }
  .grid-4 { grid-template-columns: 1fr 1fr !important; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }

  /* 16px floor kills Safari's auto-zoom on input focus */
  input[type="text"], input[type="number"], input[type="password"],
  textarea, select { font-size: 16px; }

  /* Apple HIG 44px touch targets */
  .btn, .nav-item, .tab { min-height: 44px; }
  .btn-sm, .btn-xs { min-height: 40px; }
  td .btn, td button, .table-wrap button { min-height: 40px; min-width: 40px; }

  /* Topbar: drop low-priority pills, let the action row swipe instead of overflowing */
  #sbc-mode-btn, .topbar .market-pill { display: none; }
  .topbar { padding: 0.625rem 0.875rem; }
  .topbar > .flex-row:last-child {
    flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topbar > .flex-row:last-child::-webkit-scrollbar { display: none; }
}

/* Safe-area insets — no-ops outside notched standalone PWAs */
.topbar  { padding-top: max(0.875rem, env(safe-area-inset-top)); }
.sidebar { padding-bottom: max(1.25rem, env(safe-area-inset-bottom)); }
.content { padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); }

/* Touch polish (any touch device, regardless of width) */
@media (hover: none) {
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  tr:hover td { background: inherit; }
}
.table-wrap { -webkit-overflow-scrolling: touch; }
.table-wrap thead th { position: sticky; top: 0; background: var(--bg-surface); z-index: 1; }

/* ── Stacked table cards (≤640px) — PRESERVED ───────────────── */
@media (max-width: 640px) {
  table.tbl-stack > thead { display: none; }
  table.tbl-stack, table.tbl-stack > tbody { display: block; }
  table.tbl-stack { min-width: 0 !important; }
  table.tbl-stack > tbody > tr {
    display: block; margin-bottom: 10px;
    border: 0.5px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 6px 12px;
    background: var(--bg-surface);
  }
  table.tbl-stack > tbody > tr > td {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; padding: 6px 0; border: none; text-align: right;
  }
  table.tbl-stack > tbody > tr > td:empty { display: none; }
  table.tbl-stack > tbody > tr > td::before {
    content: attr(data-label);
    font-weight: 600; font-size: 11px;
    color: var(--text-secondary);
    text-align: left; flex-shrink: 0;
  }
  table.tbl-stack > tbody > tr > td:not([data-label])::before { content: none; }
  table.tbl-stack > tbody > tr > td[colspan] { display: block; padding: 0; text-align: left; overflow-x: auto; }
  table.tbl-stack > tfoot { display: none; }
  table.tbl-stack tr:hover td { background: inherit; }
  .col-optional, .m-hide { display: none !important; }
}

/* Traceability panel arrow rotation */
details[open] .trace-arrow { transform: rotate(90deg); }

/* ── Notification Bell — PRESERVED ──────────────────────────── */
.notif-bell-wrap { position: relative; display: inline-block; }

.notif-bell-btn {
  position: relative;
  font-size: 15px;
  padding: 4px 9px;
  line-height: 1;
}

.notif-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  pointer-events: none;
  line-height: 1;
  box-shadow: 0 0 0 2px var(--bg-surface);
}

.notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 360px;
  max-height: 540px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  z-index: 9999;
  flex-direction: column;
  overflow: hidden;
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-light);
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.notif-header-badge {
  display: inline-block;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 8px;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

.notif-list {
  overflow-y: auto;
  flex: 1;
}

.notif-item {
  display: flex;
  gap: 10px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.12s;
  align-items: flex-start;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-hover); }
.notif-item.unread { background: var(--accent-primary-bg); }
.notif-item.unread:hover { filter: brightness(1.04); }

.notif-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

.notif-content { flex: 1; min-width: 0; }
.notif-title { font-size: 12.5px; font-weight: 600; margin-bottom: 2px; line-height: 1.3; }
.notif-body  { font-size: 11.5px; color: var(--text-secondary); line-height: 1.4; word-break: break-word; }
.notif-time  { font-size: 11px; color: var(--text-secondary); margin-top: 3px; opacity: 0.8; }

.notif-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

.btn-xs {
  padding: 2px 7px;
  font-size: 11px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: var(--bg-inset);
  cursor: pointer;
  color: var(--text-primary);
}
.btn-xs:hover { background: var(--bg-hover); filter: brightness(0.95); }

/* ============================================================ */
/* Page header block (title + one-line description)             */
/* Rendered above page bodies by js/navigation.js's renderPage().*/
/* Visually distinct from .card-title: larger, sits above all    */
/* cards, not inside any card. Themes automatically via the      */
/* existing --text-primary/--text-tertiary custom properties.    */
/* ============================================================ */
#page-header-block:empty { display: none; }
.page-header {
  /* Horizontal padding matches .content's 1.5rem so the title lines up with
     the page body below it; negative margin offsets .content's own top
     padding so the two blocks read as one continuous header+body unit. */
  padding: 1.5rem 1.5rem 0.9rem 1.5rem;
  margin-bottom: -0.9rem;
}
.page-header-title {
  font-size: 19px;
  font-weight: 650;
  color: var(--text-primary);
  letter-spacing: -0.2px;
  line-height: 1.25;
}
.page-header-desc {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-tertiary);
  margin-top: 3px;
  line-height: 1.4;
}
@media (max-width: 768px) {
  .page-header-title { font-size: 17px; }
  .page-header-desc  { font-size: 12px; }
}

/* ============================================================
   OPS HEADER STRIP — Dashboard-only always-on status line
   (Forven_UIUX_Adoption.md §2.4). Inline styles handle layout/colour
   directly in js/pages/dashboard.js (_buildOpsStrip); this block only
   covers small-screen wrapping so the strip doesn't overflow on mobile.
   New block — appended at end of file, does not edit any existing rule.
   ============================================================ */
@media (max-width: 480px) {
  #ops-strip {
    font-size: 10px;
    gap: 8px;
  }
  #ops-strip-clock {
    margin-left: 0 !important;
    width: 100%;
    text-align: left;
  }
}

/* ============================================================
   GLOBAL SYSTEM-CRITICAL BANNER (Forven_UIUX_Adoption.md §2.3)
   Deliberately named/classed differently from .critical-alert-banner
   (portfolio-helpers.js — a separate, portfolio-specific alert tier) to avoid
   confusing the two. App-wide, rendered via navigation.js renderPage(); off
   by default (no element when no condition is active).
   New block — appended at end of file, does not edit any existing rule.
   ============================================================ */
.system-critical-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  margin-bottom: 10px;
  border-radius: var(--radius-md, 6px);
  font-size: 13px;
  font-weight: 500;
}
.system-critical-banner-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
  animation: system-critical-pulse 1.6s ease-in-out infinite;
}
.system-critical-banner--critical {
  background: var(--down-bg);
  color: var(--down);
  border: 0.5px solid var(--down);
}
.system-critical-banner--critical .system-critical-banner-dot { background: var(--down); }
.system-critical-banner--warning {
  background: var(--warn-bg);
  color: var(--warn);
  border: 0.5px solid var(--warn);
}
.system-critical-banner--warning .system-critical-banner-dot { background: var(--warn); }
@keyframes system-critical-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .system-critical-banner-dot { animation: none; }
}
