/* ──────────────────────────────────────────────────
   DESIGN TOKENS  (dark = default)
────────────────────────────────────────────────── */
:root {
  --bg:          #07090f;
  --surface:     #0d1221;
  --surface-2:   #121929;
  --surface-3:   #1c2840;
  --border:      rgba(148, 163, 184, 0.12);
  --border-2:    rgba(148, 163, 184, 0.22);

  --blue:        #60a5fa;
  --blue-dim:    rgba(96, 165, 250, 0.14);
  --purple:      #a78bfa;
  --purple-dim:  rgba(167, 139, 250, 0.14);
  --cyan:        #22d3ee;
  --cyan-dim:    rgba(34, 211, 238, 0.14);
  --green:       #4ade80;
  --green-dim:   rgba(74, 222, 128, 0.14);
  --red:         #f87171;
  --red-dim:     rgba(248, 113, 113, 0.14);
  --orange:      #fbbf24;
  --orange-dim:  rgba(251, 191, 36, 0.14);

  --text-1:      #f1f5f9;
  --text-2:      #cbd5e1;
  --text-3:      #94a3b8;

  --radius:      10px;
  --radius-sm:   6px;
  --topbar-h:    60px;
  --sidebar-w:   210px;
  --shadow:      0 8px 32px rgba(0,0,0,0.5);

  --mono: 'JetBrains Mono', 'Fira Mono', 'Cascadia Code', 'Consolas', monospace;
}

/* ──────────────────────────────────────────────────
   LIGHT THEME OVERRIDES
────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:          #f0f4f8;
  --surface:     #ffffff;
  --surface-2:   #f4f7fb;
  --surface-3:   #e4eaf3;
  --border:      rgba(15, 23, 42, 0.09);
  --border-2:    rgba(15, 23, 42, 0.16);

  --blue:        #2563eb;
  --blue-dim:    rgba(37, 99, 235, 0.10);
  --purple:      #7c3aed;
  --purple-dim:  rgba(124, 58, 237, 0.10);
  --cyan:        #0891b2;
  --cyan-dim:    rgba(8, 145, 178, 0.10);
  --green:       #16a34a;
  --green-dim:   rgba(22, 163, 74, 0.10);
  --red:         #dc2626;
  --red-dim:     rgba(220, 38, 38, 0.10);
  --orange:      #d97706;
  --orange-dim:  rgba(217, 119, 6, 0.10);

  --text-1:      #0f172a;
  --text-2:      #334155;
  --text-3:      #64748b;

  --shadow:      0 4px 24px rgba(15, 23, 42, 0.12);
}

/* ──────────────────────────────────────────────────
   RESET
────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  overflow: hidden;
}

.mono { font-family: var(--mono); }

/* ──────────────────────────────────────────────────
   TOPBAR
────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-2);
  z-index: 100;
  gap: 16px;
}

.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }

.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.logo-name { font-weight: 700; font-size: 16px; letter-spacing: -0.3px; }
.logo-sub { font-size: 11px; color: var(--text-3); display: block; line-height: 1; }

.live-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  font-size: 13px;
  color: var(--text-2);
  transition: all 0.3s;
}
.live-pill.online { border-color: rgba(34,197,94,0.3); color: var(--green); }

.pulse {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
  transition: background 0.3s;
}
.live-pill.online .pulse {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(34,197,94,0.5);
  animation: pulse-anim 2s infinite;
}
@keyframes pulse-anim {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  70%  { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

.acct-bar { display: flex; align-items: center; gap: 4px; }
.acct-item { padding: 0 14px; text-align: right; }
.acct-label { display: block; font-size: 11px; letter-spacing: 0.8px; color: var(--text-3); font-weight: 600; }
.acct-val { font-size: 15px; font-weight: 700; }
.acct-divider { width: 1px; height: 28px; background: var(--border-2); }

.clock-wrap { text-align: right; }
.clock-time { font-size: 15px; font-weight: 700; display: block; }
.clock-date { font-size: 12px; color: var(--text-3); }

/* ──────────────────────────────────────────────────
   SIDEBAR
────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border-2);
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  overflow-y: auto;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--surface-2); color: var(--text-1); }
.nav-item.active { background: var(--blue-dim); color: var(--blue); font-weight: 600; }

.nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
  transition: opacity 0.18s;
}
.nav-item.active .nav-icon { opacity: 1; }
.nav-item:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.sidebar-refresh-hint { font-size: 12px; color: var(--text-3); }

/* ── Sidebar collapse toggle ── */
.sidebar-toggle-row {
  display: flex;
  justify-content: flex-end;
  padding: 0 2px 6px;
}
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: none; border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.2s;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text-1); }

