/* ═══════════════════════════════════════════════════════════════
   STRATLAB — Dark TradingView-inspired Design System
   ─────────────────────────────────────────────────────────────
   Tokens → Reset → Layout → Topbar → Sidebars → Chart →
   Editor → Metrics → Trade Log → Equity → Utilities
═══════════════════════════════════════════════════════════════ */

/* ── DESIGN TOKENS ─────────────────────────────────────────── */
:root {
  /* Background layers */
  --bg-base:       #0d0d0f;
  --bg-surface:    #131316;
  --bg-elevated:   #1a1a1f;
  --bg-hover:      #1f1f26;
  --bg-active:     #252530;

  /* Borders */
  --border:        #2a2a35;
  --border-subtle: #1e1e28;
  --border-focus:  #7C3AED;

  /* Text */
  --text-primary:  #e8e8f0;
  --text-secondary:#8888a0;
  --text-muted:    #55556a;
  --text-inverse:  #0d0d0f;

  /* Brand */
  --purple:        #7C3AED;
  --purple-light:  #9d6ef5;
  --purple-dim:    rgba(124,58,237,0.15);
  --amber:         #F59E0B;
  --amber-dim:     rgba(245,158,11,0.15);

  /* Semantic */
  --green:         #22c55e;
  --green-dim:     rgba(34,197,94,0.12);
  --red:           #ef4444;
  --red-dim:       rgba(239,68,68,0.12);
  --blue:          #3b82f6;
  --blue-dim:      rgba(59,130,246,0.12);

  /* Candle colours */
  --candle-up:     #26a69a;
  --candle-down:   #ef5350;

  /* Sizing */
  --topbar-h:      52px;
  --sidebar-w:     300px;
  --radius-sm:     4px;
  --radius-md:     6px;
  --radius-lg:     10px;

  /* Typography */
  --font-ui:       'Inter', system-ui, sans-serif;
  --font-mono:     'JetBrains Mono', 'Fira Code', monospace;
  --font-size-xs:  11px;
  --font-size-sm:  12px;
  --font-size-md:  13px;
  --font-size-lg:  14px;

  /* Transitions */
  --ease:          cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast:      120ms;
  --dur-med:       220ms;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--font-size-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ── SCROLLBARS ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ══════════════════════════════════════════════════════════════
   TOP BAR
══════════════════════════════════════════════════════════════ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  gap: 12px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  white-space: nowrap;
}

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

/* Symbol bar */
.symbol-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.symbol-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.symbol-icon {
  position: absolute;
  left: 8px;
  color: var(--text-muted);
  pointer-events: none;
}
.symbol-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-size-md);
  font-weight: 600;
  padding: 5px 10px 5px 28px;
  width: 110px;
  outline: none;
  transition: border-color var(--dur-fast);
  text-transform: uppercase;
}
.symbol-input:focus { border-color: var(--border-focus); }

/* Interval / Market button groups */
.interval-group, .market-group {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.interval-btn, .market-btn {
  padding: 5px 10px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
  transition: background var(--dur-fast), color var(--dur-fast);
  border-right: 1px solid var(--border);
}
.interval-btn:last-child, .market-btn:last-child { border-right: none; }
.interval-btn:hover, .market-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.interval-btn.active, .market-btn.active {
  background: var(--purple-dim);
  color: var(--purple-light);
}

/* Date range */
.date-range {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
}
.date-range input[type="date"] {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-size-xs);
  padding: 4px 8px;
  outline: none;
  cursor: pointer;
  color-scheme: dark;
}
.date-range input[type="date"]:focus { border-color: var(--border-focus); }

/* Run button */
.run-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--purple);
  color: #fff;
  font-size: var(--font-size-sm);
  font-weight: 600;
  padding: 7px 16px;
  border-radius: var(--radius-md);
  transition: background var(--dur-fast), transform var(--dur-fast);
  white-space: nowrap;
}
.run-btn:hover { background: var(--purple-light); }
.run-btn:active { transform: scale(0.97); }
.run-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Status dot */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background var(--dur-med);
}
.status-dot.idle    { background: var(--text-muted); }
.status-dot.running { background: var(--amber); animation: pulse 1s infinite; }
.status-dot.success { background: var(--green); }
.status-dot.error   { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ══════════════════════════════════════════════════════════════
   APP LAYOUT
══════════════════════════════════════════════════════════════ */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--sidebar-w);
  grid-template-rows: 1fr;
  height: calc(100vh - var(--topbar-h));
  margin-top: var(--topbar-h);
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════════════
   SHARED PANEL COMPONENTS
══════════════════════════════════════════════════════════════ */
.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  min-height: 38px;
}

.panel-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

/* Icon button */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Tab group */
.tab-group {
  display: flex;
  gap: 2px;
}
.tab-btn {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.tab-btn:hover { color: var(--text-secondary); background: var(--bg-hover); }
.tab-btn.active { color: var(--text-primary); background: var(--bg-active); }

/* Divider */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 0;
  flex-shrink: 0;
}

/* Section label */
.section-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 10px 12px 6px;
}

