@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ===== Design System ===== */
:root {
  --bg-primary: #05050a;
  --bg-secondary: rgba(18, 18, 30, 0.7);
  --bg-tertiary: rgba(30, 30, 50, 0.4);
  --bg-hover: rgba(50, 50, 80, 0.3);
  --border: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.12);
  --text-primary: #ffffff;
  --text-secondary: #cacedb;
  --text-muted: #8086a2;
  --accent: #7c3aed; /* Violet */
  --accent-glow: rgba(124, 58, 237, 0.3);
  --pos: #00f291;
  --neg: #ff4b5c;
  --warn: #ffb443;
  --radius: 16px;
  --rail-width: 280px;
  --top-bar-h: 64px;
  --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --blur: blur(12px);
  /* Product Colors */
  --color-osmium: #60a5fa;
  --color-pepper: #f87171;
  --color-chilli: #fbbf24;
  --color-cacao: #8b5cf6;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-hover: #e2e8f0;
  --border: rgba(0,0,0,0.08);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #4f46e5;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { 
  height: 100%; 
  overflow: hidden; 
  font-family: 'Inter', system-ui, -apple-system, sans-serif; 
  font-size: 13.5px; 
  line-height: 1.5;
  background: var(--bg-primary); 
  color: var(--text-primary); 
  -webkit-font-smoothing: antialiased;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== App Layout ===== */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#rail {
  width: var(--rail-width);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.05), transparent),
              radial-gradient(circle at bottom left, rgba(16, 185, 129, 0.02), transparent);
}

#top-bar {
  height: var(--top-bar-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

#content {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Rail ===== */
.rail { display: flex; flex-direction: column; height: 100%; }

.rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.rail-title { 
  font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); 
  transition: color 0.15s;
}
.rail-title:hover { color: var(--accent); }

.drop-zone {
  margin: 10px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px 10px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  font-size: 12px;
  line-height: 1.6;
}

.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(78,154,241,0.06);
  color: var(--accent);
}

.drop-zone svg { margin-bottom: 6px; opacity: 0.5; }
.drop-hint { font-size: 11px; color: var(--text-muted); }

.strategy-list { flex: 1; overflow-y: auto; padding: 4px 0; }

.strategy-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0.4;
  border-left: 3px solid transparent;
}

.strategy-row.active { 
  opacity: 1; 
  background: rgba(255,255,255,0.03);
}
.strategy-row:hover { 
  background: var(--bg-hover); 
  opacity: 0.8;
}
.strategy-row.active {
  border-left-color: var(--accent);
}

.strategy-dot { 
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; 
  box-shadow: 0 0 8px var(--dot-color, var(--accent));
}
.strategy-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 500; }

.strategy-remove {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 14px; padding: 4px;
  opacity: 0; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
}
.strategy-remove:hover { background: rgba(239, 68, 68, 0.1); color: var(--neg); }
.strategy-row:hover .strategy-remove { opacity: 1; }

.rail-samples { 
  padding: 12px 16px; 
  border-bottom: 1px solid var(--border); 
}
.rail-subtitle { 
  display: block; font-size: 10px; text-transform: uppercase; 
  letter-spacing: 0.1em; color: var(--text-muted); margin-bottom: 10px; 
  font-weight: 600;
}
.sample-list { display: flex; flex-direction: column; gap: 4px; }
.sample-item { 
  font-size: 11px; 
  padding: 6px 10px; 
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
}
.sample-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border);
}

.rail-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ===== Top Bar ===== */
.top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 100%;
}

.top-bar-left { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.top-bar-center { display: flex; align-items: center; gap: 6px; }
.top-bar-right { display: flex; align-items: center; gap: 8px; }

.scrubber {
  flex: 1;
  min-width: 80px;
  max-width: 300px;
  accent-color: var(--accent);
  cursor: pointer;
}
.scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 14px;
  width: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
  cursor: pointer;
  margin-top: -5px;
}
.scrubber::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: var(--bg-tertiary);
  border-radius: 2px;
}

.tb-tick-label { font-size: 11px; color: var(--text-muted); white-space: nowrap; min-width: 70px; }

