:root {
  --bg-01: #0b0e14; /* deep slate */
  --bg-02: #141a24;
  --card: #0f1720;
  --muted: #9aa3b2;
  --text: #e6eef6;
  --pnl-pos: #2dd36f; /* emerald */
  --pnl-neg: #ff4d4f; /* crimson */
  --accent: #2563eb;
  --glass: rgba(255,255,255,0.03);
  --border: rgba(255,255,255,0.06);
  --flash-bg: rgba(255,255,255,0.04);
  --radius-lg: 12px;
}

* { box-sizing: border-box; }


body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg,var(--bg-01),var(--bg-02));
  color: var(--text);
  -webkit-font-smoothing:antialiased;
}

.container {
  max-width: 1440px;
  margin: 24px auto;
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "header"
    "tabs"
    "controls"
    "summary"
    "runs"
    "table";
  gap: 12px 20px;
}

.topbar { grid-area: header; display:flex; align-items:center; gap:12px; }
.topbar h1 { font-size:20px; margin:0; color:var(--text); }

.controls-grid { grid-area: controls; }

.controls { display:flex; align-items:center; gap:12px; flex-wrap:wrap; background:var(--glass); border-radius: var(--radius-lg); padding:12px; border:1px solid var(--border); }
.selector-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(72px, .7fr);
  gap: 10px;
  flex: 1 0 100%;
  min-width: 0;
}
.selector-control { display:flex; flex-direction:column; align-items:stretch; gap:4px; min-width:0; }
.controls .selector-control select { width:100%; min-width:0; }
.selector-control .live-equity-picker:not([hidden]) { display:flex; flex-direction:column; align-items:stretch; gap:6px; }
.selector-control .live-equity-picker .combo input { width:100%; min-width:0; }
.selector-control .live-equity-picker select { width:100%; }


