/* A map fills the window; every control is a floating panel over it. Panels
   share one surface treatment so they read as one instrument rather than four
   unrelated widgets. */

:root {
  --surface: rgba(255, 255, 255, 0.94);
  --surface-solid: #ffffff;
  --ink: #14202b;
  --ink-muted: #5a6b7a;
  --line: rgba(20, 32, 43, 0.14);
  --accent: #1d91c0;
  --shadow: 0 2px 4px rgba(16, 27, 37, 0.08), 0 8px 24px rgba(16, 27, 37, 0.12);
  --radius: 10px;
  --gap: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: rgba(20, 27, 34, 0.94);
    --surface-solid: #141b22;
    --ink: #e8eef4;
    --ink-muted: #93a4b3;
    --line: rgba(232, 238, 244, 0.16);
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

#map {
  position: absolute;
  inset: 0;
  background: #dfe6ec;
}

@media (prefers-color-scheme: dark) {
  #map { background: #10161c; }
}

.panel {
  position: absolute;
  z-index: 500;
  padding: 10px 12px;
  background: var(--surface);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel[hidden] { display: none; }

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

.panel--head {
  top: var(--gap);
  left: 56px;              /* clears Leaflet's zoom control */
  max-width: min(340px, calc(100vw - 72px));
}

#title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
}

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

.panel--controls {
  top: var(--gap);
  right: var(--gap);
  width: 216px;
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--ink-muted);
}

.field--check {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.field select {
  width: 100%;
  padding: 5px 6px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 6px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

output { font-variant-numeric: tabular-nums; }

/* --- legend ------------------------------------------------------------- */

.panel--legend {
  right: var(--gap);
  bottom: 132px;
  padding: 6px;
  line-height: 0;
  margin: 0;
}

#legend-img {
  display: block;
  max-width: 220px;
  height: auto;
  border-radius: 4px;
  /* OWS renders legends on white; invert-free blending keeps them readable on
     the dark surface without distorting the ramp colours. */
  background: #ffffff;
}

/* --- time --------------------------------------------------------------- */

.panel--time {
  left: 50%;
  bottom: var(--gap);
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 2 * var(--gap)));
  display: grid;
  gap: 6px;
}

.time-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  flex: none;
  width: 28px;
  height: 28px;
  font-size: 12px;
  color: var(--ink);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

.time-label {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.time-count {
  flex: none;
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

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

.panel--status {
  left: 50%;
  top: var(--gap);
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 2 * var(--gap)));
  font-size: 13px;
}

.panel--status.is-error {
  border-color: #c0392b;
  color: #c0392b;
}

/* --- popups ------------------------------------------------------------- */

.leaflet-popup-content-wrapper {
  border-radius: 8px;
  background: var(--surface-solid);
  color: var(--ink);
}

.leaflet-popup-tip { background: var(--surface-solid); }

.fi-value {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.fi-unit { font-size: 13px; font-weight: 400; color: var(--ink-muted); }

.fi-meta {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
}

.leaflet-container { font: inherit; }

/* The basemap, drained. OSM's own styling -- green landcover, coloured roads --
   competes with an evapotranspiration ramp for the eye, and the ramp is the point
   of this page. Scoped to the basemap layer, never to .leaflet-tile-pane: the WMS
   data shares that pane, and filtering it would change what the colours mean. */
.viewer-basemap {
  filter: grayscale(1) brightness(1.1) contrast(0.85);
}

/* Dark mode had a dark basemap from CARTO. OSM publishes none, so it is made:
   inverting a grey map gives a dark one, and the hue rotation keeps what little
   colour survives from coming back as its opposite. */
.viewer-basemap-dark {
  filter: grayscale(1) invert(1) brightness(0.85) contrast(0.9) hue-rotate(180deg);
}

/* Narrow screens: stack the panels instead of overlapping them. */
@media (max-width: 620px) {
  .panel--controls { width: 160px; }
  .panel--head { max-width: calc(100vw - 240px); }
  .panel--legend { bottom: 128px; }
  #legend-img { max-width: 150px; }
}