/* Collapsed state — mirrors mobile media query but user-triggered */
body.sidebar-collapsed { --sidebar-w: 52px; }
body.sidebar-collapsed .sidebar          { padding: 12px 4px; }
body.sidebar-collapsed .nav-label        { display: none; }
body.sidebar-collapsed .nav-item         { justify-content: center; padding: 10px; }
body.sidebar-collapsed .sidebar-refresh-hint { display: none; }
body.sidebar-collapsed .sidebar-toggle-row   { justify-content: center; padding: 0 0 6px; }
body.sidebar-collapsed .sidebar-toggle svg   { transform: rotate(180deg); }

/* Ring progress */
.refresh-ring { position: relative; width: 36px; height: 36px; }
.ring-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--surface-3); stroke-width: 3; }
.ring-progress {
  fill: none; stroke: var(--blue); stroke-width: 3;
  stroke-dasharray: 94.2; stroke-dashoffset: 0;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear;
}
.ring-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  color: var(--text-2);
  font-family: var(--mono);
}

/* ──────────────────────────────────────────────────
   MAIN CONTENT
────────────────────────────────────────────────── */
.main {
  grid-area: main;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tab-pane { display: none; flex-direction: column; gap: 20px; }
.tab-pane.active { display: flex; animation: fadeup 0.2s ease; }

@keyframes fadeup {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text-1);
}
.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ──────────────────────────────────────────────────
   STAT CARDS
────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color 0.2s, transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); border-color: var(--border-2); }

.stat-card-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-card-icon svg { width: 20px; height: 20px; }

.accent-blue .stat-card-icon  { background: var(--blue-dim);   color: var(--blue); }
.accent-green .stat-card-icon { background: var(--green-dim);  color: var(--green); }
.accent-purple .stat-card-icon{ background: var(--purple-dim); color: var(--purple); }
.accent-orange .stat-card-icon{ background: var(--orange-dim); color: var(--orange); }

.stat-card-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.6px;
  color: var(--text-3);
  text-transform: uppercase;
}
.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 4px;
  color: var(--text-1);
}

/* ──────────────────────────────────────────────────
   CHARTS
────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.chart-wrap {
  position: relative;
  height: 220px;
  padding-top: 8px;
}

/* ──────────────────────────────────────────────────
   CARD (generic panel)
────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header-line {
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--text-1);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

/* ──────────────────────────────────────────────────
   DATA TABLE
────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border-2);
  background: var(--surface-2);
  white-space: nowrap;
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-2); }
.data-table .num { text-align: right; font-family: var(--mono); }
.data-table th.sortable { cursor: pointer; user-select: none; transition: color .12s; }
.data-table th.sortable:hover { color: var(--text-1); }
.data-table th.sorted { color: var(--blue); }

/* Inline sparkline charts in table cells */
.sparkline { overflow: visible; }

/* Colored P&L magnitude bar behind the dollar value in the P&L cell */
.pnl-bar-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 90px;
  height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  overflow: hidden;
}
.pnl-bar {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  border-radius: 4px;
  transition: width .35s ease;
}

/* Trend arrow + delta line shown under a stat-card value */
.stat-card-trend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 500;
}
.stat-card-trend.pos { color: var(--green); }
.stat-card-trend.neg { color: var(--red); }
.stat-card-trend.flat { color: var(--text-3); }

/* Per-row action buttons (Open Positions table) */
.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}
.row-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  font-size: 13px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, transform .12s;
  padding: 0;
}
.row-act:hover {
  background: var(--surface-3, var(--surface));
  color: var(--text-1);
  border-color: var(--text-3);
  transform: translateY(-1px);
}
.row-act.danger:hover {
  background: var(--red-dim);
  color: var(--red);
  border-color: var(--red);
}

