/* ── CSS Variables ── */

/* glassmorphism-dark (default) */
:root,
[data-style="glassmorphism"][data-brightness="dark"] {
  --bg: #0a0e1a;
  --color: #e2e8f0;
  --card-bg: rgba(255, 255, 255, .06);
  --card-border: rgba(255, 255, 255, .1);
  --card-border-hover: rgba(255, 255, 255, .15);
  --card-shadow: 0 4px 24px rgba(0, 0, 0, .2);
  --card-shadow-hover: 0 8px 32px rgba(0, 0, 0, .25);
  --card-inset: inset 0 1px 0 rgba(255, 255, 255, .06);
  --card-inset-hover: inset 0 1px 0 rgba(255, 255, 255, .08);
  --muted: #64748b;
  --muted2: #475569;
  --muted3: #94a3b8;
  --muted4: #cbd5e1;
  --th-color: #475569;
  --td-border: rgba(255, 255, 255, .03);
  --th-border: rgba(255, 255, 255, .06);
  --btn-bg: rgba(99, 102, 241, .15);
  --btn-border: rgba(99, 102, 241, .4);
  --btn-bg-hover: rgba(99, 102, 241, .25);
  --btn-border-hover: rgba(99, 102, 241, .6);
  --btn-shadow-hover: 0 0 20px rgba(99, 102, 241, .15);
  --input-bg: rgba(255, 255, 255, .04);
  --input-border: rgba(255, 255, 255, .08);
  --chart-bg: rgba(255, 255, 255, .06);
  --log-bg: rgba(0, 0, 0, .2);
  --log-border: rgba(255, 255, 255, .04);
  --pos-card-bg: rgba(0, 0, 0, .25);
  --pos-card-border: rgba(255, 255, 255, .08);
  --scrollbar-thumb: rgba(255, 255, 255, .1);
  --tab-bg: rgba(255, 255, 255, .02);
  --tab-border: rgba(255, 255, 255, .06);
  --tab-active-bg: rgba(255, 255, 255, .06);
  --tab-active-border: rgba(255, 255, 255, .08);
  --conf-bar-bg: rgba(255, 255, 255, .04);
  --conf-bar-below: rgba(255, 255, 255, .08);
  --event-border: rgba(255, 255, 255, .04);
  --event-hover: rgba(255, 255, 255, .03);
  --exposure-bar-bg: rgba(255, 255, 255, .04);
  --mh-track-bg: rgba(255, 255, 255, .07);
  --overlay-bg: rgba(15, 23, 42, 0.85);
  --tooltip-bg: rgba(30, 41, 59, .9);
  --section-title: #94a3b8;
  --blob-tl: radial-gradient(ellipse, rgba(56, 189, 248, .15) 0%, rgba(99, 102, 241, .06) 40%, transparent 70%);
  --blob-br: radial-gradient(ellipse, rgba(168, 85, 247, .12) 0%, rgba(236, 72, 153, .05) 40%, transparent 70%);
  --range-bar-bg: rgba(255, 255, 255, .04);
  --strategy-config-border: rgba(255, 255, 255, .06);
  --sync-tooltip-bg: rgba(30, 41, 59, .9);
  --startup-overlay-bg: rgba(15, 23, 42, 0.85);
}

/* glassmorphism-light */
[data-style="glassmorphism"][data-brightness="light"] {
  --bg: #f1f5f9;
  --color: #0f172a;
  --card-bg: rgba(255, 255, 255, .85);
  --card-border: rgba(0, 0, 0, .08);
  --card-border-hover: rgba(0, 0, 0, .14);
  --card-shadow: 0 4px 24px rgba(0, 0, 0, .07);
  --card-shadow-hover: 0 8px 32px rgba(0, 0, 0, .1);
  --card-inset: inset 0 1px 0 rgba(255, 255, 255, .9);
  --card-inset-hover: inset 0 1px 0 rgba(255, 255, 255, 1);
  --muted: #64748b;
  --muted2: #94a3b8;
  --muted3: #475569;
  --muted4: #1e293b;
  --th-color: #94a3b8;
  --td-border: rgba(0, 0, 0, .04);
  --th-border: rgba(0, 0, 0, .07);
  --btn-bg: rgba(99, 102, 241, .1);
  --btn-border: rgba(99, 102, 241, .35);
  --btn-bg-hover: rgba(99, 102, 241, .18);
  --btn-border-hover: rgba(99, 102, 241, .55);
  --btn-shadow-hover: 0 0 20px rgba(99, 102, 241, .1);
  --input-bg: rgba(255, 255, 255, .8);
  --input-border: rgba(0, 0, 0, .1);
  --chart-bg: rgba(255, 255, 255, .85);
  --log-bg: rgba(0, 0, 0, .04);
  --log-border: rgba(0, 0, 0, .06);
  --pos-card-bg: rgba(255, 255, 255, .7);
  --pos-card-border: rgba(0, 0, 0, .08);
  --scrollbar-thumb: rgba(0, 0, 0, .15);
  --tab-bg: rgba(0, 0, 0, .03);
  --tab-border: rgba(0, 0, 0, .07);
  --tab-active-bg: rgba(255, 255, 255, .85);
  --tab-active-border: rgba(0, 0, 0, .1);
  --conf-bar-bg: rgba(0, 0, 0, .06);
  --conf-bar-below: rgba(0, 0, 0, .08);
  --event-border: rgba(0, 0, 0, .04);
  --event-hover: rgba(0, 0, 0, .03);
  --exposure-bar-bg: rgba(0, 0, 0, .06);
  --mh-track-bg: rgba(0, 0, 0, .06);
  --overlay-bg: rgba(241, 245, 249, 0.9);
  --tooltip-bg: rgba(255, 255, 255, .95);
  --section-title: #475569;
  --blob-tl: radial-gradient(ellipse, rgba(56, 189, 248, .08) 0%, rgba(99, 102, 241, .03) 40%, transparent 70%);
  --blob-br: radial-gradient(ellipse, rgba(168, 85, 247, .06) 0%, rgba(236, 72, 153, .02) 40%, transparent 70%);
  --range-bar-bg: rgba(0, 0, 0, .06);
  --strategy-config-border: rgba(0, 0, 0, .06);
  --sync-tooltip-bg: rgba(255, 255, 255, .95);
  --startup-overlay-bg: rgba(241, 245, 249, 0.9);
}

/* terminal-dark */
[data-style="terminal"][data-brightness="dark"] {
  --bg: #0d0d0d;
  --color: #e0e0e0;
  --card-bg: #111111;
  --card-border: #2a2a2a;
  --card-border-hover: #3a3a3a;
  --card-shadow: none;
  --card-shadow-hover: none;
  --card-inset: none;
  --card-inset-hover: none;
  --muted: #666666;
  --muted2: #555555;
  --muted3: #999999;
  --muted4: #cccccc;
  --th-color: #555555;
  --td-border: #1e1e1e;
  --th-border: #2a2a2a;
  --btn-bg: transparent;
  --btn-border: #3a3a3a;
  --btn-bg-hover: #1a1a1a;
  --btn-border-hover: #00e676;
  --btn-shadow-hover: none;
  --input-bg: #111111;
  --input-border: #2a2a2a;
  --chart-bg: #111111;
  --log-bg: #080808;
  --log-border: #1e1e1e;
  --pos-card-bg: #111111;
  --pos-card-border: #2a2a2a;
  --scrollbar-thumb: #2a2a2a;
  --tab-bg: transparent;
  --tab-border: #2a2a2a;
  --tab-active-bg: #1a1a1a;
  --tab-active-border: #00e676;
  --conf-bar-bg: #1a1a1a;
  --conf-bar-below: #222222;
  --event-border: #1a1a1a;
  --event-hover: #161616;
  --exposure-bar-bg: #1a1a1a;
  --mh-track-bg: #1a1a1a;
  --overlay-bg: rgba(0, 0, 0, 0.92);
  --tooltip-bg: #1a1a1a;
  --section-title: #666666;
  --blob-tl: none;
  --blob-br: none;
  --range-bar-bg: #1a1a1a;
  --strategy-config-border: #1e1e1e;
  --sync-tooltip-bg: #1a1a1a;
  --startup-overlay-bg: rgba(0, 0, 0, 0.92);
  --accent: #00e676;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, monospace;
}

