:root {
    --bg-0: #07080b;
    --bg-1: #0b0d12;
    --bg-2: #11141b;
    --bg-3: #161a23;
    --line: #1d2230;
    --line-2: #262c3d;
    --txt-0: #e7eaf2;
    --txt-1: #aab0c0;
    --txt-2: #6b7388;
    --txt-3: #444b5e;

    --acc: #ff2e44;          /* primary red */
    --acc-glow: rgba(255,46,68,.35);
    --pos: #00ff9d;          /* buy / positive */
    --pos-glow: rgba(0,255,157,.25);
    --neg: #ff2e44;          /* sell / negative */
    --info: #00d9ff;         /* data / info */
    --info-glow: rgba(0,217,255,.25);
    --warn: #ffb020;
    --warn-glow: rgba(255,176,32,.2);

    --row-h: 28px;
    --pad: 14px;
    --radius: 3px;

    --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
    --sans: 'Inter', system-ui, sans-serif;
  }

  * { box-sizing: border-box; }
  html, body {
    margin: 0; padding: 0;
    background: var(--bg-0);
    color: var(--txt-0);
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
  }
  body::before {
    content: "";
    position: fixed; inset: 0;
    background:
      radial-gradient(ellipse 80% 60% at 80% 0%, rgba(255,46,68,.06), transparent 60%),
      radial-gradient(ellipse 60% 50% at 0% 100%, rgba(0,217,255,.04), transparent 60%),
      linear-gradient(transparent 95%, rgba(255,255,255,.015) 95%) 0 0/100% 32px,
      linear-gradient(90deg, transparent 95%, rgba(255,255,255,.015) 95%) 0 0/32px 100%;
    pointer-events: none;
    z-index: 0;
  }

  .mono { font-family: var(--mono); font-feature-settings: "ss01","cv11"; }
  .upper { text-transform: uppercase; letter-spacing: .12em; }
  .small { font-size: 10.5px; }
  .tiny  { font-size: 9.5px; }
  .dim   { color: var(--txt-2); }
  .dimmer { color: var(--txt-3); }
  .pos { color: var(--pos); }
  .neg { color: var(--neg); }
  .info { color: var(--info); }
  .warn { color: var(--warn); }

  /* ===== shell ===== */
  .app {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 200px 1fr 360px;
    grid-template-rows: 32px 44px 1fr;
    grid-template-areas:
      "title title title"
      "topbar topbar topbar"
      "sidebar main rail";
    height: 100vh;
    width: 100vw;
  }
  /* Narrower viewports: drop the right rail down below main as a horizontal strip */
  @media (max-width: 1400px) {
    .app {
      grid-template-columns: 200px 1fr;
      grid-template-rows: 32px 44px 1fr auto;
      grid-template-areas:
        "title title"
        "topbar topbar"
        "sidebar main"
        "sidebar rail";
    }
    .rail {
      border-left: none;
      border-top: 1px solid var(--line);
      flex-direction: row;
      max-height: 280px;
      overflow-x: auto;
      overflow-y: hidden;
    }
    .rail .rail-section {
      border-bottom: none;
      border-right: 1px solid var(--line);
      min-width: 320px;
      flex: 1 1 0;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
    .rail .rail-section.flex-grow {
      flex: 1.4 1 0;
      min-height: auto;
      min-width: 360px;
    }
    .rail .trace-list { overflow-y: auto; }
  }

  /* macOS-style title bar */
  .titlebar {
    grid-area: title;
    background: #0a0c11;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 14px;
    font-size: 11px;
    color: var(--txt-2);
    font-family: var(--mono);
  }
  .traffic { display: flex; gap: 6px; }
  .traffic span {
    width: 11px; height: 11px; border-radius: 50%;
    background: #2a2f3d;
    border: 1px solid #00000033;
  }
  .traffic span:nth-child(1) { background: #ff5f57; }
  .traffic span:nth-child(2) { background: #febc2e; }
  .traffic span:nth-child(3) { background: #28c840; }
  .titlebar .menu { display: flex; gap: 14px; margin-left: 10px; }
  .titlebar .menu span:hover { color: var(--txt-0); }

  /* ===== topbar ===== */
  .topbar {
    grid-area: topbar;
    background: var(--bg-1);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: stretch;
  }
  .brand {
    width: 200px;
    border-right: 1px solid var(--line);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 10px;
  }
  .brand-mark {
    width: 22px; height: 22px;
    background:
      conic-gradient(from 30deg, var(--acc) 0 33%, transparent 33% 66%, var(--acc) 66% 100%);
    clip-path: polygon(50% 0, 100% 100%, 0 100%);
    filter: drop-shadow(0 0 6px var(--acc-glow));
  }
  .brand-name {
    font-family: var(--mono);
    font-weight: 700;
    letter-spacing: .25em;
    font-size: 12px;
    color: var(--txt-0);
  }
  .brand-name b { color: var(--acc); }

  .ticker-strip {
    flex: 1;
    display: flex;
    align-items: center;
    overflow: hidden;
    border-right: 1px solid var(--line);
  }
  .ticker {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 0 16px;
    font-family: var(--mono);
    font-size: 11.5px;
    white-space: nowrap;
    animation: scroll 60s linear infinite;
  }
  @keyframes scroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
  }
  .tk { display: inline-flex; gap: 8px; align-items: baseline; }
  .tk b { color: var(--txt-0); font-weight: 600; letter-spacing: .05em; }

  .topbar-right {
    display: flex;
    align-items: center;
    gap: 0;
  }
  .stat-pill {
    padding: 0 14px;
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    font-family: var(--mono);
  }
  .stat-pill .lbl { font-size: 9px; color: var(--txt-3); letter-spacing: .15em; text-transform: uppercase; }
  .stat-pill .val { font-size: 12px; color: var(--txt-0); font-weight: 500; }
  .stat-pill .val.live::before {
    content: "";
    display: inline-block;
    width: 6px; height: 6px;
    background: var(--pos);
    border-radius: 50%;
    margin-right: 6px;
    box-shadow: 0 0 8px var(--pos-glow);
    animation: pulse 1.6s ease-in-out infinite;
  }
  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .35; }
  }

  /* ===== sidebar ===== */
  .sidebar {
    grid-area: sidebar;
    background: var(--bg-1);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    padding: 8px 0;
  }
  .nav-group { padding: 8px 0; }
  .nav-group-title {
    padding: 8px 16px 4px;
    font-family: var(--mono);
    font-size: 9.5px;
    color: var(--txt-3);
    letter-spacing: .2em;
    text-transform: uppercase;
  }
  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    color: var(--txt-1);
    font-size: 12.5px;
    cursor: pointer;
    border-left: 2px solid transparent;
    user-select: none;
  }
  .nav-item:hover { background: var(--bg-2); color: var(--txt-0); }
  .nav-item.active {
    background: linear-gradient(90deg, rgba(255,46,68,.12), transparent 70%);
    border-left-color: var(--acc);
    color: var(--txt-0);
    box-shadow: inset 0 0 20px rgba(255,46,68,.05);
  }
  .nav-icon {
    width: 14px; height: 14px;
    flex-shrink: 0;
    color: var(--txt-2);
  }
  .nav-item.active .nav-icon { color: var(--acc); }
  .nav-badge {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 9.5px;
    padding: 1px 5px;
    background: var(--bg-3);
    border: 1px solid var(--line-2);
    color: var(--txt-2);
    border-radius: 2px;
  }
  .nav-badge.live { color: var(--pos); border-color: rgba(0,255,157,.3); background: rgba(0,255,157,.05); }

  .sidebar-foot {
    margin-top: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 10px;
    color: var(--txt-3);
    line-height: 1.7;
  }
  .sidebar-foot .row { display: flex; justify-content: space-between; }

  /* ===== main ===== */
  .main {
    grid-area: main;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px;
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 12px;
    grid-auto-rows: min-content;
    align-content: start;
  }
  .panel {
    background: var(--bg-1);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    position: relative;
  }
  .panel-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    border-bottom: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .15em;
    color: var(--txt-2);
  }
  .panel-head .dot {
    width: 6px; height: 6px;
    background: var(--acc);
    box-shadow: 0 0 6px var(--acc-glow);
    flex-shrink: 0;
  }
  .panel-head .title { color: var(--txt-0); font-weight: 500; }
  .panel-head .right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
  .panel-head .chip {
    padding: 2px 7px;
    border: 1px solid var(--line-2);
    border-radius: 2px;
    font-size: 9.5px;
    color: var(--txt-2);
    background: var(--bg-2);
  }
  .panel-body { padding: 14px; }
  .panel-body.tight { padding: 0; }

  /* ===== signal hero ===== */
  .hero {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1.1fr 1fr 1fr;
    gap: 0;
    border: 1px solid var(--line);
    background: var(--bg-1);
    position: relative;
    overflow: hidden;
  }
  .hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
      linear-gradient(105deg, rgba(255,46,68,.05) 0%, transparent 50%),
      repeating-linear-gradient(90deg, transparent 0 79px, rgba(255,255,255,.02) 79px 80px);
    pointer-events: none;
  }
  .hero-cell { padding: 18px 20px; border-right: 1px solid var(--line); position: relative; }
  .hero-cell:last-child { border-right: none; }
  .hero-label {
    font-family: var(--mono);
    font-size: 9.5px;
    color: var(--txt-3);
    letter-spacing: .2em;
    text-transform: uppercase;
    margin-bottom: 8px;
  }
  .hero-asset {
    display: flex;
    align-items: baseline;
    gap: 10px;
  }
  .hero-symbol {
    font-family: var(--mono);
    font-size: 38px;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--txt-0);
  }
  .hero-tf {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--txt-2);
    padding: 3px 8px;
    background: var(--bg-3);
    border: 1px solid var(--line-2);
  }
  .hero-price {
    margin-top: 6px;
    font-family: var(--mono);
    font-size: 22px;
    color: var(--txt-0);
    font-weight: 500;
  }
  .hero-change { margin-left: 8px; font-size: 13px; }

  .decision-cell {
    text-align: left;
    background:
      radial-gradient(ellipse at 20% 50%, rgba(255,46,68,.08), transparent 70%);
  }
  .decision-cell.buy { background: radial-gradient(ellipse at 20% 50%, rgba(0,255,157,.08), transparent 70%); }
  .decision-cell.sell { background: radial-gradient(ellipse at 20% 50%, rgba(255,46,68,.1), transparent 70%); }

  .decision-word {
    font-family: var(--mono);
    font-size: 64px;
    font-weight: 700;
    letter-spacing: .04em;
    line-height: 1;
    margin-top: 4px;
    color: var(--warn);
    text-shadow: 0 0 24px var(--warn-glow);
  }
  .decision-word.buy { color: var(--pos); text-shadow: 0 0 24px var(--pos-glow); }
  .decision-word.sell { color: var(--neg); text-shadow: 0 0 24px var(--acc-glow); }
  .decision-meta {
    display: flex;
    gap: 16px;
    margin-top: 10px;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--txt-2);
  }
  .decision-meta b { color: var(--txt-0); font-weight: 500; }

  /* confidence bar */
  .conf {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .conf-row { display: flex; flex-direction: column; gap: 5px; }
  .conf-row-head {
    display: flex; justify-content: space-between;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--txt-2);
    letter-spacing: .1em;
    text-transform: uppercase;
  }
  .conf-row-head b { color: var(--txt-0); }
  .bar {
    height: 6px;
    background: var(--bg-3);
    border: 1px solid var(--line-2);
    position: relative;
    overflow: hidden;
  }
  .bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--acc), #ff6677);
    box-shadow: 0 0 8px var(--acc-glow);
  }
  .bar-fill.cyan { background: linear-gradient(90deg, var(--info), #66e6ff); box-shadow: 0 0 8px var(--info-glow); }
  .bar-fill.green { background: linear-gradient(90deg, var(--pos), #66ffc1); box-shadow: 0 0 8px var(--pos-glow); }
  .bar-fill.warn { background: linear-gradient(90deg, var(--warn), #ffd070); box-shadow: 0 0 8px var(--warn-glow); }

  /* ===== chart ===== */
  .chart-panel { grid-column: 1 / 2; }
  .chart-toolbar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--line);
    background: var(--bg-1);
  }
  .chart-toolbar .grp {
    display: flex;
    border-right: 1px solid var(--line);
  }
  .chart-toolbar .grp:last-child { border-right: none; margin-left: auto; }
  .tf-btn {
    padding: 6px 11px;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--txt-2);
    background: transparent;
    border: none;
    border-right: 1px solid var(--line);
    cursor: pointer;
  }
  .tf-btn:last-child { border-right: none; }
  .tf-btn.active { color: var(--acc); background: rgba(255,46,68,.08); }
  .tf-btn:hover { color: var(--txt-0); }

  .chart-wrap {
    position: relative;
    height: 320px;
    background:
      linear-gradient(transparent 95%, rgba(255,255,255,.025) 95%) 0 0/100% 32px,
      linear-gradient(90deg, transparent 98%, rgba(255,255,255,.02) 98%) 0 0/60px 100%;
  }
  .chart-wrap svg { display: block; width: 100%; height: 100%; }
  .chart-overlay {
    position: absolute;
    top: 10px;
    left: 12px;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--txt-2);
    line-height: 1.7;
    pointer-events: none;
  }
  .chart-overlay span { color: var(--txt-0); }

  .chart-legend {
    position: absolute;
    top: 10px;
    right: 12px;
    display: flex;
    gap: 14px;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--txt-2);
  }
  .chart-legend .dot {
    display: inline-block;
    width: 8px; height: 2px;
    margin-right: 5px;
    vertical-align: middle;
  }

  /* ===== signal flow pipeline ===== */
  .flow-panel { grid-column: 1 / -1; }
  .flow {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0;
    padding: 0;
  }
  .flow-step {
    padding: 14px 14px;
    border-right: 1px solid var(--line);
    position: relative;
    background: var(--bg-1);
  }
  .flow-step:last-child { border-right: none; }
  .flow-step.active {
    background: linear-gradient(180deg, rgba(255,46,68,.08), transparent);
  }
  .flow-step.active::after {
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 2px;
    background: var(--acc);
    box-shadow: 0 0 10px var(--acc-glow);
  }
  .flow-step.done .flow-status { color: var(--pos); }
  .flow-step.active .flow-status { color: var(--acc); }
  .flow-num {
    font-family: var(--mono);
    font-size: 9.5px;
    color: var(--txt-3);
    letter-spacing: .2em;
  }
  .flow-name {
    font-family: var(--mono);
    font-size: 13px;
    color: var(--txt-0);
    margin: 4px 0 6px;
    font-weight: 500;
  }
  .flow-status {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--txt-2);
    text-transform: uppercase;
    letter-spacing: .1em;
    display: flex; align-items: center; gap: 6px;
  }
  .flow-status::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 6px currentColor;
  }
  .flow-step .flow-time {
    margin-top: 8px;
    font-family: var(--mono);
    font-size: 9.5px;
    color: var(--txt-3);
  }

  /* connection lines */
  .flow-step::before {
    content: "";
    position: absolute;
    right: -4px; top: 50%;
    width: 8px; height: 1px;
    background: var(--line-2);
    z-index: 1;
  }
  .flow-step:last-child::before { display: none; }

  /* ===== positions table ===== */
  .table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: 11.5px;
  }
  .table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 9.5px;
    color: var(--txt-3);
    letter-spacing: .15em;
    text-transform: uppercase;
    font-weight: 500;
    border-bottom: 1px solid var(--line);
    background: var(--bg-2);
  }
  .table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    color: var(--txt-1);
  }
  .table tr:last-child td { border-bottom: none; }
  .table tr:hover td { background: var(--bg-2); }
  .table .sym { color: var(--txt-0); font-weight: 600; letter-spacing: .04em; }
  .side-tag {
    display: inline-block;
    padding: 1px 6px;
    font-size: 9.5px;
    letter-spacing: .1em;
    border: 1px solid;
    border-radius: 2px;
  }
  .side-tag.long { color: var(--pos); border-color: rgba(0,255,157,.3); background: rgba(0,255,157,.05); }
  .side-tag.short { color: var(--neg); border-color: rgba(255,46,68,.3); background: rgba(255,46,68,.05); }

  /* ===== watchlist ===== */
  .watch {
    display: grid;
    grid-template-columns: 1fr;
  }
  .watch-row {
    display: grid;
    grid-template-columns: 70px 1fr auto auto;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 11.5px;
    cursor: pointer;
  }
  .watch-row:last-child { border-bottom: none; }
  .watch-row:hover { background: var(--bg-2); }
  .watch-row.selected { background: rgba(255,46,68,.06); border-left: 2px solid var(--acc); padding-left: 12px; }
  .watch-sym { color: var(--txt-0); font-weight: 600; letter-spacing: .03em; }
  .watch-spark { width: 80px; height: 22px; }
  .watch-price { color: var(--txt-0); }
  .watch-chg { font-size: 10.5px; min-width: 56px; text-align: right; }
  .watch-sig {
    font-size: 9px;
    padding: 1px 5px;
    border: 1px solid;
    letter-spacing: .1em;
    border-radius: 2px;
  }
  .watch-sig.buy { color: var(--pos); border-color: rgba(0,255,157,.3); background: rgba(0,255,157,.05); }
  .watch-sig.sell { color: var(--neg); border-color: rgba(255,46,68,.3); background: rgba(255,46,68,.05); }
  .watch-sig.hold { color: var(--warn); border-color: rgba(255,176,32,.3); background: rgba(255,176,32,.05); }

  /* ===== chat ===== */
  .chat-panel { grid-column: 1 / -1; }
  .chat-wrap {
    display: grid;
    grid-template-rows: 1fr auto auto;
    height: 380px;
  }
  .chat-stream {
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .msg {
    display: flex;
    gap: 10px;
    max-width: 80%;
  }
  .msg.user { align-self: flex-end; flex-direction: row-reverse; }
  .msg-avatar {
    width: 22px; height: 22px;
    border-radius: 2px;
    display: grid; place-items: center;
    flex-shrink: 0;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
  }
  .msg.ai .msg-avatar {
    background: rgba(255,46,68,.1);
    color: var(--acc);
    border: 1px solid rgba(255,46,68,.3);
  }
  .msg.user .msg-avatar {
    background: var(--bg-3);
    color: var(--txt-1);
    border: 1px solid var(--line-2);
  }
  .msg-bubble {
    padding: 9px 12px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    font-size: 12px;
    line-height: 1.55;
    color: var(--txt-0);
  }
  .msg.user .msg-bubble { background: var(--bg-3); }
  .msg-meta {
    font-family: var(--mono);
    font-size: 9px;
    color: var(--txt-3);
    margin-top: 4px;
    letter-spacing: .1em;
  }
  .msg-bubble .ref {
    display: inline-block;
    margin-top: 4px;
    padding: 1px 6px;
    background: rgba(0,217,255,.06);
    border: 1px solid rgba(0,217,255,.25);
    color: var(--info);
    font-family: var(--mono);
    font-size: 10px;
    margin-right: 4px;
  }

  .chat-suggest {
    display: flex; gap: 8px;
    padding: 0 14px 8px;
    flex-wrap: wrap;
  }
  .sug {
    padding: 4px 9px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 10px;
    color: var(--txt-1);
    cursor: pointer;
    border-radius: 2px;
  }
  .sug:hover { color: var(--txt-0); border-color: var(--line-2); background: var(--bg-3); }

  .chat-input {
    display: grid;
    grid-template-columns: 1fr auto;
    border-top: 1px solid var(--line);
    background: var(--bg-1);
  }
  .chat-input input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--txt-0);
    padding: 11px 14px;
    font-family: var(--sans);
    font-size: 12.5px;
  }
  .chat-input input::placeholder { color: var(--txt-3); }
  .chat-send {
    padding: 0 18px;
    background: rgba(255,46,68,.1);
    border: none;
    border-left: 1px solid var(--line);
    color: var(--acc);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .15em;
    text-transform: uppercase;
    cursor: pointer;
  }
  .chat-send:hover { background: rgba(255,46,68,.18); }

  .chat-foot {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 7px 14px;
    border-top: 1px solid var(--line);
    background: var(--bg-2);
    font-family: var(--mono);
    font-size: 10px;
    color: var(--txt-2);
  }
  .chat-foot .chip {
    padding: 1px 6px;
    background: var(--bg-3);
    border: 1px solid var(--line-2);
    border-radius: 2px;
    font-size: 9.5px;
  }
  .chat-foot .chip.warn { color: var(--warn); border-color: rgba(255,176,32,.3); }

  /* ===== rail (event trace) ===== */
  .rail {
    grid-area: rail;
    background: var(--bg-1);
    border-left: 1px solid var(--line);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .rail-section { border-bottom: 1px solid var(--line); flex-shrink: 0; }
  .rail-section.flex-grow { flex: 1 1 auto; min-height: 200px; display: flex; flex-direction: column; }
  .rail-section:last-child { border-bottom: none; }
  .rail-head {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .15em;
    color: var(--txt-2);
    background: var(--bg-2);
  }
  .rail-head .title { color: var(--txt-0); font-weight: 500; }
  .rail-head .right { margin-left: auto; }

  .trace-list {
    display: flex;
    flex-direction: column;
    padding: 8px 0;
  }
  .trace-item {
    padding: 8px 14px;
    border-left: 2px solid transparent;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
    font-family: var(--mono);
    font-size: 11px;
  }
  .trace-item:hover { background: var(--bg-2); border-left-color: var(--line-2); }
  .trace-item.curr {
    background: rgba(255,46,68,.05);
    border-left-color: var(--acc);
  }
  .trace-item .ev {
    color: var(--txt-0);
    display: flex; align-items: center; gap: 8px;
  }
  .trace-item .ev::before {
    content: "";
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--txt-3);
    flex-shrink: 0;
  }
  .trace-item.done .ev::before { background: var(--pos); box-shadow: 0 0 6px var(--pos-glow); }
  .trace-item.curr .ev::before {
    background: var(--acc);
    box-shadow: 0 0 8px var(--acc-glow);
    animation: pulse 1.4s ease-in-out infinite;
  }
  .trace-item .ts {
    color: var(--txt-3);
    font-size: 9.5px;
  }
  .trace-item .det {
    grid-column: 1 / -1;
    color: var(--txt-2);
    font-size: 10px;
    margin-left: 14px;
  }

  .corr-card {
    padding: 12px 14px;
    background: var(--bg-2);
  }
  .corr-id {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--info);
    word-break: break-all;
  }
  .corr-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    gap: 8px;
    margin-top: 10px;
    font-family: var(--mono);
    font-size: 10px;
  }
  .corr-meta .k { color: var(--txt-3); letter-spacing: .12em; text-transform: uppercase; font-size: 9px; }
  .corr-meta .v { color: var(--txt-0); margin-top: 2px; }

  .latest-decision {
    padding: 14px;
  }
  .ld-word {
    font-family: var(--mono);
    font-size: 26px;
    font-weight: 700;
    color: var(--warn);
    letter-spacing: .04em;
    text-shadow: 0 0 16px var(--warn-glow);
  }
  .ld-explain {
    font-size: 11.5px;
    color: var(--txt-1);
    line-height: 1.55;
    margin-top: 8px;
  }
  .ld-tags {
    display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px;
  }
  .tag {
    font-family: var(--mono);
    font-size: 9.5px;
    padding: 2px 7px;
    border: 1px solid var(--line-2);
    background: var(--bg-3);
    color: var(--txt-2);
    letter-spacing: .08em;
    border-radius: 2px;
  }

  /* ===== status bar ===== */
  .statusbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg-1);
    border-top: 1px solid var(--line);
    height: 22px;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--txt-2);
  }
  .sb-cell {
    padding: 0 12px;
    border-right: 1px solid var(--line);
    height: 100%;
    display: flex; align-items: center; gap: 6px;
  }
  .sb-cell:last-child { margin-left: auto; border-right: none; border-left: 1px solid var(--line); }
  .sb-cell b { color: var(--txt-0); font-weight: 500; }

  /* scrollbars */
  ::-webkit-scrollbar { width: 8px; height: 8px; }
  ::-webkit-scrollbar-track { background: var(--bg-0); }
  ::-webkit-scrollbar-thumb { background: var(--bg-3); border: 1px solid var(--bg-1); }
  ::-webkit-scrollbar-thumb:hover { background: var(--line-2); }

  /* density variants */
  body[data-density="dense"] { font-size: 12px; }
  body[data-density="dense"] .panel-body { padding: 10px; }
  body[data-density="dense"] .hero-cell { padding: 14px 16px; }
  body[data-density="dense"] .decision-word { font-size: 52px; }
  body[data-density="dense"] .hero-symbol { font-size: 32px; }
  body[data-density="airy"] { font-size: 14px; }
  body[data-density="airy"] .panel-body { padding: 18px; }

  /* color accent variants — overrides --acc */
  body[data-accent="red"]    { --acc: #ff2e44; --acc-glow: rgba(255,46,68,.35); }
  body[data-accent="cyan"]   { --acc: #00d9ff; --acc-glow: rgba(0,217,255,.35); }
  body[data-accent="amber"]  { --acc: #ffb020; --acc-glow: rgba(255,176,32,.4); }
  body[data-accent="lime"]   { --acc: #9eff3a; --acc-glow: rgba(158,255,58,.35); }
  body[data-accent="violet"] { --acc: #a36bff; --acc-glow: rgba(163,107,255,.35); }

/* ============================================================
   Page-specific shared utilities (Portfolio / Backtests / Risk)
   ============================================================ */

/* page shell layout — same as dashboard but main has its own padding */
.page-main {
  grid-area: main;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
}

/* page header (above panels) */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 4px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.page-title {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--txt-0);
  letter-spacing: .04em;
  display: flex; align-items: center; gap: 12px;
}
.page-title .crumb {
  font-size: 11px;
  color: var(--txt-3);
  letter-spacing: .2em;
  text-transform: uppercase;
}
.page-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--txt-2);
  margin-top: 4px;
  letter-spacing: .04em;
}
.page-actions { display: flex; gap: 8px; align-items: center; }
.btn {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .15em;
  text-transform: uppercase;
  padding: 7px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--txt-1);
  cursor: pointer;
  border-radius: 2px;
}
.btn:hover { color: var(--txt-0); border-color: var(--line-2); background: var(--bg-3); }
.btn.primary {
  background: rgba(255,46,68,.12);
  border-color: rgba(255,46,68,.4);
  color: var(--acc);
}
body[data-accent="amber"]  .btn.primary { background: rgba(255,176,32,.12); border-color: rgba(255,176,32,.4); }
body[data-accent="cyan"]   .btn.primary { background: rgba(0,217,255,.12); border-color: rgba(0,217,255,.4); }
body[data-accent="lime"]   .btn.primary { background: rgba(158,255,58,.12); border-color: rgba(158,255,58,.4); }
body[data-accent="violet"] .btn.primary { background: rgba(163,107,255,.12); border-color: rgba(163,107,255,.4); }

/* KPI strip (used on all 3 pages) */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border: 1px solid var(--line);
  background: var(--bg-1);
  margin-bottom: 14px;
}
.kpi {
  padding: 14px 16px;
  border-right: 1px solid var(--line);
  position: relative;
}
.kpi:last-child { border-right: none; }
.kpi .lbl {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--txt-3);
  letter-spacing: .2em;
  text-transform: uppercase;
}
.kpi .val {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--txt-0);
  margin-top: 6px;
  letter-spacing: -.01em;
}
.kpi .delta {
  font-family: var(--mono);
  font-size: 11px;
  margin-top: 2px;
}
.kpi .spark {
  position: absolute;
  right: 12px; bottom: 10px;
  width: 60px; height: 22px;
  opacity: .8;
}

