/*
 * ============================================================================
 * TRADING TERMINAL DESIGN SYSTEM
 * ============================================================================
 *
 * Loaded AFTER styles.css, which keeps the structural layout (app shell,
 * sidebar, bottom nav, skip link, offline banner) and its proven
 * accessibility/responsive behaviour intact. This file is the visual
 * layer: tokens, typography, surfaces, and every component.
 *
 * Principles this file is built on:
 *
 *   Colour is information. Green and red mean profit/loss and pass/fail,
 *   nothing else. Amber means "needs attention". Everything structural is
 *   neutral, so a coloured element always carries meaning.
 *
 *   Depth comes from layered surfaces, not from borders and shadows. The
 *   surface ramp is deliberately narrow so panels read as one instrument
 *   rather than a pile of cards.
 *
 *   Density is a feature. This is a screen an operator reads for hours;
 *   it should show a lot without shouting. Type is small but never below
 *   the legibility floor, and numerals are always tabular.
 *
 *   Motion is short and functional. No decorative animation.
 *
 * Theming: dark is the primary trading experience. Light is fully
 * supported and is selected by the OS preference unless the operator has
 * explicitly chosen otherwise; an explicit choice always wins in both
 * directions. Every colour is a token — nothing paints a raw hex value,
 * because a hardcoded literal is exactly what breaks the moment the
 * surface underneath it changes.
 */

/* ==========================================================================
   1. TOKENS — DARK (primary)
   ========================================================================== */

:root {
  /* Surfaces: a cool near-black ramp. Each step is a real elevation. */
  --bg-base: #07090d;
  --bg-sunken: #0a0d13;
  --bg-surface: #0f131b;
  --bg-raised: #141922;
  --bg-overlay: #1a202b;
  --bg-hover: #1d2430;
  --bg-active: #232b39;

  /* Borders: mostly invisible. They separate, they do not decorate. */
  --border-subtle: #171d27;
  --border-default: #222a37;
  --border-strong: #33405492;

  --text-primary: #eef2f8;
  --text-secondary: #99a5bb;
  --text-muted: #66738c;
  --text-faint: #46516685;

  /* Semantic — market state and system state only. */
  --up: #16c98d;
  --up-soft: #16c98d1c;
  --up-line: #16c98d40;
  --down: #ff4d63;
  --down-soft: #ff4d631c;
  --down-line: #ff4d6340;
  --warn: #f7b32b;
  --warn-soft: #f7b32b1c;
  --warn-line: #f7b32b40;
  --accent: #3d8bff;
  --accent-soft: #3d8bff1a;
  --accent-line: #3d8bff40;
  --cyan: #22d3ee;
  --cyan-soft: #22d3ee18;
  --violet: #a78bfa;
  --neutral: #64748b;
  --neutral-soft: #64748b1f;

  /* Text drawn ON a tinted (*-soft) background. */
  --on-accent-soft: #a9c8ff;
  --on-up-soft: #6ee7b7;
  --on-down-soft: #ffa3af;
  --on-warn-soft: #fcd681;
  --on-neutral-soft: #a4b0c4;
  --on-accent-solid: #04101f;
  --accent-hover: #5c9dff;

  /* The faint interior glow that gives panels their depth. Dark only —
     on light surfaces it reads as dirt, so light theme clears it. */
  --panel-sheen: linear-gradient(180deg, #ffffff06, #ffffff00 42%);
  --chart-grid: #141b26;
  --chart-band: #3d8bff09;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 9px;
  --radius-lg: 13px;

  --shadow-panel: 0 1px 0 #ffffff05 inset, 0 1px 2px #00000059, 0 10px 30px -18px #000000b3;
  --shadow-pop: 0 10px 40px -12px #000000d9, 0 0 0 1px var(--border-default);
  --shadow-focus: 0 0 0 3px var(--accent-soft);

  --font-sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", ui-monospace, Consolas, monospace;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 64px;
}

/* ==========================================================================
   2. TOKENS — LIGHT
   --------------------------------------------------------------------------
   Dark is the product's default and is NOT conditional: a trading terminal
   should not change character because of an OS setting, and the dark ramp
   is what the whole design system is tuned for. Light is a complete,
   first-class theme that the operator opts into with the toggle, which
   stamps data-theme="light" on the root element.
   ========================================================================== */

:root[data-theme="light"] {
  --bg-base: #f2f4f8;
  --bg-sunken: #e8ecf3;
  --bg-surface: #ffffff;
  --bg-raised: #ffffff;
  --bg-overlay: #ffffff;
  --bg-hover: #eef1f6;
  --bg-active: #e3e9f2;

  --border-subtle: #e6eaf1;
  --border-default: #d3dae4;
  --border-strong: #adb8c8;

  --text-primary: #0c1119;
  --text-secondary: #4a5568;
  --text-muted: #6b7688;
  --text-faint: #93a0b28c;

  --up: #05996b;
  --up-soft: #05996b14;
  --up-line: #05996b3d;
  --down: #d4213c;
  --down-soft: #d4213c14;
  --down-line: #d4213c3d;
  --warn: #a96a00;
  --warn-soft: #a96a0014;
  --warn-line: #a96a003d;
  --accent: #1d63e6;
  --accent-soft: #1d63e612;
  --accent-line: #1d63e63d;
  --cyan: #0e7f96;
  --cyan-soft: #0e7f9614;
  --violet: #6d47d9;
  --neutral: #64748b;
  --neutral-soft: #64748b16;

  --on-accent-soft: #12439e;
  --on-up-soft: #04704f;
  --on-down-soft: #a1152c;
  --on-warn-soft: #7d4e00;
  --on-neutral-soft: #4a5568;
  --on-accent-solid: #ffffff;
  --accent-hover: #12439e;

  --panel-sheen: none;
  --chart-grid: #e6eaf1;
  --chart-band: #1d63e60a;

  --shadow-panel: 0 1px 2px #0f172a10, 0 8px 24px -16px #0f172a30;
  --shadow-pop: 0 12px 36px -12px #0f172a2e, 0 0 0 1px var(--border-default);
}

/* ==========================================================================
   3. BASE
   ========================================================================== */

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.006em;
}