/* terminal-light */
[data-style="terminal"][data-brightness="light"] {
  --bg: #f5f5f0;
  --color: #1a1a1a;
  --card-bg: #efefea;
  --card-border: #d0d0c8;
  --card-border-hover: #b0b0a8;
  --card-shadow: none;
  --card-shadow-hover: none;
  --card-inset: none;
  --card-inset-hover: none;
  --muted: #888880;
  --muted2: #aaaaaa;
  --muted3: #555550;
  --muted4: #1a1a1a;
  --th-color: #aaaaaa;
  --td-border: #e0e0d8;
  --th-border: #d0d0c8;
  --btn-bg: transparent;
  --btn-border: #c0c0b8;
  --btn-bg-hover: #e8e8e0;
  --btn-border-hover: #007a3d;
  --btn-shadow-hover: none;
  --input-bg: #efefea;
  --input-border: #d0d0c8;
  --chart-bg: #efefea;
  --log-bg: #e8e8e0;
  --log-border: #d0d0c8;
  --pos-card-bg: #efefea;
  --pos-card-border: #d0d0c8;
  --scrollbar-thumb: #c0c0b8;
  --tab-bg: transparent;
  --tab-border: #d0d0c8;
  --tab-active-bg: #e8e8e0;
  --tab-active-border: #007a3d;
  --conf-bar-bg: #e0e0d8;
  --conf-bar-below: #d0d0c8;
  --event-border: #e0e0d8;
  --event-hover: #e8e8e0;
  --exposure-bar-bg: #e0e0d8;
  --mh-track-bg: #e0e0d8;
  --overlay-bg: rgba(245, 245, 240, 0.92);
  --tooltip-bg: #efefea;
  --section-title: #555550;
  --blob-tl: none;
  --blob-br: none;
  --range-bar-bg: #e0e0d8;
  --strategy-config-border: #d8d8d0;
  --sync-tooltip-bg: #efefea;
  --startup-overlay-bg: rgba(245, 245, 240, 0.92);
  --accent: #007a3d;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, monospace;
}

/* ── Terminal style overrides (both brightness variants) ── */
[data-style="terminal"] body {
  font-family: var(--font-mono);
  letter-spacing: 0;
}

[data-style="terminal"] body::before,
[data-style="terminal"] body::after {
  display: none;
}

[data-style="terminal"] .card,
[data-style="terminal"] .strategy-card,
[data-style="terminal"] .pos-card,
[data-style="terminal"] #chart-container {
  border-radius: 2px;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

[data-style="terminal"] .card h2 {
  color: var(--accent);
  font-size: .7rem;
  letter-spacing: .12em;
}

[data-style="terminal"] .section-title {
  color: var(--accent);
  font-size: .75rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}

[data-style="terminal"] h1 {
  font-family: var(--font-mono);
  font-size: 1rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--accent);
}

[data-style="terminal"] .stat {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  color: var(--accent);
}

[data-style="terminal"] .stat-sm {
  font-family: var(--font-mono);
}

[data-style="terminal"] button {
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: .75rem;
  letter-spacing: .05em;
  text-transform: uppercase;
}

[data-style="terminal"] .signal-badge {
  border-radius: 2px;
  font-family: var(--font-mono);
}

[data-style="terminal"] .auto-badge {
  border-radius: 2px;
}

[data-style="terminal"] .conf-bar.ready {
  background: var(--accent);
}

[data-style="terminal"] .conf-bar.near {
  background: #ffab40;
}

[data-style="terminal"] .monitor-dot.on {
  background: var(--accent);
}

[data-style="terminal"] .mh-status.open {
  color: var(--accent);
}

[data-style="terminal"] .mh-bar.open {
  background: var(--accent);
}