.controls label { font-size:13px; color:var(--muted); }
.controls select { min-width:160px; padding:8px 10px; border-radius:8px; background:#151a20; color:var(--text); border:1px solid var(--border); }

/* The native option popup draws on a light system background, so the light
   --text colour needs an explicit dark one beside it or the list is unreadable.
   Global (not scoped to .controls) so every dropdown on both pages matches. */
select option { background:#151a20; color:var(--text); }

.volume input { width:90px; padding:6px 8px; border-radius:8px; border:1px solid var(--border); background:transparent; color:var(--text); }


.refresh-note {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.refresh-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.refresh-button:hover { background: rgba(255,255,255,0.09); }
.refresh-button:active { transform: translateY(1px); }

.summary {
  grid-area: summary;
  display:grid;
  grid-template-columns:repeat(4, minmax(0, 1fr));
  gap:8px;
  align-self:stretch;
}

.stat-card { min-width:0; background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01)); border-radius:10px; padding:12px 14px; border:1px solid var(--border); }
.stat-card.large { padding:12px 14px; font-size:inherit; }
.funds-card { min-width:0; padding:10px 12px; border-radius:8px; background:rgba(255,255,255,0.02); border:1px dashed rgba(255,255,255,0.03); }

.stat-label {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.stat-value {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

table { width:100%; border-collapse:collapse; table-layout:fixed; font-size:13px; background:transparent; border-radius:8px; overflow:hidden; }

thead th { position: sticky; top:0; background: rgba(255,255,255,0.02); text-align:left; padding:10px 12px; border-bottom:1px solid var(--border); font-weight:600; color:var(--muted); }

th.num { text-align: right; }

/* Click-to-sort column header. The button (not the th) carries the click so the
   control is reachable by keyboard; the th keeps aria-sort for screen readers. */
thead th.sortable { padding: 0; }
thead th.sortable .sort-btn {
  display: flex; align-items: center; gap: 6px;
  width: 100%; padding: 10px 12px;
  font: inherit; font-weight: 600; color: inherit; text-align: left;
  background: none; border: 0; cursor: pointer;
}
thead th.sortable .sort-btn:hover { color: var(--text); }
thead th.sortable .sort-caret { font-size: 10px; opacity: 0.75; }

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}

tbody tr:nth-child(even) { background: rgba(255,255,255,0.015); }

td.num { text-align: right; }

td.flash { transition: background-color 0.22s ease; background-color: var(--flash-bg); }

td.entry-updated { line-height: 1.3; white-space: nowrap; }
td.entry-updated .eu-entry,
td.entry-updated .eu-updated { display: block; font-size: 0.78em; }
td.entry-updated .eu-entry { color: var(--muted); }

/* Segmented control */
.segmented { display:inline-flex; background:rgba(255,255,255,0.02); border-radius:999px; padding:4px; border:1px solid var(--border); }
.seg-btn { border:0; padding:8px 14px; border-radius:999px; background:transparent; color:var(--muted); font-weight:700; cursor:pointer; transition: transform .12s ease, box-shadow .12s ease; }
.seg-btn.active { color:var(--text); box-shadow:0 6px 18px rgba(0,0,0,0.35); }
.seg-btn[data-side="BUY"].active { background: linear-gradient(180deg, rgba(45,211,111,0.14), rgba(45,211,111,0.06)); color:var(--pnl-pos); }
.seg-btn[data-side="SELL"].active { background: linear-gradient(180deg, rgba(255,77,79,0.12), rgba(255,77,79,0.05)); color:var(--pnl-neg); }

/* Primary button */
.primary { background: linear-gradient(90deg,var(--accent),#5b9cff); color: white; border: none; padding:10px 14px; border-radius:10px; cursor:pointer; box-shadow:0 6px 16px rgba(37,99,235,0.16); transition: transform .12s ease, box-shadow .12s ease; }
.primary:disabled { background: rgba(255,255,255,0.12); color: var(--muted); cursor: not-allowed; box-shadow: none; }
.primary:active { transform: translateY(1px) scale(.998); }
.primary.pulse { animation: pulse .45s ease; }

@keyframes pulse { 0% { transform:scale(1); } 50% { transform:scale(0.98); } 100% { transform:scale(1); } }

/* Secondary button */
.secondary {
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}

.secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary.running {
  background: rgba(255, 77, 79, 0.16);
  color: var(--pnl-neg);
  border-color: rgba(255, 77, 79, 0.55);
  box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.12);
}

.secondary:not(:disabled):active {
  transform: translateY(1px);
}

/* Responsive */
@media (max-width: 980px) {
  .container { grid-template-columns: minmax(0, 1fr); padding:16px; }
  .controls-grid { grid-template-columns: 1fr; }
  .stat-card { padding:10px 8px; }
  .stat-card.large { padding:10px 8px; }
  .funds-card { padding:8px; }
  .stat-label { font-size:10px; line-height:1.2; }
  .stat-value { font-size:16px; }
  .stat-sub { font-size:10px; line-height:1.2; }
  .funds-card .stat-value { font-size:12px; white-space:nowrap; }

  .run-card { flex-direction: column; align-items: stretch; gap: 10px; }
  .run-actions { flex-wrap: wrap; }
  .run-actions button {
    flex: 1 1 calc(50% - 8px);
    min-height: 40px;
    padding: 8px 10px;
  }
}

@media (max-width: 480px) {
  .topbar { flex-wrap:wrap; }
  .topbar h1 { flex:1 0 100%; }
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 220px;
  max-width: 320px;
  background: rgba(15, 23, 32, 0.92);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success { border-left-color: var(--pnl-pos); }
.toast.error { border-left-color: var(--pnl-neg); }

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 10px;
  font-weight: 700;
  border: 1px solid var(--border);
}

.status-badge.running {
  background: rgba(45, 211, 111, 0.12);
  color: var(--pnl-pos);
  border-color: rgba(45, 211, 111, 0.32);
}

.status-badge.stopped {
  background: rgba(255, 77, 79, 0.12);
  color: var(--pnl-neg);
  border-color: rgba(255, 77, 79, 0.32);
}

.table-wrap {
  grid-area: table;
  width: 100%;
  display: block;
  margin-top: 0;
}

.table-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.table-header h2 {
  margin: 0 auto 0 0;
  font-size: 16px;
}

.table-header label {
  font-size: 13px;
  color: var(--muted);
}

.table-header input {
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.table {
  margin-top: 0;
}

/* Trades table: full-width with horizontal scroll instead of cramped columns */
.table-scroll { overflow-x: auto; width: 100%; }
.table-wrap table { min-width: 1080px; }
.table-wrap th, .table-wrap td { white-space: nowrap; }

/* Mode segmented (Simulation / Live Trade) + trade filter */
.seg-btn[data-mode="sim"].active { background: linear-gradient(180deg, rgba(37,99,235,0.16), rgba(37,99,235,0.06)); color: var(--accent); }
.seg-btn[data-mode="trade"].active { background: linear-gradient(180deg, rgba(255,170,0,0.16), rgba(255,77,79,0.08)); color: #ffb020; }
.seg-btn[data-mode="trade"][disabled] { opacity: 0.45; cursor: not-allowed; }
.seg-btn[data-filter].active { background: rgba(255,255,255,0.06); color: var(--text); }

.run-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.clear-filter { padding: 6px 10px; }

.tf-wrap { display: inline-flex; align-items: center; gap: 8px; }

/* Active runs list */
.runs-wrap { grid-area: runs; width: 100%; margin-bottom: 6px; }
.runs-list { display: flex; flex-direction: column; gap: 8px; }
.runs-empty { color: var(--muted); font-size: 13px; margin: 4px 2px; }
.run-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--glass); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 10px 12px;
}
.run-card.starting { border-color: rgba(37,99,235,0.32); }
.run-card.running { border-color: rgba(45,211,111,0.32); }
.run-card.stopping { border-color: rgba(255,170,0,0.32); }
.run-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.run-title {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  font-weight: 700; font-size: 14px;
}
.run-name { margin-right: 2px; overflow-wrap: anywhere; }
.run-state { font-size: 12px; color: var(--muted); }
.run-parameters { font-size: 11px; }
.run-poll-wrap { display:flex; flex-direction:row; align-items:center; gap:8px; margin-top:6px; font-size:13px; color: var(--muted); }
.run-poll-wrap select { width:auto; min-width:90px; padding:6px 10px; border-radius:8px; background:#151a20; color:var(--text); border:1px solid var(--border); font-size:13px; cursor:pointer; }
.run-poll-wrap select:disabled { opacity:.55; cursor:not-allowed; }
.param-status { font-weight: 600; }
.param-status.pending { color: #ffb020; }
.param-status.approved { color: var(--pnl-pos); }
.param-status.rejected { color: var(--pnl-neg); }
.run-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.run-actions[hidden] { display: none; }
.run-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.run-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 22px rgba(37,99,235,0.16); }
.run-card.selectable { cursor: pointer; }
.run-stop { padding: 6px 14px; }
.danger {
  padding: 6px 14px; border-radius: 10px; cursor: pointer; font-weight: 700;
  color: #fff; border: 1px solid rgba(255,77,79,0.5);
  background: linear-gradient(180deg, rgba(255,77,79,0.9), rgba(220,38,38,0.9));
}
.danger:hover { filter: brightness(1.08); }
.danger:active { transform: translateY(1px); }

/* Per-trade Exit button: highlighted when the trade is open, greyed when closed */
.trade-exit {
  padding: 5px 12px; border-radius: 8px; font-weight: 700; cursor: pointer;
  color: #fff; border: 1px solid rgba(255,77,79,0.55);
  background: linear-gradient(180deg, rgba(255,77,79,0.95), rgba(220,38,38,0.95));
  box-shadow: 0 4px 12px rgba(255,77,79,0.25);
}
.trade-exit:hover { filter: brightness(1.08); }
.trade-exit:active { transform: translateY(1px); }
.trade-exit.is-closed, .trade-exit:disabled {
  background: rgba(255,255,255,0.06); color: var(--muted);
  border-color: var(--border); box-shadow: none; cursor: not-allowed; filter: none;
}

/* Mode tags */
.tag {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 999px; border: 1px solid var(--border); vertical-align: middle;
}
.tag-sim { background: rgba(37,99,235,0.12); color: var(--accent); border-color: rgba(37,99,235,0.32); }
.tag-trade { background: rgba(255,170,0,0.14); color: #ffb020; border-color: rgba(255,170,0,0.32); }
.tag-dump { background: rgba(255,255,255,0.06); color: var(--muted); }
.tag-tf { background: rgba(139,92,246,0.14); color: #a78bfa; border-color: rgba(139,92,246,0.32); }

/* Side tags (BUY/SELL) */
.tag-side {
  font-size: 9px; padding: 2px 6px;
}
.tag-buy { background: rgba(45,211,111,0.12); color: var(--pnl-pos); border-color: rgba(45,211,111,0.32); }
.tag-sell { background: rgba(255,77,79,0.12); color: var(--pnl-neg); border-color: rgba(255,77,79,0.32); }

/* Trade close reason */
.reason-tag {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.03em;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); text-transform: capitalize;
}
.reason-active { background: rgba(45,211,111,0.14); color: var(--pnl-pos); border-color: rgba(45,211,111,0.32); }
.reason-exit { background: rgba(255,77,79,0.14); color: var(--pnl-neg); border-color: rgba(255,77,79,0.32); }
.reason-signal { background: rgba(255,255,255,0.05); color: var(--muted); }

/* ---------------------------------------------------------------------------
   Tabbed data area: Trades | Investment & Profit
   --------------------------------------------------------------------------- */
.data-wrap { grid-area: table; width: 100%; display: block; }
.data-wrap table { width: 100%; }
/* Two extra cost columns over the old 10-column layout; keep per-column width. */
.data-wrap #tab-trades table { min-width: 1320px; }
.data-wrap #tab-trades th, .data-wrap #tab-trades td { white-space: nowrap; }
.data-wrap #tab-trades th:nth-child(2),
.data-wrap #tab-trades td:nth-child(2) { width: 210px; }
.data-wrap #tab-trades td.entry-updated { overflow: hidden; }

.filter-bar { flex-wrap: wrap; row-gap: 8px; }
.filter-bar select {
  padding: 7px 9px; border-radius: 8px; border: 1px solid var(--border);
  background: #151a20; color: var(--text);
  /* Without a cap the Strategy select stretches to its longest option label
     ("Bollinger momentum shift (filtered)") and dwarfs its neighbours. */
  min-width: 140px; max-width: 180px;
  text-overflow: ellipsis;
}

.tabs {
  display: flex; gap: 4px; margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.tab {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-weight: 700; font-size: 14px; padding: 10px 16px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .12s ease, border-color .12s ease;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel[hidden] { display: none; }

/* Summary card sub-lines (net-of-fee figures) */
.stat-sub { margin: 4px 0 0; font-size: 12px; color: var(--muted); font-weight: 600; }

/* Fee column sits quieter than the PnL columns it flanks */
.fee-cell { color: var(--muted); }

/* Explain a blank trades table rather than showing an empty box */
.table-empty td { text-align: center; color: var(--muted); padding: 22px 12px; }
.table-empty:nth-child(even) { background: transparent; }

/* ---------------------------------------------------------------------------
   Investment & Profit panel
   --------------------------------------------------------------------------- */
.invest-panel {
  background: var(--glass); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px;
}
.invest-panel .section-heading {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 10px;
}
.invest-panel .section-heading h2 { margin: 0; font-size: 16px; }
.invest-panel .section-heading span { color: var(--muted); font-size: 12px; text-align: right; }
.invest-panel .field-note { color: var(--muted); font-size: 12px; line-height: 1.55; margin: 0 0 14px; }

.invest-controls {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: 10px; align-items: end; margin: 0 0 16px;
}
.invest-controls label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.invest-controls input {
  width: 100%; padding: 8px 9px; border: 1px solid var(--border);
  border-radius: 7px; background: #151a20; color: var(--text);
}
.invest-controls input:focus { outline: 2px solid #76a8ff; outline-offset: 2px; }
.invest-panel .icon-button {
  align-self: end; padding: 8px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: rgba(255,255,255,0.04); color: var(--text);
}
.invest-panel .icon-button:hover { background: rgba(255,255,255,0.09); }

.invest-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin-bottom: 18px;
}
.invest-card {
  padding: 12px; border: 1px solid var(--border);
  background: rgba(255,255,255,0.025); border-radius: 8px;
}
.invest-card .kpi-label { color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.invest-card .kpi-value { font-size: 17px; font-weight: 700; }
.invest-native { font-size: 12px; color: var(--muted); margin-top: 3px; }
.invest-empty { color: var(--muted); font-size: 13px; margin: 8px 2px; }

/* Content-sized columns, unlike the fixed layout the trades table wants. */
.invest-table { width: 100%; border-collapse: collapse; table-layout: auto; }
.invest-breakdown .invest-table { min-width: 900px; }
.invest-table th, .invest-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  font-size: 13px; text-align: left; white-space: nowrap;
}
.invest-table th { color: var(--muted); font-weight: 600; }
.invest-table th.num, .invest-table td.num { text-align: right; }
.invest-table tr.proj-selected td { background: rgba(118,168,255,0.10); font-weight: 600; }
.invest-table tr.invest-total td {
  border-top: 1px solid var(--border); border-bottom: 0;
  font-weight: 700; background: rgba(255,255,255,0.02);
}

.invest-breakdown, .invest-projection { margin-top: 18px; }
.invest-tiers { margin: 0 0 12px; }
.invest-tiers label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.invest-tiers input {
  width: 100%; max-width: 340px; padding: 8px 9px; border: 1px solid var(--border);
  border-radius: 7px; background: #151a20; color: var(--text);
}
.invest-tiers input:focus { outline: 2px solid #76a8ff; outline-offset: 2px; }

.positive { color: var(--pnl-pos); }
.negative { color: var(--pnl-neg); }

@media (max-width: 980px) {
  .invest-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .invest-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}


/* ---------------------------------------------------------------------------
   Live trading. Everything here is deliberately loud: these controls move real
   money, so they should not look like the simulation controls.
   --------------------------------------------------------------------------- */

.live-banner {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: rgba(255,170,0,0.14);
  color: #ffb020;
  border: 1px solid rgba(255,170,0,0.45);
}

.live-banner[hidden] { display: none; }

.trade-wrap { display: inline-flex; align-items: center; gap: 8px; }
.trade-wrap input { width: 72px; }
.leverage-note { font-size: 12px; color: var(--muted); white-space: nowrap; }
.leverage-note.warn { color: #ffb020; font-weight: 600; }
.exit-note { font-size: 12px; color: var(--muted); white-space: nowrap; }

@media (max-width: 480px) {
  .trade-wrap { flex: 1 1 100%; flex-wrap: wrap; min-width: 0; }
  .leverage-note { flex: 1 1 100%; min-width: 0; white-space: normal; }
}

.run-card.live-trade { border-left: 3px solid #ffb020; }
.tag-broker { background: rgba(255,255,255,0.06); color: var(--muted); }
.tag-unknown { background: rgba(255,255,255,0.06); color: var(--muted); font-style: italic; }
.tag-mismatch {
  background: rgba(255,77,79,0.16);
  color: var(--pnl-neg);
  border-color: rgba(255,77,79,0.5);
  font-weight: 700;
}

/* A real commission, marked so it reads differently from the estimate beside it. */
.fee-cell.fee-real { color: #ffb020; }

.row-orphaned { background: rgba(255,77,79,0.07); }
.reason-tag.reason-orphaned {
  background: rgba(255,77,79,0.18);
  color: var(--pnl-neg);
  font-weight: 700;
}

/* Typed-confirmation dialog. */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.62);
}
.modal-backdrop.trade-authorization { z-index: 61; }
.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow: auto;
  padding: 20px 22px;
  border-radius: 12px;
  background: var(--panel, #12151c);
  border: 1px solid rgba(255,170,0,0.45);
  box-shadow: 0 24px 60px rgba(0,0,0,0.55);
}
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal-warn { margin: 0 0 14px; color: #ffb020; font-size: 13px; }
.modal label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.modal input[type="text"] {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.modal-actions button { padding: 8px 16px; border-radius: 8px; cursor: pointer; }
.modal-actions .danger {
  color: #fff;
  font-weight: 700;
  background: linear-gradient(180deg, #e03131, #b52626);
  border: 1px solid rgba(255,77,79,0.6);
}
.modal-actions .danger:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.6); }
.confirm-dialog .modal-warn { white-space: pre-line; font-size: 14px; }
.confirm-dialog .confirm-ok {
  color: #fff;
  font-weight: 700;
  background: linear-gradient(180deg, #e0a000, #b57d00);
  border: 1px solid rgba(255,170,0,0.6);
}

.preflight { border-top: 1px solid rgba(255,255,255,0.08); }
.pf-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.pf-row > span:first-child { color: var(--muted); }
.pf-row .warn { color: #ffb020; font-weight: 600; }
.pf-row .ok { color: var(--pnl-pos); font-weight: 600; }
.pf-alert {
  margin: 12px 0 0;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 13px;
  background: rgba(255,77,79,0.12);
  color: #ff8787;
  border: 1px solid rgba(255,77,79,0.38);
}
.modify-status { min-height: 18px; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.modify-status.rejected { color: var(--pnl-neg); }

/* A run with no heartbeat that may still be alive and trading. Loud on purpose:
   this is the state that most urgently needs a Stop. */
.run-card.stale {
  border-left: 3px solid var(--pnl-neg);
  background: rgba(255,77,79,0.06);
}

/* ---------------------------------------------------------------------------
   KEEP THIS LAST.

   The `hidden` attribute works only through the UA rule `[hidden]{display:none}`,
   which ANY author `display` declaration outranks. Several controls here set a
   display (inline-flex for the control groups, flex for the modal backdrop), so
   they rendered while marked hidden -- which left the live-trade confirmation
   dialog permanently on screen with an empty body and a dead confirm button.

   Declared last as well as !important so it wins on source order too. That
   matters beyond pedantry: jsdom (which drives tests/ui/live_trade_ui.mjs)
   ignores !important and applies last-declaration-wins, so a rule placed earlier
   is correct in a browser but untestable here. Anything appended after this can
   re-break every hidden element on the page.
   --------------------------------------------------------------------------- */
[hidden] { display: none !important; }

.tag-paused { background: rgba(217,119,6,0.14); color: #b45309; border-color: rgba(217,119,6,0.4); }

/* Market tabs + equity ticker combobox */
.market-tabs { margin: 4px 0 10px; }
.market-tabs .tab { padding: 8px 12px; font-size: 13px; }
.equity-picker[hidden], .equity-fields[hidden], .combo-list[hidden] { display: none; }
.combo-row { display: grid; grid-template-columns: 1fr 96px; gap: 8px; }
.combo { position: relative; }
.combo-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; max-height: 280px; overflow-y: auto; background: #151a20; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 28px rgba(0, 0, 0, .45); }
.combo-option { display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 10px; padding: 7px 9px; border-radius: 6px; cursor: pointer; }
.combo-option strong { font-size: 13px; }
.combo-option span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-option em { font-style: normal; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }
.combo-option.active, .combo-option:hover { background: rgba(118, 168, 255, .16); }
.combo-empty { padding: 8px 10px; color: var(--muted); font-size: 12px; }
.data-notice { color: #e6b450; }

/* Live dashboard: page-level market tabs and the inline ticker picker */
.page-market-tabs { grid-area: tabs; margin: 0; }
.live-equity-picker { display: inline-flex; align-items: center; gap: 8px; }
.live-equity-picker[hidden] { display: none; }
.live-equity-picker .combo input { min-width: 190px; padding: 8px 10px; border-radius: 8px; background: #151a20; color: var(--text); border: 1px solid var(--border); }
.live-equity-picker .combo input::placeholder { color: var(--muted); }
.live-equity-picker .combo input:focus { outline: 2px solid #76a8ff; outline-offset: 2px; }
.equity-badge { color: var(--muted); font-size: 12px; }
.market-note { color: var(--muted); font-size: 12px; margin-left: 8px; }
