/* Page frame: reset, header, tab bar, scroll containers, toolbar controls
   and the at-a-glance strip. Component internals live in components.css. */

* { box-sizing: border-box; }
/* `contain` stops a swipe-down inside .scroller from reaching the browser
   and firing pull-to-refresh, which reloads the whole page — on a phone that
   reads as the dashboard refreshing itself every second or two. */
html, body { height: 100%; overscroll-behavior-y: contain; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* Everything below is sized in rem against this, so the whole interface
     scales from one number. 18px reads comfortably at arm's length, which is
     how a weather dashboard is actually used. */
  font-size: 18px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  padding: 16px 24px 0;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--header-top), var(--header-bot));
  flex: none;
}
.titlebar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.titlebar .spacer { flex: 1; }
.titlebar .theme-ctl { align-self: center; }
header h1 { margin: 0; font-size: 1.45rem; font-weight: 600; letter-spacing: -0.02em; }
header .sub { color: var(--muted); font-size: 0.85rem; }
nav.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 14px; }
nav.tabs button {
  background: transparent; border: none; color: var(--text-dim);
  padding: 12px 20px; font-size: 1.02rem; font-weight: 550; font-family: inherit; cursor: pointer;
  border-bottom: 3px solid transparent; transition: color .15s, border-color .15s;
}
nav.tabs button:hover { color: var(--text); }
nav.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
section.page { display: none; flex: 1; min-height: 0; flex-direction: column; }
section.page.active { display: flex; }
.scroller { overflow-y: auto; overscroll-behavior-y: contain; padding: 18px 24px 48px; }
.inner { max-width: 1400px; margin: 0 auto; }

.toolbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 16px;
}
.ctl { display: flex; align-items: center; gap: 6px; min-width: 0; flex-wrap: wrap; }
.ctl > span.lbl { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
/* Seven window buttons don't fit across a phone. Wrapping costs the segmented
   control its unbroken outline on the narrowest screens; overflowing would cost
   the whole page its width, which is worse. */
.seg { display: flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button {
  background: var(--panel-alt); border: none; border-right: 1px solid var(--border);
  color: var(--text-dim); font-family: inherit; font-size: 0.86rem;
  padding: 7px 13px; cursor: pointer;
}
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--seg-on-bg); color: var(--seg-on-fg); }
.toolbar .spacer { flex: 1; }
/* This line's text changes on every poll. In a wrapping toolbar a change of
   width changes where the row breaks, which changes the toolbar's height, which
   steps the whole page up and down — the exact thing being avoided here. So:
   one line only, clipped rather than wrapped, and a fixed height. Nothing it
   says can change the size of its box. */
.status-line {
  font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 8px;
  min-width: 0; height: 1.7em; justify-content: flex-end; text-align: right;
}
.status-line .s-txt {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
/* Always in the layout, lit only while a poll is in flight — an indicator that
   appears and disappears would move everything beside it. */
.status-line .busy-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: var(--accent); opacity: 0; transition: opacity .18s;
}
.status-line.busy .busy-dot { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .status-line .busy-dot { transition: none; } }

/* On a narrow screen the status and the Refresh button get their own row,
   always — deterministic beats "whatever fits", which is what oscillates. */
@media (max-width: 760px) {
  .toolbar .spacer { flex: 0 0 100%; height: 0; margin: 0; }
  .status-line { flex: 1; justify-content: flex-start; text-align: left; }
}
.btn-ghost {
  background: var(--panel-alt); border: 1px solid var(--border); color: var(--text-dim);
  font-family: inherit; font-size: 0.86rem; padding: 7px 14px; border-radius: 7px; cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--hover-border); }

/* ---------- short viewports (a phone held sideways) ------------------------
   The header sits outside the scroll container, so whatever height it takes is
   gone for good — and in landscape there is only ~380px to begin with. Here the
   title, theme switch and tabs collapse onto one row, the subtitle and footer
   go, and every band of chrome above the cards tightens. */