/* generic 2-col grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-portfolio { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }
.grid-risk { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-bt { display: grid; grid-template-columns: 1.6fr 1fr; gap: 12px; }
.span-2 { grid-column: 1 / -1; }

/* allocation bar */
.alloc-list { display: flex; flex-direction: column; }
.alloc-row {
  display: grid;
  grid-template-columns: 70px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11.5px;
}
.alloc-row:last-child { border-bottom: none; }
.alloc-row .sym { color: var(--txt-0); font-weight: 600; }
.alloc-bar {
  position: relative;
  height: 8px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
}
.alloc-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--acc), rgba(255,46,68,.5));
  box-shadow: 0 0 6px var(--acc-glow);
}
.alloc-row .pct { color: var(--txt-0); min-width: 48px; text-align: right; }
.alloc-row .amt { color: var(--txt-2); font-size: 10.5px; min-width: 70px; text-align: right; }

/* heat dot */
.heat-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
}

/* equity curve / chart base */
.curve-wrap { position: relative; height: 280px; padding: 0; }
.curve-wrap svg { width: 100%; height: 100%; display: block; }
.curve-overlay {
  position: absolute; top: 12px; left: 14px;
  font-family: var(--mono); font-size: 10.5px; color: var(--txt-2);
}
.curve-overlay b { color: var(--txt-0); }

