/* ==========================================================================
   Beaux Weather - design tokens

   Light values live on bare :root. Dark values are restated twice: once for
   the OS setting, once for the in-app theme toggle, so the toggle wins in
   both directions. No colour gets its only definition inside a media block.
   ========================================================================== */

:root {
  color-scheme: light;

  --plane:         #f9f9f7;
  --surface-1:     #fcfcfb;
  --surface-2:     #f2f1ed;
  --text-1:        #0b0b0b;
  --text-2:        #52514e;
  --text-muted:    #898781;
  --grid:          #e1e0d9;
  --axis:          #c3c2b7;
  --border:        rgba(11, 11, 11, 0.10);
  --series-1:      #2a78d6;
  --series-1-soft: rgba(42, 120, 214, 0.10);
  --shadow:        0 1px 2px rgba(11, 11, 11, 0.05);

  /* Status palette is fixed - never themed. */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --r-card: 16px;
  --r-ctl: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:         #0d0d0d;
    --surface-1:     #1a1a19;
    --surface-2:     #232322;
    --text-1:        #ffffff;
    --text-2:        #c3c2b7;
    --text-muted:    #898781;
    --grid:          #2c2c2a;
    --axis:          #383835;
    --border:        rgba(255, 255, 255, 0.10);
    --series-1:      #3987e5;
    --series-1-soft: rgba(57, 135, 229, 0.14);
    --shadow:        none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:         #0d0d0d;
  --surface-1:     #1a1a19;
  --surface-2:     #232322;
  --text-1:        #ffffff;
  --text-2:        #c3c2b7;
  --text-muted:    #898781;
  --grid:          #2c2c2a;
  --axis:          #383835;
  --border:        rgba(255, 255, 255, 0.10);
  --series-1:      #3987e5;
  --series-1-soft: rgba(57, 135, 229, 0.14);
  --shadow:        none;
}

/* ========================================================================== */

* { box-sizing: border-box; }

/* No image can overflow its container, even if the stylesheet is stale or a
   width attribute disagrees with the CSS. */
img { max-width: 100%; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--plane);
  color: var(--text-1);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  /* Leaves room for the fixed tab bar. */
  padding: 0 14px calc(84px + env(safe-area-inset-bottom));
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- top bar ---------- */

/* Artwork on the left; the controls row and the station line stacked and
   centred in the space beside it. Not sticky - at this size it would eat a
   third of a phone screen on every scroll, and the hero card already carries
   the reading age. */
.topbar {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: calc(8px + env(safe-area-inset-top)) 0 12px;
  background: var(--plane);
}

/* Transparent artwork: no plate, no rounding. `contain` keeps the ragged edge
   of the cutout from being cropped; the square aspect ratio means the box
   never has to guess, even before the image loads. */
.topbar__logo {
  flex: none;
  display: block;
  width: clamp(112px, 30vw, 180px);
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: transparent;
}

.topbar__col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 10px;
}

.topbar__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.topbar__place {
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
  overflow-wrap: anywhere;
}

/* The station's own description, boxed so it reads as a sign rather than as
   another data field. */
.topbar__tagline {
  margin: 0;
  padding: 9px 13px;
  max-width: 32ch;
  border: 1.5px solid var(--text-1);
  border-radius: 10px;
  background: var(--surface-1);
  font-size: 12.5px;
  line-height: 1.45;
  font-weight: 600;
  text-align: center;
  text-wrap: balance;
  color: var(--text-1);
}

.iconbtn {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-1);
  color: var(--text-2);
  cursor: pointer;
  padding: 0;
}

.iconbtn:active { transform: scale(0.94); }
.iconbtn svg { width: 19px; height: 19px; }
.iconbtn--spin svg { animation: spin 0.9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- status chip ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-1);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

.chip__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex: none;
}

.chip[data-state="live"]    .chip__dot { background: var(--good); animation: pulse 2.4s ease-in-out infinite; }
.chip[data-state="delayed"] .chip__dot { background: var(--warning); }
.chip[data-state="offline"] .chip__dot { background: var(--critical); }
.chip[data-state="error"]   .chip__dot { background: var(--critical); }

