/*
 * HCSR map viewer, v2 — page chrome. See viewer-2.js.
 *
 * The look follows the source maps (the map developer's Streamlit theme:
 * brand navy, hairline cards, a dark basemap) on the main site's terms:
 * logical properties only, Cairo, letter-spacing 0 for Arabic, and no
 * horizontal scroll at any width.
 */

:root {
  --v2-navy: #114570;
  --v2-blue: #10456F;
  --v2-dark: #0D3454;
  --v2-mid: #4C7394;
  --v2-border: #C3D0DB;
  --v2-light: #E7ECF0;
  --v2-ink: #1F2937;
  --v2-muted: #6B7280;
  --v2-radius: 10px;
  --v2-map-h: 600px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #FFFFFF;
  color: var(--v2-ink);
  font-family: Cairo, "Segoe UI", Tahoma, sans-serif;
  letter-spacing: 0;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

.v2 {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 18px;
  max-width: 1440px;
  margin-inline: auto;
}

/* --- loading ------------------------------------------------------------- */
.v2-status { display: grid; place-items: center; gap: 10px; min-height: 60vh; color: var(--v2-mid); }
.v2-status p { margin: 0; }
.v2-spin {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--v2-light); border-block-start-color: var(--v2-blue);
  animation: v2-spin 0.9s linear infinite;
}
@keyframes v2-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .v2-spin { animation: none; } }

/* --- title --------------------------------------------------------------- */
.v2-title {
  margin: 0;
  background: linear-gradient(to left, var(--v2-dark), var(--v2-navy));
  color: #FFFFFF;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.6;
  padding: 0.45rem 1rem;
  border-radius: 8px;
}

/* --- filter bar ---------------------------------------------------------- */
.v2-filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 8px 12px;
  background: var(--v2-light);
  border-radius: var(--v2-radius);
}
.v2-filters__label { font-weight: 700; color: var(--v2-navy); font-size: 0.92rem; }
.v2-filters { gap: 8px 22px; }
.v2-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.v2-chip {
  font: inherit; font-size: 0.88rem; font-weight: 600;
  min-height: 34px; padding: 2px 14px;
  border-radius: 999px;
  border: 1px solid var(--v2-border);
  background: #FFFFFF; color: var(--v2-mid);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.v2-chip[aria-pressed="true"] { background: var(--v2-blue); border-color: var(--v2-blue); color: #FFFFFF; }
.v2-chip:focus-visible, .v2-btn:focus-visible, .v2-section summary:focus-visible, .v2-table th button:focus-visible {
  outline: 2px solid var(--v2-blue); outline-offset: 2px;
}

/* --- metrics ------------------------------------------------------------- */
.v2-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}
.v2-metric {
  display: flex; flex-direction: column;
  min-height: 5.4rem;
  padding: 0.45rem 0.9rem;
  background: #FFFFFF;
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius);
  box-shadow: 0 1px 4px rgba(17, 69, 112, 0.06);
}
.v2-metric__label { color: var(--v2-navy); font-size: 0.85rem; font-weight: 600; line-height: 1.6; }
.v2-metric__value { color: var(--v2-ink); font-size: 1.35rem; font-weight: 700; line-height: 1.5; }
.v2-metric__sub { color: var(--v2-blue); font-size: 0.8rem; }

.v2-empty {
  margin: 0; padding: 8px 12px;
  background: #EEF4FB; color: var(--v2-navy);
  border-radius: 8px; font-size: 0.92rem;
}

