/* ═══════════════════════════════════════════════════════════
   Golden Goose Platform — Shared Design System
   ═══════════════════════════════════════════════════════════ */

/* ── Variables ──────────────────────────────────────────────── */
:root {
  --bg-primary:      #111111;
  --bg-surface:      #1a1a1a;
  --bg-surface-alt:  #222222;
  --bg-surface-deep: #090909;
  --text-primary:    #e0e0e0;
  --text-muted:      #8892a0;
  --border:          rgba(255,255,255,0.06);
  --accent-green:    #26a69a;
  --accent-red:      #ef5350;
  --accent-orange:   #ffa726;
  --accent-blue:     #42a5f5;
  --sidebar-w:       48px;
  --sidebar-w-exp:   200px;
  --agent-w:         380px;
  --radius:          8px;
  --radius-sm:       6px;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface-deep);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
  transition: width 0.25s ease, min-width 0.25s ease;
  overflow: hidden;
  z-index: 100;
}
.sidebar.expanded {
  width: var(--sidebar-w-exp);
  min-width: var(--sidebar-w-exp);
}
.sidebar-toggle {
  width: 36px; height: 36px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
  margin-left: 8px;
  align-self: flex-start;
  transition: color 0.15s, background 0.15s;
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-surface-alt); }
.sidebar-items { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 0 6px; }
.nav-btn {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 6px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 18px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}
.nav-btn:hover  { background: var(--bg-surface-alt); color: var(--text-primary); }
.nav-btn.active { background: rgba(255,255,255,0.07); color: var(--text-primary); }
.nav-icon  { font-size: 22px; flex-shrink: 0; width: 28px; display: inline-flex; align-items: center; justify-content: center; }
.nav-label { font-size: 13px; font-weight: 500; opacity: 0; transition: opacity 0.2s; }
.sidebar.expanded .nav-label { opacity: 1; }

/* Egg nav icon — transparent PNG, same visual width as ⚙️ */
.nav-egg-wrap {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.nav-egg-img {
  width: 22px;
  height: auto;
  display: block;
  flex-shrink: 0;
}

/* ── Main Content ────────────────────────────────────────────── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-right 0.3s ease;
}
#main-content.agent-open { margin-right: var(--agent-w); }

/* ── Breadcrumb ──────────────────────────────────────────────── */
.breadcrumb {
  padding: 10px 52px 10px 20px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-surface-deep);
}
.crumb-version { color: var(--text-muted); font-weight: 500; }
.crumb-link {
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
}
.crumb-link:hover { color: var(--text-primary); text-decoration: underline; }
.crumb-sep { margin: 0 6px; }
.crumb-current { color: var(--text-primary); }

/* ── Pages ───────────────────────────────────────────────────── */
.page { display: none; flex: 1; overflow-y: auto; }
.page.active { display: flex; flex-direction: column; }

/* ── Placeholder Pages ───────────────────────────────────────── */
.placeholder-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
}
.placeholder-icon  { font-size: 48px; }
.placeholder-title { font-size: 20px; font-weight: 600; color: var(--text-primary); }
.placeholder-msg   { font-size: 14px; }

/* ═══════════════════════════════════════════════════════════
   HOME SCREEN
   ═══════════════════════════════════════════════════════════ */
/* Goose hero — full-size centered above charts */
.home-goose-hero {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 8px;
}
.home-goose-img {
  display: block;
  max-width: 100%;
  height: auto;
  image-rendering: auto;
}

.home-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px;
  flex: 1;
}

/* Chart panels row */
.home-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chart-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chart-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}
.live-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-green);
  background: rgba(38,166,154,0.15);
  border: 1px solid rgba(38,166,154,0.3);
  padding: 2px 8px;
  border-radius: 10px;
  animation: pulse-green 2s infinite;
}
@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
.time-range-select {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
}
.time-range-select:hover { border-color: rgba(255,255,255,0.15); }
.home-chart-wrap {
  position: relative;
  height: 220px;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}
.legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Nav cards */
.home-nav-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
.nav-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.nav-card:hover {
  background: var(--bg-surface-alt);
  border-color: rgba(255,255,255,0.15);
  transform: translateY(-2px);
}
.nav-card-icon {
  font-size: 40px;
  line-height: 1;
  filter: none;
}
.nav-card-icon--text {
  filter: none;
  color: var(--text-primary);
  font-weight: 700;
  letter-spacing: -2px;
}
.nav-card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════════
   STRATEGY GENERATOR
   ═══════════════════════════════════════════════════════════ */
.strategy-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Left panel — chat */
.strat-left {
  width: 33%;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface-deep);
}

/* Draggable divider */
.strat-divider {
  width: 6px;
  background: transparent;
  cursor: col-resize;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.strat-divider:hover,
.strat-divider.dragging { background: rgba(255,255,255,0.05); }
.strat-divider-handle {
  display: flex;
  flex-direction: column;
  gap: 3px;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.strat-divider:hover .strat-divider-handle,
.strat-divider.dragging .strat-divider-handle { opacity: 1; }
.strat-divider-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-muted);
}
.strat-left-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.strat-left-header h2 {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
}
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-surface-alt); }
.sg-model-select {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 6px;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
}
.sg-model-select:hover, .sg-model-select:focus { color: var(--text-primary); border-color: rgba(255,255,255,0.18); }

/* Chat messages */
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-msg { display: flex; flex-direction: column; gap: 4px; }
.chat-msg.user { align-items: flex-end; }
.chat-msg.ai   { align-items: flex-start; }
.msg-label {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
}
.msg-bubble {
  max-width: 90%;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-msg.user .msg-bubble {
  background: var(--bg-surface-alt);
  color: var(--text-primary);
  border-bottom-right-radius: 2px;
}
.chat-msg.ai .msg-bubble {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}
.typing-bubble .msg-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}
.typing-dot {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Chat input area */
.strat-chat-input {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
  flex-shrink: 0;
}
.sg-input-box {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sg-input-box:focus-within { border-color: rgba(255,255,255,0.18); }
.sg-input-box textarea {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  padding: 10px 12px 6px;
  resize: none;
  outline: none;
  min-height: 80px;
  max-height: 200px;
  line-height: 1.5;
  overflow-y: auto;
}
.sg-input-box textarea::placeholder { color: var(--text-muted); }
.sg-input-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
}
.sg-btn-attach {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-weight: 300;
  transition: color 0.15s, background 0.15s;
}
.sg-btn-attach:hover { color: white; background: rgba(255,255,255,0.08); }
.sg-btn-send {
  background: var(--text-primary);
  border: none;
  color: #111;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 2px;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.sg-btn-send:hover:not(:disabled) { opacity: 0.85; }
.sg-btn-send:disabled {
  background: var(--bg-surface-alt);
  color: var(--text-muted);
  cursor: not-allowed;
  border: 1px solid var(--border);
}
.sg-file-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 0;
  font-size: 12px;
}
.sg-file-badge-name {
  color: var(--accent-blue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.sg-file-remove {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
}
.sg-file-remove:hover { color: var(--text-primary); }

/* Right panel — tabs */
.strat-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.strat-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-deep);
  padding: 0 16px;
  flex-shrink: 0;
}
.strat-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.strat-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-green);
}
.strat-tab:hover:not(.active) { color: var(--text-primary); }
.strat-tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.strat-tab-content.active { display: flex; flex-direction: column; gap: 16px; }

