/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --card-radius: 12px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

[data-theme="light"] {
  --bg: #f6f8fa;
  --bg2: #ffffff;
  --bg3: #f0f0f0;
  --border: #d0d7de;
  --text: #1f2328;
  --text2: #57606a;
  --accent: #0969da;
  --green: #1a7f37;
  --red: #cf222e;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select { font-family: inherit; }
a { color: var(--accent); }

/* ── Header ─────────────────────────────────────────────────────────────────── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.mode-badge {
  background: var(--yellow); color: #000; font-size: 0.65rem;
  font-weight: 800; padding: 2px 8px; border-radius: 20px; letter-spacing: 1px;
}
.header-right { display: flex; align-items: center; gap: 16px; }
.ws-status { font-size: 0.8rem; color: var(--text2); }
.ws-status.live { color: var(--green); }
.icon-btn { font-size: 1.2rem; color: var(--text2); padding: 4px; border-radius: 6px; }
.icon-btn:hover { background: var(--bg3); }

/* ── Nav ────────────────────────────────────────────────────────────────────── */
.nav {
  display: flex; gap: 4px; padding: 8px 20px;
  background: var(--bg2); border-bottom: 1px solid var(--border); overflow-x: auto;
}
.nav-btn {
  padding: 6px 16px; border-radius: 8px; font-size: 0.9rem; color: var(--text2);
  white-space: nowrap; transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ── Main ───────────────────────────────────────────────────────────────────── */
.main { padding: 20px; max-width: 1200px; margin: 0 auto; }
.page { display: none; flex-direction: column; gap: 20px; }
.page.active { display: flex; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--card-radius); padding: 20px;
}
.card h2, .card h3 { margin-bottom: 16px; font-size: 1rem; }
.subtitle { font-size: 0.85rem; color: var(--text2); margin-bottom: 16px; display: block; }

/* ── Price Grid ─────────────────────────────────────────────────────────────── */
.price-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.price-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--card-radius); padding: 16px; cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
}
.price-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.price-card .symbol { font-size: 0.85rem; color: var(--text2); font-weight: 600; }
.price-card .price { font-size: 1.4rem; font-weight: 700; margin: 6px 0; }
.price-card .change { font-size: 0.9rem; font-weight: 600; }
.price-card .meta { font-size: 0.75rem; color: var(--text2); margin-top: 8px; }
.up { color: var(--green); }
.down { color: var(--red); }

/* ── Skeleton ───────────────────────────────────────────────────────────────── */
.skeleton {
  height: 110px; border-radius: var(--card-radius);
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg2) 50%, var(--bg3) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Chart ──────────────────────────────────────────────────────────────────── */
.chart-card { display: flex; flex-direction: column; gap: 12px; }
.chart-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 8px; }
.chart-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.chart-wrap { position: relative; height: 300px; }

select, input[type="number"] {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: 8px; font-size: 0.85rem;
}
select:focus, input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

/* ── Backtest Form ──────────────────────────────────────────────────────────── */
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--text2); }
label select, label input { color: var(--text); }

.btn-primary {
  background: var(--accent); color: #fff; padding: 10px 24px;
  border-radius: 8px; font-weight: 600; font-size: 0.9rem;
  transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Stats Grid ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px;
}
.stat-card {
  text-align: center; padding: 16px;
}
.stat-label { font-size: 0.75rem; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-value { font-size: 1.4rem; font-weight: 700; }
.stat-sub { font-size: 0.75rem; color: var(--text2); margin-top: 4px; }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.trade-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.trade-table th {
  text-align: left; padding: 8px 12px; color: var(--text2);
  border-bottom: 1px solid var(--border); font-weight: 600; white-space: nowrap;
}
.trade-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.trade-table tr:last-child td { border-bottom: none; }
.trade-table tr:hover td { background: var(--bg3); }
.empty { color: var(--text2); text-align: center; padding: 24px !important; }
.win-tag { color: var(--green); font-weight: 600; }
.loss-tag { color: var(--red); font-weight: 600; }
.buy-tag { color: var(--green); }
.sell-tag { color: var(--red); }

/* ── Portfolio ──────────────────────────────────────────────────────────────── */
.portfolio-header { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.trade-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.trade-form select, .trade-form input { flex: 1; min-width: 120px; }
.btn-buy {
  background: var(--green); color: #fff; padding: 8px 18px;
  border-radius: 8px; font-weight: 600; font-size: 0.9rem;
}
.btn-sell {
  background: var(--red); color: #fff; padding: 8px 18px;
  border-radius: 8px; font-weight: 600; font-size: 0.9rem;
}
.btn-ghost {
  border: 1px solid var(--border); color: var(--text2); padding: 6px 14px;
  border-radius: 8px; font-size: 0.85rem;
}
.btn-ghost:hover { background: var(--bg3); }
.btn-sell-sm {
  background: var(--red); color: #fff; padding: 4px 10px;
  border-radius: 6px; font-size: 0.8rem;
}
.trade-msg { font-size: 0.85rem; margin-top: 8px; min-height: 20px; }
.trade-msg.ok { color: var(--green); }
.trade-msg.err { color: var(--red); }
.positions-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.positions-header h3 { margin-bottom: 0; }

/* ── Loading Overlay ────────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  z-index: 999;
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 48px; height: 48px; border: 4px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { color: var(--text); font-size: 0.9rem; }

/* ── Alerts Page ─────────────────────────────────────────────────────────────── */
.alert-status-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 24px;
}
.alert-info-card {
  background: var(--bg3); border-radius: 10px; padding: 14px; text-align: center;
}
.alert-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.sample-alerts { display: flex; flex-direction: column; gap: 12px; }
.sample-alert {
  padding: 16px; border-radius: 10px; font-size: 0.88rem; line-height: 1.7;
  border-left: 4px solid;
}
.sample-buy { background: rgba(63,185,80,0.08); border-color: var(--green); }
.sample-sell { background: rgba(248,81,73,0.08); border-color: var(--red); }

.hidden { display: none !important; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .main { padding: 12px; }
  .chart-wrap { height: 220px; }
  .stat-value { font-size: 1.1rem; }
  .header { padding: 10px 14px; }
}
