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

:root {
  --navy: #1a2634;
  --navy-light: #243447;
  --navy-lighter: #2d4158;
  --blue: #3a7bd5;
  --blue-light: #5b9aef;
  --cyan: #00d2ff;
  --text: #e8edf2;
  --text-muted: #8a9bb5;
  --text-dim: #5a6d85;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --orange: #e67e22;
  --red: #e74c3c;
  --panel-width: 420px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--navy);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  height: 100vh;
  position: relative;
}

#map {
  flex: 1;
  height: 100%;
  z-index: 1;
}

/* Dark map tiles */
.leaflet-tile-pane {
  filter: saturate(0.7);
}

.leaflet-control-attribution {
  background: rgba(26, 38, 52, 0.8) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--blue-light) !important;
}

.leaflet-control-zoom a {
  background: var(--navy-light) !important;
  color: var(--text) !important;
  border-color: var(--navy-lighter) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--navy-lighter) !important;
}

/* ── Overlay controls ───────────────────────────────── */

#overlay-controls {
  position: absolute;
  top: 80px;
  left: 12px;
  z-index: 800;
  background: var(--navy);
  border: 1px solid var(--navy-lighter);
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  width: 72px;
}

.overlay-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 8px;
}

.overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.overlay-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  background: var(--navy-light);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 10px;
  line-height: 1;
}

.overlay-btn:hover {
  background: var(--navy-lighter);
  color: var(--text);
}

.overlay-btn.active {
  background: rgba(58, 123, 213, 0.2);
  border-color: var(--blue);
  color: var(--blue-light);
}

.overlay-btn svg {
  flex-shrink: 0;
}

/* Model selector */
.model-select {
  width: 100%;
  background: var(--navy-light);
  border: 1px solid var(--navy-lighter);
  border-radius: 5px;
  color: var(--text);
  font-size: 10px;
  padding: 5px 4px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 24 24' fill='%238a9bb5'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
}

.model-select:hover {
  background-color: var(--navy-lighter);
}

.model-select option {
  background: var(--navy);
  color: var(--text);
}

/* Unit selector */
.overlay-divider {
  height: 1px;
  background: var(--navy-lighter);
  margin: 8px 0;
}

.unit-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}

.unit-btn {
  background: var(--navy-light);
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 2px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.unit-btn:hover {
  background: var(--navy-lighter);
  color: var(--text);
}

.unit-btn.active {
  background: rgba(58, 123, 213, 0.2);
  border-color: var(--blue);
  color: var(--blue-light);
}

/* Legend */
.overlay-legend {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--navy-lighter);
  font-size: 10px;
  color: var(--text-muted);
}

.overlay-legend.hidden {
  display: none;
}

.legend-gradient {
  height: 8px;
  border-radius: 4px;
  margin: 4px 0;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-dim);
}

.overlay-status {
  margin-top: 6px;
  text-align: center;
  font-size: 10px;
  color: var(--blue-light);
  animation: pulse 1.2s ease-in-out infinite;
}

.overlay-status.hidden {
  display: none;
}

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

/* Weather canvas overlay */
.weather-canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* ── Panel restore tab ──────────────────────────────── */

.panel-restore {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 900;
  background: var(--navy);
  border: 1px solid var(--navy-lighter);
  border-right: none;
  border-radius: 8px 0 0 8px;
  color: var(--text-muted);
  padding: 12px 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.panel-restore:hover {
  background: var(--navy-lighter);
  color: var(--text);
  padding-right: 10px;
}

.panel-restore.hidden {
  display: none;
}

/* ── Panel ──────────────────────────────────────────── */

.panel {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--panel-width);
  min-width: 340px;
  max-width: 80vw;
  height: 100vh;
  background: var(--navy);
  border-left: 1px solid var(--navy-lighter);
  z-index: 1000;
  overflow-y: auto;
  padding: 24px;
  padding-left: 32px;
  transition: transform 0.3s ease;
}

.panel.hidden {
  transform: translateX(100%);
}

.panel.resizing {
  transition: none;
  user-select: none;
}

.panel-resize {
  position: absolute;
  top: 0;
  left: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 1001;
  background: transparent;
  transition: background 0.15s;
}

.panel-resize:hover,
.panel-resize.active {
  background: var(--blue);
}

#panel-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
}

#panel-close:hover {
  color: var(--text);
  background: var(--navy-lighter);
}

