:root {
  /* Dark (default) */
  --bg: #0b0e14; --panel: #141922; --panel2: #1c2330; --line: #29313d;
  --text: #e6edf3; --muted: #8b949e; --accent: #3b82f6;
  --green: #26a269; --red: #e5534b; --amber: #d29922;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.18);
}
:root[data-theme="light"] {
  --bg: #f4f6fb; --panel: #ffffff; --panel2: #eef2f8; --line: #dce2ec;
  --text: #1a2332; --muted: #667085; --accent: #2563eb;
  --green: #16a34a; --red: #dc2626; --amber: #d97706;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 6px 20px rgba(16,24,40,.06);
}
:root[data-theme="midnight"] {
  --bg: #080c18; --panel: #101728; --panel2: #182136; --line: #24314d;
  --text: #e7edf9; --muted: #8695ba; --accent: #6d8bff;
  --green: #34d399; --red: #f87171; --amber: #fbbf24;
  --shadow: 0 2px 6px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.35);
}
:root[data-theme="nord"] {
  --bg: #2e3440; --panel: #3b4252; --panel2: #434c5e; --line: #4c566a;
  --text: #eceff4; --muted: #a7b1c2; --accent: #88c0d0;
  --green: #a3be8c; --red: #bf616a; --amber: #ebcb8b;
  --shadow: 0 2px 6px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.22);
}
:root[data-theme="dracula"] {
  --bg: #282a36; --panel: #343746; --panel2: #3d4055; --line: #44475a;
  --text: #f8f8f2; --muted: #9aa0bd; --accent: #bd93f9;
  --green: #50fa7b; --red: #ff5555; --amber: #f1fa8c;
  --shadow: 0 2px 6px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.25);
}
:root[data-theme="ocean"] {
  --bg: #0b1622; --panel: #11202f; --panel2: #16283a; --line: #23384f;
  --text: #dbe9f4; --muted: #82a0ba; --accent: #2dd4bf;
  --green: #34d399; --red: #fb7185; --amber: #fbbf24;
  --shadow: 0 2px 6px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
}
:root[data-theme="rose"] {
  --bg: #191724; --panel: #1f1d2e; --panel2: #272442; --line: #3d3a5a;
  --text: #e0def4; --muted: #a29fc4; --accent: #c4a7e7;
  --green: #9ccfd8; --red: #eb6f92; --amber: #f6c177;
  --shadow: 0 2px 6px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.25);
}
:root[data-theme="solar"] {
  --bg: #fdf6e3; --panel: #fffbef; --panel2: #eee8d5; --line: #ddd6c1;
  --text: #073642; --muted: #657b83; --accent: #268bd2;
  --green: #859900; --red: #dc322f; --amber: #b58900;
  --shadow: 0 1px 2px rgba(80,60,30,.08), 0 6px 20px rgba(80,60,30,.08);
}

