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

:root {
  --sidebar-w:    260px;
  --sidebar-bg:   #1a1e2a;
  --sidebar-text: #c8cdd8;
  --accent:       #4a90d9;
  --accent-hover: #6aaaf0;
  --bg:           #f5f6f8;
  --panel-bg:     #ffffff;
  --border:       #dde1ea;
  --warn:         #e8a020;
  --error:        #cc3333;
  --radius:       6px;
  --font:         'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: #333;
  background: var(--bg);
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 20px;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid #2e3448;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

.logo-sub {
  font-size: 11px;
  color: #6b7589;
}

/* Control sections */
.control-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #6b7589;
}

.control-input {
  width: 100%;
  padding: 7px 10px;
  background: #252b3b;
  border: 1px solid #323852;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.control-input:focus {
  border-color: var(--accent);
}

select.control-input {
  cursor: pointer;
  appearance: auto;
}

/* Autocomplete */
.autocomplete-wrap { position: relative; }

#site-search { padding-right: 32px; } /* Room for GPS btn */

.gps-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  opacity: 0.6;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}

.gps-btn:hover {
  opacity: 1;
  transform: translateY(-50%) scale(1.15);
}

.gps-btn.loading {
  animation: pulseGps 1s infinite;
}

@keyframes pulseGps {
  0% { transform: translateY(-50%) scale(1); opacity: 0.5; }
  50% { transform: translateY(-50%) scale(1.2); opacity: 1; }
  100% { transform: translateY(-50%) scale(1); opacity: 0.5; }
}

.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #252b3b;
  border: 1px solid #3a4260;
  border-radius: var(--radius);
  max-height: 280px;
  overflow-y: auto;
  z-index: 100;
  list-style: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.dropdown li {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.35;
}

.dropdown li:hover,
.dropdown li.focused {
  background: #2e3754;
  color: #fff;
}

.dropdown .region-header {
  padding: 5px 10px 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #4a5170;
  cursor: default;
  pointer-events: none;
}

.selected-tag {
  background: #1e3a5f;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 12px;
  color: #aed4ff;
}

/* Warn badge */
.warn-badge {
  font-size: 11px;
  color: var(--warn);
  padding: 4px 0;
}

/* Load button */
.load-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.load-btn:hover:not(:disabled) { background: var(--accent-hover); }
.load-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  margin: 4px auto;
  border: 3px solid #2e3754;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error banner */
.error-banner {
  background: #3a1a1a;
  border: 1px solid var(--error);
  color: #ffaaaa;
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
}

/* Keyboard hint */
.kbd-hint {
  margin-top: auto;
  font-size: 11px;
  color: #4a5170;
  display: flex;
  align-items: center;
  gap: 4px;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  background: #252b3b;
  border: 1px solid #3a4260;
  border-radius: 3px;
  font-size: 10px;
  color: #8090b0;
}

.sidebar-footer {
  padding-top: 8px;
  border-top: 1px solid #2e3448;
  font-size: 11px;
}

.sidebar-footer a {
  color: #4a5170;
  text-decoration: none;
}

.sidebar-footer a:hover { color: var(--accent); }

/* ── Main content ────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tab bar */
.tab-bar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--panel-bg);
  border-bottom: 2px solid var(--border);
  padding: 0 16px;
  flex-shrink: 0;
  height: 42px;
}

.tab {
  height: 100%;
  padding: 0 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 13px;
  font-weight: 500;
  color: #888;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: #333; }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-spacer { flex: 1; }

.windgram-title {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 420px;
}

.global-site-header {
  padding: 16px 16px 4px 16px;
  background: var(--bg);
  text-align: left;
  border-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.global-site-header[hidden] {
  display: none !important;
}

.global-site-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: #1a1e2a;
  margin: 0;
  letter-spacing: -0.2px;
}

.global-site-header span {
  font-size: 13px;
  color: #6b7589;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

/* Panels */
.panel {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: var(--bg);
}

.panel.active { display: flex; }
.panel[hidden] { display: none !important; }

.img-wrap, .canvas-wrap {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
}

.placeholder {
  margin: auto;
  color: #aaa;
  font-size: 14px;
  text-align: center;
  max-width: 300px;
  line-height: 1.7;
}

.windgram-img {
  max-width: 100%;
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  display: block;
}

#windgram-canvas {
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  display: block;
}

/* ── Model switcher bar (shared across all tabs, below site header) ─────────── */
.model-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 6px 16px 8px;
  flex-shrink: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.model-nav {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 22px;
  line-height: 1;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.model-nav:hover:not(:disabled) {
  background: var(--border);
  border-color: var(--accent);
}

.model-nav:disabled {
  opacity: 0.3;
  cursor: default;
}

.model-label {
  font-size: 15px;
  font-weight: 600;
  color: #333;
  min-width: 70px;
  text-align: center;
  letter-spacing: 0.3px;
}

/* ── Map page ──────────────────────────────────────────────────────────────── */

.map-main {
  padding: 0;
  overflow: hidden;
}

.map-container {
  flex: 1;
  z-index: 1;
}

/* Top map controls container */
.top-map-controls {
  display: flex;
  flex-direction: column;
  z-index: 1000;
  width: 100%;
}

/* Time controls bar (top of map area) */
.time-bar, .param-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.param-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  width: 280px;
}

.hour-slider {
  flex: 1;
  max-width: 400px;
  accent-color: var(--accent);
}

.hour-label {
  font-size: 13px;
  font-weight: 500;
  color: #555;
  white-space: nowrap;
  min-width: 180px;
}

.time-btn {
  padding: 6px 12px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: #555;
  transition: background 0.15s;
}

.time-break {
  display: none;
}

.time-btn:hover {
  background: #e8ecf2;
}

.time-spacer {
  flex: 1;
}

/* Parameter selector (multi-line list box) */
.map-param-select {
  width: 100%;
  font-size: 12px;
  background: #252b3b;
  border: 1px solid #323852;
  border-radius: var(--radius);
  color: var(--sidebar-text);
}

.map-param-select optgroup {
  font-weight: bold;
  color: #ff8866;
  font-style: normal;
  padding-top: 4px;
}

.map-param-select option {
  font-weight: normal;
  color: var(--sidebar-text);
  padding: 3px 8px;
}

.map-param-select option:checked {
  background: var(--accent);
  color: #fff;
}

/* Opacity slider */
.map-slider {
  width: 100%;
  accent-color: var(--accent);
}

/* Legend bar (bottom of map area) */
.legend-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 12px;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 48px;
}