.tb-btn {
  background: none; border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 4px; cursor: pointer; padding: 3px 7px; font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}
.tb-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
#tb-mode { border-color: var(--accent); color: var(--accent); font-weight: 600; padding: 3px 10px; margin-right: 4px; }
#tb-mode:hover { background: var(--accent); color: white; }

.tb-select {
  background: var(--bg-tertiary); 
  border: 1px solid var(--border);
  color: var(--text-primary); 
  border-radius: 6px; 
  padding: 4px 24px 4px 10px;
  font-size: 12px; 
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: all 0.2s;
  backdrop-filter: var(--blur);
}
.tb-select:hover {
  background-color: var(--bg-hover);
  border-color: var(--accent);
}
.tb-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

[data-theme="light"] .tb-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

/* ===== Buttons ===== */
.btn-ghost {
  background: none; border: 1px solid var(--border); color: var(--text-secondary);
  border-radius: 4px; cursor: pointer; padding: 2px 8px; font-size: 11px;
  transition: background 0.15s, color 0.15s;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-ghost:active { transform: scale(0.95); }

/* ===== Toggle / Checkbox ===== */
.toggle-row {
  display: flex; 
  align-items: center; 
  gap: 8px;
  font-size: 11px; 
  color: var(--text-secondary); 
  cursor: pointer;
  user-select: none;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}
.toggle-row:hover {
  background: var(--bg-hover);
}
.toggle-row input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--bg-tertiary);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}
.toggle-row input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-row input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 5px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.toggle-row span {
  font-weight: 500;
}

/* ===== KPI ===== */
.kpi-row { display: flex; gap: 10px; flex-wrap: wrap; }
.kpi-empty { color: var(--text-muted); padding: 12px; font-size: 13px; }

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 220px;
  flex: 1;
  box-shadow: var(--shadow);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.kpi-card:hover { 
  transform: translateY(-4px); 
  border-color: var(--accent);
  background: rgba(25, 25, 45, 0.8);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 15px var(--accent-glow);
}

.kpi-name { 
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; 
  color: var(--text-muted); margin-bottom: 12px; font-weight: 700; 
}
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px 16px; }
.kpi-label { font-size: 10px; color: var(--text-muted); margin-bottom: 2px; }
.kpi-value { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-primary); }

/* ===== Charts ===== */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-height: 280px;
}

.chart-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  backdrop-filter: var(--blur);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  box-shadow: var(--shadow);
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(4px);
}

.chart-title { font-size: 12px; font-weight: 600; color: var(--text-secondary); }

.chart-body {
  flex: 1;
  position: relative;
  min-height: 0;
}

.chart-body canvas {
  position: absolute;
  inset: 0;
}

.position-row {
  grid-template-columns: 1fr;
  min-height: 180px;
}

/* ===== Bottom panels ===== */
.bottom-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.bottom-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  padding: 0 4px;
  background: var(--bg-secondary);
  border-radius: var(--radius) var(--radius) 0 0;
}

.bottom-tab {
  background: none; border: none; color: var(--text-muted);
  padding: 6px 14px; cursor: pointer; font-size: 12px;
  border-bottom: 2px solid transparent; transition: color 0.15s, border-color 0.15s;
}
.bottom-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.bottom-tab:hover:not(.active) { color: var(--text-primary); }

.bottom-panels { flex: 1; overflow: hidden; }
.bottom-panel { height: 100%; }
.bottom-panel.hidden { display: none; }

.bottom-inner {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 10px;
  height: 100%;
  padding: 10px 0 0;
}