/* --- map ----------------------------------------------------------------- */
.v2-mapcard {
  position: relative;
  height: var(--v2-map-h);
  border-radius: var(--v2-radius);
  overflow: hidden;
  border: 1px solid var(--v2-border);
}
.v2-map { position: absolute; inset: 0; background: #262626; }
.v2-map .leaflet-control-attribution { font-size: 10px; }
.v2-caption { margin: 0; color: var(--v2-muted); font-size: 0.85rem; line-height: 1.8; }

.v2-legend {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-start: 10px;
  z-index: 800;
  width: min(270px, calc(100% - 74px));
  max-height: calc(100% - 20px);
  display: flex; flex-direction: column;
  background: #FFFFFF;
  border: 1px solid var(--v2-border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.v2-legend[hidden] { display: none; }
.v2-legend h2 {
  margin: 0;
  padding: 5px 12px;
  background: var(--v2-navy); color: #FFFFFF;
  font-size: 0.88rem; font-weight: 700; text-align: center; line-height: 1.7;
}
.v2-legend__list { padding: 6px 10px 8px; overflow-y: auto; }
.v2-row {
  display: flex; align-items: center; gap: 7px;
  min-height: 30px;
  font-size: 0.82rem; font-weight: 700; color: var(--v2-navy);
  cursor: pointer;
}
.v2-row input { accent-color: var(--v2-blue); margin: 0; width: 16px; height: 16px; flex: none; }
.v2-row--labels { border-block-start: 1px solid var(--v2-light); margin-block-start: 4px; padding-block-start: 4px; }
.v2-key { display: inline-block; flex: none; width: 16px; height: 16px; border-radius: 3px; }
.v2-key--dot { border-radius: 50%; border: 1.5px solid #FFFFFF; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35); }
.v2-key--line { height: 4px; width: 22px; border-radius: 2px; }
.v2-key__n { color: var(--v2-muted); font-weight: 600; font-size: 0.72rem; }

.v2-rail {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-end: 10px;
  z-index: 800;
  display: flex; flex-direction: column; gap: 6px;
}
.v2-btn {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  padding: 0;
  background: #FFFFFF; color: var(--v2-navy);
  border: 1px solid var(--v2-border);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.v2-btn[aria-pressed="true"] { background: var(--v2-navy); color: #FFFFFF; }

/* Leaflet popups and hover tips, in the source maps' style. */
.v2-map .leaflet-popup-content { margin: 8px 10px; }
.v2-pop { direction: rtl; text-align: start; font-family: Cairo, Tahoma, sans-serif; min-width: 230px; max-width: 330px; }
.v2-pop__title { color: var(--v2-navy); font-weight: 700; font-size: 14px; line-height: 1.6; margin-block-end: 3px; }
.v2-pop__badge { display: inline-block; padding: 1px 9px; border-radius: 10px; font-weight: 600; font-size: 11px; line-height: 1.7; }
.v2-pop__rows { max-height: 190px; overflow-y: auto; margin-block-start: 5px; }
.v2-pop table { width: 100%; border-collapse: collapse; font-size: 12px; }
.v2-pop th, .v2-pop td { padding: 3px 5px; border-block-end: 1px solid var(--v2-border); text-align: start; vertical-align: top; line-height: 1.6; }
.v2-pop th { color: var(--v2-navy); font-weight: 600; width: 38%; }
.v2-pop td { color: var(--v2-ink); }
.v2-ltip { direction: rtl; font-family: Cairo, Tahoma, sans-serif; font-size: 12px; line-height: 1.6; }

/* --- sections ------------------------------------------------------------ */
.v2-section { border: 1px solid var(--v2-border); border-radius: var(--v2-radius); overflow: hidden; }
.v2-section summary {
  padding: 8px 14px;
  background: var(--v2-light); color: var(--v2-navy);
  font-weight: 600; cursor: pointer; line-height: 1.7;
}
.v2-section__body { padding: 10px 12px; min-width: 0; }

.v2-chart { display: block; max-width: 100%; height: auto; font-family: Cairo, Tahoma, sans-serif; }
.v2-grid { stroke: var(--v2-light); stroke-width: 1; }
.v2-axis { stroke: var(--v2-border); stroke-width: 1; }
.v2-tick { fill: var(--v2-navy); font-size: 11px; }
.v2-cat { fill: var(--v2-navy); font-size: 12px; }
.v2-val { fill: var(--v2-navy); font-size: 11px; font-weight: 600; }
.v2-axis-title { fill: var(--v2-navy); font-size: 12px; }
.v2-bar { transition: opacity 0.12s; }
.v2-bar:hover { opacity: 0.8; }
.v2-chart__legend { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; margin-block-end: 6px; font-size: 0.82rem; color: var(--v2-navy); }
.v2-chart__legend-title { font-weight: 700; }
.v2-chart__key { display: inline-flex; align-items: center; gap: 6px; }
.v2-chart__key i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }

.v2-tip {
  position: fixed; z-index: 2000;
  max-width: 260px;
  padding: 5px 9px;
  background: #FFFFFF; color: var(--v2-ink);
  border: 1px solid var(--v2-blue); border-radius: 6px;
  font-size: 13px; line-height: 1.6;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.v2-tip[hidden] { display: none; }

.v2-table { max-height: 420px; overflow: auto; border: 1px solid var(--v2-light); border-radius: 6px; }
.v2-table table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.v2-table th, .v2-table td { padding: 5px 9px; border-block-end: 1px solid var(--v2-light); text-align: start; white-space: nowrap; }
.v2-table thead th { position: sticky; inset-block-start: 0; background: #F6F8FA; z-index: 1; }
.v2-table th button {
  font: inherit; font-weight: 700; color: var(--v2-navy);
  background: none; border: 0; padding: 0; cursor: pointer; white-space: nowrap;
}
.v2-table__n { margin: 6px 0 0; color: var(--v2-muted); font-size: 0.8rem; }

.v2-chart__title { margin: 0 0 4px; color: var(--v2-navy); font-weight: 700; font-size: 0.88rem; text-align: center; }
.v2-charts { display: flex; flex-wrap: wrap; gap: 12px; }
.v2-charts__cell { flex: 1 1 300px; min-width: 0; }
.v2-ref { stroke: #BC0013; stroke-width: 1.5; stroke-dasharray: 3 3; }
.v2-ref-label { fill: #BC0013; font-size: 11px; font-weight: 600; paint-order: stroke; stroke: #FFFFFF; stroke-width: 3px; stroke-linejoin: round; }
.v2-dot { stroke: var(--v2-navy); stroke-width: 1; opacity: 0.9; }
.v2-note { margin: 6px 0 0; color: var(--v2-muted); font-size: 0.8rem; line-height: 1.8; }
.v2-variant { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-block-end: 8px; color: var(--v2-navy); font-weight: 600; font-size: 0.88rem; }

/* key-value tables (the environment map's air and lake readings) */
.v2-kv { width: 100%; max-width: 640px; border-collapse: collapse; font-size: 0.88rem; }
.v2-kv th, .v2-kv td { padding: 6px 10px; border-block-end: 1px solid var(--v2-light); text-align: start; }
.v2-kv th { color: var(--v2-navy); font-weight: 600; width: 55%; }

/* selects and checkboxes in the filter bar */
.v2-filter { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.v2-select {
  font: inherit; font-size: 0.88rem;
  min-height: 34px; max-width: min(420px, 100%);
  padding: 2px 10px;
  border: 1px solid var(--v2-border); border-radius: 8px;
  background: #FFFFFF; color: var(--v2-ink);
}
.v2-check { font-size: 0.88rem; color: var(--v2-navy); font-weight: 600; cursor: pointer; }
.v2-check input { accent-color: var(--v2-blue); width: 16px; height: 16px; margin: 0; }

/* icon markers: a white disc with a ring, the source maps' DivIcon */
.v2-pin-wrap { background: none; border: 0; }
.v2-pin {
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #FFFFFF;
  border: 2px solid #111111; box-shadow: 0 0 4px rgba(0, 0, 0, 0.7);
  box-sizing: border-box;
}
.v2-pin img { display: block; }
.v2-key--icon { width: 20px; height: 20px; border-radius: 50%; background: #FFFFFF; border: 1.5px solid #111111; padding: 2px; object-fit: contain; }

/* a continuous colour scale in the legend */
.v2-grad { display: flex; flex-direction: column; gap: 3px; padding-block: 4px; }
.v2-grad__title { color: var(--v2-navy); font-weight: 700; font-size: 0.8rem; }
.v2-grad__bar { display: block; height: 12px; border-radius: 3px; }
.v2-grad__ends { display: flex; justify-content: space-between; color: var(--v2-muted); font-size: 0.72rem; }

/* popup photo: a thumbnail, the full photo on click */
.v2-pop__photo { display: block; margin-block-start: 7px; text-decoration: none; }
.v2-pop__photo img { display: block; width: 240px; max-width: 100%; height: 150px; object-fit: cover; border-radius: 6px; border: 1px solid var(--v2-border); }
.v2-pop__photo span { font-size: 11px; color: var(--v2-mid); }

@media (max-width: 700px) {
  :root { --v2-map-h: 460px; }
  .v2 { padding: 10px 12px 14px; }
  .v2-title { font-size: 1.02rem; }
  .v2-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .v2-metric__value { font-size: 1.15rem; }
}