/* Toast notifications for action feedback */
.dash-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: var(--text-1);
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s, transform .25s;
  z-index: 9999;
  max-width: 320px;
}
.dash-toast.shown { opacity: 1; transform: translateY(0); }
.dash-toast.toast-ok  { background: var(--green); color: #082b13; }
.dash-toast.toast-err { background: var(--red);   color: #2a0a0a; }

/* Liquidate confirmation modal — option buttons */
.liq-option {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  color: var(--text-1);
  transition: background .15s, border-color .15s, transform .12s;
}
.liq-option:last-child { margin-bottom: 0; }
.liq-option:hover { transform: translateY(-1px); }
.liq-option-label {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}
.liq-option-sub {
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--mono);
}
.liq-warn { border-color: var(--orange); }
.liq-warn .liq-option-label { color: var(--orange); }
.liq-warn:hover { background: var(--orange-dim); border-color: var(--orange); }
.liq-danger { border-color: var(--red); }
.liq-danger .liq-option-label { color: var(--red); }
.liq-danger:hover { background: var(--red-dim); border-color: var(--red); }

/* Analyze tab: render Claude's Telegram-flavored HTML report with breathing room */
.analyze-report {
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-1);
  white-space: pre-wrap;       /* preserve line breaks the model emits */
  word-wrap: break-word;
}
.analyze-report b, .analyze-report strong {
  color: var(--text-1);
  font-weight: 600;
}
.analyze-report code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
}

/* Glossary tab — EN/FR dictionary */
.gloss-table td {
  vertical-align: top;
  padding: 10px 16px;
  font-size: 13px;
  line-height: 1.5;
}
.gloss-en  { font-weight: 600; color: var(--text-1); white-space: normal; }
.gloss-fr  { color: var(--text-2); white-space: normal; }
.gloss-note{ color: var(--text-3); white-space: normal; }
.gloss-table mark {
  background: var(--orange-dim);
  color: var(--text-1);
  padding: 0 2px;
  border-radius: 2px;
}

/* Collapsible category header */
.gloss-cat { margin-bottom: 20px; padding: 0; }
.gloss-cat > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: relative;
  padding-left: 28px;
}
.gloss-cat > summary::-webkit-details-marker { display: none; }   /* Safari */
.gloss-cat > summary::before {
  content: "▶";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--text-3);
  transition: transform .15s ease;
}
.gloss-cat[open] > summary::before { transform: translateY(-50%) rotate(90deg); }
.gloss-cat[open] > summary { border-bottom: 1px solid var(--border-2); }

/* Per-row copy button */
.gloss-copy-cell { width: 40px; text-align: center; padding-right: 12px !important; }
.gloss-copy {
  width: 26px; height: 26px;
  font-size: 13px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, transform .12s;
  padding: 0;
}
.gloss-copy:hover {
  background: var(--blue-dim);
  color: var(--blue);
  border-color: var(--blue);
  transform: translateY(-1px);
}
.gloss-copy.copied {
  background: var(--green-dim);
  color: var(--green);
  border-color: var(--green);
}

.empty-cell {
  text-align: center;
  padding: 40px !important;
  color: var(--text-3);
  font-size: 14px;
}

.ticker-cell { font-weight: 700; color: var(--text-1); }
.strat-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

/* P&L coloring */
.pos  { color: var(--green); }
.neg  { color: var(--red); }
.neut { color: var(--text-2); }

/* Strategy dot colors */
.dot-trailing_stop  { background: var(--blue); }
.dot-copy_trading   { background: var(--purple); }
.dot-twitter_signals{ background: var(--cyan); }
.dot-default        { background: var(--text-3); }

