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

:root {
  --bg-dark: #1a1a1a;
  --bg-card: #2d2d2d;
  --bg-sidebar: #242424;
  --accent: #c8a97e;
  --accent-dim: rgba(200, 169, 126, 0.15);
  --text-primary: #e8e0d5;
  --text-secondary: #9a9080;
  --text-muted: #6b6560;
  --border: #3a3a3a;
  --hover: #353535;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', 'SF Display', -apple-system, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow-x: hidden;
}

/* === Custom Scrollbar === */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #d4b98e;
}

/* === Links === */
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* === Header === */
.header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
}

.header .subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* === Layout === */
.layout {
  display: flex;
  height: calc(100vh - 52px);
}

/* === Sidebar === */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.filter-group label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.5rem;
  font-size: 0.82rem;
  width: 100%;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

select:focus {
  border-color: var(--accent);
}

.range-container {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.range-container input[type="range"] {
  width: 100%;
  cursor: pointer;
  accent-color: var(--accent);
}

#alt-range-display {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
}

#min-score-display {
  color: var(--accent);
  font-weight: 600;
}

input[type="range"] {
  accent-color: var(--accent);
}

.btn-reset {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

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

/* === Main Content === */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* === Overview Cards === */
.overview-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.card {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.card-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.card-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* === Section Headings === */
h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* === Map === */
.map-section {
  display: flex;
  flex-direction: column;
}

#world-map {
  height: 400px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1e2a1e;
  overflow: hidden;
}

/* === Charts === */
.charts-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.chart-container {
  background: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.chart-container canvas {
  flex: 1;
  min-height: 300px;
}

/* === Table === */
.table-section {
  display: flex;
  flex-direction: column;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead {
  background: var(--bg-sidebar);
  position: sticky;
  top: 0;
}

th {
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  transition: color 0.2s;
}

th:hover {
  color: var(--accent);
}

th.sort-asc::after { content: ' ▲'; color: var(--accent); }
th.sort-desc::after { content: ' ▼'; color: var(--accent); }

td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: background 0.15s;
}

tbody tr:hover {
  background: var(--hover);
}

tbody tr.highlighted {
  background: var(--accent-dim);
}

tbody tr.highlighted td {
  color: var(--accent);
}

/* === Responsive === */
@media (max-width: 1100px) {
  .overview-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-section {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .layout {
    flex-direction: column;
    height: auto;
  }
  .sidebar {
    width: 100%;
    min-width: unset;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 300px;
  }
  .sidebar h2 {
    width: 100%;
  }
  .filter-group {
    min-width: 140px;
    flex: 1;
  }
  .overview-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  #world-map {
    height: 300px;
  }
}

/* === Leaflet popup overrides === */
.leaflet-popup-content-wrapper {
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.leaflet-popup-tip {
  background: var(--bg-card);
}
.leaflet-popup-content {
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.4;
}
