/* Grandine - hail risk for Italy.
   Palette is defined once on :root and overridden for dark mode; the risk-band
   colours are shared by the gauge, the day strip, the chart and the monthly bars
   so a colour means exactly one thing everywhere in the UI. */

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d8dee6;
  --text: #16202b;
  --text-dim: #5d6b7a;
  --accent: #1f6feb;

  --band-low: #2f9e5f;
  --band-moderate: #d9a326;
  --band-high: #e2701e;
  --band-very_high: #cc2f2f;

  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #11161c;
    --surface: #1a2129;
    --surface-2: #222b35;
    --border: #2f3a46;
    --text: #e6edf3;
    --text-dim: #93a1b1;
    --accent: #4c9aff;

    --band-low: #3fb977;
    --band-moderate: #e5b641;
    --band-high: #f0853c;
    --band-very_high: #e85555;

    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

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

header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.02em;
}

header .tagline {
  color: var(--text-dim);
  font-size: 13px;
  flex: 1;
  min-width: 180px;
}

.lang-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.lang-toggle button {
  border: 0;
  background: var(--surface);
  color: var(--text-dim);
  padding: 5px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.lang-toggle button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

/* ---------- layout ---------- */

main {
  display: grid;
  grid-template-columns: minmax(320px, 4fr) minmax(360px, 5fr);
  gap: 16px;
  padding: 16px 20px 32px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 940px) {
  main { grid-template-columns: 1fr; }
}

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

.card h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.left-col, .right-col { min-width: 0; }

/* ---------- search / controls ---------- */

.search-row { display: flex; gap: 8px; margin-bottom: 10px; }

.search-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

button.primary, .search-row button {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

button.primary:disabled { opacity: 0.55; cursor: default; }

/* The suggestion list floats over the content below rather than pushing it
   down: the map must not jump a row every time a letter is typed. */
.search-wrap { position: relative; flex: 1; min-width: 0; }
.search-wrap input { width: 100%; }

.geo-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1200;              /* above Leaflet's panes and controls */
  list-style: none;
  margin: 0;
  padding: 4px 0;
  max-height: 264px;          /* ~7 rows, then it scrolls */
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.geo-results li {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
}
.geo-results li.active,
.geo-results li:hover { background: var(--surface-2); }
.geo-results .geo-name { font-weight: 600; }
.geo-results mark {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}
.geo-results .muted { color: var(--text-dim); font-size: 12px; }
.geo-results .geo-empty {
  cursor: default;
  color: var(--text-dim);
}
.geo-results .geo-empty:hover { background: none; }
.geo-results .geo-empty.is-error { color: var(--band-very_high); }

/* ---------- device location ---------- */

.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .pin::before { content: "\1F4CD"; }
.icon-btn.busy { cursor: progress; }
/* Swap the pin for a spinner in place, so the row does not resize while the
   device thinks about it. */
.icon-btn.busy .pin::before {
  content: "";
  display: block;
  width: 13px;
  height: 13px;
  margin: 0 auto;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.geo-status {
  margin: -4px 0 10px;
  font-size: 12px;
  color: var(--text-dim);
}
.geo-status.is-error { color: var(--band-very_high); }

/* The provider's own words, kept but demoted: the translated sentence above
   them is the one that tells the user what to do. */
.error-detail { display: block; margin-top: 4px; opacity: 0.75; font-size: 12px; }

.model-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
}

/* ---------- model picker + explanation bubble ---------- */

.controls-card { position: relative; z-index: 500; }

.model-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.info-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-dim);
  font: 700 11px/1 "Georgia", serif;
  cursor: pointer;
}
.info-btn:hover { color: var(--accent); border-color: var(--accent); }

.model-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

/* Anchored to the card, not to the little "i": the field sits well inside the
   left column, and a 360 px panel hung off it runs straight off the page. */
