/* ==========================================================================
   AppMeteo design system — Apple HIG translated to the web.
   Foundations: system typography with optical tracking, translucent
   materials (backdrop-filter), spring-like easing, dark/light themes,
   reduced-motion & reduced-transparency fallbacks.
   ========================================================================== */

:root {
  /* ---- palette: light ---- */
  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --card: rgba(255, 255, 255, 0.78);
  --card-solid: #ffffff;
  --chrome: rgba(249, 249, 251, 0.72);
  --separator: rgba(60, 60, 67, 0.12);
  --edge-light: rgba(255, 255, 255, 0.65);
  --text: #1d1d1f;
  --text-2: rgba(60, 60, 67, 0.62);
  --text-3: rgba(60, 60, 67, 0.36);
  --tint: #0071e3;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --shadow-lift: 0 2px 6px rgba(0,0,0,.05), 0 16px 40px rgba(0,0,0,.10);

  /* ---- data colors (Apple system palette) ---- */
  --c-temp: #ff9500;  --c-temp-hot: #ff3b30;  --c-temp-cold: #5ac8fa;
  --c-dew: #30b0c7;   --c-feels: #ff375f;
  --c-hum: #007aff;   --c-press: #af52de;
  --c-wind: #34c759;  --c-gust: #ffcc00;
  --c-rain: #0a84ff;  --c-rate: #5ac8fa;
  --c-solar: #ffd60a; --c-uv: #ff9f0a;
  --sun: #ff9f0a;

  /* ---- motion: Apple-like spring feel (critically damped) ---- */
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --dur: 0.35s;

  --radius: 20px;
  --radius-s: 12px;

  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --card: rgba(28, 28, 30, 0.72);
  --card-solid: #1c1c1e;
  --chrome: rgba(18, 18, 20, 0.68);
  --separator: rgba(84, 84, 88, 0.48);
  --edge-light: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --text-2: rgba(235, 235, 245, 0.62);
  --text-3: rgba(235, 235, 245, 0.30);
  --tint: #2997ff;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.45);
  --shadow-lift: 0 2px 8px rgba(0,0,0,.4), 0 18px 50px rgba(0,0,0,.55);
  --c-temp: #ff9f0a; --c-hum: #0a84ff; --c-press: #bf5af2;
  --c-wind: #30d158; --c-rain: #0a84ff; --c-solar: #ffd60a;
  color-scheme: dark;
}

/* ---- reset ---- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;                 /* comfortable body leading (§15) */
  min-height: 100dvh;
  transition: background-color .4s ease, color .4s ease; /* soft theme change (§14) */
}
a { color: inherit; text-decoration: none; }
button, select { font: inherit; color: inherit; }
svg { display: block; }

/* ==========================================================================
   Chrome — translucent floating toolbar, content scrolls underneath (§12)
   ========================================================================== */
.chrome {
  position: sticky; top: 0; z-index: 50;
  background: var(--chrome);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--separator);
}
.chrome-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 1.25rem;
  padding: 0.65rem 1.25rem;
  flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: .45rem;
  font-size: 1.15rem; font-weight: 700; letter-spacing: -0.015em;
}
.brand-mark { color: var(--text-2); }

