/* Radar/satellite box styles — requires style.css loaded first */

.radar-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  /* Container query so the legend tick spacing responds to THIS column's width */
  container-type: inline-size;
  container-name: radar-col;
}

.radar-map-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #0b1420;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#radar-map { position: absolute; inset: 0; }

/* Radar crossfade — duration set by radar.js via --radar-fade-ms, scales with Speed slider */
.leaflet-tile-pane .leaflet-layer.radar-frame-layer {
  transition: opacity var(--radar-fade-ms, 300ms) ease;
  will-change: opacity;
}

/* Satellite uses a near-instant cut — NightIR frames can swing in brightness, a slow fade makes it worse */
.leaflet-tile-pane .leaflet-layer.sat-frame-layer {
  transition: opacity 40ms linear;
  will-change: opacity;
}

.radar-map-wrap .leaflet-control-zoom { margin-top: 8px !important; margin-left: 8px !important; }
.radar-map-wrap .leaflet-control-zoom a {
  background: var(--bg-card2) !important; color: var(--text) !important;
  border: 1px solid var(--border) !important;
}
.radar-map-wrap .leaflet-control-zoom a:hover { background: var(--accent-dim) !important; }

/* Layer panel — top-right corner, over the map */
.radar-layer-panel {
  position: absolute; top: 6px; right: 6px; z-index: 1000;
  background: rgba(16,28,44,0.9); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 6px; font-size: 9.5px;
  backdrop-filter: blur(4px);
}
.radar-panel-row {
  display: flex; align-items: center; justify-content: space-between; gap: 5px;
  padding: 1.5px 0;
}

.radar-panel-row-checkbox-only { justify-content: flex-start; }
.radar-layer-panel label { display: flex; align-items: center; gap: 4px; cursor: pointer; color: var(--text); white-space: nowrap; }
.radar-layer-panel input[type=checkbox] { accent-color: var(--accent); width: 11px; height: 11px; margin: 0; }
.radar-layer-panel input[type=range] { width: 38px; height: 12px; accent-color: var(--accent); margin: 0; }


.radar-panel-text-label { color: var(--text); white-space: nowrap; }


.radar-bottom-bar {
  position: absolute; left: 8px; bottom: 8px; z-index: 1000;
  display: flex; align-items: center; gap: 8px;
  background: rgba(16,28,44,0.9); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 8px 6px 6px;
  backdrop-filter: blur(4px);
  max-width: calc(100% - 16px);
}
.radar-play-btn {
  width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--accent-dim); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 11px;
  flex: 0 0 auto;
}
.radar-play-btn:hover { background: var(--accent); }
#radar-frame-slider { width: 80px; accent-color: var(--accent); }
.radar-timestamp-wrap { min-width: 76px; }
.radar-timestamp { font-size: 12.5px; font-weight: 600; line-height: 1.1; color: var(--text); white-space: nowrap; }
.radar-timestamp-sub { font-size: 8.5px; color: var(--text-muted); margin-top: 1px; white-space: nowrap; }

/* Rainfall rate legend — margin-top:auto pins it to section bottom
   Colors from ECCC's RADARURPPRECIPR14-LINEAR style definition */
.radar-legend-row {
  width: 100%;
  height: 48px;
  margin-top: auto;
  background: rgba(16,28,44,0.9); border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex; flex-direction: column; justify-content: center; gap: 3px;
  padding: 6px 10px;
  box-sizing: border-box;
  flex-shrink: 0;
}
.legend-title {
  font-size: 9.5px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  white-space: nowrap;
}
.legend-bar-wrap { position: relative; width: 100%; }
.legend-bar {
  width: 100%;
  height: 10px;
  border-radius: 3px;

  background: linear-gradient(to right,
    rgb(153,204,255) 0.0%,
    rgb(0,153,255) 7.143%,
    rgb(0,153,255) 7.143%,
    rgb(0,255,102) 14.286%,
    rgb(0,255,102) 14.286%,
    rgb(0,204,0) 21.429%,
    rgb(0,204,0) 21.429%,
    rgb(0,153,0) 28.571%,
    rgb(0,153,0) 28.571%,
    rgb(0,102,0) 35.714%,
    rgb(0,102,0) 35.714%,
    rgb(255,255,51) 42.857%,
    rgb(255,255,51) 42.857%,
    rgb(255,204,0) 50.0%,
    rgb(255,204,0) 50.0%,
    rgb(255,153,0) 57.143%,
    rgb(255,153,0) 57.143%,
    rgb(255,102,0) 64.286%,
    rgb(255,102,0) 64.286%,
    rgb(255,0,0) 71.429%,
    rgb(255,0,0) 71.429%,
    rgb(255,2,153) 78.571%,
    rgb(255,2,153) 78.571%,
    rgb(153,51,204) 85.714%,
    rgb(153,51,204) 85.714%,
    rgb(102,0,153) 92.857%,
    rgb(102,0,153) 92.857%,
    rgb(51,0,77) 100.0%);
}
.legend-ticks {
  position: relative;
  width: 100%;
  height: 10px;
}
.legend-ticks span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 8px;
  line-height: 1;
  color: var(--text-muted);
  white-space: nowrap;
}

.legend-ticks span:first-child { transform: translateX(0); }
.legend-ticks span:last-child { transform: translateX(-100%); }


.radar-error-banner {
  position: absolute; top: 0; left: 0; right: 0; z-index: 1200;
  background: #5a2323; color: #ffdede; font-size: 11px;
  padding: 5px 10px; text-align: center; display: none;
}


.radar-loading-overlay {
  position: absolute; inset: 0; z-index: 1300;
  background: rgba(11,20,32,0.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; transition: opacity .35s ease;
}
.radar-loading-overlay.hidden { opacity: 0; pointer-events: none; }
.radar-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: radarSpin 0.9s linear infinite;
}
@keyframes radarSpin { to { transform: rotate(360deg); } }
.radar-loading-text { font-size: 11.5px; color: var(--text-muted); }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 959px) and (orientation: landscape) and (max-height: 500px) {
  .radar-map-wrap { aspect-ratio: 16 / 9; }
}

/* Hide every other tick label on narrow columns to prevent crowding */
@container radar-col (max-width: 490px) {
  .legend-ticks span:nth-child(even) { display: none; }
}