[data-style="terminal"] .exposure-bar-fill {
  background: linear-gradient(90deg, var(--accent), #00bcd4);
}

[data-style="terminal"] .pos-card {
  border-radius: 2px;
}

[data-style="terminal"] .tab-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

[data-style="terminal"] .sync-dot.synced {
  background: var(--accent);
}

[data-style="terminal"] .range-marker.tp {
  background: var(--accent);
}

/* terminal-dark accent overrides */
[data-style="terminal"][data-brightness="dark"] .pnl-pos {
  color: #00e676;
}

[data-style="terminal"][data-brightness="dark"] .pnl-neg {
  color: #ff5252;
}

[data-style="terminal"][data-brightness="dark"] .signal-badge.buy {
  background: transparent;
  color: #00e676;
  border-color: #00e676;
}

[data-style="terminal"][data-brightness="dark"] .signal-badge.sell {
  background: transparent;
  color: #ff5252;
  border-color: #ff5252;
}

[data-style="terminal"][data-brightness="dark"] .signal-badge.hold {
  background: transparent;
  color: #ffab40;
  border-color: #ffab40;
}

[data-style="terminal"][data-brightness="dark"] .signal-badge.monitoring {
  background: transparent;
  color: #666;
  border-color: #333;
}

[data-style="terminal"][data-brightness="dark"] .signal-badge.market-closed {
  background: transparent;
  color: #444;
  border-color: #333;
}

[data-style="terminal"][data-brightness="dark"] .pos-card.long {
  border-left-color: #00e676;
}

[data-style="terminal"][data-brightness="dark"] .pos-card.short {
  border-left-color: #ff5252;
}

[data-style="terminal"][data-brightness="dark"] .strategy-card.buy {
  border-left-color: #00e676;
}

[data-style="terminal"][data-brightness="dark"] .strategy-card.sell {
  border-left-color: #ff5252;
}

[data-style="terminal"][data-brightness="dark"] .strategy-card.hold {
  border-left-color: #ffab40;
}

[data-style="terminal"][data-brightness="dark"] .strategy-card.active {
  border-left-color: #00e676;
}

[data-style="terminal"][data-brightness="dark"] .range-marker.stop {
  background: #ff5252;
}

[data-style="terminal"][data-brightness="dark"] .event-type.trade {
  color: #00e676;
  border-color: #00e676;
  background: transparent;
}

[data-style="terminal"][data-brightness="dark"] .event-type.alert {
  color: #ff5252;
  border-color: #ff5252;
  background: transparent;
}

[data-style="terminal"][data-brightness="dark"] .event-type.opportunity {
  color: #00bcd4;
  border-color: #00bcd4;
  background: transparent;
}

[data-style="terminal"][data-brightness="dark"] .data-source-badge.ib {
  color: #00e676;
  border-color: #00e676;
  background: transparent;
}

[data-style="terminal"][data-brightness="dark"] .data-source-badge.yfinance {
  color: #ffab40;
  border-color: #ffab40;
  background: transparent;
}

[data-style="terminal"][data-brightness="dark"] .sync-dot.missing {
  background: #ff5252;
}

/* terminal-light accent overrides */
[data-style="terminal"][data-brightness="light"] .pnl-pos {
  color: #007a3d;
}

[data-style="terminal"][data-brightness="light"] .pnl-neg {
  color: #c0392b;
}

[data-style="terminal"][data-brightness="light"] .signal-badge.buy {
  background: transparent;
  color: #007a3d;
  border-color: #007a3d;
}

[data-style="terminal"][data-brightness="light"] .signal-badge.sell {
  background: transparent;
  color: #c0392b;
  border-color: #c0392b;
}

[data-style="terminal"][data-brightness="light"] .signal-badge.hold {
  background: transparent;
  color: #b8860b;
  border-color: #b8860b;
}

[data-style="terminal"][data-brightness="light"] .signal-badge.monitoring {
  background: transparent;
  color: #888;
  border-color: #ccc;
}

[data-style="terminal"][data-brightness="light"] .signal-badge.market-closed {
  background: transparent;
  color: #aaa;
  border-color: #ccc;
}

[data-style="terminal"][data-brightness="light"] .pos-card.long {
  border-left-color: #007a3d;
}

[data-style="terminal"][data-brightness="light"] .pos-card.short {
  border-left-color: #c0392b;
}

[data-style="terminal"][data-brightness="light"] .strategy-card.buy {
  border-left-color: #007a3d;
}

[data-style="terminal"][data-brightness="light"] .strategy-card.sell {
  border-left-color: #c0392b;
}

[data-style="terminal"][data-brightness="light"] .strategy-card.hold {
  border-left-color: #b8860b;
}

[data-style="terminal"][data-brightness="light"] .strategy-card.active {
  border-left-color: #007a3d;
}

[data-style="terminal"][data-brightness="light"] .range-marker.stop {
  background: #c0392b;
}

[data-style="terminal"][data-brightness="light"] .event-type.trade {
  color: #007a3d;
  border-color: #007a3d;
  background: transparent;
}

[data-style="terminal"][data-brightness="light"] .event-type.alert {
  color: #c0392b;
  border-color: #c0392b;
  background: transparent;
}

[data-style="terminal"][data-brightness="light"] .event-type.opportunity {
  color: #0077aa;
  border-color: #0077aa;
  background: transparent;
}

[data-style="terminal"][data-brightness="light"] .data-source-badge.ib {
  color: #007a3d;
  border-color: #007a3d;
  background: transparent;
}

[data-style="terminal"][data-brightness="light"] .data-source-badge.yfinance {
  color: #b8860b;
  border-color: #b8860b;
  background: transparent;
}

[data-style="terminal"][data-brightness="light"] .sync-dot.missing {
  background: #c0392b;
}

/* ── Reset ── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0
}

/* ── Base ── */
body {
  font-family: system-ui, -apple-system, 'SF Pro Display', sans-serif;
  background: var(--bg);
  color: var(--color);
  padding: 1rem 2rem;
  min-height: 100vh;
  position: relative;
  transition: background .25s, color .25s
}

body::before {
  content: '';
  position: fixed;
  top: -10%;
  left: -5%;
  width: 55%;
  height: 65%;
  background: var(--blob-tl);
  pointer-events: none;
  z-index: 0
}

body::after {
  content: '';
  position: fixed;
  bottom: -10%;
  right: -5%;
  width: 55%;
  height: 65%;
  background: var(--blob-br);
  pointer-events: none;
  z-index: 0
}

/* ── Header ── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1
}

h1 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -.02em
}

a.logout {
  color: var(--muted);
  text-decoration: none;
  font-size: .85rem;
  transition: color .2s
}

a.logout:hover {
  color: #f87171
}

/* ── Theme toggles ── */
.theme-controls {
  display: flex;
  align-items: center;
  gap: .4rem
}

.theme-btn {
  padding: .3rem .55rem;
  border-radius: 8px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--muted3);
  font-size: .75rem;
  cursor: pointer;
  transition: all .2s
}

.theme-btn:hover {
  border-color: var(--btn-border);
  color: var(--color)
}

.theme-btn.active {
  border-color: var(--btn-border);
  background: var(--btn-bg);
  color: var(--color)
}

/* ── Grids ── */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1
}

.grid-4 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1
}

.grid-5 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1
}

.grid-top {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  grid-template-rows: auto auto;
  gap: 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1
}

.grid-top>.card-tall {
  grid-row: span 2
}

/* ── Cards ── */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border-radius: 16px;
  padding: 1.25rem;
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow), var(--card-inset);
  transition: border-color .2s, box-shadow .2s
}

.card:hover {
  border-color: var(--card-border-hover);
  box-shadow: var(--card-shadow-hover), var(--card-inset-hover)
}

.card h2 {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: .75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em
}

.stat {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.02em
}

.stat-sm {
  font-size: 1.1rem;
  font-weight: 600
}

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem
}

th {
  text-align: left;
  color: var(--th-color);
  padding: .5rem;
  border-bottom: 1px solid var(--th-border)
}

td {
  padding: .5rem;
  border-bottom: 1px solid var(--td-border)
}

/* ── Actions / inputs ── */
.actions {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1
}

button {
  padding: .5rem .75rem;
  border-radius: 10px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  backdrop-filter: blur(10px);
  color: var(--color);
  font-size: .85rem;
  cursor: pointer;
  transition: all .2s;
  font-weight: 500
}

button:hover {
  background: var(--btn-bg-hover);
  border-color: var(--btn-border-hover);
  box-shadow: var(--btn-shadow-hover)
}

/* ── Chart ── */
#chart-container {
  background: var(--chart-bg);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border-radius: 16px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  min-height: 350px;
  border: 1px solid var(--card-border);
  position: relative;
  z-index: 1;
  box-shadow: var(--card-shadow);
  overflow: hidden
}

/* ── Misc ── */
.status-bar {
  font-size: .75rem;
  color: var(--muted2);
  text-align: right;
  position: relative;
  z-index: 1
}

.pnl-pos {
  color: #4ade80
}

.pnl-neg {
  color: #f87171
}

.section-title {
  font-size: 1rem;
  color: var(--section-title);
  margin-bottom: .75rem;
  position: relative;
  z-index: 1;
  font-weight: 500;
  letter-spacing: -.01em
}

/* ── Strategy cards ── */
.strategy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1
}

.strategy-card {
  background: var(--card-bg);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border-radius: 16px;
  padding: 1.25rem;
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--card-border);
  transition: border-color .2s, box-shadow .2s;
  box-shadow: var(--card-shadow), var(--card-inset);
  display: flex;
  flex-direction: column
}

.strategy-card:hover {
  box-shadow: var(--card-shadow-hover), var(--card-inset-hover)
}

.strategy-card.buy {
  border-left-color: rgba(56, 189, 248, .6)
}

.strategy-card.sell {
  border-left-color: rgba(248, 113, 113, .6)
}

.strategy-card.hold {
  border-left-color: rgba(251, 191, 36, .6)
}

.strategy-card.monitoring {
  border-left-color: rgba(71, 85, 105, .6)
}

.strategy-card.active {
  border-left-color: rgba(74, 222, 128, .6)
}

.strategy-card.error {
  border-left-color: rgba(100, 116, 139, .6)
}

.strategy-card .name {
  font-weight: 600;
  font-size: .95rem;
  margin-bottom: .25rem
}

.strategy-card .symbol {
  color: var(--muted3);
  font-size: .8rem
}

.strategy-card .reasons {
  font-size: .75rem;
  color: var(--muted);
  margin-top: .35rem
}

.strategy-card .indicators {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .2rem .75rem;
  margin-top: .6rem;
  font-size: .75rem
}

.strategy-card .ind-label {
  color: var(--muted)
}

.strategy-card .ind-value {
  color: var(--muted4);
  text-align: right
}

.strategy-card .config-line {
  font-size: .7rem;
  color: var(--muted2);
  margin-top: .5rem;
  border-top: 1px solid var(--strategy-config-border);
  padding-top: .4rem
}

