/*
 * DLI forecast: all styles live in this one external stylesheet.
 * Components declare no styles, so Angular injects no <style> elements at runtime
 * and the app runs under a strict CSP (style-src 'self'; font-src 'self').
 *
 * Saralis Bio palette: green #1ea94a, slate #4c5166, ink #333333, greys #f6f6f6 / #e0dede.
 */

/* ---------- Fonts (self-hosted, OFL-1.1, from @fontsource) ---------- */

@font-face {
  font-family: 'Days One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/days-one-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/montserrat-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/montserrat-latin-600-normal.woff2') format('woff2');
}

/* ---------- Theme tokens ---------- */

:root {
  color-scheme: light;
  --font-display: 'Days One', 'Trebuchet MS', Helvetica, sans-serif;
  --font-body: 'Montserrat', 'Helvetica Neue', Arial, sans-serif;

  --page: #f6f6f6;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --text: #333333;
  --text-secondary: #4c5166;
  --text-muted: #6b7083;
  --border: #e0dede;
  --border-strong: #c4c2c2;
  --track: #ebeaea;
  --gridline: #eeeeee;
  --axis: #c4c2c2;
  --link: #138039;
  --shadow: 0 4px 16px rgb(0 0 0 / 0.1);

  --brand: #1ea94a;
  --brand-strong: #138039;
  --on-brand: #ffffff;
  --danger: #b42318;
  --danger-bg: #fdf0ef;

  /* DLI bands: one-hue ordinal ramp, light → dark (validated vs #ffffff). */
  --band-low: #74c48b;
  --band-moderate: #1ea94a;
  --band-high: #138039;
  --band-very-high: #0a5626;

  /* Hourly chart series. */
  --series-forecast: #1a9a43;
  --series-clear: #d3ecd9;
  --series-cloud: #4c5166;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #17191e;
    --surface: #1f2229;
    --surface-raised: #2a2e37;
    --text: #eceef2;
    --text-secondary: #c2c6d2;
    --text-muted: #9ba0b0;
    --border: #343843;
    --border-strong: #4a4f5c;
    --track: #2c3039;
    --gridline: #2c3039;
    --axis: #4a4f5c;
    --link: #5fcf82;
    --shadow: 0 4px 16px rgb(0 0 0 / 0.5);

    --brand: #1ea94a;
    --brand-strong: #26c056;
    --on-brand: #ffffff;
    --danger: #ff8a80;
    --danger-bg: #3a1f1f;

    /* Dark mode ramp: deep → bright (validated vs #1f2229). */
    --band-low: #0f6a30;
    --band-moderate: #1ea94a;
    --band-high: #5fcf82;
    --band-very-high: #a6e8b9;

    --series-forecast: #3cc566;
    --series-clear: #2f4637;
    --series-cloud: #a3a9bb;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #17191e;
  --surface: #1f2229;
  --surface-raised: #2a2e37;
  --text: #eceef2;
  --text-secondary: #c2c6d2;
  --text-muted: #9ba0b0;
  --border: #343843;
  --border-strong: #4a4f5c;
  --track: #2c3039;
  --gridline: #2c3039;
  --axis: #4a4f5c;
  --link: #5fcf82;
  --shadow: 0 4px 16px rgb(0 0 0 / 0.5);

  --brand: #1ea94a;
  --brand-strong: #26c056;
  --on-brand: #ffffff;
  --danger: #ff8a80;
  --danger-bg: #3a1f1f;

  --band-low: #0f6a30;
  --band-moderate: #1ea94a;
  --band-high: #5fcf82;
  --band-very-high: #a6e8b9;

  --series-forecast: #3cc566;
  --series-clear: #2f4637;
  --series-cloud: #a3a9bb;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Shared pieces ---------- */

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
[data-band='low'] { background: var(--band-low); }
[data-band='moderate'] { background: var(--band-moderate); }
[data-band='high'] { background: var(--band-high); }
[data-band='very-high'] { background: var(--band-very-high); }

.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key.forecast { background: var(--series-forecast); }
.key.clear { background: var(--series-clear); }
.key.cloud { background: var(--series-cloud); }

/* ---------- App shell (app-root) ---------- */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.intro h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.2rem, 3.2vw, 1.6rem);
  color: var(--text);
}
.intro p { margin: 4px 0 0; color: var(--text-secondary); font-size: 0.9rem; }

.notice {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  font-size: 0.9rem;
}

.results { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; transition: opacity 150ms; }
.results.stale { opacity: 0.55; pointer-events: none; }

.location { margin: 0; font-size: 0.9rem; color: var(--text-secondary); }
.location strong { color: var(--text); }
.coords { color: var(--text-muted); font-size: 0.8rem; }

