:root {
  --navy: #00385e;
  --navy-soft: #0a4a72;
  --header-top: #084066;
  --header-mid: #3a769d;
  --header-bottom: #6dacd4;
  --sky: #64c0ff;
  --sky-bright: #50afff;
  --sky-deep: #36adff;
  --sky-light: #d1ecff;
  --sky-pale: #eef8ff;
  --sky-tint: rgb(100 192 255 / 12%);
  --text: #404757;
  --muted: #858a96;
  --surface: #ffffff;
  --surface-alt: #f7fbff;
  --border: rgb(100 192 255 / 22%);
  --border-strong: rgb(0 56 94 / 10%);
  --accent: var(--sky-deep);
  --accent-dark: var(--navy);
  --danger: #c53030;
  --shadow-sm: 0 2px 8px rgb(0 56 94 / 6%);
  --shadow-md: 0 8px 28px rgb(0 56 94 / 10%);
  --radius: 14px;
  --radius-sm: 10px;
  --table-stripe-a: var(--surface);
  --table-stripe-b: var(--surface-alt);
  --table-stripe-hover: var(--sky-pale);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: Montserrat, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--sky-pale);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 2.75rem;
  border: 0;
  border-radius: 999px;
  padding: 0 1.25rem;
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--sky-bright), var(--sky-deep));
  box-shadow: 0 4px 14px rgb(54 173 255 / 28%);
  cursor: pointer;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgb(54 173 255 / 34%);
  background: linear-gradient(135deg, var(--sky), var(--navy-soft));
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

.secondary-button {
  border: 1px solid var(--border-strong);
  color: var(--navy);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.secondary-button:hover {
  color: var(--navy);
  background: var(--sky-light);
  box-shadow: var(--shadow-sm);
}

input,
select {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  color: var(--text);
  background: var(--surface);
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--sky);
  box-shadow: 0 0 0 3px rgb(100 192 255 / 22%);
}

label {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.label-with-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.site-header {
  position: relative;
  color: #fff;
  background: linear-gradient(
    to bottom,
    var(--header-top) 0%,
    var(--header-mid) 50%,
    var(--header-bottom) 100%
  );
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.35rem clamp(1rem, 3vw, 2rem) 2.5rem;
}

.brand {
  display: flex;
  flex-shrink: 0;
  align-items: center;
}

.brand img {
  display: block;
  width: min(180px, 42vw);
  height: auto;
  filter: drop-shadow(0 2px 8px rgb(0 0 0 / 12%));
}

.header-text {
  flex: 1;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: rgb(255 255 255 / 82%);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.header-text h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.4vw, 2rem);
  font-weight: 700;
  line-height: 1.15;
}

.api-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.55rem 0 0;
  border-radius: 999px;
  padding: 0.28rem 0.75rem 0.28rem 0.55rem;
  color: rgb(255 255 255 / 92%);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  background: rgb(255 255 255 / 14%);
}

.api-status::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: rgb(255 255 255 / 55%);
}

.api-status.online::before {
  background: #68d391;
  box-shadow: 0 0 0 3px rgb(104 211 145 / 28%);
}

.api-status.offline::before {
  background: #fc8181;
  box-shadow: 0 0 0 3px rgb(252 129 129 / 28%);
}

.refresh-button {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border-strong);
  color: var(--navy);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.refresh-button:hover {
  color: var(--navy);
  background: var(--sky-light);
}

.home-button {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.75rem;
  border: 1px solid rgb(255 255 255 / 28%);
  border-radius: 999px;
  padding: 0 1.25rem;
  color: var(--navy);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  background: rgb(255 255 255 / 94%);
  box-shadow: var(--shadow-sm);
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease;
}

.home-button:hover {
  color: var(--navy);
  background: #fff;
  transform: translateY(-1px);
}

.home-icon,
.refresh-icon,
.export-icon {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
}

.export-button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.header-wave {
  display: block;
  width: 100%;
  height: 2.5rem;
  margin-top: -1px;
  color: var(--sky-pale);
}

.layout {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1.65fr) minmax(18rem, 1fr);
  grid-template-areas:
    "map sidebar"
    "kpi kpi"
    "history history";
  gap: 1.25rem;
  max-width: 76rem;
  width: 100%;
  margin: 0 auto;
  padding: 0.5rem clamp(1rem, 3vw, 2rem) 2rem;
}

.map-panel {
  display: grid;
  grid-area: map;
  grid-template-rows: auto minmax(24rem, 1fr) auto;
  min-width: 0;
  min-height: 100%;
}

