/* Northern Sardinia algae forecast.
   Colour roles come from a validated palette: categorical slots 1-3 for the
   three index components, a single-hue blue sequential ramp for magnitude,
   and reserved status tokens for the bands. Dark mode is selected, not
   flipped: the sequential ramp reverses so that "far from the surface"
   always means "more". */

:root {
  color-scheme: light;

  --plane:          #f9f9f7;
  --surface-1:      #fcfcfb;
  --surface-2:      #f2f1ed;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --shadow:         0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px rgba(11, 11, 11, 0.04);

  --series-1:       #2a78d6;  /* suspended cells */
  --series-2:       #eb6834;  /* wrack */
  --series-3:       #1baf7a;  /* benthic stock */

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  /* Sequential blue, low -> high magnitude (darker = more) */
  --seq-1: #cde2fb; --seq-2: #b7d3f6; --seq-3: #9ec5f4; --seq-4: #86b6ef;
  --seq-5: #6da7ec; --seq-6: #5598e7; --seq-7: #3987e5; --seq-8: #256abf;
  --seq-9: #1c5cab; --seq-10: #184f95;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;

    /* Reversed: on a dark surface, brighter = more */
    --seq-1: #10406f; --seq-2: #14497f; --seq-3: #18538f; --seq-4: #1c5cab;
    --seq-5: #256abf; --seq-6: #2a78d6; --seq-7: #3987e5; --seq-8: #5598e7;
    --seq-9: #86b6ef; --seq-10: #b7d3f6;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0d0d0d;
  --surface-1:      #1a1a19;
  --surface-2:      #232322;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --shadow:         none;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --seq-1: #10406f; --seq-2: #14497f; --seq-3: #18538f; --seq-4: #1c5cab;
  --seq-5: #256abf; --seq-6: #2a78d6; --seq-7: #3987e5; --seq-8: #5598e7;
  --seq-9: #86b6ef; --seq-10: #b7d3f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---------- header ---------- */

header.top {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  gap: 16px 24px; margin-bottom: 20px;
}
header.top h1 {
  margin: 0; font-size: 25px; font-weight: 640; letter-spacing: -0.015em;
}
header.top .sub {
  margin: 2px 0 0; color: var(--text-secondary); font-size: 14px; max-width: 62ch;
}
header.top .meta {
  margin-left: auto; text-align: right; color: var(--text-muted);
  font-size: 12.5px; line-height: 1.45;
}
.theme-toggle {
  background: var(--surface-1); color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); }

/* ---------- filter row ---------- */

.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin: 0 0 20px;
}
.filters .label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin-right: 2px;
}
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.day-chip {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 11px; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--text-secondary);
  display: flex; flex-direction: column; align-items: center; min-width: 62px;
  line-height: 1.25;
}
.day-chip .dow { font-weight: 600; color: var(--text-primary); font-size: 12.5px; }
.day-chip .dnum { font-size: 11.5px; color: var(--text-muted); }
.day-chip:hover { background: var(--surface-2); }
.day-chip[aria-pressed="true"] {
  border-color: var(--series-1);
  box-shadow: inset 0 0 0 1px var(--series-1);
}
.spacer { flex: 1 1 auto; }
.view-toggle { display: flex; gap: 6px; }

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

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 18px;
  position: relative; /* tooltip containing block */
}
.card > h2 {
  margin: 0 0 3px; font-size: 15.5px; font-weight: 620;
  letter-spacing: -0.005em;
}
.card > .note {
  margin: 0 0 16px; color: var(--text-secondary); font-size: 13px; max-width: 78ch;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }

/* ---------- hero + stat tiles ---------- */

