:root, [data-theme="dark"] {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-input: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #2563eb;
  --accent-hover: #3b82f6;
  --green: #3fb950;
  --orange: #d29922;
  --red: #f85149;
  --plotly-bg: #161b22;
  --plotly-grid: #21262d;
  --plotly-text: #e6edf3;
  --plotly-muted: #8b949e;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-card: #f6f8fa;
  --bg-input: #eef1f5;
  --border: #d1d9e0;
  --text: #1f2328;
  --text-muted: #59636e;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #1a7f37;
  --orange: #9a6700;
  --red: #d1242f;
  --plotly-bg: #ffffff;
  --plotly-grid: #e5e7eb;
  --plotly-text: #1f2328;
  --plotly-muted: #59636e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
header {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  margin-bottom: 24px;
}

header .header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  font-size: 24px;
  font-weight: 600;
}

header h1 span { color: var(--accent); }

header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.header-btns {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.lang-btn {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.lang-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.theme-icon {
  font-size: 18px;
  padding: 4px 10px;
  line-height: 1;
}

/* Global options */
.global-options {
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Chart legend */
.chart-legend {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

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

.legend-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-measured {
  background: var(--accent);
  border: 2px solid var(--accent);
}

.legend-estimated {
  background: rgba(210, 153, 34, 0.4);
  border: 2px dashed var(--orange);
}

.legend-suspicious {
  background: rgba(248, 81, 73, 0.3);
  border: 2px dashed var(--red);
}

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

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 12px 20px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

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

/* Tab panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  align-items: flex-end;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

select, input[type="number"], input[type="text"] {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  min-width: 180px;
}

select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
}

optgroup {
  color: var(--accent);
  font-style: normal;
  font-weight: 600;
  font-size: 12px;
  padding-top: 4px;
}

optgroup option {
  color: var(--text);
  font-weight: 400;
  font-size: 14px;
}

/* Filter bar */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}

.filter-bar h3 {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.chip:hover { border-color: var(--accent); }
.chip.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* Chart container */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
  min-height: 500px;
}

/* Data table */
.table-container {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

th {
  background: var(--bg-input);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  position: sticky;
  top: 0;
}

th:hover { color: var(--text); }
th .sort-arrow { margin-left: 4px; font-size: 10px; }

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tr:hover td { background: rgba(88, 166, 255, 0.04); }
td a { color: inherit; text-decoration: none; }
td a:hover { text-decoration: underline; }

.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Stats cards */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 4px;
}

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: 48px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 768px) {
  .container { padding: 0 8px; }
  .header-row { flex-wrap: wrap; gap: 4px; }
  .header-row > div:first-child { flex: 1 1 100%; }
  .header-row h1 { font-size: 20px; }
  .header-btns { margin-left: auto; }
  .controls { flex-direction: column; }
  select, input { min-width: 100%; }
  .stats { grid-template-columns: 1fr 1fr; }
  .global-options {
    display: block;
  }
  .global-options .checkbox-label {
    display: block; font-size: 12px; margin-bottom: 6px;
  }
  .global-options .checkbox-label input[type="checkbox"] {
    display: inline; vertical-align: middle; margin-right: 4px;
  }
  .tabs { gap: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { font-size: 13px; padding: 8px 12px; white-space: nowrap; }
  .chart-legend { flex-wrap: wrap; font-size: 11px; gap: 6px; }
  .table-container { font-size: 12px; }
  .guide-container { padding: 12px; }
}

/* Deployment Guide */
.guide-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.guide-container .md-body { line-height: 1.8; }
.guide-container .md-body h1 {
  font-size: 22px; margin-bottom: 16px; padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
}
.guide-container .md-body h2 {
  font-size: 18px; margin-top: 32px; margin-bottom: 12px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.guide-container .md-body h3 { font-size: 15px; margin-top: 20px; margin-bottom: 8px; }
.guide-container .md-body h4 { font-size: 14px; margin-top: 16px; margin-bottom: 6px; }
.guide-container .md-body p { margin-bottom: 12px; }
.guide-container .md-body ul, .guide-container .md-body ol {
  margin-bottom: 12px; padding-left: 24px;
}
.guide-container .md-body li { margin-bottom: 4px; }
.guide-container .md-body code {
  background: var(--bg-input); padding: 2px 6px; border-radius: 4px; font-size: 13px;
}
.guide-container .md-body pre {
  background: var(--bg-input); padding: 16px; border-radius: 8px;
  overflow-x: auto; margin-bottom: 16px;
}
.guide-container .md-body pre code { background: none; padding: 0; }
.guide-container .md-body a { color: var(--accent); }
.guide-container .md-body a:hover { text-decoration: underline; }
.guide-container .md-body table {
  width: 100%; border-collapse: collapse; margin-bottom: 16px;
}
.guide-container .md-body table th,
.guide-container .md-body table td {
  padding: 8px 12px; border: 1px solid var(--border); text-align: left;
}
.guide-container .md-body table th { background: var(--bg-input); }
.guide-container .md-body blockquote {
  border-left: 3px solid var(--accent); padding-left: 16px;
  color: var(--text-muted); margin-bottom: 12px;
}
.guide-container .md-body strong { color: var(--text); }
.guide-container .md-body hr {
  border: none; border-top: 1px solid var(--border); margin: 32px 0;
}

/* Plotly overrides for dark theme */
.js-plotly-plot .plotly .modebar { top: 8px !important; right: 8px !important; }