/* ===== Panel ===== */
.panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.panel-title { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.panel-subtitle { font-size: 11px; color: var(--text-muted); }
.panel-empty { color: var(--text-muted); padding: 12px; font-size: 12px; text-align: center; }

/* ===== Order Book ===== */
.ob-content { overflow-y: auto; padding: 8px; flex: 1; }
.ob-product { font-size: 11px; font-weight: 700; color: var(--text-muted); text-align: center; margin-bottom: 6px; }
.ob-spread { font-size: 11px; color: var(--text-muted); text-align: center; padding: 4px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: 2px 0; }

.ob-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 12px; font-variant-numeric: tabular-nums; }
.ob-price { width: 56px; text-align: right; font-weight: 600; }
.ob-bar-wrap { flex: 1; height: 12px; background: var(--bg-tertiary); border-radius: 2px; overflow: hidden; }
.ob-bar { height: 100%; border-radius: 2px; transition: width 0.15s; }
.ask-bar { background: rgba(241,108,78,0.5); margin-left: auto; }
.bid-bar { background: rgba(78,241,160,0.5); }
.ob-vol { width: 40px; color: var(--text-muted); }
.ob-row.ask .ob-price { color: var(--neg); }
.ob-row.bid .ob-price { color: var(--pos); }



/* ===== Fills ===== */
.fills-content { overflow: auto; flex: 1; }
.fills-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.fills-table th { padding: 4px 8px; text-align: left; color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 600; position: sticky; top: 0; background: var(--bg-secondary); }
.fills-table td { padding: 3px 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.fills-table tr:hover td { background: var(--bg-hover); }
.fills-empty { color: var(--text-muted); text-align: center; padding: 12px; }

/* ===== Logs ===== */
.logs-panel { height: 100%; }
.log-tabs { display: flex; gap: 2px; }
.log-tab { background: none; border: none; color: var(--text-muted); padding: 3px 10px; cursor: pointer; font-size: 11px; border-radius: 3px; transition: background 0.15s, color 0.15s; }
.log-tab.active { background: var(--bg-tertiary); color: var(--text-primary); }
.log-tab:hover:not(.active) { color: var(--text-primary); }
.log-content { 
  flex: 1; 
  overflow-y: auto; 
  padding: 10px; 
  font-family: 'JetBrains Mono', monospace; 
  font-size: 11px; 
  white-space: pre-wrap; 
  color: var(--text-secondary); 
  line-height: 1.6; 
}

/* ===== Summary ===== */
.summary-content { overflow: auto; flex: 1; }
.summary-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.summary-table th { padding: 5px 10px; text-align: left; color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 600; position: sticky; top: 0; background: var(--bg-secondary); }
.summary-table td { padding: 5px 10px; border-bottom: 1px solid var(--border); transition: background 0.2s cubic-bezier(0.4, 0, 0.2, 1); }
.summary-table tr:hover td { background: var(--bg-hover); }

/* ===== Colors ===== */
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; flex-shrink: 0; }
kbd { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; font-size: 11px; cursor: default; user-select: none; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-secondary); border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  border-radius: var(--radius); max-width: 540px; width: 90%; max-height: 80vh;
  overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 0 40px rgba(0,0,0,0.6), 0 0 20px var(--accent-glow);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 15px; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 16px; }
.modal-body { padding: 16px 18px; overflow-y: auto; line-height: 1.7; }
.modal-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin: 14px 0 6px; }
.modal-body ul { padding-left: 18px; }
.modal-body li { margin-bottom: 3px; font-size: 12px; }
.modal-body p { font-size: 12px; margin-bottom: 6px; }
.modal-body a { color: var(--accent); }

/* ===== Loading ===== */
#loading-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
#loading-overlay.hidden { display: none; }
.loading-spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite, pulse 1.5s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

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

/* ===== Simple Mode ===== */
.mode-simple #rail { display: none; }
.mode-simple .bottom-area { display: none; }
.mode-simple .charts-row.position-row { display: none; }
.mode-simple .top-bar-center { display: none; }
.mode-simple #tb-scrubber { max-width: 600px; }
.mode-simple .top-bar-right .toggle-row { display: none; }
.mode-simple .top-bar-right #tb-help { display: none; }
.mode-simple #content { padding: 20px; }
.mode-simple .charts-row { grid-template-columns: 1fr; height: auto; gap: 20px; }
.mode-simple .chart-panel { height: 400px; }

/* Responsive */
@media (max-width: 900px) {
  .charts-row { grid-template-columns: 1fr; }
  .charts-row.position-row { height: 300px; }
}
@media (max-width: 768px) {
  #rail { display: none; }
  .top-bar-center { display: none; }
}