.hero-row {
  display: grid; grid-template-columns: minmax(240px, 1.25fr) repeat(3, 1fr);
  gap: 18px; margin-bottom: 18px;
}
.hero-row > * { margin-bottom: 0; }
.hero .label, .tile .label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.055em;
  color: var(--text-muted); margin-bottom: 6px;
}
.hero .figure {
  font-size: 52px; font-weight: 660; line-height: 1; letter-spacing: -0.03em;
}
.hero .where { margin-top: 8px; font-size: 14px; color: var(--text-secondary); }
.hero .where strong { color: var(--text-primary); font-weight: 600; }
.tile .value {
  font-size: 27px; font-weight: 620; line-height: 1.1; letter-spacing: -0.02em;
}
.tile .value .unit {
  font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-left: 2px;
}
.tile .foot { margin-top: 5px; font-size: 12.5px; color: var(--text-muted); }

/* ---------- status chips ---------- */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 560; color: var(--text-primary);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 10px 3px 8px; white-space: nowrap;
}
.chip .dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
}
.chip svg { width: 13px; height: 13px; flex: none; }
.s-good     { color: var(--status-good); }
.s-warning  { color: var(--status-warning); }
.s-serious  { color: var(--status-serious); }
.s-critical { color: var(--status-critical); }
.bg-good     { background: var(--status-good); }
.bg-warning  { background: var(--status-warning); }
.bg-serious  { background: var(--status-serious); }
.bg-critical { background: var(--status-critical); }

/* ---------- ranked lists ---------- */

.rank { list-style: none; margin: 0; padding: 0; }
.rank li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  align-items: center; padding: 9px 0; border-top: 1px solid var(--grid);
  cursor: pointer;
}
.rank li:first-child { border-top: none; }
.rank li:hover .rname { color: var(--series-1); }
.rname { font-size: 13.5px; font-weight: 540; }
.rzone { grid-column: 1; font-size: 11.5px; color: var(--text-muted); }
.rval {
  grid-row: 1 / span 2; grid-column: 2; text-align: right;
  font-size: 19px; font-weight: 620; font-variant-numeric: tabular-nums;
}
.rval small { display: block; font-size: 11px; font-weight: 500; color: var(--text-muted); }
.meter {
  grid-column: 1 / -1; height: 6px; border-radius: 3px;
  background: var(--seq-1); overflow: hidden; margin-top: 3px;
}
.meter > span { display: block; height: 100%; border-radius: 3px; }

/* ---------- heatmap ---------- */