.sidebar {
  display: flex;
  grid-area: sidebar;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar .panel {
  min-height: 0;
}

.kpi-panel {
  grid-area: kpi;
}

.history-panel {
  grid-area: history;
}

.history-panel .panel-heading {
  margin-bottom: 0.9rem;
}

.history-data-section {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  background: var(--surface-alt);
}

.history-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 0.8rem 1.25rem;
}

.history-controls {
  display: grid;
  gap: 0.75rem;
}

.history-date-controls {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.history-chart {
  min-width: 0;
}

.history-table-section {
  margin-top: 1.7rem;
  border-top: 1px solid var(--border);
  padding-top: 1.35rem;
}

.history-section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem 1.25rem;
  margin-bottom: 0.85rem;
}

.history-section-heading h3 {
  margin: 0;
  color: var(--navy);
  font-size: 1rem;
  font-weight: 700;
}

.section-subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.wide {
  grid-column: 1 / -1;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.1rem;
}

.panel-heading h2 {
  margin: 0;
  color: var(--navy);
  font-size: 1.2rem;
  font-weight: 700;
}

.panel-subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
}

.readings-toolbar {
  align-items: end;
}

.readings-range {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.8rem;
}

.readings-range-field {
  display: grid;
  gap: 0.35rem;
  flex: 1 1 9rem;
  min-width: 8.5rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.readings-range-field input {
  min-height: 2.5rem;
}

.history-quick-ranges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.quick-range-label {
  margin-right: 0.1rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.range-chip {
  min-height: 2rem;
  border: 1px solid var(--border-strong);
  padding: 0 0.75rem;
  color: var(--navy);
  font-size: 0.78rem;
  letter-spacing: 0;
  background: var(--surface);
  box-shadow: none;
}

.range-chip:hover {
  color: var(--navy);
  background: var(--sky-light);
  box-shadow: none;
}

.station-map {
  width: 100%;
  min-width: 0;
  min-height: 24rem;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--sky-light);
}

.station-detail {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.station-detail-card {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.95rem 1rem;
  background: var(--surface-alt);
}

.station-detail-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.station-detail-card strong {
  color: var(--navy);
  font-size: 1rem;
}

.station-detail-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.station-detail-coords {
  font-variant-numeric: tabular-nums;
}

.upload-water-button {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.45rem;
}

.upload-icon {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
}

.water-data-dialog {
  width: min(58rem, calc(100vw - 2rem));
  max-height: min(46rem, calc(100vh - 2rem));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  color: var(--text);
  background: transparent;
  overflow: visible;
}

.water-data-dialog::backdrop {
  background: rgb(13 35 54 / 0.48);
}

.water-upload-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-height: min(46rem, calc(100vh - 2rem));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.water-upload-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
}

.source-badge {
  display: inline-flex;
  align-self: start;
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  color: var(--navy);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.source-smartcitizen {
  background: rgb(217 119 6 / 16%);
}

.source-water {
  background: rgb(54 173 255 / 18%);
}

.source-arduino {
  background: rgb(13 148 136 / 16%);
}

.kpi-strip {
  min-width: 0;
}

.kpi-carousel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: stretch;
}

.kpi-carousel-static {
  grid-template-columns: minmax(0, 1fr);
}

.kpi-carousel-viewport {
  container-type: inline-size;
  overflow: hidden;
  scrollbar-width: none;
  min-width: 0;
}

.kpi-carousel-viewport::-webkit-scrollbar {
  display: none;
}

.kpi-carousel-track {
  --kpi-visible: 5;
  --kpi-gap: 0.85rem;

  display: flex;
  gap: var(--kpi-gap);
  width: max-content;
  will-change: transform;
}

.kpi-carousel-track::-webkit-scrollbar {
  display: none;
}

.kpi-carousel-btn {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  align-self: center;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--navy);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.kpi-carousel-btn svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: currentColor;
}

.kpi-carousel-btn:hover {
  color: var(--navy);
  background: var(--sky-light);
}

.kpi-empty {
  margin: 0;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  text-align: center;
  background: var(--surface-alt);
}

.kpi-card {
  flex: 0 0 calc((100cqw - (var(--kpi-visible) - 1) * var(--kpi-gap)) / var(--kpi-visible));
  min-width: 10.5rem;
  display: grid;
  grid-template-rows: 2.4rem auto auto;
  gap: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  background: var(--surface-alt);
  border-top: 4px solid var(--sky-deep);
}