/* Numerals must align down a column. Tabular figures are not cosmetic
   here — they are what makes a column of prices readable at a glance. */
.num, .mono, td.num, th.num, .metric-value, .price, .kpi-value, .chart-price .last {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "zero" 1;
  letter-spacing: -0.01em;
}

h1 { font-size: 21px; font-weight: 640; letter-spacing: -0.022em; margin: 0; line-height: 1.25; }
h2 { font-size: 14px; font-weight: 620; letter-spacing: -0.012em; margin: 0; }
h3 { font-size: 12.5px; font-weight: 620; margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft); color: var(--text-primary); }

/* Scrollbars: present but quiet. */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: content-box; }

.main-content {
  background: var(--bg-base);
  padding: 18px 22px 56px;
}

/* Utilities */
.muted { color: var(--text-muted); }
.small { font-size: 11.5px; }
.strong { font-weight: 620; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--text-secondary); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1 1 auto; }
.divider { height: 1px; background: var(--border-subtle); margin: 11px 0; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.fade-in { animation: fadeIn 180ms var(--ease) both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   4. PAGE HEADER
   ========================================================================== */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}
.page-head .sub {
  margin: 5px 0 0;
  color: var(--text-muted);
  font-size: 12.5px;
  max-width: 74ch;
}
.page-head h2 { font-size: 21px; font-weight: 640; letter-spacing: -0.022em; }

/* ==========================================================================
   5. PANELS / CARDS
   --------------------------------------------------------------------------
   `.card` is the legacy container used by every older route, so it is
   restyled here rather than replaced — that is what lifts all 19 routes
   at once instead of only the screens rebuilt by hand.
   ========================================================================== */

.card {
  background-color: var(--bg-surface);
  background-image: var(--panel-sheen);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
  padding: 14px 16px;
  margin: 0 0 14px;
  position: relative;
}
.grid .card, .stack .card { margin-bottom: 0; }

.card h2 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.085em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 11px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--border-subtle);
}
.card h2:only-child { margin-bottom: 0; border-bottom: none; padding-bottom: 0; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -2px 0 11px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--border-subtle);
}
.card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.085em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* A panel that hosts a table edge-to-edge. */
.card.flush { padding: 14px 0 0; }
.card.flush .card-head { padding: 0 16px 9px; margin-bottom: 0; }

