/* Irrigation and Groundwater Explorer - page styles (relies on ../css/style.css tokens) */

:root {
  --xp-blue: #2F5F96;
  --xp-teal: #1F9C8A;
  --xp-amber: #C2620E;
  --xp-dry: #CBD5E1;
  --xp-nodata: #EEF1F5;
  --xp-panel-w: 380px;
}

.explorer-head {
  padding: clamp(36px, 4vw, 56px) var(--pad-x) 22px;
  background: linear-gradient(100deg, #FFFFFF 0%, #FFFFFF 45%, #EEF5F4 100%);
  border-bottom: 1px solid var(--border);
}

.explorer-head h1 {
  font-size: clamp(28px, 3.4vw, 40px);
  margin: 0 0 12px;
}

.explorer-head p {
  max-width: 900px;
  font-size: 17px;
  color: var(--text);
}

.explorer-wrap {
  padding: 22px var(--pad-x) 40px;
  background: var(--bg);
}

/* ---- Explorer frame ---- */
.xp {
  display: flex;
  flex-direction: column;
  min-height: 720px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  font-size: 14.5px;
}

.xp-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}

.xp-tabs {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.xp-tabs button {
  padding: 7px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.xp-tabs button[aria-selected="true"] {
  background: var(--navy);
  color: var(--white);
}

.xp-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-strong);
  font-size: 13.5px;
}

.xp-field select,
.xp-field input[type="search"] {
  font: inherit;
  font-weight: 500;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  color: var(--text-strong);
  min-width: 0;
}

.xp-field select {
  max-width: 320px;
}

.xp-field input[type="search"] {
  width: 200px;
}

.xp-year {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.xp-year input[type="range"] {
  width: 170px;
  accent-color: var(--teal);
}

.xp-year output {
  min-width: 2ch;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--navy);
}