.kpi-card.status-good,
.kpi-card.status-warn,
.kpi-card.status-bad,
.kpi-card.status-neutral {
  border-top-color: var(--sky-deep);
}

.kpi-label-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.35rem;
  min-height: 2.4rem;
}

.kpi-label {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.metric-hint {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--sky-deep);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  transition: color 140ms ease;
}

.metric-hint:hover,
.metric-hint:focus-visible {
  color: var(--navy);
  outline: none;
}

.metric-hint-popup {
  position: fixed;
  z-index: 40;
  max-width: 14rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--navy);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.4;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  pointer-events: none;
}

.metric-hint-popup[hidden] {
  display: none;
}

.upload-access {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  background: var(--surface-alt);
}

.kpi-value {
  color: var(--navy);
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.kpi-recorded {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.chart-wrap {
  position: relative;
  height: 18rem;
}

.chart-control {
  display: grid;
  gap: 0.35rem;
  min-width: 13rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chart-control select {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.form-grid button,
.form-grid .full {
  grid-column: 1 / -1;
}

.forms-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(16rem, 1fr);
  gap: 1rem;
  align-items: stretch;
}

.preview-box {
  grid-column: 1 / -1;
}

.manual-entry-box,
.upload-box {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.1rem;
  background: var(--surface-alt);
}

.manual-entry-form,
.csv-form {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.9rem;
}

.manual-entry-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.manual-entry-form button[type="submit"],
.csv-form button[type="submit"] {
  margin-top: auto;
}

.manual-entry-box h4,
.upload-box h4 {
  margin: 0;
  color: var(--navy);
  font-size: 0.86rem;
  font-weight: 700;
}

.csv-form {
  min-height: 0;
}

.preview-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.1rem;
  background: var(--surface);
}

.preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
}

.preview-heading small,
.preview-group-heading small,
.preview-metric small {
  display: block;
  color: var(--muted);
}

.preview-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.preview-stats span {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  color: var(--navy-soft);
  background: var(--sky-tint);
  font-size: 0.82rem;
  font-weight: 600;
}

.preview-list {
  display: grid;
  gap: 0.75rem;
}

.preview-note {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.preview-note:last-child {
  margin: 0.85rem 0 0;
}

.preview-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-alt);
}

.preview-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.85rem;
  background: var(--sky-tint);
}

.preview-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1px;
  background: var(--border);
}

.preview-metric {
  min-height: 5.3rem;
  border-left: 4px solid var(--border-strong);
  padding: 0.7rem 0.85rem;
  background: #fff;
}

.preview-metric span,
.preview-metric strong,
.preview-metric small {
  display: block;
}

.preview-metric span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.preview-metric strong {
  margin-top: 0.25rem;
  color: var(--navy);
}

.preview-metric.new {
  border-left-color: #38a169;
}

.preview-metric.duplicate {
  border-left-color: var(--muted);
}

.preview-metric.conflict,
.preview-metric.invalid {
  border-left-color: var(--danger);
}

.measurement-list {
  display: grid;
  gap: 0.9rem;
}

.measurement-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-alt);
}

.measurement-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.95rem;
  background: linear-gradient(90deg, var(--sky-tint), rgb(100 192 255 / 4%));
}

.measurement-group-heading strong {
  color: var(--navy);
}

.measurement-group-heading small {
  color: var(--muted);
  font-weight: 500;
}

.measurement-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 1px;
  background: var(--border);
}

.measurement-metric {
  min-height: 5.6rem;
  padding: 0.8rem 0.95rem;
  background: #fff;
  border-top: 3px solid transparent;
}

.measurement-metric.status-good {
  border-top-color: #38a169;
}

.measurement-metric.status-warn {
  border-top-color: #d69e2e;
}

.measurement-metric.status-bad {
  border-top-color: var(--danger);
}

.measurement-metric span,
.measurement-metric strong,
.measurement-metric small {
  display: block;
}

