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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242735;
  --border: #2e3140;
  --text: #e1e4ea;
  --text2: #8b8fa3;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --yellow: #eab308;
  --accent: #6366f1;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* ── Login ────────────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f1117 0%, #1a1d27 100%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  text-align: center;
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text2);
  margin-bottom: 28px;
  font-size: 14px;
}

#login-form input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

#login-form input:focus {
  border-color: var(--accent);
}

#login-form button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

#login-form button:hover { opacity: 0.9; }

.error {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 18px; }
.header-right { display: flex; align-items: center; gap: 12px; }
#header-user { color: var(--text2); font-size: 14px; }

.date-badge {
  background: var(--surface2);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text2);
}

.btn-sm {
  padding: 6px 14px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
}

.btn-sm:hover { background: var(--border); }

.btn-sync {
  background: rgba(34, 197, 94, 0.1);
  border-color: var(--green);
  color: var(--green);
}
.btn-sync:hover { background: rgba(34, 197, 94, 0.2); }
.btn-sync:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sync.syncing { animation: pulse-dot 1s ease-in-out infinite; }

.btn-dummy {
  background: rgba(234, 179, 8, 0.1);
  border-color: var(--yellow);
  color: var(--yellow);
}
.btn-dummy:hover { background: rgba(234, 179, 8, 0.2); }

.btn-primary {
  padding: 8px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
}

.btn-primary:hover { opacity: 0.9; }

/* ── Filters ──────────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: flex-end;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text2);
}

.filters input, .filters select {
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

/* ── Tabs ──────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 12px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  font-size: 14px;
  cursor: pointer;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab:hover { color: var(--text); }

.tab-content { display: none; padding: 24px; }
.tab-content.active { display: block; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-label { font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.card-value { font-size: 28px; font-weight: 700; }
.card-value.positive { color: var(--green); }
.card-value.negative { color: var(--red); }

/* ── Panels ────────────────────────────────────────────────────────────────── */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.panel h3 {
  font-size: 15px;
  margin-bottom: 16px;
  color: var(--text2);
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.metric-label { color: var(--text2); }
.metric-value { font-weight: 600; }

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface2);
  color: var(--text2);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tr:hover td { background: var(--surface2); }

/* Status badges */
.badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-pending  { background: #1e293b; color: var(--text2); }
.badge-executed { background: #1e3a5f; color: var(--blue); }
.badge-target   { background: #14532d; color: var(--green); }
.badge-sl       { background: #451a1a; color: var(--red); }
.badge-expired  { background: #1e293b; color: var(--text2); }
.badge-finetuned { background: #422006; color: var(--yellow); }
.badge-dropped  { background: #1e1e1e; color: #666; text-decoration: line-through; }

/* ── Insights ──────────────────────────────────────────────────────────────── */
#insights-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.insight {
  padding: 12px 16px;
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 13px;
  line-height: 1.5;
}

.recommendation {
  padding: 14px 16px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
}

/* ── Sub Tabs (trade categories) ───────────────────────────────────────────── */
.sub-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.sub-tab {
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
}

.sub-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.sub-tab:hover:not(.active) { background: var(--surface2); }

/* ── Modal Overlay ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px; right: 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover { background: var(--border); }

.modal h3 { margin-bottom: 16px; }

/* ── Trade Analysis Panel ─────────────────────────────────────────────────── */
.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.analysis-section {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 16px;
}

.analysis-section h4 {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.analysis-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.analysis-label { color: var(--text2); }
.analysis-val { font-weight: 600; }

.reasoning-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  padding: 10px 0;
}

.reasoning-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.expand-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}

.expand-btn:hover { background: var(--surface2); }

.time-cell { font-family: monospace; font-size: 12px; color: var(--text2); }

/* ── Agent Status Indicator ────────────────────────────────────────────────── */
.agent-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.agent-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.agent-running {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
}
.agent-running .agent-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse-dot 2s ease-in-out infinite;
}

.agent-stopped {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
}
.agent-stopped .agent-dot {
  background: var(--red);
}

.agent-unknown {
  background: var(--surface2);
  color: var(--text2);
}
.agent-unknown .agent-dot {
  background: var(--text2);
}

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

/* ── Logs ──────────────────────────────────────────────────────────────────── */
.logs-toolbar {
  display: flex;
  gap: 16px;
  padding: 14px 0;
  align-items: flex-end;
  flex-wrap: wrap;
}

.logs-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text2);
}

.logs-toolbar input,
.logs-toolbar select {
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.auto-refresh-label {
  flex-direction: row !important;
  align-items: center !important;
  gap: 6px !important;
  font-size: 13px !important;
}

.log-viewer {
  background: #0a0c10;
  color: #c9d1d9;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 16px;
  margin: 0;
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: auto;
  white-space: pre;
  border-radius: var(--radius);
}

.log-line-error { color: var(--red); }
.log-line-warning { color: var(--yellow); }
.log-line-info { color: #c9d1d9; }
.log-line-critical { color: #ff6b6b; font-weight: 700; }

/* ── Chart ─────────────────────────────────────────────────────────────────── */
.chart-controls {
  display: flex;
  gap: 16px;
  padding: 14px 0;
  align-items: flex-end;
}

.chart-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text2);
  flex: 1;
  max-width: 400px;
}

.chart-controls select {
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.chart-layout {
  display: flex;
  gap: 16px;
  min-height: 560px;
}

.chart-sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-header h4 {
  font-size: 13px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-header select {
  padding: 4px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  outline: none;
}

.signal-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.signal-empty {
  color: var(--text2);
  font-size: 13px;
  text-align: center;
  padding: 24px 12px;
}

.signal-card {
  padding: 10px 12px;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.signal-card:hover {
  border-color: var(--border);
  background: var(--border);
}

.signal-card.selected {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

.signal-card .sig-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.signal-card .sig-symbol {
  font-weight: 700;
  font-size: 13px;
}

.signal-card .sig-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text2);
  padding: 1px 0;
}

.signal-card .sig-val { color: var(--text); font-weight: 500; }
.signal-card .sig-pnl-pos { color: var(--green); font-weight: 600; }
.signal-card .sig-pnl-neg { color: var(--red); font-weight: 600; }

.chart-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.chart-detail-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  font-size: 12px;
}

.chart-detail-bar .detail-item {
  display: flex;
  gap: 6px;
}

.chart-detail-bar .detail-label { color: var(--text2); }
.chart-detail-bar .detail-val { font-weight: 600; }

.chart-legend {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(15, 17, 23, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  z-index: 10;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.chart-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .panels { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr 1fr; }
  .filters { flex-wrap: wrap; }
  .logs-toolbar { flex-direction: column; align-items: stretch; }
  .chart-layout { flex-direction: column; }
  .chart-sidebar { width: 100%; min-width: unset; max-height: 200px; }
}