/* ==========================================================================
   6. GRIDS
   ========================================================================== */

/* Panels in a multi-column row align to the top rather than stretching to
   the tallest sibling: a short control panel beside a long table was
   growing a large dead area at its foot. */
.grid { display: grid; gap: 14px; align-items: start; }
.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-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
/* Chart column takes the room. The rail has a floor so it never collapses
   into an unreadable sliver. */
.grid-terminal { grid-template-columns: minmax(0, 1fr) minmax(292px, 336px); }

/* ==========================================================================
   7. KPI / METRIC TILES
   ========================================================================== */

.metric-tile, .kpi {
  background-color: var(--bg-surface);
  background-image: var(--panel-sheen);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  position: relative;
  overflow: hidden;
}
/* A hairline of meaning along the top edge. */
.kpi::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--accent);
  opacity: 0.55;
}
.kpi.kpi-up::before { background: var(--up); }
.kpi.kpi-down::before { background: var(--down); }
.kpi.kpi-warn::before { background: var(--warn); }
.kpi.kpi-neutral::before { background: var(--neutral); opacity: 0.35; }

.metric { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.metric-label, .kpi-label {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.075em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric-value, .kpi-value {
  font-size: 21px;
  font-weight: 620;
  line-height: 1.15;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric-sub, .kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric-value .metric-sub { font-size: 11.5px; margin-left: 2px; }

/* ==========================================================================
   8. BADGES / PILLS / TAGS
   ========================================================================== */

.badge, .trading-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 100px;
  border: 1px solid transparent;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.045em;
  line-height: 1.5;
  white-space: nowrap;
  background: var(--neutral-soft);
  color: var(--on-neutral-soft);
  border-color: var(--border-default);
}
.badge-up      { background: var(--up-soft);      color: var(--on-up-soft);      border-color: var(--up-line); }
.badge-down    { background: var(--down-soft);    color: var(--on-down-soft);    border-color: var(--down-line); }
.badge-warn    { background: var(--warn-soft);    color: var(--on-warn-soft);    border-color: var(--warn-line); }
.badge-accent  { background: var(--accent-soft);  color: var(--on-accent-soft);  border-color: var(--accent-line); }
.badge-neutral { background: var(--neutral-soft); color: var(--on-neutral-soft); border-color: var(--border-default); }
.badge-locked  { background: var(--down-soft);    color: var(--on-down-soft);    border-color: var(--down-line); }

/* The trading-mode badge is global chrome; it gets its colour inline from
   tradingModeColor() and needs readable text on whatever that returns. */
.trading-mode-badge { color: #fff; border-color: transparent; text-transform: uppercase; }

.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
/* A running engine is the one place a pulse earns its keep. */
.dot-live { box-shadow: 0 0 0 0 currentColor; animation: pulse 2.4s var(--ease) infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
  70%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 7px;
  background: var(--neutral);
  vertical-align: middle;
}
.status-dot.ok { background: var(--up); }
.status-dot.bad { background: var(--down); }

/* Directional tag for LONG / SHORT — squarer than a badge so a side reads
   as a hard fact rather than a soft label. */
.side {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  border: 1px solid transparent;
}
.side-long  { background: var(--up-soft);   color: var(--on-up-soft);   border-color: var(--up-line); }
.side-short { background: var(--down-soft); color: var(--on-down-soft); border-color: var(--down-line); }

/* ==========================================================================
   9. STATUS ROWS (label ↔ value)
   --------------------------------------------------------------------------
   The single most-used component in the app — 160+ instances across the
   legacy routes. Getting this right is most of the visual uplift.
   ========================================================================== */

.status-row, .prov-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12.5px;
  color: var(--text-secondary);
  min-width: 0;
}
.status-row:last-child, .prov-line:last-child { border-bottom: none; }
.status-row > span:first-child, .prov-line > span:first-child {
  color: var(--text-secondary);
  min-width: 0;
  overflow-wrap: anywhere;
}
.status-row > span:last-child, .prov-line > .v {
  color: var(--text-primary);
  font-weight: 560;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.prov-line .v.strong { font-weight: 660; }
.status-row.emphasis { padding: 9px 0; }
.status-row.emphasis > span:last-child { font-size: 13.5px; font-weight: 640; }

/* ==========================================================================
   10. TABLES
   ========================================================================== */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -16px -14px;
  padding: 0;
}
.card.flush .table-wrap { margin: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}
tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
  vertical-align: middle;
}
tbody td.strong, tbody td .strong { color: var(--text-primary); font-weight: 620; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 110ms var(--ease); }
tbody tr:hover td { background: var(--bg-hover); }
th.num, td.num { text-align: right; }
td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 220px; }