.measurement-metric span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.measurement-metric strong {
  margin-top: 0.25rem;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.measurement-metric small {
  margin-top: 0.25rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.measurement-empty {
  margin: 0;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1.5rem;
  color: var(--muted);
  text-align: center;
  background: var(--surface-alt);
}

.measurement-more {
  justify-self: center;
}

.list {
  display: grid;
  gap: 0.65rem;
}

.sidebar .panel + .panel .list {
  max-height: 24rem;
  overflow: auto;
  padding-right: 0.15rem;
  scrollbar-width: thin;
  scrollbar-color: var(--sky) transparent;
}

.list-item {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  background: var(--surface-alt);
}

button.list-item {
  width: 100%;
  min-height: auto;
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  color: var(--text);
  font-weight: 500;
  letter-spacing: normal;
  text-align: left;
  background: var(--surface-alt);
  box-shadow: none;
}

.selector-card {
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

button.selector-card:hover {
  border-color: var(--sky);
  background: var(--sky-light);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

button.selector-card.selected {
  border-color: var(--sky-deep);
  background: linear-gradient(135deg, rgb(100 192 255 / 16%), rgb(100 192 255 / 6%));
  box-shadow:
    inset 4px 0 0 var(--sky-deep),
    var(--shadow-sm);
  transform: none;
}

.station-card {
  display: grid;
  gap: 0.3rem;
}

.list-item strong {
  display: block;
  color: var(--navy);
}

.list-item small {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.school-card-content {
  display: grid;
  grid-template-columns: 3.75rem minmax(0, 1fr);
  gap: 0.85rem;
  align-items: center;
}

.school-card-content > span {
  min-width: 0;
}

.school-logo {
  width: 3.75rem;
  height: 3.75rem;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.3rem;
  background: #fff;
}

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--sky-pale));
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.1rem clamp(1rem, 3vw, 2rem);
}

.footer-copy {
  margin: 0;
  color: var(--navy);
  font-size: 0.92rem;
  font-weight: 600;
}

.footer-copy a {
  color: var(--navy);
  text-decoration: none;
}

.footer-copy a:hover {
  color: var(--sky-deep);
  text-decoration: underline;
}

.footer-eu-logo {
  display: block;
  width: auto;
  max-width: min(220px, 38vw);
  height: auto;
}

.history-table-wrap {
  max-height: 22rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.history-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--sky-pale);
  box-shadow: 0 1px 0 var(--border);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.history-table th,
.history-table td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid rgb(0 56 94 / 6%);
  text-align: left;
  vertical-align: top;
}

.history-table th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background-color: var(--sky-pale);
}

.history-table tbody tr:last-child td {
  border-bottom: 0;
}

.history-table tbody tr.timestamp-group-even {
  background: var(--table-stripe-a);
}

.history-table tbody tr.timestamp-group-odd {
  background: var(--table-stripe-b);
}

.history-table tbody tr:hover {
  background: var(--table-stripe-hover);
}

.history-table td:nth-child(3) {
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.history-table td:first-child {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

[hidden] {
  display: none !important;
}

.message {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  max-width: min(28rem, calc(100vw - 2rem));
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.1rem;
  color: var(--navy);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.message:empty {
  display: none;
}

.message.error {
  border-color: rgb(197 48 48 / 28%);
  color: var(--danger);
  background: #fff5f5;
}

.empty {
  color: var(--muted);
}

@media (max-width: 820px) {
  .kpi-carousel-track {
    --kpi-visible: 2;
  }

  .header-inner,
  .topbar,
  .panel-heading,
  .preview-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .header-text {
    order: 2;
  }

  .home-button {
    align-self: flex-start;
    order: 3;
  }

  .refresh-button {
    align-self: flex-start;
  }

  .preview-actions {
    justify-content: stretch;
  }

  .preview-actions button {
    flex: 1;
  }

  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "map"
      "sidebar"
      "kpi"
      "history";
  }

  .water-data-dialog {
    width: calc(100vw - 1rem);
    max-height: calc(100vh - 1rem);
  }

  .water-upload-panel {
    max-height: calc(100vh - 1rem);
    padding: 1rem;
  }

  .map-panel {
    grid-template-rows: auto auto auto;
    min-height: 0;
  }

  .forms-row {
    grid-template-columns: 1fr;
  }

  .manual-entry-row {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .station-map {
    min-height: 18rem;
    height: 18rem;
  }

  .chart-wrap {
    height: 15rem;
  }

  .panel-actions {
    justify-content: stretch;
  }

  .panel-actions button {
    flex: 1;
  }

  .history-data-section {
    padding: 0.85rem;
  }

  .history-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .history-toolbar .chart-control {
    min-width: 0;
  }

  .history-heading,
  .history-section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .history-heading .upload-water-button {
    align-self: flex-start;
  }

  .history-section-heading button {
    align-self: flex-start;
  }

  .history-quick-ranges .range-chip {
    flex: 0 1 auto;
  }
}
