/* ============================================================
   KELOWNA WEATHER DASHBOARD — style.css
   Responsive breakpoints:
     xs  : < 480px   (small phones, portrait)
     sm  : 480–699px (large phones, small tablets portrait)
     md  : 700–959px (tablets, small laptops)
     lg  : 960–1399px (desktops — base design target)
     xl  : 1400px+   (widescreen / 4K monitors)
   ============================================================ */

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

:root {
  --bg:          #0d1117;
  --bg-card:     #161b22;
  --bg-card2:    #1c2330;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #58a6ff;
  --accent-warm: #f0883e;
  --overlay-bg:  rgba(8, 12, 18, 0.82);
  --radius:      10px;
  --shadow:      0 4px 24px rgba(0,0,0,0.5);

  /* Fluid type scale — clamp(min, preferred, max) */
  --text-xs:   clamp(0.62rem, 1.2vw, 0.72rem);
  --text-sm:   clamp(0.72rem, 1.4vw, 0.82rem);
  --text-base: clamp(0.82rem, 1.6vw, 0.95rem);
  --text-lg:   clamp(0.95rem, 1.8vw, 1.1rem);
  --text-xl:   clamp(1.1rem,  2vw,   1.4rem);
  --text-2xl:  clamp(1.4rem,  2.5vw, 1.8rem);
}

html {
  font-size: 16px;
  /* Prevent iOS font-size inflation on landscape flip */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  min-height: 100dvh; /* iOS safari safe-area aware */
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Prevent horizontal scroll on mobile */
  overflow-x: hidden;
}

/* ── Header ──────────────────────────────────────────────── */
header {
  width: 100%;
  padding: clamp(0.6rem, 2vw, 1.1rem) clamp(1rem, 4vw, 2rem) clamp(0.4rem, 1.5vw, 0.6rem);
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  /* Safe area for notched phones */
  padding-top: max(clamp(0.6rem, 2vw, 1.1rem), env(safe-area-inset-top));
  padding-left:  max(clamp(1rem, 4vw, 2rem), env(safe-area-inset-left));
  padding-right: max(clamp(1rem, 4vw, 2rem), env(safe-area-inset-right));
}

header h1 {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  margin-top: 0.3rem;
}

#kelowna-date {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-weight: 400;
}

#kelowna-time {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

/* ── Main container ──────────────────────────────────────── */
main {
  width: 100%;
  max-width: 1400px; /* allow full use of widescreen */
  padding: clamp(0.75rem, 2vw, 1.5rem) clamp(0.75rem, 2vw, 1rem) 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  /* Respect notch/home-bar on mobile */
  padding-left:  max(clamp(0.75rem, 2vw, 1rem), env(safe-area-inset-left));
  padding-right: max(clamp(0.75rem, 2vw, 1rem), env(safe-area-inset-right));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

/* ── Webcam section ──────────────────────────────────────── */
.cam-section { width: 100%; }

.cam-wrapper {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}

#webcam-stream {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* Placeholder sits below overlay */
.cam-placeholder {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: var(--text-base);
  text-align: center;
  padding: 1.5rem 1.5rem 7rem;
}
.cam-placeholder p:first-child { font-size: clamp(1.8rem, 5vw, 2.5rem); }

#cam-btn {
  margin-top: 0.5rem;
  padding: 0.6rem 1.6rem;
  background: var(--accent);
  color: #000;
  border: none; border-radius: 6px;
  font-size: var(--text-base); font-weight: 600;
  cursor: pointer;
  /* Large touch target on mobile */
  min-height: 44px;
  touch-action: manipulation;
}
#cam-btn:hover { opacity: 0.85; }

/* ── Conditions Overlay ──────────────────────────────────── */
.cam-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 2;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255,255,255,0.07);
  padding: clamp(0.4rem, 1.5vw, 0.75rem) clamp(0.5rem, 2vw, 1.1rem);
}

/* Desktop default — single row */
.overlay-row {
  display: flex;
  align-items: center;
  gap: clamp(0.5rem, 1.5vw, 1.2rem);
}

/* LEFT — Big temp + feels like */
.ov-temp-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: clamp(64px, 9vw, 90px);
  flex-shrink: 0;
}