/* Strategy Document */
.strat-doc-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.strat-doc-label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.strat-doc-value { font-size: 15px; font-weight: 600; color: var(--text-primary); margin-bottom: 12px; }
.strat-doc-desc  { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.5; }
.doc-divider     { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.doc-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.doc-section-items {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.doc-section-items li {
  font-size: 13px;
  color: var(--text-primary);
  padding-left: 14px;
  position: relative;
  line-height: 1.4;
}
.doc-section-items li::before {
  content: '•';
  position: absolute;
  left: 2px;
  color: var(--text-muted);
}
.doc-pending {
  font-size: 12px;
  color: var(--accent-orange);
  display: flex;
  align-items: center;
  gap: 4px;
}
.doc-section { margin-bottom: 16px; }

/* Rendered Strategy Document (markdown via marked.js) */
.strat-doc-rendered {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  line-height: 1.7;
  color: var(--text-primary);
  font-size: 13px;
  overflow-y: auto;
}
.strat-doc-rendered h1 {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 16px 0;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  color: var(--text-primary);
}
.strat-doc-rendered h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 24px 0 10px 0;
  color: var(--text-primary);
}
.strat-doc-rendered h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 18px 0 8px 0;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.strat-doc-rendered h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px 0;
  color: var(--text-primary);
}
.strat-doc-rendered p {
  margin: 0 0 10px 0;
}
.strat-doc-rendered ul, .strat-doc-rendered ol {
  margin: 6px 0 12px 0;
  padding-left: 22px;
}
.strat-doc-rendered li {
  margin-bottom: 4px;
}
.strat-doc-rendered strong {
  color: var(--text-primary);
  font-weight: 600;
}
.strat-doc-rendered code {
  background: var(--bg-surface-deep);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.strat-doc-rendered pre {
  background: var(--bg-surface-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  overflow-x: auto;
  margin: 10px 0;
}
.strat-doc-rendered pre code {
  background: none;
  padding: 0;
}
.strat-doc-rendered table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12px;
}
.strat-doc-rendered th, .strat-doc-rendered td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.strat-doc-rendered th {
  background: var(--bg-surface-deep);
  font-weight: 600;
}
.strat-doc-rendered hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}
.strat-doc-actions {
  margin-top: 20px;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Python Code */
.code-wrap {
  background: var(--bg-surface-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.7;
  color: #abb2bf;
  white-space: pre;
  overflow-x: auto;
}
.py-kw   { color: #c678dd; }
.py-fn   { color: #61afef; }
.py-str  { color: #98c379; }
.py-num  { color: #d19a66; }
.py-cm   { color: #5c6370; font-style: italic; }
.py-key  { color: #e06c75; }
.py-section { color: #e5c07b; font-weight: bold; }
.code-placeholder {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Summary & Launch */
.summary-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.summary-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}
.summary-items {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}
.summary-items li {
  font-size: 13px;
  color: var(--text-muted);
  padding-left: 14px;
  position: relative;
  line-height: 1.5;
}
.summary-items li::before {
  content: '•';
  position: absolute;
  left: 2px;
  color: var(--text-muted);
}
.summary-items li strong { color: var(--text-primary); }
.summary-sections {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 24px;
}
.summary-section {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  font-size: 13px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.summary-section:last-child { border-bottom: none; }
.summary-section-label {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}
.summary-section-value {
  color: var(--text-muted);
  line-height: 1.6;
}
/* Backtest Code tab toolbar */
.backtest-code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color, #2a3040);
  background: var(--bg-surface, #1a2030);
  flex-shrink: 0;
}
.btn-sm {
  height: 24px;
  padding: 0 10px;
  font-size: 11px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.btn-secondary {
  background: var(--bg-surface-alt, #222);
  color: var(--text-muted);
  border: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
  padding: 0 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: opacity 0.15s;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.btn-secondary:hover { opacity: 0.8; }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-green {
  background: var(--accent-green, #26a69a);
  color: #fff;
  border: none;
  padding: 0 12px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.btn-green:hover { opacity: 0.85; }
.btn-green:disabled { opacity: 0.4; cursor: not-allowed; }
/* QA Check results */
.qa-pass {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--accent-green, #4caf50);
  background: rgba(76,175,80,0.08);
  border-bottom: 1px solid var(--border);
}
.qa-results-list {
  max-height: 200px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
}
.qa-issue {
  padding: 6px 12px;
  font-size: 12px;
  line-height: 1.5;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.qa-issue:last-child { border-bottom: none; }
.qa-severity {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}
.qa-high .qa-severity { background: #e06c75; color: #fff; }
.qa-med .qa-severity  { background: #d19a66; color: #1a1a2e; }
.qa-low .qa-severity  { background: #5c6370; color: #fff; }
.qa-loc {
  font-size: 10px;
  color: #61afef;
  margin-right: 6px;
}
.summary-launch-row {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}
.btn-launch {
  display: inline-block;
  width: auto;
  background: var(--accent-green);
  border: none;
  color: white;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
  letter-spacing: 0.01em;
}
.btn-launch:not(:disabled):hover {
  opacity: 0.9;
  box-shadow: 0 0 0 3px rgba(38,166,154,0.25);
}
.btn-launch.pulsing {
  animation: launch-pulse 2s infinite;
}
@keyframes launch-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(38,166,154,0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(38,166,154,0); }
}
.btn-launch:disabled {
  background: var(--bg-surface-alt);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}
.perm-badge {
  display: inline-block;
  background: rgba(38,166,154,0.12);
  border: 1px solid rgba(38,166,154,0.3);
  color: var(--accent-green);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}

/* ═══════════════════════════════════════════════════════════
   AGENT ZERO CHAT
   ═══════════════════════════════════════════════════════════ */
.agent-btn {
  position: fixed;
  top: 0;
  right: 0;
  width: 48px;
  height: 37px;
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.15s;
}
.agent-btn:hover { opacity: 0.7; }
.agent-pulse { display: none; }
.agent-panel {
  position: fixed;
  top: 0; right: 0;
  width: var(--agent-w);
  height: 100%;
  background: var(--bg-surface-deep);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform 0.3s ease;
}
.agent-panel.hidden { transform: translateX(100%); pointer-events: none; }
.agent-panel.fullscreen { width: 100%; }
.agent-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}
.agent-panel-header button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.agent-panel-header button:hover { color: var(--text-primary); }
.agent-panel-header span { flex: none; }
.agent-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.agent-footer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.agent-footer textarea {
  flex: 1;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  resize: none;
  outline: none;
  line-height: 1.4;
}
.agent-footer textarea:focus { border-color: rgba(255,255,255,0.15); }
#agent-send {
  background: var(--bg-surface-alt);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s;
}
#agent-send:hover { opacity: 0.85; }

/* ═══════════════════════════════════════════════════════════
   BACKTEST RESULTS (M2)
   ═══════════════════════════════════════════════════════════ */
.bt-layout {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  overflow-y: auto;
}
.bt-page-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.bt-groups { display: flex; flex-direction: column; gap: 16px; }

/* Group card */
.bt-group {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.bt-group.grp-running { border-left: 3px solid var(--accent-blue); animation: pulse-left 2s infinite; }
.bt-group.grp-failed  { border-left: 3px solid var(--accent-red); }
.bt-group.grp-partial { border-left: 3px solid var(--accent-orange); }
@keyframes pulse-left { 0%,100% { border-left-color: var(--accent-blue); } 50% { border-left-color: rgba(66,165,245,0.3); } }

/* Group header */
.bt-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  background: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.bt-group-header:hover { background: rgba(255,255,255,0.05); }
.bt-chevron {
  color: var(--text-muted);
  font-size: 14px;
  transition: transform 0.2s;
  display: inline-block;
}
.bt-chevron.expanded { transform: rotate(90deg); }
.bt-run-label { color: var(--text-primary); font-weight: 500; }
.bt-group-launch {
  color: var(--accent-green);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.bt-group-launch:hover { opacity: 0.8; }
.bt-group-launch.disabled { color: var(--text-muted); cursor: default; text-decoration: none; }
.bt-group-capital { margin-left: auto; color: var(--text-muted); font-size: 12px; }
.bt-parent-link {
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
}
.bt-parent-link:hover { color: var(--text-secondary); }
.bt-iterate-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 5px;
  transition: border-color 0.15s, background 0.15s;
}
.bt-iterate-btn:hover {
  border-color: var(--accent-green);
  background: rgba(38,166,154,0.1);
}
.bt-iterate-btn:disabled { opacity: 0.4; cursor: default; }
.bt-act-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  transition: border-color 0.15s, background 0.15s;
}
.bt-act-btn:hover { border-color: var(--border); background: rgba(255,255,255,0.05); }
.bt-act-btn.bt-act-delete:hover { border-color: #e57373; background: rgba(229,115,115,0.1); }

/* Column layout — same grid for header and rows */
/* Name | Cap | Trades | Net$ | ROI | IRR | Win% | Alpha | Beta | Sharpe | PF | MaxDD | Iterate | Walk Fwd | Paper | Live | Archive | Delete */
.bt-col-header,
.bt-strat-row {
  display: grid;
  grid-template-columns: 180px 90px 76px 76px 92px 68px 64px 68px 56px 64px 72px 64px 56px 80px 76px 76px 52px 52px;
  align-items: center;
  padding: 0 16px;
  column-gap: 6px;
}
.bt-col-header {
  padding-top: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  background: transparent;
}
.bt-col-header .bt-cell { font-size: 11px; color: var(--text-muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bt-strat-row {
  min-height: 38px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.bt-strat-row:last-child { border-bottom: none; }
.bt-strat-row.alt { background: rgba(255,255,255,0.015); }
.bt-strat-row:hover { background: var(--bg-surface-alt) !important; }

/* Cells */
.bt-cell { font-size: 13px; padding: 2px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-cell-name { overflow: hidden; }
.bt-strat-name {
  cursor: default;
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.bt-strat-name:hover { color: white; }
.bt-spin-cell { color: var(--text-muted); }
.bt-spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.bt-egg-spin {
  width: 18px; height: 18px; object-fit: contain;
  display: inline-block; vertical-align: middle; margin: 0 5px;
  animation: egg-roll 1.2s ease-in-out infinite;
  transform-origin: 50% 65%;
}
@keyframes egg-roll {
  0%   { transform: rotate(-18deg); }
  50%  { transform: rotate(18deg);  }
  100% { transform: rotate(-18deg); }
}

/* Launch cell */
.bt-launch { font-weight: 600; cursor: pointer; }
.bt-launch.link  { color: var(--accent-green); }
.bt-launch.link:hover { opacity: 0.7; }
.bt-launch.error { color: var(--accent-red); cursor: default; }
.bt-launch.running { color: var(--text-muted); cursor: default; }
.bt-launch.queued { color: var(--text-muted); cursor: default; }
.bt-launch.paper  { cursor: pointer; font-size: 14px; text-align: center; }
.bt-launch.paper:hover { opacity: 0.7; }
.bt-launch.trade  { cursor: pointer; font-size: 14px; text-align: center; }
.bt-launch.trade:hover { opacity: 0.7; }
.bt-cell.muted    { color: var(--text-muted); }
.bt-cell.bt-cell-ctr { text-align: center; }
.bt-strat-row.bt-row-clickable { cursor: pointer; }

/* Confirmation popup */
.bt-confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
.bt-confirm-dialog {
  background: var(--bg-surface-alt);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  padding: 32px 40px;
  text-align: center;
  min-width: 280px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.bt-confirm-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}
.bt-confirm-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.bt-confirm-btns {
  display: flex;
  justify-content: center;
  gap: 24px;
}
.bt-confirm-yes, .bt-confirm-no {
  background: transparent;
  border: none;
  font-size: 32px;
  cursor: pointer;
  transition: transform 0.1s;
}
.bt-confirm-yes:hover, .bt-confirm-no:hover { transform: scale(1.2); }

/* Paper trading params modal */
.bt-paper-dialog { width: 480px; max-width: 95vw; text-align: left; }
.bt-paper-strat {
  font-size: 13px;
  color: var(--accent-blue);
  margin-bottom: 20px;
  text-align: center;
}
.bt-params-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.bt-params-row {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  align-items: flex-start;
}
.bt-params-field { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.bt-params-field-sm { flex: 0 0 90px; }
.bt-params-label { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.bt-params-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.bt-params-input-wrap:focus-within { border-color: rgba(255,255,255,0.25); }
.bt-params-prefix {
  padding: 0 8px;
  color: var(--text-muted);
  font-size: 13px;
  border-right: 1px solid var(--border);
  line-height: 34px;
}
.bt-params-input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 10px;
  width: 100%;
  -moz-appearance: textfield;
}
.bt-params-input::-webkit-outer-spin-button,
.bt-params-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.bt-params-hint { font-size: 11px; color: var(--text-muted); min-height: 16px; }
.bt-paper-btns { justify-content: space-between !important; margin-top: 4px; }
.bt-paper-start {
  font-size: 13px !important;
  padding: 8px 18px;
  background: var(--accent-blue) !important;
  color: #fff !important;
  border-radius: var(--radius-sm) !important;
  border: none !important;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.bt-paper-start:hover { opacity: 0.88 !important; transform: none !important; }

/* Home page deployment cards */
.home-deploy-list {
  padding: 12px 16px;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.home-deploy-loading { color: var(--text-muted); font-size: 12px; }
.home-deploy-empty {
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.home-deploy-link {
  color: var(--accent-blue);
  cursor: pointer;
  font-size: 12px;
}
.home-deploy-link:hover { text-decoration: underline; }
.home-deploy-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.home-deploy-row:last-child { border-bottom: none; }
.home-deploy-dot { font-size: 10px; flex-shrink: 0; }
.home-deploy-dot-active { color: var(--accent-green); }
.home-deploy-dot-idle   { color: var(--text-muted); }
.home-deploy-label { flex: 1; font-weight: 500; }
.home-deploy-cap   { color: var(--text-muted); font-size: 12px; }
.home-deploy-status { font-size: 11px; color: var(--text-muted); min-width: 52px; text-align: right; }

/* Value colors */
.bt-cell.green  { color: var(--accent-green); }
.bt-cell.red    { color: var(--accent-red); }
.bt-cell.orange { color: var(--accent-orange); }

/* Tooltip */
.bt-tooltip {
  display: none;
  position: fixed;
  background: var(--bg-surface-alt);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-primary);
  z-index: 500;
  max-width: 280px;
  line-height: 1.6;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.bt-tooltip strong { color: var(--text-muted); font-weight: 600; }

/* Walk Forward Test — child row */
.bt-strat-row.wft-child-row {
  background: rgba(255,255,255,0.035);
  border-left: 2px solid rgba(255,255,255,0.08);
}
.bt-strat-row.wft-child-row.wft-child-pass {
  background: rgba(34,197,94,0.07);
  border-left: 2px solid rgba(34,197,94,0.28);
}
.bt-strat-row.wft-child-row.wft-child-marginal {
  background: rgba(245,158,11,0.07);
  border-left: 2px solid rgba(245,158,11,0.28);
}
.bt-strat-row.wft-child-row.wft-child-fail {
  background: rgba(239,68,68,0.07);
  border-left: 2px solid rgba(239,68,68,0.28);
}
.bt-strat-row.wft-child-row:hover {
  background: rgba(255,255,255,0.06) !important;
}
.bt-strat-row.wft-child-row.wft-child-running {
  background: rgba(66,165,245,0.05);
  border-left: 2px solid rgba(66,165,245,0.30);
}

/* ── Permutation chain — linked group cards ─────────────────── */
.bt-group-chain-parent {
  border-left: 3px solid rgba(66,165,245,0.30) !important;
  border-bottom-left-radius: 0 !important;
}
.bt-group-child {
  margin-top: -16px;           /* cancel the .bt-groups gap */
  border-left: 3px solid rgba(66,165,245,0.30) !important;
  border-top-left-radius: 0 !important;
  border-bottom-left-radius: 0 !important;
}
.bt-group-child:last-child,
.bt-group-child:not(:has(+ .bt-group-child)) {
  border-bottom-left-radius: var(--radius) !important;
}
.bt-chain-badge {
  font-size: 11px; color: rgba(66,165,245,0.65);
  font-weight: 500; letter-spacing: 0.3px;
}

.wft-child-name {
  padding-left: 20px;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Walk Forward icon button */
.bt-wft-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 5px;
  transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}
.bt-wft-btn:hover {
  border-color: var(--accent-blue);
  background: rgba(66,165,245,0.1);
}
.bt-wft-btn.wft-running {
  opacity: 0.6;
  cursor: not-allowed;
  animation: spin 1.2s linear infinite;
}
.bt-wft-btn.wft-disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* WFT ratio badge in child row */
.wft-ratio {
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
}
.wft-ratio:hover { text-decoration: underline; }

/* Gated (disabled) paper/live buttons */
.bt-launch.gated {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.bt-launch.gated-marginal {
  position: relative;
}
.bt-launch.gated-marginal::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 6px;
  height: 6px;
  background: #f59e0b;
  border-radius: 50%;
}

/* WFT tooltip popover (styled, positioned by JS) */
.bt-wft-tip {
  display: none;
  position: fixed;
  background: #1e293b;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: #f8fafc;
  z-index: 600;
  max-width: 300px;
  line-height: 1.6;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  white-space: pre-line;
}

/* ═══════════════════════════════════════════════════════════
   TRADE AUTOMATION (M4)
   ═══════════════════════════════════════════════════════════ */
.td-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.td-header-row {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-deep);
  flex-shrink: 0;
  gap: 20px;
}
.td-page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}
/* Trading page wrapper */
.trading-wrap { display: flex; flex-direction: column; height: 100%; }
.td-fetch-error {
  background: rgba(243,139,168,.12);
  border-bottom: 1px solid rgba(243,139,168,.3);
  color: #f38ba8;
  font-size: 12px;
  padding: 6px 20px;
  flex-shrink: 0;
}
.trading-header {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-deep);
  flex-shrink: 0;
}
.trading-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
}
.td-tab-btn {
  padding: 6px 18px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.td-tab-btn.active { background: var(--accent-green); color: white; }
.td-tab-btn:not(.active):hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.td-tab-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* Section dividers */
.td-section { margin-bottom: 24px; }
.td-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

/* Column layout — completed/archived: Name + Capital + Trades + 9 data + Actions */
.td-col-header,
.td-row-grid {
  display: grid;
  grid-template-columns: 180px 90px 56px 100px 64px 68px 64px 68px 56px 64px 72px 64px auto;
  align-items: center;
  padding: 0 16px;
}
/* Active paper: Name + Capital + Trades + 9 data + Stop + Live Trade */
.td-col-header.active-paper,
.td-row-grid.active-paper {
  grid-template-columns: 180px 90px 56px 100px 64px 68px 64px 68px 56px 64px 72px 64px 62px 62px;
}
/* Active live: Name + Capital + Trades + 9 data + Stop */
.td-col-header.active-live,
.td-row-grid.active-live {
  grid-template-columns: 180px 90px 56px 100px 64px 68px 64px 68px 56px 64px 72px 64px 62px;
}
.td-col-header {
  padding-top: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  background: transparent;
}
.td-col-header .td-cell { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.td-cell-action-hdr { text-align: right; }
.td-cell-icon-hdr { text-align: center; }
.td-cell.td-cell-ctr { text-align: center; }
.td-action-icon {
  text-align: center;
  cursor: pointer;
  font-size: 16px;
  opacity: 0.7;
  padding: 2px;
  border-radius: 4px;
  transition: opacity 0.15s;
}
.td-action-icon:hover { opacity: 1; background: rgba(255,255,255,0.08); }

/* Strategy rows — flat like BT */
.td-row {
  transition: background 0.15s;
}
.td-row-grid {
  min-height: 36px;
  border-bottom: 1px solid var(--border);
  padding-top: 4px;
  padding-bottom: 4px;
}
.td-row-grid:last-child { border-bottom: none; }
.td-row-grid:hover { background: var(--bg-surface-alt); }

.td-cell { font-size: 13px; padding: 2px 4px; }
.td-cell.green  { color: var(--accent-green); }
.td-cell.red    { color: var(--accent-red); }
.td-cell.orange { color: var(--accent-orange); }
.td-cell-name { overflow: hidden; }
.td-strat-name {
  font-weight: 600;
  color: var(--text-primary);
  cursor: default;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.td-strat-name:hover { color: white; }
.td-subtitle-row {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 0 4px 0;
}
.td-actions { display: flex; gap: 6px; justify-content: flex-end; }
.td-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.td-btn:hover { opacity: 1; background: rgba(255,255,255,0.08); }
.td-btn-stop { color: var(--accent-red); }
.td-btn-delete:hover { color: var(--accent-red); }
.td-btn-view { color: var(--accent-green); font-weight: 700; }
.td-row-clickable { cursor: pointer; }

/* Archive toggle */
.td-archive-toggle {
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  user-select: none;
  margin-bottom: 4px;
}
.td-archive-toggle:hover { color: var(--text-primary); }
.td-archive-chev {
  font-size: 10px;
  transition: transform 0.2s;
  display: inline-block;
}
.td-archive-chev.open { transform: rotate(90deg); }

/* Dashboard sidebar button — hidden until a dashboard is open */
#nav-dashboard { display: none; }

/* Dashboard iframe page — full bleed, no inner padding */
.page-dashboard-frame {
  padding: 0 !important;
  overflow: hidden;
}
#dashboard-iframe { display: block; width: 100%; height: 100%; border: none; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .home-charts-row { grid-template-columns: 1fr; }
  .home-nav-cards  { grid-template-columns: 1fr; }
  .strat-left      { width: 50%; min-width: 240px; }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE — single breakpoint, all overrides inside
   Target: iPhone 17 Pro (393 × 852 CSS pts). Desktop untouched.
   ══════════════════════════════════════════════════════════════ */

/* ── Safe area CSS variables ─────────────────────────────────── */
:root {
  --safe-top:    env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left:   env(safe-area-inset-left);
  --safe-right:  env(safe-area-inset-right);
}

/* ── Mobile header (hidden on desktop) ───────────────────────── */
.mobile-header {
  display: none;
}
.mobile-nav-overlay { display: none; }
.mobile-nav-panel   { display: none; }

/* Mobile swipe row cards — hidden on desktop */
.bt-row-mobile { display: none; }

/* Mobile strategy tab bar — hidden on desktop */
.sg-mobile-tabs { display: none; }

/* Trading empty state */
.td-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 10px;
  text-align: center;
}
.td-empty-icon  { font-size: 40px; }
.td-empty-title { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.td-empty-msg   { font-size: 13px; color: var(--text-muted); }
.td-empty-btn {
  margin-top: 8px;
  padding: 8px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent-blue);
  font-size: 13px;
  cursor: pointer;
}

@media (max-width: 767px) {
  /* ── Root overrides ────────────────────────────────────────── */
  :root {
    --sidebar-w:       0px;
    --sidebar-w-exp:   280px;
    --agent-w:         100vw;
    --mobile-header-h: 52px;
    --touch-min:       44px;
  }

  /* ── Body ──────────────────────────────────────────────────── */
  body {
    overscroll-behavior: none;
  }
  * { touch-action: manipulation; }
  /* Restore natural touch-action on scrollable containers */
  .chat-history,
  .bt-group-body,
  .strat-tab-content,
  .bt-row-scroller,
  #sg-messages,
  .agent-messages { touch-action: pan-y; }

  /* ── Hide desktop sidebar ──────────────────────────────────── */
  .sidebar { display: none; }

  /* ── Main content: full width, push down for mobile header ─── */
  #main-content {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-top: calc(var(--mobile-header-h) + var(--safe-top));
  }
  #main-content.agent-open { margin-right: 0; }

  /* ── Breadcrumb: hidden (mobile header takes over) ─────────── */
  .breadcrumb { display: none; }

  /* ── Mobile header ─────────────────────────────────────────── */
  .mobile-header {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--bg-surface-deep);
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding-left: 12px;
    padding-right: 8px;
    z-index: 2000;
    gap: 10px;
  }
  .mobile-header-logo {
    width: 26px;
    height: 26px;
    object-fit: contain;
    flex-shrink: 0;
  }
  .mobile-header-title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mobile-hamburger {
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-shrink: 0;
    padding: 0;
  }
  .mobile-hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
  }
  body.mobile-nav-open .mobile-hamburger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  body.mobile-nav-open .mobile-hamburger span:nth-child(2) { opacity: 0; }
  body.mobile-nav-open .mobile-hamburger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* ── Mobile nav overlay ────────────────────────────────────── */
  .mobile-nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    z-index: 2900;
    pointer-events: none;
    transition: background 0.25s;
  }
  body.mobile-nav-open .mobile-nav-overlay {
    background: rgba(0,0,0,0.5);
    pointer-events: auto;
  }

  /* ── Mobile nav panel (slide-out) ──────────────────────────── */
  .mobile-nav-panel {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--bg-surface-deep);
    border-right: 1px solid var(--border);
    z-index: 3000;
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(24px + var(--safe-bottom));
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }
  body.mobile-nav-open .mobile-nav-panel {
    transform: translateX(0);
  }
  .mobile-nav-items {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 8px;
  }
  .mobile-nav-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    height: 52px;
    padding: 0 12px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius);
    text-align: left;
    transition: background 0.15s, color 0.15s;
  }
  .mobile-nav-btn:hover, .mobile-nav-btn.active {
    background: rgba(255,255,255,0.07);
    color: var(--text-primary);
  }
  .mobile-nav-btn.active {
    border-left: 3px solid var(--accent-blue);
    padding-left: 9px;
  }
  .mobile-nav-icon {
    font-size: 20px;
    width: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .mobile-nav-egg {
    width: 22px;
    height: auto;
  }
  .mobile-nav-footer {
    padding: 16px 20px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
  }

  /* ── Agent panel full-screen on mobile ─────────────────────── */
  .agent-panel {
    width: 100vw;
    top: 0;
    right: 0;
    z-index: 2500;
  }
  .agent-btn { display: none; }

  /* ── Touch targets ─────────────────────────────────────────── */
  .nav-btn       { min-height: 52px; }
  .sg-btn-send   { min-width: 44px; min-height: 44px; }
  .bt-iterate-btn, .bt-wft-btn, .bt-act-btn, .bt-launch { min-width: 44px; min-height: 44px; }
  .strat-tab     { min-height: 48px; }
  select         { min-height: 44px; }
  input, textarea { font-size: 16px !important; } /* prevent iOS auto-zoom */

  /* ══════════════════════════════════════════════════════════
     HOME — mobile layout
     ══════════════════════════════════════════════════════════ */
  .home-layout {
    padding: 16px;
    gap: 16px;
  }
  .home-goose-hero img {
    max-width: 120px;
  }
  .home-nav-cards {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    order: -1; /* nav cards first on mobile */
  }
  .nav-card {
    padding: 20px 12px;
    gap: 10px;
  }
  .nav-card-icon { font-size: 32px; }
  .nav-card-title { font-size: 13px; }
  .home-charts-row {
    grid-template-columns: 1fr; /* stack vertically */
    gap: 12px;
  }
  .home-chart-wrap { height: 180px; }

  /* ══════════════════════════════════════════════════════════
     STRATEGY GENERATOR — mobile layout
     ══════════════════════════════════════════════════════════ */

  /* Mobile tab bar */
  .sg-mobile-tabs {
    display: flex;
    position: sticky;
    top: calc(var(--mobile-header-h) + var(--safe-top));
    z-index: 1200;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
    flex-shrink: 0;
  }
  .sg-mobile-tabs::-webkit-scrollbar { display: none; }
  .sg-mobile-tab {
    flex: 1;
    min-width: 60px;
    height: 44px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    padding: 0 8px;
    transition: color 0.15s, border-color 0.15s;
  }
  .sg-mobile-tab.active {
    color: var(--accent-green);
    border-bottom-color: var(--accent-green);
  }
  .sg-mobile-tab:disabled {
    opacity: 0.35;
    cursor: not-allowed;
  }

  /* Two-panel → single-panel */
  .strategy-layout { flex-direction: column; overflow: visible; }
  .strat-divider   { display: none; }

  .strat-left {
    width: 100%;
    min-width: unset;
    display: none;
    flex: 1;
  }
  .strat-left.mobile-active { display: flex; }

  .strat-right {
    width: 100%;
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
  }
  .strat-right.mobile-active { display: flex; }

  /* Desktop right-panel tabs hidden; mobile tab bar takes over */
  .strat-tabs { display: none; }

  /* Make right panel content fill space */
  .strat-tab-content {
    flex: 1;
    overflow-y: auto;
  }

  /* Sticky chat input */
  .strat-chat-input {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding-bottom: calc(10px + var(--safe-bottom));
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    z-index: 1500;
  }
  /* Keyboard awareness — updated by JS visualViewport handler */
  .strat-chat-input { bottom: var(--keyboard-h, 0px); }

  /* Extra scroll padding so last message isn't hidden behind fixed input */
  #sg-messages { padding-bottom: 80px; }

  /* Inline checklist card in chat */
  .chat-checklist-card {
    background: var(--bg-surface-alt);
    border: 1px solid rgba(38,166,154,0.3);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 4px;
  }
  .chat-checklist-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-green);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  .chat-checklist-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 4px 6px;
  }
  .chat-checklist-item {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
  }
  .chat-checklist-item.done { color: var(--text-primary); }
  .chat-checklist-progress {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .chat-checklist-bar {
    flex: 1;
    height: 3px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
    overflow: hidden;
  }
  .chat-checklist-bar-fill {
    height: 100%;
    background: var(--accent-green);
    border-radius: 2px;
    transition: width 0.3s ease;
  }
  .chat-checklist-count {
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  /* ══════════════════════════════════════════════════════════
     BACKTESTS — mobile layout
     ══════════════════════════════════════════════════════════ */
  .bt-layout { padding: 12px; }
  .bt-page-title { font-size: 18px; }

  /* Hide desktop grid header and rows on mobile */
  .bt-col-header { display: none; }
  .bt-strat-row  { display: none; }

  /* Show mobile swipe cards */
  .bt-row-mobile { display: block; }

  /* Compact group header on mobile */
  .bt-group-header {
    flex-wrap: wrap;
    padding: 12px;
    gap: 4px;
  }
  .bt-group-capital { font-size: 11px; }

  /* Swipe card row */
  .bt-row-mobile {
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
  }
  .bt-row-mobile + .bt-row-mobile { border-top: none; }
  .bt-row-scroller {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .bt-row-scroller::-webkit-scrollbar { display: none; }
  .bt-row-page {
    flex: 0 0 100%;
    scroll-snap-align: start;
    padding: 10px 14px;
  }
  .bt-row-page-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .bt-row-page-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
  }
  .bt-row-metric {
    display: flex;
    flex-direction: column;
    gap: 1px;
  }
  .bt-row-metric-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }
  .bt-row-metric-value {
    font-size: 13px;
    font-weight: 600;
  }
  .bt-row-metric-value.green { color: var(--accent-green); }
  .bt-row-metric-value.red   { color: var(--accent-red); }
  .bt-row-metric-value.orange { color: var(--accent-orange); }
  .bt-row-page-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 14px;
  }
  .bt-mob-action-btn {
    height: 44px;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s;
  }
  .bt-mob-action-btn:hover { background: rgba(255,255,255,0.08); }
  .bt-mob-action-btn.danger { color: var(--accent-red); border-color: rgba(239,83,80,0.3); }
  .bt-mob-action-btn.primary { color: var(--accent-green); border-color: rgba(38,166,154,0.3); }
  .bt-mob-action-btn:disabled { opacity: 0.35; cursor: not-allowed; }

  /* Dot indicators under each swipe row */
  .bt-row-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 6px 0 8px;
  }
  .bt-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    transition: background 0.2s;
  }
  .bt-dot.active { background: var(--accent-blue); }

  /* ══════════════════════════════════════════════════════════
     MODALS — full-screen on mobile
     ══════════════════════════════════════════════════════════ */
  .bt-confirm-dialog,
  .bt-paper-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 0;
    padding: 16px;
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
    overflow-y: auto;
  }
  .bt-confirm-overlay .bt-confirm-btn,
  .bt-confirm-overlay .bt-cancel-btn {
    width: 100%;
    height: 52px;
    font-size: 16px;
  }

  /* ══════════════════════════════════════════════════════════
     TRADING — mobile layout
     ══════════════════════════════════════════════════════════ */

  /* Hide desktop grid rows and column headers */
  .td-row.td-row-grid { display: none; }
  .td-col-header      { display: none; }
  .td-section-label   { padding: 10px 12px 4px; font-size: 11px; }

  /* Full-width tab buttons */
  .trading-wrap { display: flex; flex-direction: column; }
  .trading-tabs { display: flex; width: 100%; }
  .td-tab-btn   { flex: 1; height: 44px; font-size: 14px; }

  /* Section spacing */
  .td-section { margin-bottom: 8px; }

  /* Empty state: already styled globally, just ensure it shows */
  .td-empty-state { padding: 48px 20px; }
  .td-empty-btn   { min-height: 44px; min-width: 44px; }

  /* ══════════════════════════════════════════════════════════
     TYPOGRAPHY & SPACING
     ══════════════════════════════════════════════════════════ */
  .bt-page-title { font-size: 18px; }
  .home-layout, .bt-layout { padding: 12px; gap: 12px; }
  .chart-card, .strat-doc-card { padding: 12px; }
  .bt-groups { gap: 12px; }
  .msg-bubble { font-size: 14px; }
}


/* ═══════════════════════════════════════════════════════════
   AUTH OVERLAY
   ═══════════════════════════════════════════════════════════ */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.auth-overlay.hidden { display: none; }

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.auth-logo-img {
  width: 96px;
  height: 96px;
  object-fit: contain;
}
.auth-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
  text-align: center;
}

.auth-form-wrap { display: flex; flex-direction: column; gap: 16px; }
.auth-form-wrap.hidden { display: none; }

.auth-form-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}
.auth-form-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.auth-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.auth-field input {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
}
.auth-field input:focus { border-color: var(--accent-blue); }
.auth-field input::placeholder { color: var(--text-muted); }

.auth-submit-btn {
  background: var(--accent-blue);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 11px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.auth-submit-btn:hover:not(:disabled) { opacity: 0.85; }
.auth-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-error {
  background: rgba(239,83,80,0.12);
  border: 1px solid rgba(239,83,80,0.3);
  border-radius: var(--radius-sm);
  color: var(--accent-red);
  font-size: 13px;
  padding: 10px 12px;
}
.auth-success {
  background: rgba(38,166,154,0.12);
  border: 1px solid rgba(38,166,154,0.3);
  border-radius: var(--radius-sm);
  color: var(--accent-green);
  font-size: 13px;
  padding: 10px 12px;
}
.auth-error.hidden, .auth-success.hidden { display: none; }

.auth-switch {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}
.auth-switch a {
  color: var(--accent-blue);
  text-decoration: none;
}
.auth-switch a:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════════════
   SETTINGS PAGE
   ═══════════════════════════════════════════════════════════ */

.settings-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.settings-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-surface-deep);
  gap: 12px;
}
.settings-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  margin: 0;
}
.settings-logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  padding: 6px 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.settings-logout-btn:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.settings-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-deep);
  padding: 0 20px;
  flex-shrink: 0;
}
.settings-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.settings-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-green);
}
.settings-tab:hover:not(.active) { color: var(--text-primary); }

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-section { display: flex; flex-direction: column; gap: 16px; }

.settings-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.settings-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.settings-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin: -8px 0 4px;
}

.settings-profile-grid { display: flex; flex-direction: column; gap: 12px; }
.settings-profile-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.settings-profile-row:last-child { border-bottom: none; }
.settings-label {
  font-size: 12px;
  color: var(--text-muted);
  width: 120px;
  flex-shrink: 0;
}
.settings-value {
  font-size: 14px;
  color: var(--text-primary);
  flex: 1;
}

.settings-role-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.05em;
}
.settings-role-admin {
  background: rgba(66,165,245,0.15);
  border: 1px solid rgba(66,165,245,0.3);
  color: var(--accent-blue);
}
.settings-role-user {
  background: rgba(136,146,160,0.15);
  border: 1px solid rgba(136,146,160,0.3);
  color: var(--text-muted);
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.settings-field input {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
}
.settings-field input:focus { border-color: var(--accent-blue); }
.settings-field input::placeholder { color: var(--text-muted); }

.settings-btn-primary {
  background: var(--accent-blue);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  padding: 9px 18px;
  cursor: pointer;
  align-self: flex-start;
  transition: opacity 0.15s;
}
.settings-btn-primary:hover:not(:disabled) { opacity: 0.85; }
.settings-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.settings-btn-danger {
  background: transparent;
  border: 1px solid var(--accent-red);
  border-radius: var(--radius-sm);
  color: var(--accent-red);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  padding: 9px 18px;
  cursor: pointer;
  transition: background 0.15s;
}
.settings-btn-danger:hover { background: rgba(239,83,80,0.1); }

.settings-msg {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}
.settings-msg-error {
  background: rgba(239,83,80,0.12);
  border: 1px solid rgba(239,83,80,0.3);
  color: var(--accent-red);
}
.settings-msg-success {
  background: rgba(38,166,154,0.12);
  border: 1px solid rgba(38,166,154,0.3);
  color: var(--accent-green);
}
.settings-msg.hidden { display: none; }

.settings-loading {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px;
}
.settings-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}

/* API Keys */
.settings-apikeys-list { display: flex; flex-direction: column; gap: 16px; }

.apikey-row {
  padding: 16px;
  background: var(--bg-surface-alt);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.apikey-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.apikey-desc {
  font-size: 12px;
  color: var(--text-muted);
}
.apikey-set-indicator {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}
.apikey-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}
.apikey-input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: monospace;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
  min-width: 0;
}
.apikey-input:focus { border-color: var(--accent-blue); }
.apikey-input::placeholder { color: var(--text-muted); font-family: inherit; }
.apikey-save-btn { flex-shrink: 0; padding: 8px 14px; }
.apikey-del-btn  { flex-shrink: 0; padding: 8px 14px; }

.apikey-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
}
.apikey-badge-valid {
  background: rgba(38,166,154,0.15);
  border: 1px solid rgba(38,166,154,0.3);
  color: var(--accent-green);
}
.apikey-badge-invalid {
  background: rgba(239,83,80,0.12);
  border: 1px solid rgba(239,83,80,0.3);
  color: var(--accent-red);
}

.apikey-msg {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}
.apikey-msg-success {
  background: rgba(38,166,154,0.1);
  color: var(--accent-green);
}
.apikey-msg-error {
  background: rgba(239,83,80,0.1);
  color: var(--accent-red);
}
.apikey-msg-warn {
  background: rgba(255,167,38,0.1);
  color: var(--accent-orange);
}
.apikey-msg.hidden { display: none; }

/* Admin */
.settings-admin-users { display: flex; flex-direction: column; gap: 12px; }
.admin-user-row {
  background: var(--bg-surface-alt);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.admin-user-inactive { opacity: 0.5; }
.admin-user-info { flex: 1; min-width: 0; }
.admin-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.admin-user-you {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}
.admin-user-email {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.admin-user-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.admin-user-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.admin-role-select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-family: inherit;
  padding: 6px 10px;
  cursor: pointer;
  outline: none;
}
.admin-toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
}
.admin-toggle-label input[type="checkbox"] { cursor: pointer; }

/* ── Market Regimes Page ──────────────────────────────────── */
.regimes-page { padding: 24px; max-width: 900px; }
.regimes-header { margin-bottom: 24px; }
.regimes-title { font-size: 22px; font-weight: 600; color: var(--text-primary); margin: 0 0 6px; }
.regimes-subtitle { font-size: 13px; color: var(--text-muted); margin: 0; }
.regimes-loading { color: var(--text-muted); padding: 40px 0; font-size: 14px; }
.regimes-error { color: #ef4444; padding: 20px 0; font-size: 14px; }

.regime-status-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.regime-status-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 99px;
  white-space: nowrap;
}
.regime-status-badge.fitted  { background: #166534; color: #86efac; }
.regime-status-badge.pending { background: #7c2d12; color: #fdba74; }
.regime-status-badge.waiting { background: #1e1b4b; color: #a5b4fc; }
.regime-status-detail { font-size: 13px; color: var(--text-muted); flex: 1; }
.regime-fit-btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  margin-left: auto;
}
.regime-fit-btn:hover:not(.disabled) { opacity: 0.85; }
.regime-fit-btn.disabled { opacity: 0.4; cursor: not-allowed; }

.regime-current-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.regime-current-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.regime-current-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.regime-current-name { font-size: 26px; font-weight: 700; margin-bottom: 4px; }
.regime-current-date { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.regime-current-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.regime-confidence { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.regime-guidance {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-top: 8px;
}

.regime-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.regime-legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.regime-legend-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.regime-legend-label { font-size: 13px; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: 6px; }
.regime-legend-desc { font-size: 11px; color: var(--text-muted); line-height: 1.4; }

.regime-blocks-section { margin-top: 8px; }
.regime-blocks-title { font-size: 15px; font-weight: 600; color: var(--text-primary); margin: 0 0 12px; }
.regime-blocks-table { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.regime-blocks-head,
.regime-blocks-row {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1.2fr 0.6fr;
  padding: 10px 16px;
  font-size: 12px;
  align-items: center;
  gap: 8px;
}
.regime-blocks-head { background: var(--bg-hover); color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.regime-blocks-row { color: var(--text-secondary); border-top: 1px solid var(--border); }
.regime-blocks-row span { display: flex; align-items: center; gap: 6px; }

/* ── Brokers Tab ──────────────────────────────────────────── */
.broker-section-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 16px;
}
@media (max-width: 700px) { .broker-section-grid { grid-template-columns: 1fr; } }
.broker-group { display: flex; flex-direction: column; gap: 10px; }
.broker-group-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.broker-field-row { display: flex; flex-direction: column; gap: 4px; }
.broker-field-label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.broker-field-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}
.broker-field-controls .apikey-input { flex: 1; min-width: 0; }

/* ── Broker Request section ─────────────────────────────────── */
.settings-btn-secondary {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  transition: background 0.15s;
}
.settings-btn-secondary:hover { background: var(--border); }

/* ── FTUE Overlay ───────────────────────────────────────────── */
.ftue-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.ftue-overlay.ftue-fade-out {
  animation: ftue-fade 0.4s forwards;
}
@keyframes ftue-fade { to { opacity: 0; } }

.ftue-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  transition: opacity 0.12s, transform 0.12s;
}
.ftue-card.ftue-animating {
  opacity: 0;
  transform: scale(0.97);
}
#ftue-body {
  padding: 32px 32px 0;
  flex: 1;
}
.ftue-footer {
  padding: 20px 32px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}
.ftue-dots {
  display: flex;
  gap: 6px;
  flex: 1;
}
.ftue-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s;
}
.ftue-dot.active { background: var(--accent); }
.ftue-btns {
  display: flex;
  gap: 8px;
  align-items: center;
}
.ftue-btn-skip {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  transition: color 0.15s;
}
.ftue-btn-skip:hover { color: var(--text); }
.ftue-btn-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 8px;
  transition: background 0.15s;
}
.ftue-btn-back:hover { background: var(--bg-secondary); }
.ftue-btn-back.hidden { display: none; }
.ftue-btn-next {
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 22px;
  border-radius: 8px;
  transition: opacity 0.15s;
}
.ftue-btn-next:hover { opacity: 0.88; }

/* Welcome step */
.ftue-welcome { text-align: center; }
.ftue-egg-wrap { margin-bottom: 16px; }
.ftue-egg { width: 80px; height: 80px; }
.ftue-egg-spin { animation: ftue-spin 1.8s ease-in-out; }
@keyframes ftue-spin { 0% { transform: rotate(-15deg) scale(0.8); } 60% { transform: rotate(8deg) scale(1.05); } 100% { transform: rotate(0deg) scale(1); } }
.ftue-welcome-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
}
.ftue-welcome-sub {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.5;
  margin: 0 0 24px;
}
.ftue-welcome-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 16px 20px;
}
.ftue-welcome-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
}
.ftue-welcome-step span { font-size: 18px; }