/* ── Badges ── */
.auto-badge {
  display: inline-block;
  padding: .1rem .4rem;
  border-radius: 6px;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .3px;
  vertical-align: middle;
  margin-left: .4rem
}

.auto-badge.on {
  background: rgba(248, 113, 113, .1);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, .15)
}

.auto-badge.off {
  background: rgba(251, 191, 36, .1);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, .15)
}

/* ── Adaptation badge (adaptive-strategy-runtime §R6) ── */
/* Rendered by _renderAdaptationBadge() in dashboard.js when a
   strategy carries a non-default adaptation_state. Each state
   gets a distinct tint so operators can scan a card row and tell
   why the strategy isn't behaving at baseline. Clicking opens
   the expanded panel via toggleAdaptationPanel(). */
.adapt-badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 6px;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .3px;
  vertical-align: middle;
  margin-left: .4rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter 120ms ease
}

.adapt-badge:hover {
  filter: brightness(1.15)
}

/* Event-tightening — yellow tint for the "something's imminent,
   exits are closer-to-entry" posture. Matches the hold signal
   palette to read as caution rather than alarm. */
.adapt-badge.adapt-event_tightening {
  background: rgba(251, 191, 36, .15);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, .25)
}

/* Disabled temporary — slate/grey for "this strategy is paused".
   Deliberately flat to stand apart from the active / buy / sell
   signal colours on the card. */
.adapt-badge.adapt-disabled_temporary {
  background: rgba(100, 116, 139, .15);
  color: #94a3b8;
  border-color: rgba(100, 116, 139, .25)
}

/* Size-adjusted — blue, matches the info tone used for
   informational states elsewhere on the card. The budget cut
   isn't a warning, it's a deliberate posture. */
.adapt-badge.adapt-size_adjusted {
  background: rgba(99, 102, 241, .15);
  color: #818cf8;
  border-color: rgba(99, 102, 241, .25)
}

/* Custom — orange, loud enough to catch the eye because a
   ``custom`` state is an escape hatch by definition and the
   operator should look at the expanded panel for details. */
.adapt-badge.adapt-custom {
  background: rgba(251, 146, 60, .15);
  color: #fb923c;
  border-color: rgba(251, 146, 60, .25)
}

.signal-badge {
  display: inline-block;
  padding: .25rem .75rem;
  border-radius: 8px;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-top: .5rem;
  letter-spacing: .5px
}

.signal-badge.buy {
  background: rgba(74, 222, 128, .12);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, .2)
}

.signal-badge.sell {
  background: rgba(248, 113, 113, .12);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, .2)
}

.signal-badge.hold {
  background: rgba(251, 191, 36, .12);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, .2)
}

.signal-badge.monitoring {
  background: rgba(74, 222, 128, .12);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, .2)
}

.signal-badge.market-closed {
  background: rgba(100, 116, 139, .1);
  color: #64748b;
  border: 1px solid rgba(100, 116, 139, .2)
}

.signal-badge.error {
  background: rgba(100, 116, 139, .1);
  color: #64748b;
  border: 1px solid rgba(100, 116, 139, .2)
}

.data-source-badge {
  display: inline-block;
  padding: .1rem .4rem;
  border-radius: 6px;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .3px;
  margin-left: .4rem
}

.data-source-badge.ib {
  background: rgba(74, 222, 128, .1);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, .15)
}

.data-source-badge.yfinance {
  background: rgba(251, 191, 36, .1);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, .15)
}

/* ── Confidence bar ── */
.conf-bar-wrap {
  margin-top: .5rem;
  position: relative;
  height: 18px;
  background: var(--conf-bar-bg);
  border-radius: 6px;
  overflow: hidden
}

.conf-bar {
  height: 100%;
  border-radius: 4px;
  transition: width .3s
}

.conf-bar.below {
  background: var(--conf-bar-below)
}

.conf-bar.near {
  background: #fbbf24
}

.conf-bar.ready {
  background: #4ade80
}

.conf-threshold {
  position: absolute;
  top: 0;
  height: 100%;
  width: 2px;
  background: #f87171;
  z-index: 1
}

.conf-labels {
  display: flex;
  justify-content: space-between;
  font-size: .65rem;
  color: var(--muted);
  margin-top: .15rem
}

/* ── Monitor dot ── */
.monitor-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px
}

.monitor-dot.on {
  background: #4ade80;
  animation: pulse 2s ease-in-out infinite
}

.monitor-dot.off {
  background: #f87171
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: .4
  }
}

/* ── Event log ── */
.event-log {
  max-height: 300px;
  overflow-y: auto;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: .75rem;
  line-height: 1.6;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent
}

.event-log::-webkit-scrollbar {
  width: 4px
}

.event-log::-webkit-scrollbar-track {
  background: transparent
}

.event-log::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px
}

#strategy-perf-rows::-webkit-scrollbar,
#exposure-pos-rows::-webkit-scrollbar,
#portfolio-alloc-rows::-webkit-scrollbar {
  width: 4px
}

#strategy-perf-rows::-webkit-scrollbar-track,
#exposure-pos-rows::-webkit-scrollbar-track,
#portfolio-alloc-rows::-webkit-scrollbar-track {
  background: transparent
}

#strategy-perf-rows::-webkit-scrollbar-thumb,
#exposure-pos-rows::-webkit-scrollbar-thumb,
#portfolio-alloc-rows::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px
}

.event-item {
  padding: .4rem .6rem;
  border-bottom: 1px solid var(--event-border);
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  transition: background .15s
}

.event-item:hover {
  background: var(--event-hover)
}

.event-type {
  font-weight: 600;
  font-size: .7rem;
  padding: .1rem .4rem;
  border-radius: 6px;
  white-space: nowrap
}

.event-type.opportunity {
  background: rgba(96, 165, 250, .1);
  color: #60a5fa;
  border: 1px solid rgba(96, 165, 250, .15)
}

.event-type.trade {
  background: rgba(74, 222, 128, .1);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, .15)
}

.event-type.alert {
  background: rgba(248, 113, 113, .1);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, .15)
}

.event-time {
  color: var(--muted);
  white-space: nowrap;
  font-size: .7rem
}

.event-detail {
  color: var(--muted3);
  flex: 1;
  word-break: break-word
}

/* ── Log viewer ── */
.log-viewer {
  max-height: 250px;
  overflow-y: auto;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: .7rem;
  line-height: 1.5;
  background: var(--log-bg);
  border-radius: 12px;
  padding: .75rem;
  color: var(--muted3);
  border: 1px solid var(--log-border)
}

.log-viewer .log-error {
  color: #f87171
}

.log-viewer .log-warn {
  color: #fbbf24
}

.log-viewer .log-info {
  color: var(--muted)
}

/* ── Tabs ── */
.tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 0
}

.tab-btn {
  padding: .4rem .8rem;
  font-size: .8rem;
  border: 1px solid var(--tab-border);
  background: var(--tab-bg);
  color: var(--muted);
  cursor: pointer;
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  transition: all .2s
}

.tab-btn.active {
  background: var(--tab-active-bg);
  color: var(--color);
  border-color: var(--tab-active-border)
}

.tab-content {
  display: none
}

.tab-content.active {
  display: block
}

/* ── Position cards ── */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem
}

.pos-card {
  background: var(--pos-card-bg);
  border-radius: 12px;
  padding: 1rem;
  border: 1px solid var(--pos-card-border);
  border-left: 4px solid var(--card-border);
  transition: box-shadow .2s;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px)
}

.pos-card:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, .2)
}

.pos-card.long {
  border-left-color: rgba(74, 222, 128, .5)
}