/* A row whose P&L is decided — a whisper of tint, never a highlighter. */
tbody tr.row-up td    { box-shadow: inset 2px 0 0 var(--up-line); }
tbody tr.row-down td  { box-shadow: inset 2px 0 0 var(--down-line); }

.empty-state {
  color: var(--text-muted);
  font-size: 12.5px;
  text-align: center;
  padding: 26px 18px;
  margin: 0;
  line-height: 1.6;
}
.empty-state .empty-title {
  display: block;
  color: var(--text-secondary);
  font-weight: 620;
  font-size: 13px;
  margin-bottom: 4px;
}

/* ==========================================================================
   11. BUTTONS
   ========================================================================== */

button, .btn {
  font-family: inherit;
  cursor: pointer;
  transition: background 120ms var(--ease), border-color 120ms var(--ease), color 120ms var(--ease), transform 60ms var(--ease);
}
button:active, .btn:active { transform: translateY(0.5px); }

.btn, .btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 580;
  line-height: 1.4;
  white-space: nowrap;
}
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn:hover, .btn-sm:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent-solid); font-weight: 640; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border-default); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: var(--down-soft); border-color: var(--down-line); color: var(--on-down-soft); }
.btn-danger:hover { background: var(--down); border-color: var(--down); color: #fff; }
.btn-success { background: var(--up-soft); border-color: var(--up-line); color: var(--on-up-soft); }
.btn-success:hover { background: var(--up); border-color: var(--up); color: var(--on-accent-solid); }

button:disabled, .btn:disabled, .btn-sm:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}

/* The legacy full-width submit, kept for the login form. */
button.primary {
  width: 100%;
  min-height: 42px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent-solid);
  font-weight: 640;
  font-size: 13.5px;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.primary:disabled { opacity: 0.42; cursor: not-allowed; }

/* A row of related actions. `button.primary` is width:100% for the login
   form, so inside a flex row it would otherwise swallow its siblings. */
.action-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.action-row button.primary, .action-row button {
  width: auto;
  min-height: 36px;
  padding: 8px 15px;
  font-size: 12.5px;
  white-space: nowrap;
}
.action-row button:disabled { opacity: 0.42; cursor: not-allowed; }

/* ==========================================================================
   12. SEGMENTED CONTROLS
   ========================================================================== */

.seg {
  display: inline-flex;
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.seg button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 11px;
  font-size: 11.5px;
  font-weight: 640;
  letter-spacing: 0.02em;
  border-radius: var(--radius-xs);
}
.seg button:hover { background: var(--bg-hover); color: var(--text-primary); }
.seg button[aria-pressed="true"] {
  background: var(--bg-active);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 1px var(--border-default);
}
.seg button[aria-pressed="true"].on-accent { color: var(--on-accent-soft); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-line); }

/* ==========================================================================
   13. INPUTS
   ========================================================================== */

input, select, textarea {
  font-family: inherit;
  font-size: 12.5px;
  background: var(--bg-sunken);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}
/* styles.css targets these by type, which beats a bare `input` selector,
   so they are bound to the terminal tokens explicitly. */