.legend-img {
  max-width: 100%;
  max-height: 44px;
}

/* Parameter description in sidebar */
.param-desc {
  font-size: 11px;
  color: #6b7589;
  line-height: 1.5;
  padding: 4px 0;
  max-height: 100px;
  overflow-y: auto;
}

/* Weather overlay: ensure it renders crisply */
.weather-overlay {
  image-rendering: auto;
}

/* Wind arrow toggle */
.arrow-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--sidebar-text);
  cursor: pointer;
}

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

/* Wind arrow canvas — overlaid on the map, no pointer events */
.wind-arrow-canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 450;  /* above tile layers (200), below popups (700) */
}

/* ── Mobile: hamburger button ────────────────────────────────────────────── */
.mobile-menu-btn {
  display: none;          /* hidden on desktop */
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 2001;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--sidebar-bg);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Backdrop overlay behind bottom sheet */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Bottom sheet drag handle */
.sheet-handle {
  display: none;          /* hidden on desktop */
  text-align: center;
  padding: 8px 0 4px;
  cursor: grab;
}

.sheet-handle span {
  display: inline-block;
  width: 4px;
  height: 36px;
  border-radius: 2px;
  background: #4a5170;
}

/* ── Mobile layout (< 768px) ────────────────────────────────────────────── */
@media (max-width: 767px) {

  /* Show hamburger inline in tab bar (not floating) */
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: static;
    width: 36px;
    height: 36px;
    background: transparent;
    color: #888;
    box-shadow: none;
    border: none;
    flex-shrink: 0;
    margin-right: 2px;
    font-size: 22px;
  }
  .sheet-handle { display: none !important; }

  body {
    flex-direction: column;
    overflow-x: hidden;
  }

  /* Sidebar → left drawer */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 85%;
    max-width: 320px;
    height: 100%;
    max-height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000;
    border-radius: 0 16px 16px 0;
    padding: 16px 14px;
    gap: 14px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
    overflow-y: auto;
    overflow-x: hidden;
  }

  .sidebar.open {
    transform: translateX(0) !important;
  }

  .sidebar-header {
    padding-top: 4px;
    padding-bottom: 8px;
  }

  /* Main content: fill viewport */
  .main,
  .map-main {
    width: 100%;
    height: 100vh;
    height: 100dvh;          /* dynamic viewport height for mobile browsers */
  }

  /* ── Map page mobile ─────────────────────────────────────────────────── */

  /* Top Map Controls wrapper: absolute position over the map */
  .top-map-controls {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
  }

  /* Time bar & Param bar: compact overlay */
  .time-bar, .param-bar {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 8px 16px; /* Substantially increased side padding */
    gap: 8px 6px; /* Increased minor horizontal gap */
    display: flex; /* Ensure inline layout */
    flex-wrap: wrap; /* allow 2 lines */
  }

  .time-break {
    display: block;
    flex-basis: 100%;
    height: 0;
  }

  .hour-slider {
    flex: 1;
    max-width: none;
  }

  .hour-label {
    min-width: auto;
    font-size: 11px;
    flex: 1; /* Pushes play button right in the second line */
  }

  .time-btn {
    padding: 4px 8px;
    font-size: 12px;
  }

  .time-spacer {
    flex: 0;
    display: none;
  }

  /* Map container: leave room for time bar at top and legend at bottom */
  .map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
  
  /* Push leaflet zoom controls down below the time bar overlay */
  .leaflet-top {
    margin-top: 86px !important;
  }

  /* Parameter selector: single-row dropdown on mobile */
  .map-param-select {
    height: 38px !important;
    overflow: hidden !important;
    max-width: 100%;
  }

  .control-input {
    max-width: 100%;
    text-overflow: ellipsis;
  }

  /* Legend bar: thinner, overlaid at bottom */
  .legend-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 4px 8px;
    min-height: 36px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  .legend-img {
    max-height: 32px;
  }

  /* ── Windgram page mobile ────────────────────────────────────────────── */

  /* Run bar: full width above image, never side-by-side */
  .model-bar {
    padding: 4px 8px 6px;
  }

  /* Tab bar: compact */
  .tab-bar {
    padding: 0 8px;
    height: 38px;
  }

  .tab {
    padding: 0 10px;
    font-size: 12px;
  }

  .windgram-title {
    display: none;                /* hide long title on mobile */
  }

  .panel {
    padding: 8px;
  }

  /* Windgram image: fit screen width, allow pinch zoom */
  .img-wrap,
  .canvas-wrap {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .windgram-img {
    max-width: 100%;
    height: auto;
  }

  #windgram-canvas {
    max-width: 100%;
    height: auto;
  }

  /* Keyboard hint: hide on mobile (no keyboard) */
  .kbd-hint {
    display: none;
  }

  /* Sidebar footer */
  .sidebar-footer {
    padding-top: 6px;
  }
}
