* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  line-height: 1.6;
  min-height: 100vh;
}

body.theme-light {
  background: #f8fafc;
  color: #1e293b;
}

/* ===== Header ===== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 2rem;
  border-bottom: 1px solid #334155;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  position: sticky;
  top: 0;
  z-index: 100;
}

body.theme-light header {
  background: rgba(248, 250, 255, 0.8);
  border-color: #cbd5e1;
}

header h1 { font-size: 1.15rem; font-weight: 600; }

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Mode toggle */
.mode-toggle {
  display: flex;
  gap: 0.25rem;
  border-radius: 8px;
  padding: 0.25rem;
  background: rgba(51, 65, 85, 0.5);
}

body.theme-light .mode-toggle {
  background: rgba(203, 213, 227, 0.5);
}

.mode-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active, .mode-btn:hover {
  background: #38bdf8;
  color: #0f172a;
}

#theme-toggle {
  background: #1e293b;
  border: none;
  color: #e2e8f0;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
}

body.theme-light #theme-toggle {
  background: #e2e8f0;
  color: #1e293b;
}

/* ===== Loading ===== */
#loading-screen {
  text-align: center;
  padding: 4rem 1rem;
}

.spinner {
  border: 3px solid #334155;
  border-top: 3px solid #38bdf8;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }
.error { color: #f87171; }

/* ===== Live status bar ===== */
#live-status-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 2rem;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  font-size: 0.85rem;
}

body.theme-light #live-status-bar {
  background: #ffffff;
  border-color: #d1d5db;
}

#live-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
  display: inline-block;
}

#live-status-dot.disconnected {
  background: #f87171;
  box-shadow: 0 0 8px #f87171;
}

.last-update {
  margin-left: auto;
  opacity: 0.5;
  font-size: 0.8rem;
}

/* ===== Summary cards ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
  padding: 1.5rem 2rem;
}

.card {
  background: #1e293b;
  border-radius: 12px;
  padding: 1rem 1.2rem;
  text-align: center;
  border: 1px solid #334155;
}

body.theme-light .card {
  background: #ffffff;
  border-color: #d1d5db;
}

.card .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.5;
  display: block;
  margin-bottom: 0.4rem;
}

.card .value {
  font-size: 1.7rem;
  font-weight: 700;
}

.card.green .value { color: #4ade80; }
.card.red .value { color: #f87171; }
.card.amber .value { color: #fbbf24; }

/* ===== Charts ===== */
.chart-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 880px) {
  .chart-section { grid-template-columns: 1fr; }
}

.chart-card {
  background: #1e293b;
  border-radius: 12px;
  border: 1px solid #334155;
  padding: 1.25rem;
}

body.theme-light .chart-card {
  background: #ffffff;
  border-color: #d1d5db;
}

.chart-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #94a3b8;
}

body.theme-light .chart-card h3 { color: #64748b; }

.mini-chart { width: 100%; height: auto; }
.chart-footer {
  margin-top: 0.6rem;
  font-size: 0.75rem;
  opacity: 0.5;
  text-align: center;
}

/* ===== Table ===== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid #334155;
  border-radius: 8px;
  max-height: 480px;
  overflow-y: auto;
}

body.theme-light .table-wrap { border-color: #d1d5db; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 0.5rem 0.75rem; text-align: right; border-bottom: 1px solid #334155; }
body.theme-light th, body.theme-light td { border-color: #e2e8f0; }
th { opacity: 0.5; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
.fold-num { text-align: center; opacity: 0.5; }
.fold-dates { text-align: center; font-size: 0.8rem; }
td.pos { color: #4ade80; font-weight: 600; }
td.neg { color: #f87171; font-weight: 600; }
td.center { text-align: center; }
tr:hover td { background: rgba(56, 189, 248, 0.05); }

/* ===== Metadata ===== */
.meta-table { width: 100%; max-width: 600px; }
.meta-table td { padding: 0.4rem 0.75rem; border-bottom: 1px solid #334155; }
body.theme-light .meta-table td { border-color: #e2e8f0; }
.meta-table td:first-child { font-weight: 600; opacity: 0.6; width: 45%; }

/* ===== Sections ===== */
section h2 {
  padding: 0 2rem;
  margin: 1rem 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 600;
}

#charts { padding: 1rem 2rem; }

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 1.5rem;
  opacity: 0.4;
  font-size: 0.8rem;
}

/* ===== Utility ===== */
.hidden { display: none; }