.pos-card.short {
  border-left-color: rgba(248, 113, 113, .5)
}

.pos-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem
}

.pos-header .pos-symbol {
  font-weight: 600;
  font-size: .95rem
}

.pos-header .pos-pnl {
  font-weight: 700;
  font-size: .95rem
}

.pos-meta {
  font-size: .75rem;
  color: var(--muted);
  margin-bottom: .3rem
}

/* ── Sync dot ── */
.sync-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  position: relative;
  cursor: default
}

.sync-dot.synced {
  background: #4ade80
}

.sync-dot.missing {
  background: #f87171
}

.sync-dot.qty_mismatch {
  background: #fbbf24
}

.sync-dot .sync-tooltip {
  visibility: hidden;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--sync-tooltip-bg);
  backdrop-filter: blur(10px);
  color: var(--color);
  font-size: .7rem;
  padding: 4px 8px;
  border-radius: 8px;
  white-space: nowrap;
  border: 1px solid var(--card-border);
  z-index: 10;
  font-weight: 400
}

.sync-dot:hover .sync-tooltip {
  visibility: visible
}

/* ── Range bar ── */
.range-bar {
  position: relative;
  height: 22px;
  background: var(--range-bar-bg);
  border-radius: 8px;
  margin: 1.6rem 0 .4rem;
  overflow: visible
}

.range-label {
  position: absolute;
  top: -16px;
  font-size: .6rem;
  color: var(--muted);
  transform: translateX(-50%)
}

.range-marker {
  position: absolute;
  top: 0;
  height: 100%;
  width: 2px;
  z-index: 2
}

.range-marker.stop {
  background: #f87171
}

.range-marker.entry {
  background: #94a3b8
}

.range-marker.tp {
  background: #4ade80
}

.range-fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 4px;
  opacity: .35
}

.range-current {
  position: absolute;
  top: 2px;
  width: 8px;
  height: 18px;
  border-radius: 3px;
  background: #fbbf24;
  z-index: 3;
  transform: translateX(-50%)
}

.range-labels-bottom {
  display: flex;
  justify-content: space-between;
  font-size: .65rem;
  color: var(--muted);
  margin-top: .15rem
}

/* ── Market hours ── */
.mh-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
  font-size: .85rem
}

.mh-label {
  flex: 0 0 20%;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  overflow: hidden
}

.mh-label-name {
  color: var(--muted3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.mh-label-perf {
  display: flex;
  align-items: center;
  gap: .3rem;
  overflow: hidden
}

.mh-ticker {
  font-size: .65rem;
  color: var(--muted2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0
}

.mh-sparkline {
  display: block;
  flex-shrink: 0
}

.mh-price {
  font-size: .68rem;
  font-weight: 600;
  color: var(--muted3);
  flex-shrink: 0;
  white-space: nowrap
}

.mh-pct {
  font-size: .7rem;
  font-weight: 600;
  flex-shrink: 0;
  white-space: nowrap
}

.mh-pct.pos {
  color: #4ade80
}

.mh-pct.neg {
  color: #f87171
}

.mh-pct.flat {
  color: var(--muted)
}

.mh-bar-wrap {
  flex: 1;
  min-width: 40px;
  position: relative;
  height: 16px;
  background: none;
  border-radius: 5px;
  overflow: visible
}

.mh-track {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--mh-track-bg);
  border-radius: 5px;
  padding: .2rem .4rem;
  min-width: 40px
}

.mh-bar {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 5px;
  opacity: .5
}

.mh-bar.open {
  background: #4ade80
}

.mh-bar.closed {
  background: rgba(248, 113, 113, .15)
}

.mh-now {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: #fbbf24;
  z-index: 2
}

.mh-status {
  flex: 0 0 48px;
  text-align: right;
  font-size: .7rem;
  font-weight: 600;
  margin-left: .4rem
}

.mh-status.open {
  color: #4ade80
}

.mh-status.closed {
  color: var(--muted)
}

.mh-hours {
  display: flex;
  justify-content: space-between;
  font-size: .65rem;
  color: var(--muted2);
  margin-left: 20%;
  padding: 0 calc(48px + .4rem + .5rem) 0 .4rem;
  margin-bottom: .5rem
}

/* ── Exposure bar ── */
.exposure-bar-wrap {
  position: relative;
  height: 8px;
  background: var(--exposure-bar-bg);
  border-radius: 4px;
  overflow: hidden
}

.exposure-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(99, 102, 241, .4), rgba(168, 85, 247, .4));
  transition: width .4s ease
}

/* ── Responsive: tablet ── */
@media (max-width: 900px) {
  body {
    padding: .75rem
  }

  .grid-4,
  .grid-5,
  .grid-top {
    grid-template-columns: 1fr 1fr
  }

  .grid-top {
    grid-template-rows: auto
  }

  .grid-top>.card-tall {
    grid-row: auto
  }

  .grid {
    grid-template-columns: 1fr
  }

  .actions {
    flex-wrap: wrap;
    gap: .4rem
  }

  .mh-label {
    flex-basis: 40%
  }

  .mh-hours {
    margin-left: 40%
  }
}

/* ── Responsive: phone ── */
@media (max-width: 540px) {
  body {
    padding: .5rem .6rem
  }

  body::before,
  body::after {
    display: none
  }

  .grid-4,
  .grid-5,
  .grid-top {
    grid-template-columns: 1fr
  }

  .grid-top {
    grid-template-rows: auto
  }

  .grid-top>.card-tall {
    grid-row: auto
  }

  .grid {
    grid-template-columns: 1fr
  }

  .grid-3 {
    grid-template-columns: 1fr
  }

  .strategy-grid {
    grid-template-columns: 1fr
  }

  .pos-grid {
    grid-template-columns: 1fr
  }

  .stat {
    font-size: 1.3rem
  }

  .card {
    padding: 1rem;
    border-radius: 12px
  }

  .strategy-card {
    border-radius: 12px
  }

  .actions input,
  .actions select,
  .actions button {
    font-size: .8rem;
    min-width: 0
  }

  #symbol-input {
    min-width: 100%
  }

  .mh-label {
    flex-basis: 35%;
    font-size: .7rem
  }

  .mh-hours {
    margin-left: 35%
  }

  header h1 {
    font-size: 1.1rem
  }
}

/* ── Indicator matrix (strategy setup visualization) ── */
.ind-matrix {
  margin-top: .5rem;
  border-top: 1px solid var(--strategy-config-border);
  padding-top: .5rem
}

.ind-matrix-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .35rem
}

.ind-matrix-title {
  font-size: .65rem;
  color: var(--muted2);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600
}

.ind-matrix-body {
  display: flex;
  flex-direction: column;
  gap: .45rem
}

.ind-row {
  display: grid;
  grid-template-columns: 118px 1fr 54px;
  align-items: center;
  gap: .5rem;
  font-size: .7rem
}

.ind-row-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0
}