@keyframes pulse { 50% { opacity: 0.3; } }

@media (prefers-reduced-motion: reduce) {
  .chip[data-state="live"] .chip__dot { animation: none; }
  .iconbtn--spin svg { animation: none; }
  .iconbtn:active { transform: none; }
}

/* ---------- cards ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}

.card__head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}

.card__title {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
}

.card__sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------- hero ---------- */

.hero { padding: 18px 16px 16px; }

.hero__row { display: flex; align-items: flex-start; gap: 14px; }

/* Hero figure: system sans, proportional figures (tabular-nums reads loose
   at display sizes). Exactly one hero per view. */
.hero__temp {
  margin: 0;
  font-size: 68px;
  line-height: 0.92;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.hero__none {
  font-size: 25px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0;
}

.hero__unit {
  font-size: 25px;
  font-weight: 500;
  color: var(--text-2);
  vertical-align: super;
  letter-spacing: 0;
}

.hero__meta {
  margin-left: auto;
  text-align: right;
  font-size: 12px;
  color: var(--text-2);
  padding-top: 5px;
}

.hero__feels { margin: 12px 0 0; font-size: 13px; color: var(--text-2); }
.hero__feels b { color: var(--text-1); font-weight: 650; }

.hero__range {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
}

.hero__range b {
  color: var(--text-1);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* ---------- banner ---------- */

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 13px;
  border-radius: var(--r-card);
  border: 1px solid var(--border);
  background: var(--surface-1);
  margin-bottom: 10px;
  font-size: 12.5px;
  color: var(--text-2);
}

.banner svg { width: 17px; height: 17px; flex: none; margin-top: 2px; }
.banner b { color: var(--text-1); display: block; font-size: 13px; }
.banner[data-tone="warning"]  svg { color: var(--warning); }
.banner[data-tone="serious"]  svg { color: var(--serious); }
.banner[data-tone="critical"] svg { color: var(--critical); }

/* ---------- stat tiles ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

@media (min-width: 470px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 12px 13px;
  min-width: 0;
}

.tile__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.tile__value {
  margin-top: 3px;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.tile__value small {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0;
}

.tile__note {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A supporting second line under a tile note. */
.tile__note--sub {
  color: var(--text-muted);
  margin-top: 1px;
}

/* ---------- wind ---------- */

.wind { display: flex; align-items: center; gap: 16px; }
.wind__dial { flex: none; width: 96px; height: 96px; }
.wind__stats { flex: 1; min-width: 0; }

.wind__row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-2);
}