.ov-temp {
  font-size: clamp(1.6rem, 4.5vw, 3rem);
  font-weight: 700;
  color: #fff;
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ov-feels {
  font-size: clamp(0.62rem, 1.2vw, 0.76rem);
  color: rgba(255,255,255,0.65);
  margin-top: 0.2rem;
  white-space: nowrap;
  min-height: 1em;
}

/* CENTRE — Icon + condition */
.ov-icon-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  min-width: clamp(52px, 7vw, 70px);
  flex-shrink: 0;
}

.ov-icon-block img {
  width: clamp(36px, 5.5vw, 52px);
  height: clamp(36px, 5.5vw, 52px);
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.6));
}

.ov-icon-block span {
  font-size: clamp(0.62rem, 1.1vw, 0.78rem);
  font-weight: 500;
  color: rgba(255,255,255,0.9);
  text-align: center;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  line-height: 1.2;
  max-width: clamp(70px, 10vw, 90px);
}

/* Details grid — two columns of label:value pairs */
.ov-details-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(0.15rem, 0.5vw, 0.28rem) clamp(0.5rem, 1.5vw, 1.2rem);
  min-width: 0;
}

.ov-det-item {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
}

.ov-det-label {
  font-size: clamp(0.58rem, 1vw, 0.72rem);
  color: rgba(255,255,255,0.45);
  font-weight: 500;
  flex-shrink: 0;
}

.ov-det-val {
  font-size: clamp(0.65rem, 1.1vw, 0.82rem);
  color: rgba(255,255,255,0.92);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* FAR RIGHT — Sunrise / Sunset */
.ov-sun-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex-shrink: 0;
  padding-left: clamp(0.4rem, 1vw, 0.8rem);
  border-left: 1px solid rgba(255,255,255,0.1);
}

.ov-sun-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* ── Alerts Bar ──────────────────────────────────────────── */
#alerts-container { width: 100%; }

.alert-bar {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.alert-bar-none {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  font-size: var(--text-sm);
  color: var(--text-muted);
  border-radius: var(--radius);
  text-align: center;
}

.alert-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: filter 0.15s;
  touch-action: manipulation;
  min-height: 44px; /* touch target */
}
.alert-header:hover { filter: brightness(1.08); }

.alert-icon   { font-size: 1.1rem; flex-shrink: 0; }

.alert-title {
  flex: 1;
  font-weight: 700;
  font-size: clamp(0.78rem, 1.5vw, 0.92rem);
  letter-spacing: 0.04em;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.alert-chevron {
  font-size: 0.9rem;
  flex-shrink: 0;
}

.alert-body {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
  padding: 1rem clamp(0.75rem, 3vw, 1.2rem);
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--text);
  border-radius: 0 0 var(--radius) var(--radius);
}
.alert-body.open { display: block; }

.alert-meta       { color: var(--text-muted); font-size: var(--text-xs); margin-bottom: 0.5rem; }
.alert-meta-row   { margin-bottom: 0.2rem; }
.alert-divider    { border: none; border-top: 1px solid var(--border); margin: 0.7rem 0; }
.alert-text p     { margin-bottom: 0.6rem; }
.alert-text p:last-child { margin-bottom: 0; }
.alert-in-effect  { margin-top: 0.8rem; font-size: var(--text-xs); color: var(--text-muted); }
.alert-feed-link  { margin-top: 0.8rem; font-size: var(--text-xs); color: var(--text-muted); }
.alert-feed-link a { color: var(--accent); text-decoration: none; }
.alert-feed-link a:hover { text-decoration: underline; }

/* ── Timestamps bar ──────────────────────────────────────── */
#timestamps-bar {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
  padding: 0 0.1rem;
}

#obs-time-label,
#refresh-time-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  opacity: 0.7;
}

/* ── 5-Day Forecast ──────────────────────────────────────── */
.forecast-section { width: 100%; margin-top: 0.5rem; }

.forecast-header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.8rem;
  gap: 1rem;
}

.forecast-section h2 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.unit-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: var(--text-sm);
  color: var(--text-muted);
  user-select: none;
  -webkit-user-select: none;
}

.unit-sep { color: var(--border); }

.unit-btn {
  cursor: pointer;
  padding: 0.15rem 0.25rem;
  color: var(--text-muted);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: transparent;
  transition: color 0.15s, text-decoration-color 0.15s;
  min-height: 44px;       /* touch target */
  display: flex;
  align-items: center;
  touch-action: manipulation;
}
.unit-btn:hover  { color: var(--text); text-decoration-color: var(--border); }
.unit-btn.active { color: var(--text); font-weight: 700; text-decoration-color: var(--accent); }