/* Nav: iOS segmented-control feel */
.tabs {
  display: flex; gap: .15rem;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  padding: .2rem; border-radius: 999px;
}
.tabs a {
  padding: .35rem 1rem; border-radius: 999px;
  font-size: .92rem; font-weight: 500; color: var(--text-2);
  transition: color var(--dur) var(--ease-spring),
              background-color var(--dur) var(--ease-spring),
              transform .15s var(--ease-spring);
}
.tabs a:active { transform: scale(0.96); }   /* instant press feedback (§1) */
.tabs a.active {
  background: var(--card-solid); color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.chrome-actions { margin-left: auto; display: flex; align-items: center; gap: .6rem; }

.station-picker {
  appearance: none; -webkit-appearance: none;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border: none; border-radius: 999px;
  padding: .4rem 2rem .4rem 1rem;
  font-size: .9rem; font-weight: 500;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .8rem center;
}
.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  border: none; cursor: pointer;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  transition: transform .15s var(--ease-spring), background-color .2s;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn:hover { background: color-mix(in srgb, var(--text) 11%, transparent); }

/* ==========================================================================
   Layout
   ========================================================================== */
.view {
  max-width: 1200px; margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
  outline: none;
}
/* View enter: gentle rise + fade — replaced by fade only under reduced motion */
.view > .page { animation: page-in .5s var(--ease-spring) both; }
@keyframes page-in {
  from { opacity: 0; transform: translateY(10px) scale(.995); }
  to   { opacity: 1; transform: none; }
}

.footer {
  max-width: 1200px; margin: 0 auto; padding: 0 1.25rem 2.5rem;
  color: var(--text-3); font-size: .8rem;
}

/* ==========================================================================
   Hero — current conditions. Display typography: tight leading,
   negative tracking as size grows (§15).
   ========================================================================== */
.hero {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 2rem; flex-wrap: wrap;
  padding: 1.5rem 0.5rem 2rem;
}
.hero-temp {
  font-size: clamp(4.5rem, 12vw, 7.5rem);
  font-weight: 250;
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.hero-temp .deg { color: var(--text-3); font-weight: 200; }
.hero-meta { padding-bottom: .5rem; }
.hero-station {
  font-size: 1.35rem; font-weight: 600; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: .5rem;
}
.hero-cond { color: var(--text-2); font-size: 1.05rem; margin-top: .1rem; }
.hero-range { color: var(--text-2); font-size: .95rem; margin-top: .35rem; font-variant-numeric: tabular-nums; }
.hero-side { text-align: right; color: var(--text-2); font-size: .9rem; }
.hero-side .big { font-size: 1.4rem; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }

/* live pulse dot — ring animates transform/opacity only (compositor-friendly, §11) */
.dot { position: relative; width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on  { background: #30d158; }
.dot.off { background: var(--text-3); }
.dot.on::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: rgba(48, 209, 88, .4);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  70%, 100% { transform: scale(3); opacity: 0; }
}

/* ==========================================================================
   Cards — material surfaces with bright top edge (light catching, §12)
   ========================================================================== */
.grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
}
.card {
  /* Solid-ish surface: cards sit on a flat background, so translucency
     buys nothing and backdrop-filter per card is GPU-expensive (Pi!). */
  background: var(--card-solid);
  border-radius: var(--radius);
  border: 1px solid var(--separator);
  border-top-color: var(--edge-light);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem 1.2rem;
  transition: transform var(--dur) var(--ease-spring), box-shadow var(--dur) var(--ease-spring);
}
@media (hover: hover) {
  .card.lift:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
}
.card h3 {
  font-size: .78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em;            /* small text: positive tracking (§15) */
  color: var(--text-2);
  display: flex; align-items: center; gap: .4rem;
  margin-bottom: .55rem;
}
.card h3 svg { opacity: .8; }
.metric {
  font-size: 2.1rem; font-weight: 600; letter-spacing: -0.02em;
  line-height: 1.1; font-variant-numeric: tabular-nums;
}
.metric small { font-size: 1.05rem; font-weight: 500; color: var(--text-2); letter-spacing: 0; }
.sub { color: var(--text-2); font-size: .88rem; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.sub b { color: var(--text); font-weight: 600; }

.trend-up   { color: #30d158; }
.trend-down { color: #ff453a; }
.trend-flat { color: var(--text-2); }

/* wide cards for charts */
.card.wide { grid-column: 1 / -1; }
.card .chart { width: 100%; height: 300px; }
.card .chart.tall { height: 340px; }
.card .chart.mini { height: 120px; }

/* ==========================================================================
   Compass (wind) — needle animates with spring easing from current angle
   ========================================================================== */
.compass-wrap { display: flex; gap: 1.1rem; align-items: center; }
.compass { width: 116px; height: 116px; flex: none; }
.compass .needle {
  transform-origin: 60px 60px;
  transition: transform 0.8s var(--ease-spring);  /* re-targets from live value (§3) */
}
.compass text { font-size: 11px; font-weight: 600; fill: var(--text-3); }
.compass .ring { stroke: var(--separator); }
.compass .tick { stroke: var(--text-3); }

/* UV / battery style level bar */
.levelbar { display: flex; gap: 3px; margin-top: .45rem; }
.levelbar i {
  height: 5px; flex: 1; border-radius: 3px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
}
.levelbar i.on { background: var(--seg, var(--c-uv)); }

/* ==========================================================================
   Segmented control (range picker) — iOS style with sliding thumb feel
   ========================================================================== */
.segmented {
  display: inline-flex; gap: .15rem;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border-radius: 999px; padding: .2rem;
}
.segmented button {
  border: none; background: transparent; cursor: pointer;
  padding: .34rem 1.05rem; border-radius: 999px;
  font-size: .9rem; font-weight: 500; color: var(--text-2);
  transition: transform .15s var(--ease-spring), background-color var(--dur) var(--ease-spring), color var(--dur);
}
.segmented button:active { transform: scale(0.95); }
.segmented button.active {
  background: var(--card-solid); color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}

.toolbar-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.page-title { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.022em; }
.page-sub { color: var(--text-2); font-size: .95rem; margin-top: .15rem; }

/* ==========================================================================
   Tables (stats)
   ========================================================================== */
.stat-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stat-table th, .stat-table td { text-align: right; padding: .55rem .4rem; font-size: .92rem; }
.stat-table th { color: var(--text-2); font-weight: 500; }
.stat-table td:first-child, .stat-table th:first-child { text-align: left; }
.stat-table tr + tr td { border-top: 1px solid var(--separator); }
.stat-table td b { font-weight: 600; }

/* ==========================================================================
   Records
   ========================================================================== */
.record-value { font-size: 1.9rem; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.record-date { color: var(--text-2); font-size: .85rem; margin-top: .2rem; }

/* ==========================================================================
   Stations view / forms / modal sheet
   ========================================================================== */
.station-row {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.25rem;
}
.station-row + .station-row { border-top: 1px solid var(--separator); }
.station-row .info { flex: 1; min-width: 0; }
.station-row .name { font-weight: 600; letter-spacing: -0.01em; }
.station-row .meta { color: var(--text-2); font-size: .85rem; }
.badge {
  font-size: .72rem; font-weight: 600; padding: .18rem .6rem; border-radius: 999px;
  background: color-mix(in srgb, var(--tint) 14%, transparent); color: var(--tint);
}
.badge.warn { background: rgba(255,159,10,.16); color: #ff9f0a; }

.btn {
  border: none; cursor: pointer;
  background: var(--tint); color: #fff;
  padding: .55rem 1.3rem; border-radius: 999px;
  font-weight: 600; font-size: .95rem;
  transition: transform .15s var(--ease-spring), filter .2s;
}
.btn:active { transform: scale(0.96); }
.btn:hover { filter: brightness(1.08); }
.btn.ghost {
  background: color-mix(in srgb, var(--text) 7%, transparent);
  color: var(--text);
}
.btn.danger { background: rgba(255,69,58,.14); color: #ff453a; }

.field { margin-bottom: .9rem; }
.field label { display: block; font-size: .85rem; color: var(--text-2); margin-bottom: .3rem; }
.field input {
  width: 100%; border: 1px solid var(--separator); border-radius: var(--radius-s);
  background: var(--bg-elevated); color: var(--text);
  padding: .6rem .8rem; font-size: 1rem;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus {
  outline: none; border-color: var(--tint);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--tint) 22%, transparent);
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; font-size: .92rem; }
.kv dt { color: var(--text-2); }
.kv dd { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .86rem; word-break: break-all; }

.callout {
  background: color-mix(in srgb, var(--tint) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--tint) 22%, transparent);
  border-radius: var(--radius-s);
  padding: .9rem 1.1rem; font-size: .9rem; margin-top: 1rem;
}
.callout ol { padding-left: 1.2rem; display: grid; gap: .3rem; margin-top: .4rem; }

/* Modal sheet: dim scrim + surface materializes (blur+scale together, §12) */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.35);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  display: grid; place-items: center;
  animation: fade-in .25s ease both;
  padding: 1rem;
}
.sheet {
  width: min(560px, 100%);
  max-height: 86dvh; overflow: auto;
  background: var(--bg-elevated);
  border-radius: 24px;
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-lift);
  padding: 1.6rem 1.6rem 1.4rem;
  animation: sheet-in .45s var(--ease-spring) both;
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(26px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.sheet h2 { font-size: 1.35rem; letter-spacing: -0.02em; margin-bottom: 1rem; }
.sheet-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }

/* skeleton shimmer while loading */
.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(100deg,
    color-mix(in srgb, var(--text) 5%, transparent) 40%,
    color-mix(in srgb, var(--text) 9%, transparent) 50%,
    color-mix(in srgb, var(--text) 5%, transparent) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.empty {
  text-align: center; padding: 4rem 1rem; color: var(--text-2);
}
.empty .big { font-size: 2.6rem; margin-bottom: .6rem; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 760px) {
  .chrome-inner { gap: .6rem; padding: .55rem .9rem; }
  .tabs { order: 3; width: 100%; justify-content: space-between; }
  .tabs a { flex: 1; text-align: center; padding: .35rem .2rem; }
  .hero { padding: 1rem 0 1.4rem; }
  .hero-side { text-align: left; }
  .card .chart { height: 240px; }
}

/* ==========================================================================
   Accessibility preferences (§14)
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .view > .page { animation: none; opacity: 1; transform: none; }
  .dot.on { animation: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .chrome { background: var(--bg-elevated); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .card, .chrome { border-color: var(--text-2); }
}