input[type="email"], input[type="password"], input[type="text"], input[type="number"] {
  background: var(--bg-sunken);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: var(--shadow-focus);
}
input::placeholder { color: var(--text-faint); }
label { font-size: 11.5px; color: var(--text-secondary); font-weight: 560; }
select {
  cursor: pointer;
  padding-right: 26px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 11px top 52%, right 6px top 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  color: var(--text-primary);
}
input[type="range"] { accent-color: var(--accent); padding: 0; background: transparent; border: none; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ==========================================================================
   14. SIDEBAR / NAVIGATION
   ========================================================================== */

.app-shell { background: var(--bg-base); }

.sidebar-nav {
  background: var(--bg-sunken);
  border-right: 1px solid var(--border-subtle);
  padding: 0 0 14px;
  width: var(--sidebar-w);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-nav .brand-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 9px;
  padding: 14px 14px 13px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  background: var(--bg-sunken);
  z-index: 2;
}
.topbar .brand-mark { width: 24px; height: 24px; border-radius: 6px; }
.topbar .brand-mark svg { width: 13px; height: 13px; }
.brand-mark {
  width: 27px; height: 27px;
  border-radius: 7px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--cyan));
  color: #fff;
  box-shadow: 0 2px 10px -3px var(--accent);
}
.brand-mark svg { width: 15px; height: 15px; display: block; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-name {
  font-size: 12.5px;
  font-weight: 680;
  letter-spacing: -0.012em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-env {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.brand-row .trading-mode-badge { font-size: 9.5px; padding: 2px 7px; }

.nav-group-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 13px 16px 5px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  margin: 1px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 540;
  text-decoration: none;
  min-height: 32px;
  position: relative;
  transition: background 110ms var(--ease), color 110ms var(--ease);
}
.sidebar-nav a .nav-icon {
  width: 15px; height: 15px;
  flex-shrink: 0;
  opacity: 0.72;
  display: block;
}
.sidebar-nav a .nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-nav a:hover { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; }
.sidebar-nav a:hover .nav-icon { opacity: 1; }
.sidebar-nav a.active {
  background: var(--accent-soft);
  color: var(--text-primary);
  font-weight: 620;
}
.sidebar-nav a.active .nav-icon { opacity: 1; color: var(--accent); }
.sidebar-nav a.active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 17px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

/* Live engine indicator pinned to the bottom of the rail. */
.nav-footer {
  margin: 12px 8px 0;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.nav-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 10.5px;
  color: var(--text-muted);
}
.nav-footer-row .v { font-weight: 650; letter-spacing: 0.03em; }
.nav-footer-row .trading-mode-badge { font-size: 9.5px; padding: 2px 7px; }
.nav-footer-row .theme-toggle { margin: -3px -3px -3px 0; }

/* Collapsed rail: icons only. Keyed off an attribute stamped on <html>
   by the boot script, so a collapsed rail is collapsed on the very first
   paint instead of flashing open and then snapping shut. */
:root[data-nav="collapsed"] .sidebar-nav { width: var(--sidebar-w-collapsed); padding-bottom: 10px; }
:root[data-nav="collapsed"] .sidebar-nav .nav-label,
:root[data-nav="collapsed"] .sidebar-nav .nav-group-label,
:root[data-nav="collapsed"] .brand-text,
:root[data-nav="collapsed"] .nav-footer { display: none; }
:root[data-nav="collapsed"] .sidebar-nav a { justify-content: center; padding: 8px 0; margin: 2px 9px; }
:root[data-nav="collapsed"] .sidebar-nav a.active::before { left: -9px; }
:root[data-nav="collapsed"] .brand-row { justify-content: center; padding: 14px 0 13px; gap: 0; }
:root[data-nav="collapsed"] .brand-row .spacer { display: none; }
:root[data-nav="collapsed"] .nav-group-sep { display: block; height: 1px; background: var(--border-subtle); margin: 9px 14px 5px; }
:root[data-nav="collapsed"] .nav-collapse-btn svg { transform: rotate(180deg); }
.nav-group-sep { display: none; }

.nav-collapse-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  padding: 4px;
  display: grid;
  place-items: center;
  line-height: 0;
}
.nav-collapse-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-collapse-btn svg { width: 15px; height: 15px; transition: transform 150ms var(--ease); }

.theme-toggle {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  padding: 4px;
  min-height: 0;
  min-width: 0;
  display: grid;
  place-items: center;
  line-height: 0;
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.theme-toggle svg { width: 15px; height: 15px; display: block; }

/* Mobile topbar + bottom nav */
/* NOTE: no `display` here. styles.css hides the topbar on desktop from
   inside a media query, and an unconditional `display: flex` in this file
   would override it (same specificity, later file) and pin the mobile bar
   to every desktop screen. */
.topbar {
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border-subtle);
  padding: 9px 14px;
  align-items: center;
  gap: 9px;
}
.topbar .brand { font-size: 13px; font-weight: 660; color: var(--text-primary); }

.bottom-nav {
  background: color-mix(in srgb, var(--bg-sunken) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-subtle);
}
.bottom-nav a {
  flex-direction: column;
  color: var(--text-muted);
  font-size: 9.5px;
  font-weight: 620;
  letter-spacing: 0.01em;
  gap: 3px;
  padding: 7px 0 calc(7px + env(safe-area-inset-bottom));
}
.bottom-nav a .nav-icon { width: 17px; height: 17px; display: block; }
.bottom-nav a.active { color: var(--accent); background: transparent; }

/* ==========================================================================
   15. BANNERS
   ========================================================================== */

.emergency-stop-banner {
  background: var(--down);
  color: #fff;
  border-bottom: 1px solid #00000040;
  font-weight: 580;
  font-size: 12.5px;
}
.emergency-stop-reset-btn {
  background: #ffffff1f;
  border: 1px solid #ffffff4d;
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 620;
}
.emergency-stop-reset-btn:hover { background: #ffffff33; }

.offline-banner { background: var(--warn); color: #12100a; font-weight: 600; }

.skip-link { background: var(--accent); color: var(--on-accent-solid); border-radius: var(--radius-sm); font-weight: 620; }

/* A prominent inline notice inside a panel. */
.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-sunken);
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}
.notice-danger { border-color: var(--down-line); background: var(--down-soft); color: var(--on-down-soft); }
.notice-warn   { border-color: var(--warn-line); background: var(--warn-soft); color: var(--on-warn-soft); }
.notice-accent { border-color: var(--accent-line); background: var(--accent-soft); color: var(--on-accent-soft); }
.notice-title { font-weight: 660; display: block; margin-bottom: 3px; color: inherit; }
.notice ul { margin: 5px 0 0 16px; padding: 0; }
.notice li { margin: 2px 0; }

.error-text { color: var(--down); font-size: 12.5px; margin: 0 0 10px; }
.save-status { font-size: 11.5px; }
.save-status.ok { color: var(--up); }
.save-status.err { color: var(--down); }

/* ==========================================================================
   16. CHART
   ========================================================================== */

.chart-shell {
  background-color: var(--bg-surface);
  background-image: var(--panel-sheen);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
  background: var(--bg-sunken);
}
.chart-price { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.chart-price .sym {
  font-size: 14.5px;
  font-weight: 680;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}
.chart-price .last { font-size: 20px; font-weight: 620; color: var(--text-primary); line-height: 1.1; }
.chart-price .small { font-size: 12px; font-weight: 620; }

.chart-canvas-wrap {
  position: relative;
  padding: 6px 4px 0;
  min-height: 300px;
  background: var(--bg-surface);
}
.chart-canvas-wrap canvas { display: block; width: 100%; }
.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 9px 14px;
  border-top: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-sunken);
}
.legend-key { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.legend-swatch { width: 10px; height: 2px; border-radius: 2px; display: inline-block; }
.legend-key.legend-level .legend-swatch { height: 0; border-top: 2px dashed currentColor; width: 12px; background: none !important; }

/* ==========================================================================
   17. ACTIVITY FEED
   ========================================================================== */

.feed { max-height: 316px; overflow-y: auto; margin: 0 -4px; }
.feed-row {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 9px;
  padding: 6px 8px;
  border-radius: var(--radius-xs);
  border-left: 2px solid transparent;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.feed-row + .feed-row { margin-top: 1px; }
.feed-row:hover { background: var(--bg-hover); }
.feed-time { color: var(--text-faint); font-family: var(--font-mono); font-size: 10.5px; padding-top: 1px; }
.feed-text { overflow-wrap: anywhere; }
.feed-row.ev-fill   { border-left-color: var(--up);     background: var(--up-soft); }
.feed-row.ev-order  { border-left-color: var(--accent); background: var(--accent-soft); }
.feed-row.ev-reject { border-left-color: var(--warn);   background: var(--warn-soft); }
.feed-row.ev-venue  { border-left-color: var(--down);   background: var(--down-soft); }

/* ==========================================================================
   18. FUNNEL / PROGRESS
   ========================================================================== */

.funnel-row { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; }
.funnel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 12px; }
.funnel-head .v { font-family: var(--font-mono); font-weight: 640; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.funnel-bar { height: 4px; border-radius: 3px; background: var(--bg-sunken); overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 3px; background: var(--accent); opacity: 0.8; transition: width 260ms var(--ease); }
.funnel-fill.is-up { background: var(--up); }
.funnel-fill.is-warn { background: var(--warn); }
.funnel-fill.is-muted { background: var(--neutral); opacity: 0.55; }

/* ==========================================================================
   19. CONFIGURATION
   ========================================================================== */

.config-section { margin-bottom: 14px; }
.config-row {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.75fr) minmax(0, 0.9fr);
  gap: 18px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border-subtle);
  align-items: start;
}
.config-row:last-child { border-bottom: none; }
.config-label { font-size: 12.5px; font-weight: 620; color: var(--text-primary); }
.config-help { font-size: 11.5px; color: var(--text-muted); margin: 3px 0 0; line-height: 1.5; }
.config-control { display: flex; flex-direction: column; gap: 8px; }
.config-input-row { display: flex; align-items: center; gap: 9px; }
.config-input-row input[type="number"] { width: 116px; }
.config-input-row input[type="range"] { flex: 1; min-width: 90px; }
.config-range-val { font-family: var(--font-mono); font-size: 12px; color: var(--text-primary); min-width: 46px; font-variant-numeric: tabular-nums; }
.provenance {
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
}
.provenance .prov-line { font-size: 11.5px; padding: 3px 0; border-bottom: none; }
.provenance .prov-line.effective { border-top: 1px solid var(--border-subtle); margin-top: 3px; padding-top: 6px; }
.provenance .prov-line.effective span { color: var(--text-primary); font-weight: 660; }
.masked-field { font-family: var(--font-mono); color: var(--text-muted); font-size: 12px; }
.risk-field, .risk-field-bool { display: flex; align-items: center; gap: 9px; }
.strategy-toggle { display: flex; align-items: center; gap: 8px; }