/* Win/loss badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-win  { background: var(--green-dim);  color: var(--green); }
.badge-loss { background: var(--red-dim);    color: var(--red); }
.badge-pend { background: var(--orange-dim); color: var(--orange); }
.badge-on   { background: var(--green-dim);  color: var(--green); }
.badge-off  { background: var(--surface-3);  color: var(--text-3); }

/* Win rate bar */
.wr-bar-wrap { display: flex; align-items: center; gap: 8px; }
.wr-bar-bg { flex: 1; height: 5px; background: var(--surface-3); border-radius: 3px; overflow: hidden; min-width: 60px; }
.wr-bar-fill { height: 100%; border-radius: 3px; background: var(--green); }
.wr-pct { font-family: var(--mono); min-width: 44px; text-align: right; font-size: 13px; font-weight: 600; }

/* ──────────────────────────────────────────────────
   LEVEL STRIP (strategies tab)
────────────────────────────────────────────────── */
.level-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.level-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color 0.2s;
}
.level-pill:hover { border-color: var(--border-2); }

.level-pill-num {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800;
  flex-shrink: 0;
}
.l1 .level-pill-num { background: var(--blue-dim);   color: var(--blue); }
.l2 .level-pill-num { background: var(--purple-dim); color: var(--purple); }
.l3 .level-pill-num { background: var(--cyan-dim);   color: var(--cyan); }

.level-pill-body { flex: 1; }
.level-pill-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; color: var(--text-1); }
.level-pill-desc { font-size: 13px; color: var(--text-3); line-height: 1.4; }

/* ──────────────────────────────────────────────────
   STRATEGY LIST (strategies tab)
────────────────────────────────────────────────── */
.strategy-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.strategy-row:last-child { border-bottom: none; }
.strategy-row:hover { background: var(--surface-2); }

.strategy-row-sym { font-weight: 700; font-size: 16px; width: 64px; flex-shrink: 0; color: var(--text-1); }
.strategy-row-name { flex: 1; color: var(--text-2); font-size: 14px; }
.strategy-row-meta {
  display: flex; gap: 20px;
  font-size: 13px; color: var(--text-3);
  font-family: var(--mono);
}
.strategy-row-meta span { white-space: nowrap; }
.strategy-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.empty-state {
  padding: 48px;
  text-align: center;
  color: var(--text-3);
  font-size: 15px;
}

/* ──────────────────────────────────────────────────
   LOGS
────────────────────────────────────────────────── */
.logs-card { flex: 1; }
.logs-controls { display: flex; align-items: center; gap: 12px; }
.autoscroll-label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; color: var(--text-2); }
.autoscroll-label input { accent-color: var(--blue); }

.logs-body {
  height: 60vh;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 13px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.log-line {
  padding: 3px 8px;
  border-radius: 4px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-line:hover { background: var(--surface-2); }
.log-line .log-ts { color: var(--text-3); font-size: 12px; }
.log-line.log-error   { color: var(--red);    background: var(--red-dim); }
.log-line.log-warning { color: var(--orange); }
.log-line.log-info    { color: var(--text-2); }
.log-line.log-debug   { color: var(--text-3); }

/* ──────────────────────────────────────────────────
   BUTTONS
────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary:hover { background: #2563eb; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(59,130,246,0.35); }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { background: var(--surface-3); color: var(--text-1); }

.btn-ghost {
  padding: 8px 16px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-icon {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 15px;
  cursor: pointer;
  color: var(--text-2);
  transition: all 0.2s;
}
.btn-icon:hover { background: var(--surface-3); color: var(--text-1); }

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-sm:hover { background: var(--surface-3); color: var(--text-1); }

.btn-danger-ghost {
  padding: 8px 16px;
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-danger-ghost:hover { background: var(--red-dim); }

/* ──────────────────────────────────────────────────
   TOGGLE SWITCH
────────────────────────────────────────────────── */
.toggle-row {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  cursor: pointer;
}
.toggle-row-label { font-size: 13px; font-weight: 500; color: var(--text-1); }

.sw { position: relative; }
.sw input { position: absolute; opacity: 0; width: 0; height: 0; }
.sw-track {
  display: flex; align-items: center;
  width: 40px; height: 22px;
  border-radius: 11px;
  background: var(--surface-3);
  transition: background 0.2s;
  padding: 2px;
  cursor: pointer;
}
.sw input:checked + .sw-track { background: var(--blue); }
.sw-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text-3);
  transition: all 0.2s;
}
.sw input:checked + .sw-track .sw-thumb {
  transform: translateX(18px);
  background: white;
}