@media (max-height: 560px) {
  header { display: flex; align-items: center; gap: 14px; padding: 3px 14px 0; }
  .titlebar { flex: 0 0 auto; gap: 10px; }
  .titlebar .spacer { display: none; }
  header h1 { font-size: 1rem; }
  header .sub { display: none; }
  nav.tabs { margin-top: 0; margin-left: auto; }
  nav.tabs button { padding: 7px 12px; font-size: 0.88rem; border-bottom-width: 2px; }

  .scroller { padding: 10px 14px 24px; }
  .toolbar { padding: 6px 10px; margin-bottom: 10px; gap: 10px 12px; }
  .ctl > span.lbl { display: none; }
  .seg button { padding: 5px 10px; font-size: 0.8rem; }
  .btn-ghost { padding: 5px 11px; font-size: 0.8rem; }
  .glance { margin-bottom: 10px; }
  .glance-item { padding: 6px 10px; }
  .glance-item .g-meta, .glance-item .g-dir { font-size: 0.72rem; }
  .chart-key { margin-bottom: 10px; gap: 4px 12px; font-size: 0.75rem; }
  .chart-key .note { display: none; }
  footer { display: none; }
}

/* ---------- at-a-glance ----------------------------------------------------
   Always in the order the stations are declared. Nothing here re-sorts: a strip
   that reorders itself is one you have to re-read every time you look at it. */
.glance { margin-bottom: 16px; }
.glance-rows { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 9px; }
.glance-item {
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 13px; cursor: pointer; text-align: left; font-family: inherit;
  display: flex; align-items: center; gap: 11px; overflow: hidden; color: inherit;
}
.glance-item:hover { border-color: var(--hover-border); }
.glance-item .dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.glance-item .g-txt {
  min-width: 0; flex: 1;
  display: grid; grid-template-columns: 1fr auto; gap: 1px 10px; align-items: baseline;
}
.glance-item .g-name { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.glance-item .g-val { font-size: 1.02rem; font-weight: 650; text-align: right; }
.glance-item .g-val i { font-style: normal; font-size: 0.76rem; font-weight: 400; color: var(--muted); }
.glance-item .g-meta { font-size: 0.78rem; font-weight: 600; }
.glance-item .g-alt { font-size: 0.8rem; color: var(--muted); text-align: right; grid-column: 2; }
.glance-item .g-dir { font-size: 0.76rem; color: var(--muted); text-align: right; }

/* ---------- the page's one chart key ---------- */
.chart-key {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 15px;
  font-size: 0.8rem; color: var(--text-dim); margin-bottom: 15px; padding: 0 2px;
}
.chart-key .key { display: inline-flex; align-items: center; gap: 6px; }
.chart-key .note { color: var(--muted); font-size: 0.77rem; }
.chart-key .sep { width: 1px; height: 13px; background: var(--border); }
.chart-key .swatch { width: 18px; height: 4px; border-radius: 2px; }
.chart-key .swatch.s-lull { background: var(--series-lull); }
.chart-key .swatch.s-gust { background: var(--series-gust); }
/* The average is an area, so its key is a block with the same fade, capped by
   the line — a flat dash would misdescribe what is on the chart. */
.chart-key .swatch.s-area {
  width: 20px; height: 13px; border-radius: 2px;
  border-top: 2.5px solid var(--series-avg);
  background: linear-gradient(to bottom,
    color-mix(in srgb, var(--series-avg) 55%, transparent),
    color-mix(in srgb, var(--series-avg) 6%, transparent));
}
.chart-key .wash { width: 19px; height: 13px; border-radius: 3px; border: 1px solid; border-left-width: 3px; }
.chart-key .wash.w-ok     { background: var(--band-ok);     border-color: var(--good); }
.chart-key .wash.w-strong { background: var(--band-strong); border-color: var(--serious); }
.chart-key .wash.w-over   { background: var(--band-over);   border-color: var(--critical); }