/* Form steps (apikey, broker) */
.ftue-form-step { }
.ftue-step-icon { font-size: 36px; margin-bottom: 12px; }
.ftue-step-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
}
.ftue-step-desc {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 20px;
}
.ftue-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.ftue-input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.15s;
}
.ftue-input:focus { border-color: var(--accent); }
.ftue-save-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.ftue-save-btn:hover { opacity: 0.85; }
.ftue-save-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ftue-msg { font-size: 13px; margin-top: 6px; padding: 8px 12px; border-radius: 6px; }
.ftue-msg.hidden { display: none; }
.ftue-msg-success { background: rgba(34,197,94,0.12); color: #22c55e; }
.ftue-msg-error   { background: rgba(239,68,68,0.12);  color: #ef4444; }
.ftue-msg-warn    { background: rgba(245,158,11,0.12); color: #f59e0b; }
.ftue-link {
  display: inline-block;
  margin-top: 12px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}
.ftue-link:hover { text-decoration: underline; }

/* Broker step */
.ftue-broker-choice {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.ftue-broker-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.ftue-broker-btn.active {
  border-color: var(--accent);
  background: rgba(99,102,241,0.15);
  color: var(--accent);
}
.ftue-broker-fields { display: flex; flex-direction: column; gap: 10px; }
.ftue-field-row { display: flex; flex-direction: column; gap: 4px; }
.ftue-field-row label { font-size: 12px; color: var(--text-secondary); }
.ftue-broker-request {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.ftue-broker-req-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}
.ftue-broker-req-row {
  display: flex;
  gap: 8px;
}
.ftue-broker-req-row .ftue-input { font-family: var(--font-sans, inherit); }

/* Tour steps */
.ftue-tour-step { }
.ftue-tour-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
}
.ftue-tour-blurb {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 20px;
}
.ftue-demo-frame {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  min-height: 160px;
  overflow: hidden;
}

/* Demo: chat */
.demo-chat { display: flex; flex-direction: column; gap: 10px; }
.demo-msg { display: flex; gap: 8px; align-items: flex-start; }
.demo-msg.hidden { display: none; }
.demo-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  padding-top: 4px;
  min-width: 26px;
}
.demo-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  flex: 1;
  min-height: 18px;
}
.demo-msg-user .demo-bubble { background: rgba(99,102,241,0.1); border-color: rgba(99,102,241,0.3); }
.demo-bubble-launch { color: var(--text-secondary); }
.demo-launch-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.demo-launch-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 1.2s ease;
}