/* ──────────────────────────────────────────────────
   MODAL
────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.overlay.open { display: flex; animation: fadeup 0.15s ease; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
}
.modal-x {
  background: none; border: none;
  color: var(--text-3); font-size: 18px;
  cursor: pointer; line-height: 1;
  transition: color 0.15s;
}
.modal-x:hover { color: var(--text-1); }

.modal-bd { padding: 22px; display: flex; flex-direction: column; gap: 16px; }

.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-group input {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13px;
  padding: 9px 12px;
  width: 100%;
  transition: border-color 0.15s;
}
.field-group input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-dim); }

.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.modal-ft {
  display: flex; align-items: center; justify-content: flex-end;
  padding: 16px 22px;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-ft-split { justify-content: space-between; }

/* ──────────────────────────────────────────────────
   TOASTS
────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow);
  pointer-events: all;
  animation: toast-in 0.25s ease;
  max-width: 320px;
  border: 1px solid transparent;
}
.toast-success { background: #0d2418; border-color: rgba(34,197,94,0.3); color: var(--green); }
.toast-error   { background: #200e0e; border-color: rgba(239,68,68,0.3); color: var(--red); }
.toast-info    { background: var(--surface-2); border-color: var(--border-2); color: var(--text-1); }
.toast-warn    { background: #201600; border-color: rgba(245,158,11,0.3); color: var(--orange); }

.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-close { margin-left: auto; background: none; border: none; color: inherit; opacity: 0.6; cursor: pointer; font-size: 16px; line-height: 1; }
.toast-close:hover { opacity: 1; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
.toast-out { animation: toast-out 0.2s ease forwards; }
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px) scale(0.97); }
}

/* ──────────────────────────────────────────────────
   SCROLLBAR
────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ──────────────────────────────────────────────────
   RESPONSIVE
────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .level-strip { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  :root { --sidebar-w: 52px; }
  .nav-label       { display: none; }
  .logo-text       { display: none; }
  .acct-bar        { display: none; }
  .market-status   { display: none; }
  .stats-grid      { grid-template-columns: 1fr; }
  .field-row-3     { grid-template-columns: 1fr; }
  .sidebar         { padding: 12px 4px; }
  .nav-item        { justify-content: center; padding: 10px; }
  .main            { padding: 14px; }
}

/* ──────────────────────────────────────────────────
   THEME TOGGLE BUTTON
────────────────────────────────────────────────── */
.theme-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  transition: all 0.2s;
  flex-shrink: 0;
}
.theme-btn:hover {
  background: var(--surface-3);
  color: var(--text-1);
  transform: rotate(20deg);
}

/* ──────────────────────────────────────────────────
   MARKET STATUS PILL
────────────────────────────────────────────────── */
.market-status {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
  cursor: default;
  transition: all 0.3s;
  white-space: nowrap;
}
.market-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.market-status.mkt-open   { border-color: rgba(74,222,128,0.35); color: var(--green); }
.market-status.mkt-pre    { border-color: rgba(251,191,36,0.35); color: var(--orange); }
.market-status.mkt-after  { border-color: rgba(251,191,36,0.35); color: var(--orange); }
.market-status.mkt-closed { border-color: var(--border-2);       color: var(--text-3); }

.market-status.mkt-open   .market-dot { background: var(--green);  animation: pulse-anim 2s infinite; }
.market-status.mkt-pre    .market-dot { background: var(--orange); }
.market-status.mkt-after  .market-dot { background: var(--orange); }
.market-status.mkt-closed .market-dot { background: var(--text-3); }

/* ──────────────────────────────────────────────────
   TRADE MODAL
────────────────────────────────────────────────── */
.trade-modal { max-width: 420px; }

.trade-modal-hd { background: var(--surface-2); }

.trade-symbol-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-1);
  font-family: var(--mono);
}

