:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #f89f1b;
  --accent2: #00b8d9;
  --text: #e4e6f0;
  --text-muted: #7a7f9a;
  --success: #36b37e;
  --danger: #ff5630;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body.light {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface2: #eaecf5;
  --border: #cdd1e4;
  --text: #1a1d27;
  --text-muted: #5a6080;
  --shadow: 0 4px 24px rgba(0,0,0,0.1);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; width: 100%; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

header .logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

header .logo span { color: var(--text); }

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}

.tab-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.45rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.15s;
}

.tab-btn:hover { border-color: var(--accent); color: var(--text); }
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #000; font-weight: 600; }

.theme-divider { width: 1px; background: var(--border); align-self: stretch; margin: 0 0.25rem; }
.theme-toggle { min-width: 6rem; }

main { max-width: 1200px; margin: 0 auto; padding: 2rem; }

footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

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

.footer-db-info { margin-bottom: 0.4rem; }

.search-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.search-section h2 {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.search-row {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  flex-wrap: wrap;
}

.field { display: flex; flex-direction: column; justify-content: space-between; flex: 1; min-width: 160px; }

.field label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.2;
  padding-left: 0.4rem;
}

.field-btn-wrap {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.label-spacer {
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.2;
  visibility: hidden;
  pointer-events: none;
  user-select: none;
}

input[type="text"], select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
  height: 2.5rem;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

input[type="text"]:focus, select:focus { border-color: var(--accent); }
select option { background: var(--surface2); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.4rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  height: 2.5rem;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover { background: #e8920f; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

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

.stat-card .value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .value.u2 { color: var(--accent2); }
.stat-card .sub { font-size: 0.78rem; color: var(--text-muted); }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.chart-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.compare-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.compare-col { display: flex; flex-direction: column; gap: 0.75rem; }

.compare-col .col-header {
  font-size: 1rem;
  font-weight: 700;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid;
}

.compare-col.u1 .col-header { color: var(--accent); border-color: var(--accent); }
.compare-col.u2 .col-header { color: var(--accent2); border-color: var(--accent2); }

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.stat-row .skey { font-size: 0.82rem; color: var(--text-muted); }
.stat-row .sval { font-size: 0.95rem; font-weight: 600; }

.error-msg {
  background: rgba(255, 86, 48, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: 0.95rem; }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }
[x-cloak] { display: none !important; }

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
}

.autocomplete-list li {
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  font-size: 0.875rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.autocomplete-list li:hover,
.autocomplete-list li.highlighted { background: var(--border); }
.autocomplete-list li .region-badge {
  font-size: 0.7rem;
  background: var(--border);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  color: var(--text-muted);
}

.pos-relative { position: relative; }

@media (max-width: 600px) {
  main { padding: 1rem; }
  .compare-stats { grid-template-columns: 1fr; }
  header { padding: 1rem; }
  .tabs { margin-left: 0; margin-top: 0.5rem; }
  header { flex-wrap: wrap; }
}