:root { --radius: 12px; --radius-sm: 8px; --sb-w: 226px; }
* { box-sizing: border-box; }
/* The HTML `hidden` attribute must always win. Component rules like
   `.daily-banner { display: flex }` otherwise override the UA default and leave
   `hidden` elements (the alert banners) stuck visible. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
body, .card, table, .panel, input, select, .btn, .pill, .tab, .conv-list, .chat-log {
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}
/* themed scrollbars */
* { scrollbar-color: var(--line) transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- app shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sb-w); flex: 0 0 var(--sb-w); background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  gap: 4px; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 20px; font-weight: 800; letter-spacing: .2px; padding: 4px 10px 18px; }
.brand span { color: var(--accent); }
.tabs { display: flex; flex-direction: column; gap: 2px; }
.tab {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: none; border: none; color: var(--muted); padding: 10px 12px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; font-weight: 500;
}
.tab:hover { background: var(--panel2); color: var(--text); }
.tab.active {
  color: var(--accent); font-weight: 600; background: var(--panel2);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.nav-ico { width: 18px; height: 18px; flex: 0 0 18px; }
.sidebar-foot {
  margin-top: auto; display: flex; flex-direction: column; gap: 8px;
  padding-top: 14px; border-top: 1px solid var(--line);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 26px; border-bottom: 1px solid var(--line);
  background: var(--panel);
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.status { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.content { padding: 24px 26px; width: 100%; max-width: 1320px; }

/* ---------- pills / status ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 7px; background: var(--panel2);
  border: 1px solid var(--line); color: var(--muted); padding: 4px 11px;
  border-radius: 999px; font-size: 12px; font-weight: 500;
}
.pill.live { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.pill.paused { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 45%, var(--line)); }
.pill.live::before, .pill.paused::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 7px currentColor;
}
.muted { color: var(--muted); font-size: 12px; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: 0 0 9px; }
.live-dot.on { background: var(--green); animation: live-pulse 1.6s ease-in-out infinite; }
@keyframes live-pulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 60%, transparent); } 50% { box-shadow: 0 0 0 5px transparent; } }
@media (prefers-reduced-motion: reduce) { .live-dot.on { animation: none; } }
.theme-select {
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  padding: 7px 10px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; width: 100%;
}

/* ---------- panels / headings ---------- */
.panel { display: none; }
.panel.active { display: block; animation: fadein .22s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
h3 {
  margin: 28px 0 12px; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .6px; font-weight: 600;
}
h4 { margin: 20px 0 10px; font-size: 13px; font-weight: 600; }
.panel > h3:first-child { margin-top: 4px; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); gap: 14px; }
.analytics-cards { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .12s ease, border-color .2s ease;
}
.card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent); opacity: 0; transition: opacity .2s ease;
}
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.card:hover::before { opacity: .75; }
.card .k { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.card .v { font-size: 26px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.card .v.big { font-size: 22px; }

/* value change flash (count-up cells) */
@keyframes flash-up-kf { 0% { color: var(--green); } 100% { color: inherit; } }
@keyframes flash-down-kf { 0% { color: var(--red); } 100% { color: inherit; } }
.flash-up { animation: flash-up-kf .7s ease-out; }
.flash-down { animation: flash-down-kf .7s ease-out; }

/* skeleton shimmer while loading */
.skeleton, .sk {
  position: relative; color: transparent !important; border-radius: 6px;
  background: linear-gradient(90deg, var(--panel2) 25%, var(--line) 37%, var(--panel2) 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) {
  .flash-up, .flash-down, .skeleton, .sk, .panel.active { animation: none !important; }
}

/* ---------- tables ---------- */
table {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; background: var(--panel2); }
tbody tr { transition: background-color .12s ease; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
tbody tr.row-click { cursor: pointer; }
tr:last-child td { border-bottom: none; }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }
.side-long { color: var(--green); font-weight: 600; }
.side-short { color: var(--red); font-weight: 600; }
.flat { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  padding: 8px 15px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; font-weight: 500; line-height: 1.2;
}
.btn { transition: background-color .15s ease, border-color .15s ease, transform .08s ease; }
.btn:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--panel2)); }
.btn:active { transform: scale(.96); }
.btn.ok { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ok:hover { filter: brightness(1.08); background: var(--green); }
.btn.warn { border-color: var(--amber); color: var(--amber); }
.btn.warn:hover { background: color-mix(in srgb, var(--amber) 14%, transparent); }
.btn.danger { border-color: color-mix(in srgb, var(--red) 55%, var(--line)); color: var(--red); }
.btn.danger:hover { background: color-mix(in srgb, var(--red) 15%, transparent); }
.btn.sm { padding: 5px 11px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
.control-row { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- forms ---------- */
.form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px;
  align-items: end; max-width: 680px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.form-grid h3 { grid-column: 1 / -1; margin: 0; }
.form-grid h4 { grid-column: 1 / -1; margin: 6px 0 0; }
.form-grid > .btn, .form-grid > button { justify-self: start; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 500; }
input, select {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  padding: 9px 11px; border-radius: var(--radius-sm); font-size: 13px; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[readonly] { color: var(--muted); }

/* ---------- analytics filter / calendar ---------- */
.analytics-filter {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.analytics-filter label { flex-direction: row; align-items: center; gap: 7px; color: var(--muted); }
.analytics-filter .spacer { flex: 1; }
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cal-title { font-weight: 600; min-width: 150px; text-align: center; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; color: var(--muted); font-size: 11px; text-transform: uppercase; padding: 2px 0; }
.cal-cell {
  min-height: 60px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 7px; background: var(--panel); display: flex; flex-direction: column;
}
.cal-cell.empty { background: transparent; border: none; }
.cal-cell .d { font-size: 11px; color: var(--muted); }
.cal-cell .p { margin-top: auto; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-cell.pos { background: color-mix(in srgb, var(--green) 15%, var(--panel)); border-color: color-mix(in srgb, var(--green) 50%, var(--line)); }
.cal-cell.neg { background: color-mix(in srgb, var(--red) 15%, var(--panel)); border-color: color-mix(in srgb, var(--red) 50%, var(--line)); }

/* ---------- system status strip + setup checklist ---------- */
.status-strip { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.stat-chip {
  display: flex; align-items: center; gap: 8px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 14px;
  box-shadow: var(--shadow); font-size: 13px;
}
.stat-chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: 0 0 9px; }
.stat-chip.ok .dot { background: var(--green); box-shadow: 0 0 7px var(--green); }
.stat-chip.warn .dot { background: var(--amber); box-shadow: 0 0 7px var(--amber); }
.stat-chip.bad .dot { background: var(--red); box-shadow: 0 0 7px var(--red); }
.stat-chip .lbl { color: var(--muted); }
.stat-chip .val { font-weight: 600; }

.setup-card {
  flex-direction: column; gap: 9px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.setup-card h4 { margin: 0 0 4px; font-size: 13px; }
.setup-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.setup-row .mark {
  width: 19px; height: 19px; flex: 0 0 19px; display: inline-flex; align-items: center;
  justify-content: center; border-radius: 50%; font-size: 12px; font-weight: 700;
}
.setup-row.done .mark { background: color-mix(in srgb, var(--green) 25%, transparent); color: var(--green); }
.setup-row.todo .mark { background: color-mix(in srgb, var(--amber) 25%, transparent); color: var(--amber); }
.setup-row.info .mark { background: var(--panel2); color: var(--muted); }
.setup-row .s-hint { color: var(--muted); font-size: 12px; }

/* ---------- collapsible section headers ---------- */
.panel > h3.collapsible { cursor: pointer; user-select: none; display: flex; align-items: center; }
.panel > h3.collapsible::before {
  content: "▾"; display: inline-block; margin-right: 7px; font-size: 10px;
  color: var(--muted); transition: transform .15s ease;
}
.panel > h3.collapsible.collapsed::before { transform: rotate(-90deg); }
.panel > h3.collapsible:hover { color: var(--text); }
.sec-hidden { display: none !important; }

/* ---------- today summary strip ---------- */
.today-strip {
  display: flex; flex-wrap: wrap; gap: 22px; margin: 16px 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 18px; box-shadow: var(--shadow);
}
.ts-item { display: flex; flex-direction: column; gap: 2px; }
.ts-item span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.ts-item b { font-size: 16px; font-variant-numeric: tabular-nums; }
.ts-item .tv.pos { color: var(--green); } .ts-item .tv.neg { color: var(--red); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- compact density ---------- */
body.compact .card { padding: 12px; }
body.compact .card .v { font-size: 22px; }
body.compact th, body.compact td { padding: 6px 10px; }
body.compact .content { padding: 16px 18px; }
body.compact .today-strip { padding: 9px 14px; gap: 16px; }
body.compact h3 { margin: 16px 0 8px; }

/* ---------- markets: mini price cards + sparklines ---------- */
.markets { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.mkt-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer;
  transition: transform .12s ease, border-color .2s ease;
}
.mkt-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.mkt-top { display: flex; justify-content: space-between; align-items: baseline; }
.mkt-name { font-weight: 600; text-transform: capitalize; }
.mkt-sym { color: var(--muted); font-size: 11px; }
.mkt-price { font-size: 18px; font-weight: 700; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.mkt-chg { font-size: 12px; font-weight: 600; }
.mkt-spark { margin-top: 6px; height: 34px; }
.mkt-spark svg { width: 100%; height: 34px; display: block; }
.mkt-pos-badge { font-size: 10px; padding: 1px 6px; border-radius: 999px; border: 1px solid currentColor; }

/* ---------- risk: liquidation bar ---------- */
.liq-wrap { min-width: 180px; }
.liq-bar {
  position: relative; height: 10px; border-radius: 6px; overflow: hidden;
  background: var(--panel2); border: 1px solid var(--line);
}
.liq-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px 0 0 6px; }
.liq-fill.ok { background: var(--green); }
.liq-fill.warn { background: var(--amber); }
.liq-fill.bad { background: var(--red); }
.liq-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--red); opacity: .85; }
.liq-mark::after {
  content: "⚑"; position: absolute; top: -15px; left: -5px; font-size: 11px; color: var(--red);
}
.liq-label { font-size: 11px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ---------- charts get a card frame ---------- */
canvas { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
/* ...but NOT the LightweightCharts price charts: they layer several absolutely-
   positioned canvases, and the frame above (opaque background + padding) makes the
   top crosshair-overlay canvas cover the candle canvas beneath it and shifts the
   drawing — leaving the chart blank. Reset those canvases to bare. */
#pc-chart canvas, #st-chart canvas { background: none; border: 0; border-radius: 0; padding: 0; box-shadow: none; }

/* ---------- notification center ---------- */
.notif-wrap { position: relative; }
.notif-bell {
  position: relative; background: var(--panel2); border: 1px solid var(--line);
  color: var(--muted); width: 34px; height: 34px; border-radius: var(--radius-sm);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.notif-bell:hover { border-color: var(--accent); color: var(--text); }
.notif-badge {
  position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 4px;
}
.notif-panel {
  position: absolute; right: 0; top: 42px; width: 320px; max-height: 62vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); display: none; z-index: 40;
}
.notif-panel.show { display: block; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.notif-list { padding: 6px; }
.notif-item { display: flex; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); font-size: 13px; }
.notif-item:hover { background: var(--panel2); }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--muted); flex: 0 0 8px; }
.notif-item.success .notif-dot { background: var(--green); }
.notif-item.warn .notif-dot { background: var(--amber); }
.notif-item.danger .notif-dot { background: var(--red); }
.notif-item.info .notif-dot { background: var(--accent); }

/* ---------- hover tooltips (data-tip) ---------- */
.tip-pop {
  position: fixed; z-index: 80; max-width: 260px; pointer-events: none;
  background: var(--panel2); color: var(--text); border: 1px solid var(--accent);
  border-radius: 8px; padding: 8px 11px; font-size: 12px; line-height: 1.45;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(3px);
  transition: opacity .12s ease, transform .12s ease;
}
.tip-pop.show { opacity: 1; transform: translateY(0); }

/* ---------- confirm modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; padding: 20px;
  display: none; align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; animation: fadein .15s ease; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; width: 440px; max-width: 100%;
}
.modal h3 { margin: 0 0 4px; font-size: 15px; color: var(--text); text-transform: none; letter-spacing: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.preview-grid { display: grid; grid-template-columns: 1fr; gap: 0; margin: 14px 0 4px; }
.preview-grid > div {
  display: flex; justify-content: space-between; gap: 14px; padding: 8px 0;
  border-bottom: 1px solid var(--line); font-size: 13px; font-variant-numeric: tabular-nums;
}
.preview-grid span { color: var(--muted); }
.form-col { display: flex; flex-direction: column; gap: 12px; margin: 14px 0 2px; }

/* ---------- daily loss circuit-breaker banner ---------- */
.daily-banner {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 0 0 14px; padding: 12px 16px; border-radius: 10px;
  background: rgba(220, 38, 38, .12); border: 1px solid rgba(220, 38, 38, .5);
  color: var(--text); font-size: 14px;
}
.daily-banner.warn-only {
  background: rgba(234, 179, 8, .12); border-color: rgba(234, 179, 8, .5);
}
.daily-banner .db-text { flex: 1; min-width: 240px; }
.daily-banner.warn-only #db-resume { display: none; }

/* ---------- correlation / diversification warnings ---------- */
.corr-warning {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 8px; padding: 10px 14px; border-radius: 10px;
  background: rgba(234, 179, 8, .12); border: 1px solid rgba(234, 179, 8, .5);
  color: var(--text); font-size: 13px;
}
.corr-warning b { font-variant-numeric: tabular-nums; }

.cooldown-tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 10px;
  font-size: 11px; background: rgba(234, 179, 8, .18); color: var(--text);
  border: 1px solid rgba(234, 179, 8, .5); font-variant-numeric: tabular-nums;
}

/* ---------- settings: basic/advanced + change markers ---------- */
.form-grid .adv { display: none; }
.form-grid.show-adv .adv { display: flex; }
label.changed::before { content: "● "; color: var(--amber); font-size: 11px; }
#settings-changed.has-changes { color: var(--amber); }

/* ---------- strategy preset picker ---------- */
.preset-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.preset-card { text-align: left; padding: 12px 13px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg); color: var(--text); font: inherit;
  cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .05s; }
.preset-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.preset-card:active { transform: translateY(1px); }
.preset-card .p-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.preset-card .p-desc { color: var(--muted); font-size: 11.5px; margin-top: 5px; line-height: 1.4; }
.preset-card .p-vals { color: var(--muted); font-size: 11px; margin-top: 8px; font-family: var(--mono, monospace); }
.preset-card.active { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
.preset-card .p-badge { font-size: 10px; font-weight: 600; color: var(--green); border: 1px solid var(--green);
  border-radius: 999px; padding: 1px 7px; }
.preset-card:not(.active) .p-badge { display: none; }

/* ---------- strategy monitor ---------- */
.strat-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.strat-method { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--accent); color: var(--accent); }
.pill.warn { border-color: var(--amber); color: var(--amber); }
.strat-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
@media (max-width: 820px) { .strat-cols { grid-template-columns: 1fr; } }
.strat-steps { margin: 6px 0 0; padding-left: 0; list-style: none; }
.strat-steps li { margin: 0 0 11px; }
.strat-steps .s-title { font-weight: 600; font-size: 13.5px; }
.strat-steps .s-text { color: var(--muted); font-size: 12.5px; margin-top: 2px; line-height: 1.45; }
.strat-guards { margin: 6px 0 0; padding-left: 18px; }
.strat-guards li { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; line-height: 1.4; }
.strat-feed { list-style: none; margin: 6px 0 0; padding: 0; max-height: 340px; overflow-y: auto; }
.strat-feed li { display: flex; gap: 9px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.strat-feed li:last-child { border-bottom: none; }
.strat-feed .f-time { color: var(--muted); font-size: 11px; white-space: nowrap; min-width: 58px; }
.strat-feed .f-text { flex: 1; }

/* ---------- exit-rule editor ---------- */
.fld { display: flex; flex-direction: column; gap: 5px; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.fld select, .fld input { margin-top: 2px; }
.ex-params { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.ex-params[data-for="trailing"] { grid-template-columns: 1fr; }

/* ---------- command palette (Ctrl-K) ---------- */
.cmdk-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 70; padding: 12vh 16px 16px;
  display: none; justify-content: center; align-items: flex-start;
}
.cmdk-overlay.show { display: flex; animation: fadein .12s ease; }
.cmdk {
  width: 540px; max-width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
#cmdk-input {
  width: 100%; border: none; border-bottom: 1px solid var(--line); background: var(--panel);
  color: var(--text); padding: 15px 16px; font-size: 15px; border-radius: 0;
}
#cmdk-input:focus { outline: none; box-shadow: none; }
.cmdk-list { max-height: 340px; overflow-y: auto; padding: 6px; }
.cmdk-item { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; }
.cmdk-item.active, .cmdk-item:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.cmdk-item .k { color: var(--muted); font-size: 11px; }

/* win celebration + sound toggle */
@keyframes win-pop { 0% { transform: scale(.8); opacity: 0; } 30% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); opacity: 0; } }
.win-burst { position: fixed; top: 22%; left: 50%; transform: translateX(-50%); z-index: 90;
  font-size: 44px; pointer-events: none; animation: win-pop 1.1s ease-out forwards; }
@media (prefers-reduced-motion: reduce) { .win-burst { display: none; } }

/* ---------- toasts (stacked, typed) ---------- */
.toasts {
  position: fixed; bottom: 22px; right: 22px; z-index: 50;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
}
.toast {
  background: var(--panel); border: 1px solid var(--accent); border-left-width: 4px;
  padding: 11px 15px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  opacity: 0; transform: translateX(18px); transition: .25s; cursor: pointer;
  max-width: 340px; font-size: 13px; line-height: 1.4;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.success { border-color: var(--green); }
.toast.warn { border-color: var(--amber); }
.toast.danger { border-color: var(--red); }
.toast.info { border-color: var(--accent); }

/* ---------- admin gating ---------- */
.admin-only { display: none; }
body.is-admin .admin-only { display: flex; }
.control-row.admin-only { display: none; }
body.is-admin .control-row.admin-only { display: flex; }

/* Read-only "investor" viewers: hide all trading controls, show a note. */
.view-only-note { display: none; color: var(--muted); font-size: 12px; font-style: italic; }
body.is-viewer .trade-btn { display: none; }
body.is-viewer .view-only-note { display: inline; }

/* ---------- assistant / chat ---------- */
.assistant-wrap { display: grid; grid-template-columns: 240px 1fr; gap: 14px; }
.conv-list { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 10px; height: 64vh; overflow-y: auto; box-shadow: var(--shadow); }
.conv-item { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.conv-item:hover { background: var(--panel2); }
.conv-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.conv-item .c-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv-item .c-del { color: var(--muted); font-size: 12px; border: none; background: none; cursor: pointer; }
.conv-item .c-del:hover { color: var(--red); }
.conv-main { min-width: 0; }
.chat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.chat-log {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; height: 54vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow);
}
.chat-hint { text-align: center; margin: auto; }
.msg { max-width: 78%; padding: 10px 13px; border-radius: 12px; white-space: pre-wrap; line-height: 1.5; font-size: 13.5px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--panel2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.tool { align-self: flex-start; background: transparent; color: var(--muted); font-size: 12px; padding: 2px 6px; }
.proposal { align-self: flex-start; background: var(--panel2); border: 1px solid var(--amber); border-radius: 12px; padding: 13px; max-width: 78%; }
.proposal .p-act { font-weight: 700; text-transform: capitalize; }
.proposal .p-row { display: flex; gap: 8px; margin-top: 10px; }
.chat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chat-chips.disabled { opacity: .45; pointer-events: none; }
.chip-btn {
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px; cursor: pointer;
}
.chip-btn:hover { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--accent) 10%, var(--panel2)); }
.chat-input { display: flex; gap: 8px; margin-top: 12px; }
.chat-input input { flex: 1; }
.chat-attachment {
  display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 6px 10px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  font-size: 12.5px; color: var(--muted); width: fit-content;
}
.chip-x {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px;
  padding: 0 2px; line-height: 1;
}
.chip-x:hover { color: var(--red); }
#chat-mic.listening { color: var(--red); border-color: var(--red); animation: mic-pulse 1.2s infinite; }
@keyframes mic-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px; width: 340px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
}
.login-card .brand { text-align: center; padding: 0 0 6px; font-size: 24px; }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: sticky; top: 0; z-index: 30;
    flex-direction: row; align-items: center; gap: 8px; padding: 10px 12px; overflow-x: auto;
  }
  .brand { padding: 0 8px 0 4px; font-size: 18px; }
  .tabs { flex-direction: row; gap: 2px; }
  .tab span { display: none; }
  .tab { padding: 9px 11px; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; border: none; padding: 0; }
  .theme-select { width: auto; }
  .content { padding: 18px 14px; }
  .topbar { padding: 12px 14px; }
  .assistant-wrap { grid-template-columns: 1fr; }
  /* Forms stack to one column so inputs stay tappable. */
  .form-grid { grid-template-columns: 1fr; padding: 16px; }
  /* Wide tables scroll horizontally instead of squishing / clipping. */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { white-space: nowrap; }
  .today-strip { gap: 14px; padding: 10px 12px; }
  .msg, .proposal { max-width: 90%; }
}

@media (max-width: 560px) {
  .content { padding: 14px 10px; }
  .brand { font-size: 16px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .card .v { font-size: 20px; }
  #updated { display: none; }                 /* trim topbar clutter on phones */
  .today-strip { gap: 12px; }
  .ts-item b { font-size: 15px; }
  th, td { padding: 9px 11px; }
  /* Full-width primary action buttons read better on a phone. */
  .form-grid > .btn, .form-grid > button { justify-self: stretch; width: 100%; text-align: center; }
  .daily-banner { flex-direction: column; align-items: stretch; }
  .daily-banner .btn { width: 100%; }
}