.tm-price-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}
.tm-price-block {
  background: var(--surface-2);
  padding: 14px 16px;
  text-align: center;
}
.tm-price-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-3);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.tm-price-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-1);
}

.tm-side-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 18px 22px 0;
}
.tm-side-btn {
  padding: 12px;
  border: 2px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.18s;
  color: var(--text-3);
}
.tm-buy.active  { background: var(--green-dim);  border-color: var(--green);  color: var(--green); }
.tm-sell.active { background: var(--red-dim);    border-color: var(--red);    color: var(--red); }
.tm-buy:hover:not(.active)  { border-color: var(--green); color: var(--green); }
.tm-sell:hover:not(.active) { border-color: var(--red);   color: var(--red); }

.tm-qty-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 22px 0;
}
.tm-qty-step {
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.tm-qty-step:hover { background: var(--surface-3); color: var(--text-1); }

.tm-qty-input {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  background: var(--surface-2);
  border: 2px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 20px;
  font-weight: 700;
  transition: border-color 0.15s;
  min-width: 0;
}
.tm-qty-input:focus { outline: none; border-color: var(--blue); }
.tm-qty-input::-webkit-inner-spin-button,
.tm-qty-input::-webkit-outer-spin-button { -webkit-appearance: none; }

/* Mode toggle */
.tm-mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 16px 22px 0;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.tm-mode-btn {
  padding: 9px;
  background: var(--surface-2);
  border: none;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.tm-mode-btn:first-child { border-right: 1px solid var(--border-2); }
.tm-mode-btn.active { background: var(--blue-dim); color: var(--blue); }
.tm-mode-btn:hover:not(.active) { color: var(--text-1); background: var(--surface-3); }

/* Dollar input wrapper */
.tm-dollar-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}
.tm-dollar-sign {
  position: absolute;
  left: 12px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-3);
  pointer-events: none;
  font-family: var(--mono);
}
.tm-dollar-input-wrap .tm-qty-input { padding-left: 28px; }

/* Hint text under qty row */
.tm-qty-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  padding: 6px 22px 0;
}

.tm-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  margin-top: 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.tm-total-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.tm-total-value { font-size: 20px; font-weight: 700; color: var(--text-1); }

.tm-warning {
  margin: 0 22px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  display: none;
}
.tm-warning.show { display: block; background: var(--red-dim); color: var(--red); }

/* Order status pill */
.order-status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-3);
  text-transform: capitalize;
  white-space: nowrap;
}
.order-status-pill.pos  { background: var(--green-dim); color: var(--green); }
.order-status-pill.neut { background: var(--blue-dim);  color: var(--blue); }
.order-status-pill.neg  { background: var(--red-dim);   color: var(--red); }

/* Cancel order button */
.btn-cancel-order {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(239,68,68,0.3);
  background: transparent;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}
.btn-cancel-order:hover { background: var(--red-dim); border-color: var(--red); }

/* Clickable ticker anywhere in the app */
.ticker-link {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  transition: color 0.15s;
}
.ticker-link:hover { color: var(--blue) !important; }

.btn-trade {
  flex: 1;
  padding: 12px 20px;
  background: var(--green);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.3px;
}
.btn-trade:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-trade.sell  { background: var(--red); color: #fff; }
.btn-trade:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ──────────────────────────────────────────────────
   LIGHT THEME SPECIFIC ADJUSTMENTS
────────────────────────────────────────────────── */
[data-theme="light"] .topbar    { box-shadow: 0 1px 0 var(--border-2); }
[data-theme="light"] .sidebar   { box-shadow: 1px 0 0 var(--border-2); }
[data-theme="light"] .stat-card { box-shadow: 0 1px 4px rgba(15,23,42,0.07); }
[data-theme="light"] .card      { box-shadow: 0 1px 4px rgba(15,23,42,0.07); }
[data-theme="light"] .data-table tr:hover td { background: var(--surface-3); }
[data-theme="light"] .badge-off { background: var(--surface-3); color: var(--text-3); }
[data-theme="light"] .log-line.log-info { color: var(--text-2); }
[data-theme="light"] .log-line.log-debug { color: var(--text-3); }
[data-theme="light"] body { color: var(--text-1); }