.ind-row-name {
  display: flex;
  align-items: baseline;
  gap: .25rem;
  color: var(--muted3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.ind-row-weight {
  color: var(--muted);
  font-size: .65rem
}

.ind-row-hint {
  color: var(--muted);
  font-size: .6rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2
}

.ind-row-val {
  text-align: right;
  color: var(--muted4);
  font-variant-numeric: tabular-nums;
  font-size: .7rem;
  font-weight: 500
}

.ind-row-val--hit-buy {
  color: #4ade80;
  font-weight: 600
}

.ind-row-val--hit-sell {
  color: #f87171;
  font-weight: 600
}

.ind-row-bar {
  position: relative;
  height: 10px;
  background: var(--conf-bar-bg);
  border-radius: 4px;
  overflow: visible
}

.ind-row-bar--empty {
  background: var(--conf-bar-bg);
  opacity: .4
}

/* zone variants */
.ind-zone {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 3px
}

.ind-zone--buy {
  background: rgba(74, 222, 128, .22)
}

.ind-zone--sell {
  background: rgba(248, 113, 113, .22)
}

.ind-zone--neutral {
  background: rgba(148, 163, 184, .12)
}

.ind-zone--strong {
  background: rgba(56, 189, 248, .22)
}

.ind-zone--warm {
  background: rgba(251, 191, 36, .18)
}

.ind-zone--info {
  background: rgba(148, 163, 184, .14)
}

.ind-zone-center {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: var(--muted2);
  opacity: .4;
  z-index: 1
}

/* trigger brackets — underline the zone(s) the strategy is hunting for */
.ind-trigger {
  position: absolute;
  bottom: -4px;
  height: 2px;
  border-radius: 1px;
  z-index: 2
}

.ind-trigger--buy {
  background: #4ade80;
  box-shadow: 0 0 4px rgba(74, 222, 128, .6)
}

.ind-trigger--sell {
  background: #f87171;
  box-shadow: 0 0 4px rgba(248, 113, 113, .6)
}

.ind-trigger--both {
  background: #60a5fa;
  box-shadow: 0 0 4px rgba(96, 165, 250, .6)
}

/* needle */
.ind-needle {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 3px;
  border-radius: 2px;
  transform: translateX(-50%);
  z-index: 3;
  transition: left .3s ease, background .2s, box-shadow .2s
}

.ind-needle--neutral {
  background: var(--color);
  box-shadow: 0 0 0 1px var(--card-bg)
}

.ind-needle--hit-buy {
  background: #4ade80;
  box-shadow: 0 0 0 1px var(--card-bg), 0 0 6px rgba(74, 222, 128, .7)
}

.ind-needle--hit-sell {
  background: #f87171;
  box-shadow: 0 0 0 1px var(--card-bg), 0 0 6px rgba(248, 113, 113, .7)
}

/* terminal theme tweaks */
[data-style="terminal"] .ind-row-bar {
  border-radius: 2px
}

[data-style="terminal"] .ind-zone {
  border-radius: 0
}

[data-style="terminal"] .ind-needle {
  border-radius: 0;
  box-shadow: none
}

[data-style="terminal"] .ind-needle--neutral {
  background: var(--accent)
}

[data-style="terminal"] .ind-trigger {
  border-radius: 0;
  box-shadow: none
}

/* phone layout — shrink label column, drop weight */
@media (max-width: 540px) {
  .ind-row {
    grid-template-columns: 100px 1fr 48px;
    font-size: .65rem
  }

  .ind-row-weight {
    display: none
  }

  .ind-row-hint {
    font-size: .58rem
  }
}

/* ── Past performance (baseline backtest) ── */
.perf-block {
  margin-top: auto;
  padding-top: .75rem;
  border-top: 1px solid var(--strategy-config-border)
}

.perf-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .35rem;
  gap: .5rem
}

.perf-title {
  font-size: .65rem;
  color: var(--muted2);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600
}

.perf-head-right {
  display: flex;
  align-items: center;
  gap: .4rem
}

.perf-hint {
  font-size: .65rem;
  color: var(--muted)
}

.perf-age {
  font-size: .6rem;
  color: var(--muted);
  white-space: nowrap
}

.perf-stale-badge {
  font-size: .6rem;
  color: #fbbf24;
  background: rgba(251, 191, 36, .1);
  border: 1px solid rgba(251, 191, 36, .15);
  padding: .05rem .3rem;
  border-radius: 5px;
  font-weight: 600;
  white-space: nowrap
}

.perf-refresh {
  padding: 1px 6px;
  font-size: .75rem;
  line-height: 1.1;
  border-radius: 5px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--muted3);
  cursor: pointer;
  transition: all .15s
}

.perf-refresh:hover {
  color: var(--color);
  border-color: var(--btn-border);
  background: var(--btn-bg)
}

.perf-body {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  min-width: 0
}

.perf-body--empty,
.perf-body--pending {
  font-size: .7rem;
  color: var(--muted);
  padding: .25rem 0
}

.perf-spark {
  width: 100%;
  color: var(--muted2)
}

.perf-spark-svg {
  display: block;
  width: 100%;
  height: 32px;
  border-radius: 4px
}

.perf-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .45rem .6rem;
  font-size: .7rem
}

.perf-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .1rem;
  min-width: 0
}

.perf-stat-label {
  color: var(--muted);
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  line-height: 1
}

.perf-stat-val {
  color: var(--muted4);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: .8rem;
  line-height: 1.1;
  min-width: 0;
  white-space: nowrap
}

.perf-pf--good {
  color: #4ade80
}

.perf-pf--ok {
  color: var(--muted4)
}

.perf-pf--weak {
  color: #fbbf24
}

/* terminal theme */
[data-style="terminal"] .perf-refresh,
[data-style="terminal"] .perf-spark-svg,
[data-style="terminal"] .perf-stale-badge {
  border-radius: 2px
}

/* phone */
@media (max-width: 540px) {
  .perf-body {
    flex-direction: column;
    align-items: stretch;
    gap: .35rem
  }

  .perf-spark {
    flex: 0 0 auto;
    width: 100%
  }

  .perf-stats {
    grid-template-columns: repeat(3, 1fr)
  }
}

.perf-window-badge {
  font-size: .6rem;
  color: var(--muted3);
  background: rgba(148, 163, 184, .08);
  border: 1px solid rgba(148, 163, 184, .15);
  padding: .05rem .3rem;
  border-radius: 5px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: .02em
}

[data-style="terminal"] .perf-window-badge {
  border-radius: 2px
}


/* ── Strategy card action buttons ───────────────────────────────
   "Optimize" + "Edit" sit on the same row at the bottom of each
   card, below the performance block. Kept compact so they don't
   steal visual weight from the signal + performance content — the
   primary read on the card. */

.strategy-actions {
  display: flex;
  gap: .4rem;
  margin-top: .6rem;
  padding-top: .5rem;
  border-top: 1px solid var(--card-border);
}

.strategy-action-btn {
  flex: 1;
  padding: .35rem .5rem;
  font-size: .72rem;
  border-radius: 6px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--muted4);
  cursor: pointer;
  font-weight: 500;
  transition: background 120ms, border-color 120ms;
}

.strategy-action-btn:hover {
  background: rgba(255, 255, 255, .06);
  border-color: var(--input-border-hover, rgba(255, 255, 255, .15));
}

.strategy-action-btn.primary {
  color: #93c5fd;
  border-color: rgba(147, 197, 253, .2);
}

.strategy-action-btn.primary:hover {
  background: rgba(147, 197, 253, .08);
  border-color: rgba(147, 197, 253, .35);
}

/* ── Modal ─────────────────────────────────────────────────────
   Shared shell for both optimize + edit modals. Same transition +
   backdrop so opening one feels consistent with the other.  */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--card-bg, #0f1117);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
  width: min(640px, 100%);
  max-height: calc(100vh - 3rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--card-border);
  gap: .75rem;
}

.modal-header h3 {
  margin: 0;
  font-size: .95rem;
  font-weight: 600;
  color: var(--muted4);
}

.modal-sub {
  font-size: .75rem;
  color: var(--muted);
  margin-top: .1rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted2);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 .25rem;
  line-height: 1;
}

.modal-close:hover {
  color: var(--muted4);
}

.modal-body {
  padding: 1rem 1.1rem;
  overflow-y: auto;
  flex: 1 1 auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: .75rem 1.1rem;
  border-top: 1px solid var(--card-border);
  background: var(--card-bg-muted, rgba(0, 0, 0, .2));
}

