/* =============================================
   Weather Radar App — Dark Theme
   ============================================= */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d1117;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #e6edf3;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* =============================================
   Weather Sidebar
   ============================================= */

#weather-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1000;
  width: 300px;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
}

/* Collapsed state */
#weather-sidebar:not(.sidebar-open) {
  transform: translateX(-284px); /* leave toggle button visible */
}

#sidebar-toggle {
  position: absolute;
  top: 50%;
  right: -18px;
  transform: translateY(-50%);
  width: 18px;
  height: 54px;
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-left: none;
  border-radius: 0 6px 6px 0;
  color: #8b949e;
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  letter-spacing: 0.05em;
  transition: color 0.15s, background 0.15s;
  z-index: 1;
  padding: 0;
}

#sidebar-toggle:hover {
  color: #58a6ff;
  background: rgba(88, 166, 255, 0.1);
}

#sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(88, 166, 255, 0.3) transparent;
}

#sidebar-content::-webkit-scrollbar {
  width: 4px;
}
#sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}
#sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(88, 166, 255, 0.3);
  border-radius: 2px;
}

/* ── Sections ── */
.wx-section {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.wx-section:last-child {
  border-bottom: none;
}

.wx-section-title {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #58a6ff;
  margin-bottom: 10px;
}

.wx-loading {
  font-size: 0.78rem;
  color: #8b949e;
  font-style: italic;
}

.wx-error {
  font-size: 0.78rem;
  color: #f85149;
}

/* ── Alerts ── */
#alerts-section {
  padding: 0;
}

.alert-banner {
  padding: 10px 16px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.alert-banner.severity-extreme {
  background: rgba(248, 81, 73, 0.25);
  border-left: 3px solid #f85149;
  color: #ffa198;
}

.alert-banner.severity-severe {
  background: rgba(210, 105, 30, 0.25);
  border-left: 3px solid #e07a35;
  color: #ffb366;
}

.alert-banner.severity-moderate {
  background: rgba(187, 163, 0, 0.2);
  border-left: 3px solid #d4b700;
  color: #ffe066;
}

.alert-banner.severity-minor,
.alert-banner.severity-unknown {
  background: rgba(88, 166, 255, 0.1);
  border-left: 3px solid #58a6ff;
  color: #79c0ff;
}

.alert-event {
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.alert-headline {
  font-size: 0.72rem;
  font-weight: 400;
  opacity: 0.85;
}

/* ── Current Conditions ── */
#conditions-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cond-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cond-temp {
  font-size: 2.6rem;
  font-weight: 300;
  color: #e6edf3;
  line-height: 1;
}

.cond-temp span {
  font-size: 1.2rem;
  color: #8b949e;
}

.cond-icon-desc {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cond-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.cond-desc {
  font-size: 0.78rem;
  color: #c9d1d9;
}

.cond-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 4px;
}

.cond-detail {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.cond-detail-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8b949e;
}

.cond-detail-value {
  font-size: 0.82rem;
  color: #e6edf3;
}

.cond-station {
  font-size: 0.65rem;
  color: #8b949e;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cond-location {
  font-size: 0.75rem;
  color: #58a6ff;
  font-weight: 600;
  margin-top: 4px;
}

/* ── Hourly Forecast ── */
#hourly-body {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(88, 166, 255, 0.3) transparent;
}

#hourly-body::-webkit-scrollbar {
  height: 3px;
}
#hourly-body::-webkit-scrollbar-thumb {
  background: rgba(88, 166, 255, 0.3);
  border-radius: 2px;
}

.hourly-strip {
  display: flex;
  gap: 6px;
  width: max-content;
}

.hourly-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 52px;
  padding: 6px 4px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.hourly-time {
  font-size: 0.65rem;
  color: #8b949e;
  font-variant-numeric: tabular-nums;
}

.hourly-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.hourly-temp {
  font-size: 0.82rem;
  font-weight: 600;
  color: #e6edf3;
}

/* ── 7-Day Forecast ── */
.daily-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.daily-item {
  display: grid;
  grid-template-columns: 62px 32px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 6px;
  transition: background 0.15s;
}

.daily-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.daily-name {
  font-size: 0.78rem;
  color: #c9d1d9;
  font-weight: 500;
}

.daily-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.daily-desc {
  font-size: 0.68rem;
  color: #8b949e;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.daily-temps {
  font-size: 0.78rem;
  text-align: right;
  white-space: nowrap;
}

.daily-high {
  color: #e6edf3;
  font-weight: 600;
}

.daily-low {
  color: #8b949e;
  font-size: 0.72rem;
}

/* =============================================
   Radar Controls (top-right)
   ============================================= */
#controls {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1000;
  background: rgba(13, 17, 23, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px 18px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#app-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #58a6ff;
}

/* ---- Timestamp ---- */
#timestamp-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#timestamp {
  font-size: 0.8rem;
  color: #8b949e;
  font-variant-numeric: tabular-nums;
  min-height: 1.1em;
}

/* ---- Playback Controls ---- */
#playback-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#playback-row button {
  background: rgba(88, 166, 255, 0.15);
  border: 1px solid rgba(88, 166, 255, 0.3);
  color: #58a6ff;
  border-radius: 6px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

#playback-row button:hover {
  background: rgba(88, 166, 255, 0.28);
  border-color: rgba(88, 166, 255, 0.6);
}

#playback-row button:active {
  background: rgba(88, 166, 255, 0.4);
}