.wind__row b {
  color: var(--text-1);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.dial__ring  { fill: none; stroke: var(--grid); stroke-width: 1.5; }
.dial__tick  { stroke: var(--axis); stroke-width: 1; }
.dial__card  { fill: var(--text-muted); font-size: 9px; font-weight: 600; }
.dial__arrow { fill: var(--series-1); }
.dial__hub   { fill: var(--surface-1); stroke: var(--series-1); stroke-width: 1.5; }
.dial__val   { fill: var(--text-1); font-size: 10px; font-weight: 650; }

/* ---------- charts ---------- */

.chart { position: relative; width: 100%; touch-action: pan-y; }

.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart__grid  { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart__axis  { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart__tick  { fill: var(--text-muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart__line  { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart__area  { fill: var(--series-1-soft); }
.chart__bar   { fill: var(--series-1); }
.chart__dot   { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart__label { fill: var(--text-1); font-size: 11px; font-weight: 650; }
.chart__cross { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart__focus { fill: none; stroke: var(--series-1); stroke-width: 2; }

.chart svg:focus { outline: none; }
.chart svg:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 4px; }

.chart__empty {
  padding: 26px 4px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
}

.tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  transform: translate(-50%, -100%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-ctl);
  box-shadow: 0 4px 14px rgba(11, 11, 11, 0.16);
  padding: 7px 9px;
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
  line-height: 1.35;
}

.tip b {
  display: block;
  color: var(--text-1);
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* ---------- table view: the WCAG-clean twin of every chart ---------- */

.toggle {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 11px;
  cursor: pointer;
  margin-left: auto;
  flex: none;
}

.toggle[aria-pressed="true"] {
  background: var(--series-1);
  color: #fff;
  border-color: transparent;
}

.dtable-wrap { max-height: 260px; overflow: auto; }

.dtable {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.dtable th,
.dtable td {
  text-align: right;
  padding: 5px 8px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

.dtable th:first-child,
.dtable td:first-child { text-align: left; }

.dtable thead th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}

/* ---------- refetch: hold the previous render, never a skeleton flash ---- */

.is-refetching .fadeable { opacity: 0.55; }
.fadeable { transition: opacity 0.15s ease; }

/* ---------- setup + settings ---------- */

.setup {
  max-width: 430px;
  margin: 7vh auto 0;
  padding: 0 16px calc(30px + env(safe-area-inset-bottom));
}

.setup__logo { width: 72px; height: 72px; border-radius: 16px; display: block; margin-bottom: 16px; background: #000; }
.setup h1 { font-size: 21px; margin: 0 0 6px; }
.setup p { font-size: 13.5px; color: var(--text-2); margin: 0 0 16px; }
.setup ol { font-size: 13px; color: var(--text-2); padding-left: 20px; margin: 0 0 18px; }
.setup li { margin-bottom: 6px; }
.setup a { color: var(--series-1); }

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 5px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 11px 12px;
  font: inherit;
  font-size: 16px;
  color: var(--text-1);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-ctl);
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

.field textarea { resize: vertical; line-height: 1.45; font-size: 15px; }

.field__hint { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }

.btn {
  width: 100%;
  padding: 13px;
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  color: #fff;
  background: var(--series-1);
  border: 0;
  border-radius: var(--r-ctl);
  cursor: pointer;
}

.btn:active { transform: scale(0.99); }
.btn--ghost { background: var(--surface-2); color: var(--text-1); border: 1px solid var(--border); }
.btn[disabled] { opacity: 0.55; cursor: default; }

.formerr {
  font-size: 12.5px;
  color: var(--critical);
  margin: 0 0 12px;
  font-weight: 600;
}

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 100%;
  max-height: 100%;
  color: var(--text-1);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.5); }

.sheet {
  width: min(440px, calc(100vw - 24px));
  max-height: 88vh;
  overflow-y: auto;
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}

.sheet h2 { margin: 0 0 16px; font-size: 17px; }
.sheet__actions { display: flex; gap: 10px; margin-top: 18px; }

.seg {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-ctl);
}

.seg button {
  flex: 1;
  padding: 8px 4px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.seg button[aria-pressed="true"] {
  background: var(--surface-1);
  color: var(--text-1);
  box-shadow: var(--shadow);
}

.footnote {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 6px 0 0;
  line-height: 1.7;
}

.footnote a { color: var(--text-2); }

/* ---------- data-quality note ---------- */

.qnote {
  margin: -2px 0 10px;
  padding: 0 2px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-muted);
}

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  background: var(--plane);
  border-top: 1px solid var(--border);
}

.tabbar__btn {
  flex: 0 1 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 4px 5px;
  font: inherit;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.tabbar__btn svg { width: 22px; height: 22px; }
.tabbar__btn[aria-selected="true"] { color: var(--series-1); }

/* ---------- history: day drill-down ---------- */

.daystat {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 14px;
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--text-2);
}

.daystat div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid var(--grid);
}

.daystat b {
  color: var(--text-1);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.subhead {
  margin: 14px 0 8px;
  font-size: 12px;
  font-weight: 650;
  color: var(--text-2);
}

.spinner {
  display: block;
  width: 20px;
  height: 20px;
  margin: 22px auto;
  border: 2px solid var(--grid);
  border-top-color: var(--series-1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