.modal-btn {
  padding: .45rem .85rem;
  font-size: .8rem;
  border-radius: 6px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--muted4);
  cursor: pointer;
  font-weight: 500;
}

.modal-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, .06);
}

.modal-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.modal-btn.primary {
  border-color: rgba(147, 197, 253, .35);
  background: rgba(147, 197, 253, .12);
  color: #93c5fd;
}

.modal-btn.primary:hover:not(:disabled) {
  background: rgba(147, 197, 253, .2);
}

.modal-btn.success {
  border-color: rgba(74, 222, 128, .35);
  background: rgba(74, 222, 128, .12);
  color: #4ade80;
}

.modal-btn.success:hover:not(:disabled) {
  background: rgba(74, 222, 128, .2);
}

.modal-btn.danger {
  border-color: rgba(248, 113, 113, .3);
  color: #f87171;
}

/* ── Form fields (shared) ─────────────────────────────────────── */

.form-row {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  margin-bottom: .75rem;
}

.form-row label {
  font-size: .75rem;
  color: var(--muted2);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-row label.form-toggle {
  justify-content: flex-start;
  font-size: .8rem;
  color: var(--muted3);
  font-weight: 400;
  gap: .4rem;
  cursor: pointer;
}

.form-row input,
.form-row select,
.form-row textarea {
  padding: .45rem .6rem;
  border-radius: 6px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--color);
  font-size: .8rem;
  font-family: inherit;
}

.form-row textarea {
  font-family: ui-monospace, SFMono-Regular, 'Menlo', monospace;
  font-size: .75rem;
  min-height: 140px;
  resize: vertical;
}

.form-row-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}

.form-row-inline .form-row {
  margin-bottom: 0;
}

.form-hint {
  font-size: .7rem;
  color: var(--muted);
  margin-top: .1rem;
  margin-bottom: .4rem;
  line-height: 1.35;
}

.form-error {
  background: rgba(248, 113, 113, .1);
  border: 1px solid rgba(248, 113, 113, .2);
  color: #fca5a5;
  padding: .5rem .6rem;
  border-radius: 6px;
  font-size: .75rem;
  margin-bottom: .75rem;
}

.form-toggle {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  color: var(--muted3);
  cursor: pointer;
  justify-content: flex-start;
}

.form-toggle input[type="checkbox"] {
  margin: 0;
  accent-color: #93c5fd;
}

/* ── Optimize-specific ────────────────────────────────────────── */

.opt-status {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .75rem;
  border-radius: 6px;
  background: var(--card-bg-muted, rgba(255, 255, 255, .03));
  border: 1px solid var(--card-border);
  font-size: .8rem;
  margin-bottom: .75rem;
}

.opt-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(147, 197, 253, .2);
  border-top-color: #93c5fd;
  border-radius: 50%;
  animation: opt-spin 800ms linear infinite;
}

@keyframes opt-spin {
  to {
    transform: rotate(360deg);
  }
}

.opt-decision {
  border-radius: 8px;
  padding: .75rem;
  margin-top: .75rem;
  border: 1px solid var(--card-border);
}

.opt-decision.apply {
  border-color: rgba(74, 222, 128, .35);
  background: rgba(74, 222, 128, .06);
}

.opt-decision.keep {
  border-color: rgba(251, 191, 36, .3);
  background: rgba(251, 191, 36, .04);
}

.opt-decision-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .4rem;
}

.opt-decision-action {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: .15rem .4rem;
  border-radius: 4px;
}

.opt-decision.apply .opt-decision-action {
  background: rgba(74, 222, 128, .15);
  color: #4ade80;
}

.opt-decision.keep .opt-decision-action {
  background: rgba(251, 191, 36, .15);
  color: #fbbf24;
}

.opt-decision-reason {
  font-size: .8rem;
  color: var(--muted3);
  margin-bottom: .5rem;
}

.opt-decision-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: .5rem;
  margin-top: .4rem;
}

.opt-decision-metric {
  background: var(--card-bg-muted, rgba(0, 0, 0, .2));
  border-radius: 4px;
  padding: .3rem .4rem;
  font-size: .7rem;
}

.opt-decision-metric-label {
  color: var(--muted);
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.opt-decision-metric-val {
  color: var(--muted4);
  font-weight: 600;
  font-size: .8rem;
}

.opt-warnings {
  margin-top: .5rem;
  font-size: .7rem;
  color: #fbbf24;
}

.opt-warnings ul {
  margin: .2rem 0 0 1rem;
  padding: 0;
}

.opt-params-block {
  margin-top: .6rem;
  padding-top: .6rem;
  border-top: 1px dashed var(--card-border);
}

.opt-params-title {
  font-size: .7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: .3rem;
}

.opt-params-kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .15rem .6rem;
  font-size: .75rem;
  font-family: ui-monospace, SFMono-Regular, 'Menlo', monospace;
}

.opt-params-kv dt {
  color: var(--muted2);
}

.opt-params-kv dd {
  color: var(--muted4);
  margin: 0;
}

/* ── Diff (edit modal) ────────────────────────────────────────── */

.diff-block {
  font-family: ui-monospace, SFMono-Regular, 'Menlo', monospace;
  font-size: .75rem;
  background: var(--card-bg-muted, rgba(0, 0, 0, .2));
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: .5rem .6rem;
  margin-top: .6rem;
  max-height: 220px;
  overflow-y: auto;
}

.diff-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: .5rem;
  padding: .2rem 0;
  border-bottom: 1px dashed rgba(255, 255, 255, .04);
}

.diff-row:last-child {
  border-bottom: none;
}

.diff-key {
  color: var(--muted);
}

.diff-val {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  align-items: center;
}

.diff-old {
  color: #f87171;
  text-decoration: line-through;
  opacity: .7;
}

.diff-arrow {
  color: var(--muted);
}

.diff-new {
  color: #4ade80;
  font-weight: 500;
}

.diff-empty {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: .75rem;
}

/* ── Indicator editor (edit modal) ────────────────────────────── */

.edit-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  margin-bottom: .5rem;
  padding-top: .75rem;
  border-top: 1px solid var(--card-border);
}

.edit-section-title {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted3);
  margin: 0;
}

.edit-add-btn {
  font-size: .7rem;
  padding: .2rem .5rem;
  border-radius: 4px;
  border: 1px solid rgba(147, 197, 253, .3);
  background: rgba(147, 197, 253, .08);
  color: #93c5fd;
  cursor: pointer;
  transition: background .15s;
}

.edit-add-btn:hover {
  background: rgba(147, 197, 253, .18);
}

.ind-edit-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: .4rem;
  align-items: start;
  padding: .5rem .6rem;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card-bg-muted, rgba(0, 0, 0, .15));
  margin-bottom: .4rem;
}

.ind-edit-main {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.ind-edit-top {
  display: flex;
  gap: .4rem;
  align-items: center;
}

.ind-edit-type {
  flex: 1;
  padding: .3rem .5rem;
  border-radius: 4px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--color);
  font-size: .75rem;
}

.ind-edit-weight {
  width: 60px;
  padding: .3rem .4rem;
  border-radius: 4px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--color);
  font-size: .75rem;
  text-align: center;
}

.ind-edit-params {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}

.ind-edit-param {
  display: flex;
  align-items: center;
  gap: .25rem;
}

.ind-edit-param label {
  font-size: .65rem;
  color: var(--muted);
  white-space: nowrap;
}

.ind-edit-param input {
  width: 52px;
  padding: .2rem .35rem;
  border-radius: 4px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--color);
  font-size: .7rem;
  text-align: center;
}