/* ══════════════════════════════════════════════════════════════
   LEFT SIDEBAR — CODE EDITOR
══════════════════════════════════════════════════════════════ */
.sidebar-left {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.editor-tab {
  display: none;
  flex: 1;
  overflow: hidden;
}
.editor-tab.active { display: flex; flex-direction: column; flex: 1; }

.editor-wrap {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Line numbers */
.line-numbers {
  width: 36px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  padding: 12px 0;
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-align: right;
  padding-right: 8px;
  overflow: hidden;
  user-select: none;
  line-height: 1.6;
}

/* Code textarea */
.code-editor {
  flex: 1;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: 1.6;
  padding: 12px 12px 12px 10px;
  border: none;
  outline: none;
  resize: none;
  overflow-y: auto;
  overflow-x: auto;
  white-space: pre;
  tab-size: 4;
  caret-color: var(--purple-light);
}
.code-editor::placeholder {
  color: var(--text-muted);
  font-style: italic;
}
.code-editor:focus { background: var(--bg-elevated); }

/* Sidebar footer */
.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.convert-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.convert-btn:hover {
  background: var(--purple-dim);
  border-color: var(--purple);
  color: var(--purple-light);
}

/* ══════════════════════════════════════════════════════════════
   CENTER — CHART AREA
══════════════════════════════════════════════════════════════ */
.chart-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

/* Chart toolbar */
.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  min-height: 36px;
}

.chart-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chart-symbol {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.chart-interval {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.ohlc-display {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  display: flex;
  gap: 8px;
}

.chart-tools { display: flex; gap: 4px; }

/* Chart container */
.chart-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.chart-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  text-align: center;
}
.chart-placeholder p {
  font-size: var(--font-size-lg);
  font-weight: 500;
  color: var(--text-secondary);
}
.chart-placeholder span {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}
.chart-placeholder strong { color: var(--text-secondary); }

/* ── Trade Log ─────────────────────────────────────────────── */
.trade-log-panel {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  max-height: 220px;
}

.trade-count {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 2px 7px;
  border-radius: 99px;
}

.trade-log-wrap {
  overflow: auto;
  flex: 1;
}

.trade-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-xs);
  font-family: var(--font-mono);
}

.trade-table th {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  font-size: 10px;
}

.trade-table td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
}

.trade-table tbody tr:hover td { background: var(--bg-hover); }

.trade-table .empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-family: var(--font-ui);
  font-style: italic;
}

.trade-table .trade-long  { color: var(--green); }
.trade-table .trade-short { color: var(--red); }
.trade-table .pnl-pos { color: var(--green); }
.trade-table .pnl-neg { color: var(--red); }

/* ══════════════════════════════════════════════════════════════
   RIGHT SIDEBAR — PERFORMANCE
══════════════════════════════════════════════════════════════ */
.sidebar-right {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Metrics grid */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 12px;
  background: var(--bg-surface);
  transition: background var(--dur-fast);
}
.metric-card:hover { background: var(--bg-hover); }

.metric-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-value {
  font-size: 18px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.metric-value.positive { color: var(--green); }
.metric-value.negative { color: var(--red); }

/* Equity chart */
.equity-section { display: flex; flex-direction: column; }

.equity-chart {
  height: 90px;
  margin: 0 12px 10px;
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
}

.equity-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  font-style: italic;
}

/* Stats list */
.stats-list {
  display: flex;
  flex-direction: column;
  padding: 4px 0 8px;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px;
  transition: background var(--dur-fast);
}
.stat-row:hover { background: var(--bg-hover); }

.stat-key {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.stat-val {
  font-size: var(--font-size-xs);
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-secondary);
}
.stat-val.positive { color: var(--green); }
.stat-val.negative { color: var(--red); }

/* Log output */
.log-section { display: flex; flex-direction: column; flex: 1; min-height: 80px; }

.log-output {
  flex: 1;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  overflow-y: auto;
  line-height: 1.7;
}

.log-idle { color: var(--text-muted); font-style: italic; }
.log-info  { color: var(--text-secondary); }
.log-success { color: var(--green); }
.log-error   { color: var(--red); }
.log-warn    { color: var(--amber); }

/* ══════════════════════════════════════════════════════════════
   LOADING OVERLAY
══════════════════════════════════════════════════════════════ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,13,15,0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity var(--dur-med);
}
.loading-overlay.hidden { display: none; }

.loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 36px;
}

.loading-inner p {
  font-size: var(--font-size-md);
  color: var(--text-secondary);
}

.spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ══════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
══════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.25s var(--ease);
  max-width: 320px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--blue); }
.toast.warn    { border-left: 3px solid var(--amber); }
.toast.fade-out { animation: toastOut 0.2s ease forwards; }

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

/* ══════════════════════════════════════════════════════════════
   LIGHTWEIGHT CHARTS OVERRIDES
══════════════════════════════════════════════════════════════ */
#chartContainer > div { width: 100% !important; height: 100% !important; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — collapse sidebars on small screens
══════════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  :root { --sidebar-w: 260px; }
}

@media (max-width: 860px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .sidebar-left, .sidebar-right {
    display: none;
  }
  .symbol-bar { display: none; }
  .date-range label { display: none; }
}