.forecast-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(0.25rem, 1vw, 0.5rem);
  width: 100%;
}

.forecast-day-col {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.forecast-day-header {
  background: var(--bg-card2);
  text-align: center;
  padding: clamp(0.3rem, 1vw, 0.45rem) 0.3rem;
  font-size: clamp(0.65rem, 1.2vw, 0.78rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
}

.forecast-period {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(0.4rem, 1.2vw, 0.65rem) clamp(0.2rem, 0.8vw, 0.4rem);
  gap: clamp(0.15rem, 0.5vw, 0.3rem);
  text-align: center;
  /* No border here — dividing line comes from NIGHT's border-top instead */
}

.forecast-period-label {
  font-size: clamp(0.6rem, 1vw, 0.68rem);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.forecast-period img.forecast-icon {
  width:  clamp(32px, 5vw, 44px);
  height: clamp(32px, 5vw, 44px);
  object-fit: contain;
  margin: 0.1rem 0;
}

.forecast-temp {
  font-size: clamp(0.95rem, 1.8vw, 1.2rem);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}
.forecast-temp.high { color: var(--accent-warm); }
.forecast-temp.low  { color: #79c0ff; }

.forecast-pop     { font-size: clamp(0.62rem, 1vw, 0.78rem); color: #79c0ff; font-weight: 500; }

.forecast-summary {
  font-size: clamp(0.6rem, 1vw, 0.72rem);
  color: var(--text-muted);
  line-height: 1.3;
  max-width: 90px;
}

.forecast-period.night {
  background: rgba(255,255,255,0.02);
  /* This top border is the DAY/NIGHT dividing line.
     It always renders regardless of whether the DAY slot has
     real content or is just an invisible spacer. */
  border-top: 1px solid var(--border);
}

.forecast-day-spacer {
  pointer-events: none;
  /* Invisible — the dividing line now comes from .forecast-period.night
     border-top, so we don't need any border tricks here */
  visibility: hidden;
}

/* ── Skeleton ────────────────────────────────────────────── */
@keyframes skelPulse {
  0%, 100% { opacity: 0.35; }
  50%       { opacity: 0.7;  }
}
.skel-pulse {
  animation: skelPulse 1.4s ease-in-out infinite;
  background: var(--border);
  border-radius: 4px;
}
.skeleton-icon  { width: 44px; height: 44px; border-radius: 50%; margin: 0.1rem auto; }
.skeleton-temp  { width: 46px; height: 22px; margin: 0.2rem auto 0.1rem; }
.skeleton-text  { width: 70%; height: 11px; margin: 0.1rem auto; }
.skeleton-col .forecast-period-label { color: var(--border); }

/* ── Error box ───────────────────────────────────────────── */
.weather-error {
  width: 100%;
  background: #3d1a1a;
  border: 1px solid #6e2222;
  color: #f8a0a0;
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  font-size: var(--text-sm);
  line-height: 1.5;
}

/* ── Footer ──────────────────────────────────────────────── */
footer {
  width: 100%;
  text-align: center;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  font-size: var(--text-xs);
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: auto;
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }


/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* ── XL: Widescreen 1400px+ ─────────────────────────────── */
@media (min-width: 1400px) {
  main { padding: 1.5rem 2rem 2rem; }

  .ov-temp        { font-size: 3.2rem; }
  .ov-details-grid { gap: 0.35rem 1.8rem; }

  .forecast-grid { gap: 0.65rem; }
  .forecast-temp { font-size: 1.35rem; }
  .forecast-period img.forecast-icon { width: 52px; height: 52px; }

  /* Wider screens get bigger summary text */
  .forecast-summary { font-size: 0.78rem; max-width: 110px; }
}

/* ── MD: Tablets and small laptops 700–959px ────────────── */
@media (max-width: 959px) and (min-width: 700px) {
  /* Overlay: hide sunrise/sunset to save space */
  .ov-sun-block { display: none; }

  /* Details grid: single column to avoid cramping */
  .ov-details-grid { grid-template-columns: 1fr 1fr; gap: 0.2rem 0.7rem; }

  /* Forecast: still 5 columns but tighter */
  .forecast-grid { gap: 0.3rem; }
  .forecast-summary { display: none; } /* drop text, keep icon+temp+pop */
}

/* ── SM: Large phones / small tablets 480–699px ─────────── */
@media (max-width: 699px) {

  /* Header: tighter */
  header h1 { font-size: 1.05rem; }
  #kelowna-time { font-size: 0.95rem; }
  #kelowna-date { font-size: 0.75rem; }

  /* Overlay: stack into two rows */
  .cam-overlay { padding: 0.5rem 0.65rem; }

  .overlay-row {
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: flex-start;
  }

  /* Row 1: temp block + icon + details fill width */
  .ov-temp-block { min-width: 60px; }
  .ov-temp       { font-size: 2rem; }
  .ov-feels      { font-size: 0.6rem; }

  .ov-icon-block         { min-width: 52px; }
  .ov-icon-block img     { width: 36px; height: 36px; }
  .ov-icon-block span    { font-size: 0.62rem; max-width: 68px; }

  .ov-details-grid { grid-template-columns: 1fr 1fr; gap: 0.15rem 0.5rem; }

  /* Sunrise/sunset: move to its own row spanning full width */
  .ov-sun-block {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    gap: 1.5rem;
    padding-left: 0;
    padding-top: 0.3rem;
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.1);
  }

  /* Placeholder bottom padding matches new overlay height */
  .cam-placeholder { padding-bottom: 9rem; }

  /* Forecast: 5 cols compressed */
  .forecast-grid { gap: 0.2rem; }
  .forecast-day-header { font-size: 0.62rem; padding: 0.3rem 0.1rem; }
  .forecast-period { padding: 0.4rem 0.1rem; gap: 0.15rem; }
  .forecast-period img.forecast-icon { width: 28px; height: 28px; }
  .forecast-temp  { font-size: 0.88rem; }
  .forecast-pop   { font-size: 0.6rem; }
  .forecast-summary { display: none; }

  /* Timestamps: centre them on small screens */
  #timestamps-bar { align-items: center; text-align: center; }
}

/* ── XS: Small phones < 480px ───────────────────────────── */
@media (max-width: 479px) {

  header h1 { font-size: 0.92rem; letter-spacing: 0; }

  /* On very small screens the overlay becomes tall — cap its content */
  .ov-temp   { font-size: 1.7rem; }
  .ov-details-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.12rem 0.3rem;
  }
  .ov-det-label { font-size: 0.56rem; }
  .ov-det-val   { font-size: 0.62rem; }

  /* Sunrise/sunset: hide on very small screens — already short on space */
  .ov-sun-block { display: none; }
  .cam-placeholder { padding-bottom: 7rem; }

  /* Forecast: drop to 3 columns (TODAY / next 2 days) ...
     Actually keep 5 but make them very compact */
  .forecast-grid { grid-template-columns: repeat(5, 1fr); gap: 0.15rem; }
  .forecast-day-header { font-size: 0.56rem; padding: 0.25rem 0; letter-spacing: 0; }
  .forecast-period { padding: 0.3rem 0.05rem; gap: 0.1rem; }
  .forecast-period img.forecast-icon { width: 24px; height: 24px; }
  .forecast-temp  { font-size: 0.8rem; }
  .forecast-pop   { font-size: 0.56rem; }
  .forecast-period-label { font-size: 0.52rem; letter-spacing: 0; }

  /* Alert title smaller */
  .alert-title { font-size: 0.72rem; letter-spacing: 0; }
}

/* ── Landscape phones (short viewport, wide) ─────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  /* On landscape phone the webcam would be tiny — let it scroll naturally */
  .cam-wrapper { aspect-ratio: 16 / 6; }

  /* Overlay: single compact row, no sunrise/sunset */
  .ov-sun-block   { display: none; }
  .cam-overlay    { padding: 0.3rem 0.7rem; }
  .ov-temp        { font-size: 1.5rem; }
  .ov-feels       { display: none; }
  .ov-icon-block img { width: 30px; height: 30px; }
  .ov-details-grid { gap: 0.1rem 0.5rem; }
  .cam-placeholder { padding-bottom: 5rem; }
}

/* ── Touch device: remove hover states that can get stuck ── */
@media (hover: none) {
  .unit-btn:hover         { color: var(--text-muted); text-decoration-color: transparent; }
  .alert-header:hover     { filter: none; }
  footer a:hover          { text-decoration: none; }
  .alert-feed-link a:hover { text-decoration: none; }
  #cam-btn:hover          { opacity: 1; }
}