/* ==========================================================================
   20. LOGIN
   ========================================================================== */

.login-wrap {
  background-color: var(--bg-surface);
  background-image: var(--panel-sheen);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 28px 26px;
}
.login-wrap h1 { font-size: 19px; margin-bottom: 4px; }

/* ==========================================================================
   21. SKELETON
   ========================================================================== */

.skeleton {
  background: linear-gradient(90deg, var(--bg-sunken), var(--bg-hover), var(--bg-sunken));
  background-size: 220% 100%;
  animation: shimmer 1.3s linear infinite;
  border-radius: var(--radius-xs);
  color: transparent;
}
@keyframes shimmer { from { background-position: 220% 0; } to { background-position: -20% 0; } }

/* ==========================================================================
   22. RESPONSIVE
   --------------------------------------------------------------------------
   Desktop keeps density. Below the terminal breakpoint the chart takes the
   full width and the rail drops beneath it, because a 300px-wide chart is
   not a chart. Mobile drops to one column throughout.
   ========================================================================== */

@media (max-width: 1500px) {
  .grid-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1240px) {
  .grid-terminal { grid-template-columns: minmax(0, 1fr); }
  .grid-5, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .config-row { grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr); }
  .config-row .provenance { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .main-content { padding: 16px 14px 84px; }
}