.model-info {
  position: absolute;
  top: calc(100% + 6px);
  left: 14px;
  right: 14px;
  z-index: 1200;
  width: auto;
  max-width: 420px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  text-align: left;
}
.model-info h3 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.model-row {
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.model-row:first-of-type { border-top: 0; padding-top: 0; }
.model-row-head { display: flex; align-items: center; gap: 8px; }
.model-pick {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.model-pick:hover { text-decoration: underline; }
.model-current {
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.model-row.current { background: var(--surface-2); border-radius: 7px; padding: 8px 8px; }
.model-summary { margin: 4px 0 6px; color: var(--text); }
.model-specs {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  margin: 0;
  color: var(--text-dim);
}
.model-specs dt { font-weight: 600; }
.model-specs dd { margin: 0; }
.model-warning {
  margin: 10px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
}

.model-row select {
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

#map {
  height: 380px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  z-index: 0;
}

.map-hint { color: var(--text-dim); font-size: 12px; margin-top: 8px; }

/* ---------- gauge ---------- */

.gauge {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.gauge-number {
  font-size: 54px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.gauge-meta { flex: 1; min-width: 150px; }

.band-pill {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.03em;
}

.gauge-sub { color: var(--text-dim); font-size: 12.5px; margin-top: 6px; }

.hail-flag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 4px 9px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--band-very_high) 16%, transparent);
  border: 1px solid var(--band-very_high);
  color: var(--band-very_high);
  font-size: 12px;
  font-weight: 600;
}

/* ---------- 7-day strip ---------- */

.day-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

@media (max-width: 520px) {
  .day-strip { grid-template-columns: repeat(4, 1fr); }
}

.day {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.12s, transform 0.12s;
}

.day:hover { transform: translateY(-1px); }
.day[aria-selected="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.day .dow { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.day .dnum { font-size: 11px; color: var(--text-dim); }
.day .dval {
  font-size: 19px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
}
.day .dbar { height: 3px; border-radius: 2px; margin-top: 6px; }

/* A day the model stopped inside: the figure is real but partial, so the card
   is dimmed and labelled rather than shown as an equal member of the week. */
.day.partial { border-style: dashed; }
.day.partial .dval { opacity: 0.65; }
.day .dpartial {
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ---------- drivers ---------- */

.driver { margin-bottom: 9px; }

.driver-head {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 3px;
}

.driver-head .val { color: var(--text-dim); font-variant-numeric: tabular-nums; }

.driver-track {
  height: 7px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.driver-fill { height: 100%; border-radius: 4px; }

.raw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.raw-item .k { font-size: 11px; color: var(--text-dim); }
.raw-item .v { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* A field the model does not publish. The value is dimmed so it does not read
   as a measurement; the reason follows under the grid so it does not read as a
   bug, and so one wrapped explanation cannot stretch a whole row of cells. */
.raw-item.absent .v { color: var(--text-dim); font-weight: 500; }
.raw-footnote {
  margin-top: 8px;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--text-dim);
}

/* Constrains the Chart.js canvas; see the comment in index.html. */
.chart-box { position: relative; height: 190px; }

/* ---------- climatology ---------- */

.clim-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.clim-big { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.clim-unit { color: var(--text-dim); font-size: 12.5px; }

.month-bars {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-top: 12px;
}

.month-bar { text-align: center; }
.month-bar .track {
  height: 54px;
  background: var(--surface-2);
  border-radius: 5px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.month-bar .fill { width: 100%; border-radius: 5px 5px 0 0; }
.month-bar .lbl { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.month-bar .num { font-size: 11px; font-variant-numeric: tabular-nums; }

/* ---------- briefing ---------- */

.briefing-text { white-space: pre-wrap; font-size: 13.5px; line-height: 1.62; }

.notice {
  padding: 9px 11px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12.5px;
}

.error {
  padding: 9px 11px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--band-very_high) 12%, transparent);
  border: 1px solid var(--band-very_high);
  color: var(--text);
  font-size: 12.5px;
}

/* ---------- methodology ---------- */

details.methodology { margin-top: 4px; }

details.methodology summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 4px 0;
}

details.methodology .body { font-size: 12.5px; color: var(--text-dim); }
details.methodology p { margin: 8px 0; }

footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 0 20px 28px;
}

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 7px;
}

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

.hidden { display: none !important; }

/* The API's own error text, shown under a translated notice. */
.notice-detail {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  opacity: 0.85;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-word;
}

/* ---------- plain-language narrative ---------- */

#narrative p { margin: 0 0 10px; }
#narrative p:last-child { margin-bottom: 0; }

.narr-headline { font-size: 15.5px; font-weight: 600; line-height: 1.45; }
.narr-why { font-size: 13.5px; line-height: 1.6; }

.narr-advice {
  font-size: 13.5px;
  line-height: 1.55;
  padding: 9px 11px;
  border-radius: 7px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
}

.narr-outlook, .narr-history { font-size: 13px; color: var(--text-dim); line-height: 1.55; }

.narr-disclaimer {
  font-size: 11.5px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 9px;
  line-height: 1.5;
}

/* ---------- plain-language factors ---------- */

.drivers-intro {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.factor { margin-bottom: 13px; }
.factor:last-of-type { margin-bottom: 4px; }

.factor-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.factor-name { font-size: 13.5px; font-weight: 600; }
.factor-level { font-size: 12.5px; font-weight: 700; white-space: nowrap; }

.factor-tag {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: 1px;
}

.factor-tag.limiting {
  background: color-mix(in srgb, var(--band-low) 18%, transparent);
  color: var(--band-low);
  border: 1px solid var(--band-low);
}

.factor-tag.supporting {
  background: color-mix(in srgb, var(--band-very_high) 15%, transparent);
  color: var(--band-very_high);
  border: 1px solid var(--band-very_high);
}

.factor-hint { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; line-height: 1.45; }

details.technical { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }

details.technical summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}

details.technical .raw-grid { border-top: 0; margin-top: 10px; padding-top: 0; }