.xp-btn {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  color: var(--text-strong);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.xp-btn:hover {
  background: var(--teal-light);
  border-color: var(--teal);
}

.xp-btn[aria-pressed="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--white);
}

.xp-spacer {
  flex: 1 1 auto;
}

.xp-hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Body: map + panel ---- */
.xp-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.xp-map {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 560px;
  background: #FBFCFD;
  overflow: hidden;
}

.xp-map svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.xp-map .county {
  stroke: #FFFFFF;
  stroke-width: 0.4;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill 0.25s ease;
}

.xp-map .county.dim {
  cursor: default;
}

.xp-map .county.hover {
  stroke: var(--navy);
  stroke-width: 1.6;
}

.xp-map .county.selected {
  stroke: var(--navy);
  stroke-width: 2.2;
}

.xp-map .states {
  fill: none;
  stroke: #9AA7B8;
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.xp-map .nation {
  fill: none;
  stroke: #7B8798;
  stroke-width: 0.9;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.xp-map .hpa-outline {
  fill: none;
  stroke: var(--navy);
  stroke-width: 2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.xp-map .hpa-halo {
  fill: none;
  stroke: #FFFFFF;
  stroke-width: 4;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.xp-map .state-label {
  font-weight: 600;
  fill: #5B6775;
  letter-spacing: 0.06em;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.85);
}

.xp-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 600;
  background: #FBFCFD;
  z-index: 5;
}

/* Legend */
.xp-legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: calc(100% - 28px);
  padding: 10px 12px 9px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(18, 53, 91, 0.08);
  font-size: 12.5px;
  color: var(--text);
}

.xp-legend h4 {
  margin: 0 0 7px;
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: 0;
}

.xp-legend .bins {
  display: flex;
  gap: 2px;
}

.xp-legend .bin {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 46px;
}

.xp-legend .bin i {
  display: block;
  width: 100%;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.xp-legend .bin span {
  margin-top: 4px;
  font-size: 11.5px;
  white-space: nowrap;
}

.xp-legend .cats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.xp-legend .cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.xp-legend .cat i {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* Zoom controls */
.xp-zoom {
  position: absolute;
  right: 14px;
  top: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.xp-zoom button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--navy);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.xp-zoom button:hover {
  background: var(--teal-light);
  border-color: var(--teal);
}

/* Tooltip */
.xp-tip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  min-width: 170px;
  max-width: 280px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 8px 22px rgba(18, 53, 91, 0.12);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  opacity: 0;
  transition: opacity 0.1s ease;
}

.xp-tip.on {
  opacity: 1;
}

.xp-tip .t-name {
  font-weight: 700;
  color: var(--navy);
}

.xp-tip .t-sub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.xp-tip .t-val {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.xp-tip .t-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
}

.xp-tip .t-row b {
  font-variant-numeric: tabular-nums;
  color: var(--text-strong);
  font-weight: 600;
}

/* Side panel */
.xp-panel {
  flex: 0 0 var(--xp-panel-w);
  width: var(--xp-panel-w);
  padding: 18px 20px 20px;
  border-left: 1px solid var(--border);
  background: var(--white);
  overflow-y: auto;
}

.xp-panel h3 {
  font-size: 19px;
  margin: 0 0 2px;
}

.xp-panel .p-sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
}

.xp-panel h4 {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 0 8px;
}

.xp-panel p {
  font-size: 13.5px;
  line-height: 1.55;
  margin: 0 0 10px;
}

.xp-panel .p-close {
  float: right;
  margin: -4px -6px 0 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.xp-panel .p-close:hover {
  color: var(--navy);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  padding: 9px 11px;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: var(--bg);
}

.stat .v {
  display: block;
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
}

.stat .l {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.3;
}

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

.chart {
  position: relative;
  margin-top: 4px;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart .axis text {
  font-family: var(--font-body);
  font-size: 10.5px;
  fill: var(--muted);
}

.chart .axis line,
.chart .axis path {
  stroke: var(--border);
}

.chart .grid line {
  stroke: var(--border-soft);
}

.chart .series-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart .marker-line {
  stroke: var(--xp-amber);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart .marker-text {
  font-size: 10.5px;
  fill: var(--xp-amber);
  font-weight: 600;
}

.chart .crosshair {
  stroke: var(--navy);
  stroke-width: 1;
  opacity: 0;
}

.chart .readout {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 12px;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.9);
  padding: 1px 6px;
  border-radius: 5px;
  pointer-events: none;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 4px 0 0;
  font-size: 11.5px;
  color: var(--text);
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-legend i {
  width: 11px;
  height: 11px;
  border-radius: 2px;
}

.p-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.p-link {
  font-weight: 600;
  text-decoration: none;
}

.p-link:hover {
  text-decoration: underline;
}

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
}

.rank-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
}

.rank-list li:hover {
  color: var(--navy);
}

.rank-list li b {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-strong);
}

/* Table view */
.xp-table {
  flex: 1 1 auto;
  overflow: auto;
  max-height: 70vh;
  padding: 0 16px 16px;
}

.xp-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.xp-table th,
.xp-table td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

.xp-table th {
  position: sticky;
  top: 0;
  background: var(--bg);
  color: var(--text-strong);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.xp-table th.num,
.xp-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.xp-table tr:hover td {
  background: var(--teal-light);
}

.xp-table caption {
  text-align: left;
  padding: 12px 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.xp-credit {
  margin: 0;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  background: var(--white);
}

.xp-credit a {
  color: var(--teal);
}

/* Notes below the explorer (standalone page only) */
.explorer-notes {
  padding: 0 var(--pad-x) clamp(48px, 6vw, 72px);
  background: var(--bg);
}

.explorer-notes .notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.explorer-notes article {
  padding: 22px 24px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.explorer-notes h2 {
  font-size: 19px;
  margin-bottom: 10px;
}

.explorer-notes p,
.explorer-notes li {
  font-size: 14.5px;
  line-height: 1.6;
}

.explorer-notes ul {
  padding-left: 20px;
}

/* ---- Embedded mode (iframe on the home page) ---- */
body.embed {
  background: var(--white);
}

body.embed .site-header,
body.embed .skip-link,
body.embed .explorer-head,
body.embed .explorer-notes,
body.embed .site-footer {
  display: none;
}

body.embed .explorer-wrap {
  padding: 0;
  background: var(--white);
}

body.embed .xp {
  height: 100vh;
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.embed .xp-map {
  min-height: 0;
}

@media (max-width: 900px) {
  body.embed .xp-panel {
    display: none;
  }

  body.embed .xp-map {
    flex: 1 1 auto;
  }
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  :root {
    --xp-panel-w: 320px;
  }
}

@media (max-width: 900px) {
  .xp-body {
    flex-direction: column;
  }

  .xp-map {
    min-height: 62vh;
  }

  .xp-panel {
    flex: 0 0 auto;
    width: auto;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .xp-field select {
    max-width: 100%;
  }

  .xp-field input[type="search"] {
    width: 150px;
  }

  .xp-legend .bin {
    min-width: 38px;
  }
}

@media (max-width: 600px) {
  .xp-toolbar {
    padding: 10px 12px;
    gap: 8px 12px;
  }

  .xp-year input[type="range"] {
    width: 120px;
  }

  .xp-map {
    min-height: 420px;
  }

  .xp-legend {
    left: 8px;
    bottom: 8px;
    padding: 8px 9px 7px;
  }

  .xp-legend .bin {
    min-width: 32px;
  }

  .xp-legend .bin span {
    font-size: 10px;
  }

  .xp-zoom {
    right: 8px;
    top: 8px;
  }

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

@media (prefers-reduced-motion: reduce) {
  .xp-map .county,
  .xp-tip,
  .xp-btn {
    transition: none;
  }
}