@media (max-width: 640px) {
  body { font-size: 13px; }
  .main-content { padding: 13px 11px 88px; }
  .grid, .grid-2, .grid-3, .grid-4, .grid-5, .grid-6, .grid-terminal { grid-template-columns: minmax(0, 1fr); gap: 11px; }
  .config-row { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  h1, .page-head h2 { font-size: 18px; }
  .page-head { margin-bottom: 13px; padding-bottom: 11px; }
  .metric-value, .kpi-value { font-size: 18px; }
  .card { padding: 12px 13px; border-radius: var(--radius-sm); }
  .table-wrap { margin: 0 -13px -12px; }
  thead th { padding: 7px 11px; }
  tbody td { padding: 8px 11px; }
  .chart-toolbar { padding: 9px 11px; gap: 7px; }
  .chart-price .last { font-size: 17px; }
  .chart-legend { padding: 8px 11px; gap: 10px; font-size: 10.5px; }
  .feed-row { grid-template-columns: 50px 1fr; }
  /* On a phone the status strip must not push the title off-screen. */
  .page-head { flex-direction: column; align-items: stretch; }
  .badge, .trading-mode-badge { font-size: 10px; padding: 3px 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   Operator console additions: chart toolbar, OHLCV readout,
   deployment stage list, evidence lists, code blocks.
   Mobile-first: every one of these collapses to a single column
   and scrolls inside itself rather than pushing the page wide.
   ============================================================ */

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

.chart-toolbar .tf-group,
.chart-toolbar .ind-group {
  display: flex;
  gap: 2px;
  background: var(--surface-2, #161a22);
  border: 1px solid var(--border, #262c38);
  border-radius: 6px;
  padding: 2px;
}

.chart-toolbar button {
  background: transparent;
  border: 0;
  color: var(--text-secondary, #99a5bb);
  font: 500 11px/1 Inter, "Segoe UI", system-ui, sans-serif;
  padding: 5px 9px;
  border-radius: 4px;
  cursor: pointer;
}

.chart-toolbar button[aria-pressed="true"],
.chart-toolbar button.active {
  background: var(--accent-dim, #1d2a44);
  color: var(--accent, #4c8dff);
}

.chart-toolbar button:hover { color: var(--text-primary, #e6ecf5); }

/* The live OHLCV readout. Pinned above the canvas so a crosshair
   reading never covers the candles it describes. */
.ohlc-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
  min-height: 18px;
  font: 500 11px/1.4 "JetBrains Mono", ui-monospace, Consolas, monospace;
  color: var(--text-secondary, #99a5bb);
  margin-bottom: 4px;
}
.ohlc-readout .ohlc-k { color: var(--text-muted, #6b7688); margin-right: 3px; }
.ohlc-readout .ohlc-t { color: var(--text-primary, #e6ecf5); }

.chart-shell { position: relative; }
.chart-shell:fullscreen { background: var(--bg, #0f1115); padding: 16px; }
.chart-shell:fullscreen canvas { height: calc(100vh - 120px) !important; }

.chart-pinned {
  position: absolute;
  top: 6px;
  right: 100px;
  font: 500 10px/1 Inter, system-ui, sans-serif;
  color: var(--warn, #e0a33e);
  background: var(--surface-2, #161a22);
  border: 1px solid var(--warn, #e0a33e);
  border-radius: 4px;
  padding: 3px 6px;
  pointer-events: none;
}

.stage-list { list-style: none; padding: 0; margin: 8px 0 0; }
.stage-list li {
  padding: 3px 0;
  font: 500 12px/1.5 Inter, "Segoe UI", system-ui, sans-serif;
}

.evidence-list { margin: 4px 0 0 18px; padding: 0; }
.evidence-list li { font-size: 12px; line-height: 1.6; }

.code-block {
  background: var(--surface-2, #161a22);
  border: 1px solid var(--border, #262c38);
  border-radius: 6px;
  padding: 10px;
  overflow-x: auto;
  font: 400 11px/1.5 "JetBrains Mono", ui-monospace, Consolas, monospace;
  color: var(--text-secondary, #99a5bb);
  max-height: 340px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font: 500 11px/1.4 Inter, "Segoe UI", system-ui, sans-serif;
  color: var(--text-secondary, #99a5bb);
}
.form-grid input,
.form-grid select,
.form-grid textarea {
  background: var(--surface-2, #161a22);
  border: 1px solid var(--border, #262c38);
  border-radius: 6px;
  color: var(--text-primary, #e6ecf5);
  padding: 7px 9px;
  font: 400 12px/1.4 "JetBrains Mono", ui-monospace, Consolas, monospace;
  width: 100%;
}
.form-grid textarea { resize: vertical; }
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: none;
  border-color: var(--accent, #4c8dff);
}

.detail-row td { background: var(--surface-2, #161a22); }
.clickable { cursor: pointer; }

@media (max-width: 720px) {
  .chart-toolbar { gap: 4px; }
  .chart-toolbar button { padding: 6px 8px; }
  .ohlc-readout { font-size: 10px; gap: 7px; }
  .chart-pinned { right: 8px; }
  .form-grid { grid-template-columns: 1fr; }
}