#play-btn {
  width: 42px !important;
  height: 42px !important;
  font-size: 1rem !important;
}

#frame-counter {
  font-size: 0.75rem;
  color: #8b949e;
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}

/* ---- Opacity Slider ---- */
#opacity-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#opacity-row label {
  font-size: 0.78rem;
  color: #8b949e;
  flex-shrink: 0;
  width: 46px;
}

#opacity-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 4px;
  background: rgba(88, 166, 255, 0.25);
  outline: none;
  cursor: pointer;
}

#opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #58a6ff;
  cursor: pointer;
  border: 2px solid #0d1117;
  box-shadow: 0 0 4px rgba(88, 166, 255, 0.5);
}

#opacity-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #58a6ff;
  cursor: pointer;
  border: 2px solid #0d1117;
}

#opacity-value {
  font-size: 0.75rem;
  color: #58a6ff;
  width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---- Status ---- */
#status-row {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 8px;
}

#status {
  font-size: 0.72rem;
  color: #8b949e;
}

#status.error {
  color: #f85149;
}

#status.ok {
  color: #3fb950;
}

/* ---- Leaflet overrides ---- */
.leaflet-control-attribution {
  background: rgba(13, 17, 23, 0.75) !important;
  color: #8b949e !important;
}

.leaflet-control-attribution a {
  color: #58a6ff !important;
}

.leaflet-control-zoom a {
  background: rgba(13, 17, 23, 0.88) !important;
  color: #e6edf3 !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

.leaflet-control-zoom a:hover {
  background: rgba(88, 166, 255, 0.2) !important;
}

/* =============================================
   Bottom Sheet Handle (hidden on desktop)
   ============================================= */
#sheet-handle-area {
  display: none; /* shown only on mobile via media query */
  flex-direction: column;
  align-items: center;
  padding: 8px 0 4px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

#sheet-drag-handle {
  width: 40px;
  height: 4px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

#sheet-peek-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0 16px 6px;
}

#peek-temp {
  font-size: 1.3rem;
  font-weight: 300;
  color: #e6edf3;
  flex-shrink: 0;
}

#peek-cond {
  font-size: 0.82rem;
  color: #c9d1d9;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#sheet-chevron {
  font-size: 0.7rem;
  color: #8b949e;
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

/* =============================================
   Mobile Layout (<= 768px) — Bottom Sheet
   ============================================= */
@media (max-width: 768px) {

  /* Prevent any horizontal scroll */
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* Show handle, hide desktop toggle tab */
  #sheet-handle-area {
    display: flex;
  }

  #sidebar-toggle {
    display: none;
  }

  /* ── Sidebar becomes bottom sheet ── */
  #weather-sidebar {
    /* Reset desktop positioning */
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-right: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6);
    flex-direction: column;

    /* Collapsed height: handle + peek row (~72px) */
    --sheet-collapsed-height: 72px;
    /* Expanded height: 60% of viewport */
    --sheet-expanded-height: 60dvh;

    height: var(--sheet-collapsed-height);
    max-height: 100dvh;
    transition: height 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    transform: none !important; /* override desktop slide */
    overflow: hidden;
  }

  /* Expanded state */
  #weather-sidebar.sidebar-open {
    height: var(--sheet-expanded-height);
  }

  /* When expanded, chevron points down */
  #weather-sidebar.sidebar-open #sheet-chevron {
    transform: rotate(180deg);
  }

  /* Scrollable content area inside sheet */
  #sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    /* Allow overscroll for native feel */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom, 16px);
  }

  /* Map fills full screen (sidebar overlays on top) */
  #map {
    height: 100%;
    width: 100%;
  }

  /* ── Radar Controls ── move to bottom-left, compact ── */
  #controls {
    top: auto;
    bottom: calc(var(--sheet-collapsed-height) + 12px);
    right: auto;
    left: 8px;
    min-width: unset;
    width: calc(100vw - 16px);
    max-width: 360px;
    padding: 10px 14px;
    gap: 8px;
    border-radius: 12px;
    transition: bottom 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  }

  /* Push controls up when sheet is expanded */
  #weather-sidebar.sidebar-open ~ #controls {
    bottom: calc(var(--sheet-expanded-height) + 12px);
  }

  #app-title {
    font-size: 0.88rem;
  }

  #timestamp {
    font-size: 0.72rem;
  }

  /* Compact playback buttons — still touch-friendly (min 44px) */
  #playback-row button {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }

  #play-btn {
    min-width: 48px !important;
    min-height: 48px !important;
    width: 48px !important;
    height: 48px !important;
  }

  /* Opacity row: slightly more compact */
  #opacity-row {
    gap: 8px;
  }

  #opacity-slider::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  /* ── Touch-friendly sidebar content ── */
  .wx-section {
    padding: 14px 16px;
  }

  .hourly-item {
    min-width: 58px;
    min-height: 80px;
    padding: 8px 6px;
  }

  .daily-item {
    padding: 10px 4px;
    min-height: 44px;
  }

  /* Leaflet zoom controls — push up from bottom sheet */
  .leaflet-top.leaflet-left {
    top: 12px;
  }
  .leaflet-bottom {
    bottom: calc(var(--sheet-collapsed-height) + 8px);
  }

  /* Larger tap targets for leaflet zoom buttons */
  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
  }
}

/* ── Very small screens (iPhone SE, etc.) ── */
@media (max-width: 390px) {
  #controls {
    padding: 8px 10px;
    gap: 6px;
  }

  #controls-header {
    display: none; /* hide title to save space */
  }
}