.panel-header {
  margin-bottom: 20px;
  padding-right: 32px;
}

.panel-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.panel-header p {
  font-size: 13px;
  color: var(--text-muted);
}

/* Condition cards */
.condition-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.condition-card {
  background: var(--navy-light);
  border-radius: 10px;
  padding: 14px;
}

.condition-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.condition-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.condition-unit {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.condition-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.wind-card {
  grid-column: 1 / -1;
}

.wind-display {
  display: flex;
  align-items: center;
  gap: 16px;
}

#wind-arrow {
  flex-shrink: 0;
}

/* Wind speed colors */
.wind-light { color: var(--green); }
.wind-moderate { color: var(--yellow); }
.wind-fresh { color: var(--orange); }
.wind-strong { color: var(--red); }

/* Forecast section */
.forecast-section {
  margin-bottom: 24px;
}

.forecast-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.time-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.time-btn {
  background: var(--navy-light);
  border: 1px solid var(--navy-lighter);
  color: var(--text-muted);
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.time-btn:hover {
  background: var(--navy-lighter);
  color: var(--text);
}

.time-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.chart-container {
  background: var(--navy-light);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.chart-container canvas {
  width: 100% !important;
  height: clamp(140px, 20vw, 280px) !important;
}

/* Hourly table */
.hourly-table-wrapper {
  max-height: 400px;
  overflow-y: auto;
  border-radius: 10px;
  border: 1px solid var(--navy-lighter);
}

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

#hourly-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

#hourly-table th {
  background: var(--navy-lighter);
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

#hourly-table td {
  padding: 8px;
  border-bottom: 1px solid var(--navy-lighter);
  white-space: nowrap;
}

#hourly-table tr:hover {
  background: var(--navy-light);
}

#hourly-table .wind-dir-arrow {
  display: inline-block;
  font-size: 16px;
  line-height: 1;
  vertical-align: middle;
}

/* Instructions overlay */
.instructions {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  pointer-events: none;
  transition: opacity 0.5s;
}

.instructions.fade-out {
  opacity: 0;
}

.instructions-content {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--navy);
  border: 1px solid var(--navy-lighter);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.instructions-content svg {
  color: var(--blue-light);
  flex-shrink: 0;
}

/* Wind marker on map */
.wind-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  pointer-events: none;
}

.wind-marker-arrow {
  font-size: 28px;
  line-height: 1;
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}

.wind-marker-label {
  background: rgba(26, 38, 52, 0.85);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
  white-space: nowrap;
}

/* Loading spinner */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 38, 52, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--navy-lighter);
  border-top-color: var(--blue-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Scrollbar */
.panel::-webkit-scrollbar,
.hourly-table-wrapper::-webkit-scrollbar {
  width: 6px;
}

.panel::-webkit-scrollbar-track,
.hourly-table-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.panel::-webkit-scrollbar-thumb,
.hourly-table-wrapper::-webkit-scrollbar-thumb {
  background: var(--navy-lighter);
  border-radius: 3px;
}

/* ── Time control ───────────────────────────────────── */

.time-control {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  background: var(--navy);
  border: 1px solid var(--navy-lighter);
  border-radius: 10px;
  padding: 8px 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.time-control.hidden {
  display: none;
}

.tc-inner {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tc-btn {
  background: var(--navy-light);
  border: 1px solid var(--navy-lighter);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.tc-btn:hover {
  background: var(--navy-lighter);
  color: var(--text);
}

.tc-btn.playing {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

#tc-slider {
  width: 220px;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--navy-lighter);
  border-radius: 2px;
  outline: none;
}

#tc-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--blue-light);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

#tc-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--blue-light);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.tc-label {
  font-size: 12px;
  color: var(--text);
  font-weight: 600;
  min-width: 140px;
  text-align: center;
  white-space: nowrap;
}

/* Responsive */
@media (max-width: 768px) {
  .panel {
    width: 100%;
    --panel-width: 100%;
  }

  #overlay-controls {
    top: 10px;
    left: 50px;
    width: auto;
    flex-direction: row;
    padding: 6px 10px;
  }

  .overlay-buttons {
    flex-direction: row;
  }

  .overlay-title {
    display: none;
  }

  .instructions {
    bottom: 16px;
  }

  .instructions-content {
    font-size: 13px;
    padding: 10px 16px;
  }
}
