:root {
  --bg: #0f1923;
  --bg-card: #1a2736;
  --bg-card-hover: #1f3044;
  --text: #e8edf2;
  --text-muted: #8899aa;
  --accent: #4fc3f7;
  --accent-dim: rgba(79, 195, 247, 0.15);
  --gust: #ff7043;
  --gust-dim: rgba(255, 112, 66, 0.15);
  --green: #66bb6a;
  --yellow: #fdd835;
  --red: #ef5350;
  --border: #2a3a4a;
  --radius: 12px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

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

.header-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  margin-right: 4px;
  animation: pulse 2s infinite;
}

.status-dot.error { background: var(--red); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Nav */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.nav-brand span { color: var(--accent); }

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-links a {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.2s;
}

.nav-links a:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.nav-links a.active { color: var(--accent); background: var(--accent-dim); }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ===== Regional Dashboard Layout ===== */

.regional-layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr 380px;
  grid-template-areas:
    "map     sidebar"
    "chart   chart";
}

.map-section { grid-area: map; padding: 0; overflow: hidden; }
.regional-sidebar { grid-area: sidebar; display: flex; flex-direction: column; gap: 20px; }
.regional-chart { grid-area: chart; }

/* Map */
.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.map-header .card-title { margin-bottom: 0; }

.station-map {
  height: 450px;
  background: var(--bg);
}

.zone-controls {
  display: flex;
  gap: 6px;
}

.zone-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.zone-btn:hover { border-color: var(--accent); color: var(--text); }
.zone-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* Wind marker (map) */
.wind-marker { background: none; border: none; }

/* Leaflet dark popup */
.dark-popup .leaflet-popup-content-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.dark-popup .leaflet-popup-tip { background: var(--bg-card); }
.dark-popup .leaflet-popup-content { margin: 12px 14px; }

/* Gust Leaderboard */
.leaderboard { min-height: 60px; }

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  transition: background 0.2s;
}

.leaderboard-item:hover { background: var(--bg-card-hover); }

.leaderboard-rank {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  width: 24px;
  text-align: center;
}

.leaderboard-item:first-child .leaderboard-rank { color: var(--gust); }

.leaderboard-name {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
}

.leaderboard-name a {
  color: var(--text);
  text-decoration: none;
}
.leaderboard-name a:hover { color: var(--accent); }

.leaderboard-value {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
}

.leaderboard-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 2px;
}

/* Station Table */
.table-wrap { overflow-x: auto; }

.station-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.station-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.station-table th.sortable { cursor: pointer; }
.station-table th.sortable:hover { color: var(--accent); }
.station-table th.active { color: var(--accent); }
.station-table th.active::after { content: ' \u25BC'; font-size: 0.6rem; }

.station-table td {
  padding: 10px;
  border-bottom: 1px solid rgba(42,58,74,0.4);
  white-space: nowrap;
}

.station-table tbody tr { transition: background 0.15s; }
.station-table tbody tr:hover { background: var(--bg-card-hover); }

.station-table .wind-val {
  font-family: var(--mono);
  font-weight: 600;
}

.station-table .station-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.station-table .station-link:hover { color: var(--accent); }

/* ===== Station Detail Layout (used by station.html) ===== */

.wind-hero {
  text-align: center;
  padding: 40px 24px;
}

.wind-speed-value {
  font-family: var(--mono);
  font-size: 6rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.04em;
}

.wind-speed-unit {
  font-size: 1.5rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}

.wind-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.wind-gust {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 8px 20px;
  background: var(--gust-dim);
  border-radius: 20px;
  font-size: 1rem;
}

.wind-gust-value {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--gust);
}

.wind-gust-label {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.wind-daily-max {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.wind-daily-max strong {
  color: var(--gust);
  font-family: var(--mono);
}

/* Compass */
.compass-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.compass {
  position: relative;
  width: 200px;
  height: 200px;
}

.compass-ring {
  width: 100%;
  height: 100%;
  border: 2px solid var(--border);
  border-radius: 50%;
  position: relative;
}

.compass-label {
  position: absolute;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.compass-label.n { top: 8px; left: 50%; transform: translateX(-50%); }
.compass-label.s { bottom: 8px; left: 50%; transform: translateX(-50%); }
.compass-label.e { right: 8px; top: 50%; transform: translateY(-50%); }
.compass-label.w { left: 8px; top: 50%; transform: translateY(-50%); }

.compass-arrow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 70px;
  margin-left: -2px;
  margin-top: -55px;
  transform-origin: 2px 55px;
  transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.compass-arrow::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 20px solid var(--accent);
}

.compass-arrow::after {
  content: '';
  position: absolute;
  top: 20px;
  left: 0;
  width: 4px;
  height: 50px;
  background: linear-gradient(to bottom, var(--accent), transparent);
  border-radius: 2px;
}

.compass-direction {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 16px;
  color: var(--accent);
}

.compass-degrees {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Details Grid */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.detail-item {
  padding: 12px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
}

.detail-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-value {
  font-family: var(--mono);
  font-size: 1.3rem;
  font-weight: 600;
}

.detail-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Chart */
.chart-card { }

.chart-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.chart-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.chart-btn:hover { border-color: var(--accent); color: var(--text); }
.chart-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.chart-container {
  position: relative;
  height: 300px;
}

/* Loading & Error */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  color: var(--text-muted);
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 12px;
}

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

.error-banner {
  padding: 12px 20px;
  background: rgba(239, 83, 80, 0.1);
  border: 1px solid rgba(239, 83, 80, 0.3);
  border-radius: 8px;
  color: var(--red);
  text-align: center;
  margin: 20px 24px 0;
  font-size: 0.85rem;
}

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

/* ===== Responsive ===== */

@media (max-width: 900px) {
  .regional-layout {
    padding: 16px;
    gap: 16px;
    grid-template-columns: 1fr;
    grid-template-areas:
      "map"
      "sidebar"
      "chart";
  }

  .station-map { height: 350px; }
  .map-header { flex-wrap: wrap; gap: 8px; }
  .zone-controls { flex-wrap: wrap; }
}

@media (max-width: 768px) {
  .wind-speed-value { font-size: 4rem; }
  .wind-gust-value { font-size: 1.2rem; }
  .header { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .header h1 { font-size: 1.1rem; }
  .chart-container { height: 250px; }
  .station-map { height: 300px; }
}

@media (max-width: 400px) {
  .wind-speed-value { font-size: 3.2rem; }
  .detail-grid { grid-template-columns: 1fr; }
}