/* Demo: backtest */
.demo-backtest { }
.demo-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.demo-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
}
.demo-stat.demo-stat-pop { opacity: 1; transform: translateY(0); }
.demo-stat-val { font-size: 15px; font-weight: 700; font-family: var(--font-mono); }
.demo-stat-lbl { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.demo-equity-label { font-size: 11px; color: var(--text-secondary); margin-bottom: 6px; }
.demo-equity-chart canvas { display: block; width: 100%; }

/* Demo: regime */
.demo-regime { display: flex; flex-direction: column; gap: 12px; }
.demo-regime-current { }
.demo-regime-now {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.demo-regime-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.demo-regime-name { font-size: 16px; font-weight: 700; }
.demo-regime-conf { font-size: 12px; color: var(--text-secondary); }
.demo-regime-hint { font-size: 12px; color: var(--text-secondary); font-style: italic; }
.demo-regime-blocks { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.demo-regime-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
}
.demo-regime-blk-label { min-width: 100px; }
.demo-regime-bar-wrap { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.demo-regime-bar { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.demo-regime-days { min-width: 32px; text-align: right; color: var(--text-secondary); }

/* Demo: trading */
.demo-trading { }
.demo-deploy-card { }
.demo-deploy-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.demo-deploy-name { font-weight: 600; font-size: 14px; color: var(--text); }
.demo-deploy-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}
.demo-badge-paper { background: rgba(99,102,241,0.2); color: var(--accent); }
.demo-deploy-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
}
.demo-dp-stat { display: flex; flex-direction: column; font-size: 12px; color: var(--text-secondary); gap: 2px; }
.demo-dp-val { font-size: 15px; font-weight: 700; font-family: var(--font-mono); color: var(--text); }
.demo-dp-val.green { color: #22c55e; }
.demo-deploy-log { display: flex; flex-direction: column; gap: 4px; }
.demo-log-row {
  display: grid;
  grid-template-columns: 70px 42px 50px 40px 64px;
  gap: 4px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text);
  padding: 4px 8px;
  background: var(--bg-card);
  border-radius: 4px;
  border: 1px solid var(--border);
}
.demo-log-time { color: var(--text-secondary); }

/* Done step */
.ftue-done { text-align: center; padding-bottom: 8px; }
.ftue-egg-celebrate { animation: ftue-celebrate 0.6s ease; }
@keyframes ftue-celebrate {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.15) rotate(-8deg); }
  60%  { transform: scale(1.1) rotate(6deg); }
  100% { transform: scale(1) rotate(0deg); }
}
.ftue-done-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin: 8px 0 6px;
}
.ftue-done-sub {
  color: var(--text-secondary);
  font-size: 15px;
  margin: 0 0 20px;
}
.ftue-done-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 16px 20px;
}
.ftue-done-item {
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