.skeleton { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.skeleton span {
  height: 150px;
  border-radius: 10px;
  background: var(--track);
  animation: pulse 1.2s ease-in-out infinite alternate;
}
@keyframes pulse { to { opacity: 0.45; } }

.bands {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.bands li { display: inline-flex; align-items: center; gap: 6px; }
.bands .range { color: var(--text-muted); }

.foot { font-size: 0.75rem; color: var(--text-muted); }
.foot p { margin: 0 0 4px; }
.foot a { color: var(--link); }

/* ---------- Postcode form (app-postcode-form) ---------- */

.postcode-form { display: grid; gap: 6px; }
.postcode-form label { font-weight: 600; font-size: 0.875rem; color: var(--text-secondary); }
.postcode-form .row { display: flex; gap: 8px; }
.postcode-form input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 1rem;
  text-transform: uppercase;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}
.postcode-form input::placeholder { text-transform: none; color: var(--text-muted); }
.postcode-form input:focus-visible,
.postcode-form button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.postcode-form input[aria-invalid] { border-color: var(--danger); }
.postcode-form button {
  flex: 0 0 auto;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: var(--on-brand);
}
.postcode-form button:hover:not(:disabled) { background: var(--brand-strong); }
.postcode-form button:disabled { opacity: 0.6; cursor: progress; }
.postcode-form .error { margin: 0; min-height: 1.25em; font-size: 0.875rem; color: var(--danger); }

/* ---------- 7-day cards (app-forecast-week) ---------- */

.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.week .day {
  display: grid;
  grid-template-rows: auto auto auto auto auto;
  gap: 6px;
  min-width: 0;
  padding: 12px 10px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 120ms, box-shadow 120ms;
}
.week .day:hover { border-color: var(--border-strong); }
.week .day:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.week .day.active {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.week .when { display: flex; flex-direction: column; }
.week .name { font-family: var(--font-display); font-size: 0.95rem; }
.week .date { font-size: 0.75rem; color: var(--text-muted); }

.week .value { display: flex; flex-direction: column; }
.week .dli {
  font-family: var(--font-display);
  font-size: 1.6rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.week .unit { font-size: 0.7rem; color: var(--text-muted); }

.week .band {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.week .meter {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
}
.week .fill { display: block; height: 100%; border-radius: 3px; }

.week .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ---------- Day detail + hourly chart (app-day-detail) ---------- */

.detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.detail .head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.15rem; }
.detail .condition { margin: 2px 0 0; font-size: 0.85rem; color: var(--text-muted); }

.detail .stats {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}
.detail .stat { min-width: 0; }
.detail .stat dt { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 2px; }
.detail .stat dd { margin: 0; font-variant-numeric: tabular-nums; color: var(--text); }
.detail .big { font-family: var(--font-display); font-size: 2rem; line-height: 1; }
.detail .unit { font-size: 0.75rem; color: var(--text-muted); }
.detail .sub { display: block; font-size: 0.75rem; color: var(--text-secondary); }
.detail .band {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.detail .chart-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 16px; }
.detail .chart-head h3 { margin: 0; font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }
.detail .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.detail .legend li { display: inline-flex; align-items: center; gap: 6px; }

.detail .chart-box { position: relative; width: 100%; min-width: 0; min-height: 60px; overflow: hidden; }
.detail svg { display: block; overflow: visible; touch-action: pan-y; }
.detail .grid { stroke: var(--gridline); stroke-width: 1; }
.detail .baseline { stroke: var(--axis); stroke-width: 1; }
.detail .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.detail .bar-clear { fill: var(--series-clear); }
.detail .bar-forecast { fill: var(--series-forecast); }
.detail .cloud { fill: var(--series-cloud); }
.detail .dim { opacity: 0.45; }
.detail .hit { fill: transparent; cursor: crosshair; }

.detail .tooltip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  display: grid;
  gap: 2px;
  min-width: 150px;
  padding: 8px 10px;
  font-size: 0.75rem;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  pointer-events: none;
  white-space: nowrap;
}
.detail .tooltip span { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.detail .tooltip .key { width: 8px; height: 8px; }

.detail .empty { margin: 0; color: var(--text-muted); font-size: 0.85rem; }

.detail .link {
  justify-self: start;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: var(--link);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}
.detail .link:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.detail .table-wrap { overflow-x: auto; }
.detail table { width: 100%; border-collapse: collapse; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.detail th,
.detail td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.detail th:first-child { text-align: left; }
.detail thead th { font-weight: 600; color: var(--text-secondary); }
.detail tbody th { font-weight: 400; }

/* ---------- Responsive ---------- */

/* Medium widths: let day cards wrap. */
@media (max-width: 760px) {
  .week { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

@media (max-width: 640px) {
  .detail { padding: 12px; }
  .detail .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail .hero { grid-column: 1 / -1; }
}

/* Phones: one compact row per day. */
@media (max-width: 480px) {
  .skeleton { grid-template-columns: 1fr; }
  .skeleton span { height: 52px; }

  .week { grid-template-columns: 1fr; gap: 6px; }
  .week .day {
    grid-template-columns: 4.2rem 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 10px;
    row-gap: 6px;
    padding: 10px 12px;
  }
  .week .when { grid-column: 1; grid-row: 1 / span 2; }
  .week .value { grid-column: 2; grid-row: 1; flex-direction: row; align-items: baseline; gap: 6px; }
  .week .dli { font-size: 1.35rem; }
  .week .band { grid-column: 3; grid-row: 1; justify-self: end; }
  .week .meter { grid-column: 2; grid-row: 2; }
  .week .meta { grid-column: 3; grid-row: 2; justify-self: end; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton span { animation: none; }
  .results, .week .day { transition: none; }
}