/* mini-chart embedded in cards */
.mini-chart { width: 100%; height: 80px; display: block; }

/* heatmap (correlation) */
.heatmap {
  display: grid;
  gap: 1px;
  padding: 14px;
  background: var(--line);
  border-radius: 0;
}
.hm-cell {
  background: var(--bg-1);
  font-family: var(--mono);
  font-size: 10.5px;
  text-align: center;
  padding: 8px 0;
  color: var(--txt-1);
  position: relative;
}
.hm-cell.head { color: var(--txt-3); background: var(--bg-2); font-size: 9.5px; letter-spacing: .1em; }

/* risk gauge (semi-circle) */
.gauge { display: flex; flex-direction: column; align-items: center; padding: 18px 14px; }
.gauge svg { display: block; }
.gauge-label {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--txt-3);
  letter-spacing: .2em;
  text-transform: uppercase;
  margin-top: 8px;
}
.gauge-value {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 600;
  color: var(--txt-0);
  margin-top: 2px;
}
.gauge-status {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .15em;
  text-transform: uppercase;
  margin-top: 4px;
}

/* risk limit row */
.limit-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.limit-row:last-child { border-bottom: none; }
.limit-row .lname {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--txt-0);
}
.limit-row .ldesc {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--txt-3);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-top: 2px;
}
.limit-row .lprog {
  margin-top: 6px;
  height: 4px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  position: relative;
}
.limit-row .lprog .fill { height: 100%; }
.limit-row .lprog .fill.ok   { background: var(--pos); box-shadow: 0 0 4px var(--pos-glow); }
.limit-row .lprog .fill.warn { background: var(--warn); box-shadow: 0 0 4px var(--warn-glow); }
.limit-row .lprog .fill.crit { background: var(--neg); box-shadow: 0 0 4px var(--acc-glow); }
.limit-row .lval {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--txt-0);
  text-align: right;
}
.limit-row .lcap {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--txt-3);
  text-align: right;
}

/* status badges */
.badge {
  font-family: var(--mono);
  font-size: 9.5px;
  padding: 2px 7px;
  border: 1px solid;
  letter-spacing: .12em;
  text-transform: uppercase;
  border-radius: 2px;
  display: inline-block;
}
.badge.ok    { color: var(--pos);  border-color: rgba(0,255,157,.3); background: rgba(0,255,157,.05); }
.badge.warn  { color: var(--warn); border-color: rgba(255,176,32,.3); background: rgba(255,176,32,.05); }
.badge.crit  { color: var(--neg);  border-color: rgba(255,46,68,.3); background: rgba(255,46,68,.05); }
.badge.info  { color: var(--info); border-color: rgba(0,217,255,.3); background: rgba(0,217,255,.05); }
.badge.neutral { color: var(--txt-2); border-color: var(--line-2); background: var(--bg-3); }

/* page main grid */
.page-grid { display: grid; gap: 12px; }