.ind-edit-remove {
  padding: .25rem .4rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .85rem;
  line-height: 1;
  border-radius: 4px;
  transition: color .15s, background .15s;
  align-self: center;
}

.ind-edit-remove:hover {
  color: #f87171;
  background: rgba(248, 113, 113, .1);
}

.ind-edit-desc {
  font-size: .65rem;
  color: var(--muted);
  font-style: italic;
  margin-top: .1rem;
}


/* Proposals card (agentic-runtime Track 1) */

.proposal-row {
  padding: .6rem 0;
  border-bottom: 1px solid var(--td-border);
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.proposal-row:last-child {
  border-bottom: none;
}

.proposal-head {
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.proposal-meta {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.proposal-kind {
  color: var(--muted4);
  font-weight: 600;
}

.proposal-target {
  color: var(--muted3);
}

.proposal-age {
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

.proposal-summary {
  font-size: .85rem;
  color: var(--muted4);
  line-height: 1.4;
}

.proposal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .35rem;
}

.proposal-btn {
  font-size: .7rem;
  padding: .3rem .7rem;
  border-radius: 6px;
  border: 1px solid var(--card-border);
  background: transparent;
  color: var(--muted3);
  cursor: pointer;
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}

.proposal-btn:hover {
  border-color: var(--card-border-hover);
  color: var(--muted4);
}

.proposal-btn.approve {
  color: #4ade80;
  border-color: rgba(74, 222, 128, .25);
}

.proposal-btn.approve:hover {
  background: rgba(74, 222, 128, .08);
  border-color: rgba(74, 222, 128, .45);
}

.proposal-btn.reject {
  color: #f87171;
  border-color: rgba(248, 113, 113, .25);
}

.proposal-btn.reject:hover {
  background: rgba(248, 113, 113, .08);
  border-color: rgba(248, 113, 113, .45);
}

.proposal-btn.diff {
  color: var(--muted3);
}

.proposal-diff {
  margin-top: .4rem;
  padding: .5rem;
  background: var(--card-bg-muted, rgba(255, 255, 255, .02));
  border: 1px solid var(--card-border);
  border-radius: 6px;
}

.proposal-diff-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
}

.proposal-diff-table th {
  text-align: left;
  padding: .25rem .4rem;
  font-weight: 500;
  color: var(--muted2);
  text-transform: uppercase;
  font-size: .6rem;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--td-border);
}

.proposal-diff-table td {
  padding: .25rem .4rem;
  border-bottom: 1px solid var(--td-border);
}

.proposal-diff-table .diff-field {
  color: var(--muted3);
}

.proposal-diff-table .diff-old {
  color: #f87171;
}

.proposal-diff-table .diff-new {
  color: #4ade80;
}

/* Tier 2 runs card (agentic-runtime Milestone F) */

.tier2-row {
  padding: .5rem 0;
  border-bottom: 1px solid var(--td-border);
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.tier2-row:last-child {
  border-bottom: none;
}

.tier2-head {
  display: flex;
  gap: .6rem;
  font-size: .75rem;
  align-items: center;
}

.tier2-source {
  color: var(--muted3);
  text-transform: uppercase;
  font-size: .6rem;
  letter-spacing: .05em;
}

.tier2-started {
  color: var(--muted);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.tier2-meta {
  display: flex;
  gap: 1rem;
  font-size: .75rem;
  color: var(--muted2);
  font-variant-numeric: tabular-nums;
}

.tier2-focus {
  font-size: .7rem;
  color: var(--muted);
  font-style: italic;
}

.tier2-error {
  font-size: .75rem;
  color: #f87171;
  background: rgba(248, 113, 113, .08);
  border-radius: 4px;
  padding: .2rem .4rem;
  margin-top: .2rem;
}

.status-ok {
  color: #4ade80;
  text-transform: uppercase;
  font-size: .65rem;
  letter-spacing: .05em;
}

.status-bad {
  color: #f87171;
  text-transform: uppercase;
  font-size: .65rem;
  letter-spacing: .05em;
}

.status-neutral {
  color: var(--muted2);
  text-transform: uppercase;
  font-size: .65rem;
  letter-spacing: .05em;
}

.proposal-row.proposal-history .proposal-actions {
  display: none;
}


/* Notifications card — persisted /api/notify/* messages.
   Same row pattern as proposals so the eye reads them as a
   coherent agent-to-user surface. The channel badge + bell-icon
   counter give the card its own identity. */

.notif-bell {
  position: relative;
}

.notif-bell-badge {
  position: absolute;
  top: -.2rem;
  right: -.2rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 .25rem;
  border-radius: .55rem;
  background: rgba(248, 113, 113, .9);
  color: #fff;
  font-size: .65rem;
  font-weight: 600;
  line-height: 1.1rem;
  text-align: center;
  pointer-events: none;
}

.notif-row {
  padding: .55rem 0;
  border-bottom: 1px solid var(--td-border);
  display: flex;
  flex-direction: column;
  gap: .25rem;
  cursor: pointer;
  transition: background .15s;
}

.notif-row:last-child {
  border-bottom: none;
}

.notif-row:hover {
  background: rgba(255, 255, 255, .015);
}

.notif-row.notif-unread {
  border-left: 2px solid rgba(96, 165, 250, .6);
  padding-left: .5rem;
}

.notif-head {
  display: flex;
  gap: .5rem;
  align-items: center;
  font-size: .7rem;
  flex-wrap: wrap;
}

.notif-channel {
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
  padding: .1rem .4rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, .04);
  color: var(--muted3);
}

/* Per-channel accent — keeps Telegram and agent-log distinguishable
   at a glance. New channels just need a .notif-<channel> rule. */
.notif-channel.notif-telegram {
  color: #60a5fa;
  background: rgba(96, 165, 250, .1);
}

.notif-channel.notif-agent-log {
  color: #a78bfa;
  background: rgba(167, 139, 250, .1);
}

.notif-age {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.notif-attachments-badge {
  font-size: .75rem;
  opacity: .7;
}

.notif-actions {
  margin-left: auto;
  display: flex;
  gap: .3rem;
}

.notif-btn {
  font-size: .65rem;
  padding: .2rem .5rem;
  border-radius: 4px;
  border: 1px solid var(--card-border);
  background: transparent;
  color: var(--muted3);
  cursor: pointer;
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}

.notif-btn:hover {
  border-color: var(--card-border-hover);
  color: var(--muted4);
}

.notif-btn.read {
  color: #60a5fa;
  border-color: rgba(96, 165, 250, .25);
}

.notif-btn.read:hover {
  background: rgba(96, 165, 250, .08);
  border-color: rgba(96, 165, 250, .45);
}

.notif-text {
  font-size: .85rem;
  color: var(--muted4);
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.notif-detail {
  margin-top: .4rem;
  padding: .5rem;
  background: var(--card-bg-muted, rgba(255, 255, 255, .02));
  border: 1px solid var(--card-border);
  border-radius: 6px;
  font-size: .8rem;
  color: var(--muted3);
}

.notif-full-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  margin-bottom: .5rem;
  color: var(--muted4);
}

.notif-attachments {
  width: 100%;
  border-collapse: collapse;
  font-size: .7rem;
  font-variant-numeric: tabular-nums;
}

.notif-attachments th {
  text-align: left;
  padding: .25rem .4rem;
  font-weight: 500;
  color: var(--muted2);
  text-transform: uppercase;
  font-size: .6rem;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--td-border);
}

.notif-attachments td {
  padding: .25rem .4rem;
  border-bottom: 1px solid var(--td-border);
  word-break: break-all;
}

.notif-attachments td.notif-att-url a {
  color: #93c5fd;
  text-decoration: none;
}

.notif-attachments td.notif-att-url a:hover {
  text-decoration: underline;
}