.heat { width: 100%; overflow-x: auto; }
.heat table { border-collapse: separate; border-spacing: 2px; min-width: 660px; }
.heat th {
  font-size: 11.5px; font-weight: 560; color: var(--text-muted);
  text-align: center; padding: 0 0 4px; font-variant-numeric: tabular-nums;
}
.heat th.rowhead {
  text-align: left; font-weight: 540; color: var(--text-primary);
  font-size: 12.5px; padding: 0 10px 0 0; white-space: nowrap;
  position: sticky; left: 0; background: var(--surface-1); z-index: 1;
  cursor: pointer;
}
.heat th.rowhead:hover { color: var(--series-1); }
.heat th.zonehead {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); padding: 12px 0 2px;
  position: sticky; left: 0; background: var(--surface-1);
}
.heat td {
  width: 62px; height: 30px; text-align: center; border-radius: 4px;
  font-size: 12px; font-weight: 560; font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.heat td:hover { outline: 2px solid var(--text-primary); outline-offset: -2px; }

.scale { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.scale .steps { display: flex; gap: 2px; }
.scale .steps i { width: 22px; height: 9px; border-radius: 2px; display: block; }
.scale .cap { font-size: 11.5px; color: var(--text-muted); }

/* ---------- map ---------- */

.map-wrap { position: relative; }
.map-wrap svg { width: 100%; height: auto; display: block; }

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

.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.small-mults { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.small-mults .sm-title {
  font-size: 12.5px; font-weight: 560; margin-bottom: 1px;
}
.small-mults .sm-sub { font-size: 11.5px; color: var(--text-muted); margin-bottom: 6px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0 0 12px; }
.legend .item {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-secondary);
}
/* Mirrors the mark it labels: a line-key for line series. 3px so it is
   actually visible at legend size — a 2px key reads as empty space. */
.legend .key { width: 16px; height: 3px; border-radius: 1.5px; flex: none; }
.legend .key.rect { height: 10px; width: 10px; border-radius: 2px; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 20;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-width: 128px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  font-size: 12.5px; opacity: 0; transition: opacity 0.09s;
}
.tooltip.on { opacity: 1; }
.tooltip .tt-head {
  font-size: 11.5px; color: var(--text-muted); margin-bottom: 5px;
}
.tooltip .tt-row {
  display: flex; align-items: baseline; gap: 7px; margin-top: 3px;
}
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tt-val {
  font-weight: 620; color: var(--text-primary); font-variant-numeric: tabular-nums;
}
.tooltip .tt-name { color: var(--text-secondary); font-size: 12px; }

/* ---------- detail ---------- */

.detail-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px 14px;
  margin-bottom: 4px;
}
.detail-head h2 { margin: 0; font-size: 18px; font-weight: 640; }
.detail-head .zone { color: var(--text-muted); font-size: 13px; }
.close-btn {
  margin-left: auto; background: none; border: 1px solid var(--border);
  border-radius: 999px; width: 26px; height: 26px; cursor: pointer;
  color: var(--text-secondary); font: inherit; line-height: 1;
}
.close-btn:hover { background: var(--surface-2); }
.traits { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }
.traits .t {
  font-size: 11.5px; color: var(--text-secondary); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px;
}
.driver-grid { margin-top: 18px; }

/* ---------- table view ---------- */

table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data th, table.data td {
  text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
table.data th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 560; white-space: nowrap;
}
table.data th:first-child, table.data td:first-child,
table.data th:nth-child(2), table.data td:nth-child(2) {
  text-align: left; font-variant-numeric: normal;
}
table.data tbody tr:hover { background: var(--surface-2); }
.table-scroll { overflow-x: auto; }

/* ---------- method ---------- */

.method h3 {
  font-size: 13.5px; font-weight: 600; margin: 18px 0 4px;
}
.method p, .method li {
  color: var(--text-secondary); font-size: 13.5px; margin: 0 0 8px;
}
.method ul { margin: 0; padding-left: 20px; }
.method a { color: var(--series-1); }
.disclaimer {
  border-left: 2px solid var(--status-warning);
  padding: 2px 0 2px 12px; margin: 14px 0 0;
}
.disclaimer p { margin: 0; color: var(--text-primary); font-size: 13.5px; }

footer.foot {
  margin-top: 22px; color: var(--text-muted); font-size: 12.5px;
  display: flex; flex-wrap: wrap; gap: 4px 16px;
}
footer.foot a { color: var(--text-secondary); }

.loading, .errbox {
  padding: 40px 20px; text-align: center; color: var(--text-secondary);
}
.errbox { color: var(--status-critical); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (max-width: 980px) {
  .hero-row { grid-template-columns: 1fr 1fr; }
  .small-mults { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .wrap { padding: 18px 14px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .hero-row { grid-template-columns: 1fr; }
  header.top .meta { margin-left: 0; text-align: left; }
  .hero .figure { font-size: 44px; }

  /* Fit all seven days on a phone. At the desktop cell width the table is
     660px wide, so a 320px viewport showed the beach name and two days —
     useless for the view whose whole job is comparing across the week.
     Names truncate instead; the row is tappable for the full breakdown. */
  .card { padding: 16px 14px; }
  .heat table { min-width: 0; width: 100%; }
  .heat td { width: auto; min-width: 27px; height: 27px; font-size: 11px; }
  .heat th { font-size: 10.5px; }
  .heat th.rowhead {
    font-size: 11px; max-width: 96px; padding-right: 6px;
    overflow: hidden; text-overflow: ellipsis;
  }
}
