/* Forest Monitor — styles per spec §4.0 (visual language is the contract) */

:root {
  --ink: #1A2B22;
  --ink-soft: #5B6B62;
  --bg: #F7F8F6;
  --surface: #FFFFFF;
  --green: #2E7D46;
  --brown: #A05A2C;
  --neutral: #5B6B62;
  --accent: #1F6E43;
  --border: #E2E6E1;
  --warn-bg: #FFF7E8;
  --warn-ink: #7A5A18;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur: 180ms;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* --------------------------------------------------- layout + left sidebar */
/* embalses.net pattern: a fixed left index column (brand + search + browsable
   municipality lists) beside the scrolling content column. */

.layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); align-items: start; }

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  padding: 16px 14px 32px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.main-col { min-width: 0; }

.brand { padding: 4px 6px 12px; }
.brand-title { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.brand-tag { font-size: 12px; color: var(--ink-soft); margin: 2px 0 0; }

.side-block { margin-bottom: 8px; }

.side-head {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: #EEF3EE;
  border-radius: 6px;
  padding: 6px 10px;
  margin: 16px 0 8px;
}
.side-nav .side-head:first-child { margin-top: 4px; }

.side-list { list-style: none; margin: 0 0 4px; padding: 0; }
.side-link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);          /* anchors: kill the default blue */
  text-decoration: none;      /* anchors: kill the default underline */
  font: inherit;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.side-link:hover { background: #EEF3EE; color: var(--accent); }
/* muted capital-city hint shown when the region name differs from the town */
.side-cap { font-size: 12px; font-weight: 400; color: var(--ink-soft); white-space: nowrap; }

.search-wrap { position: relative; width: 100%; }

#search-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.search-progress {
  position: absolute;
  left: 0; right: 0; top: 100%;
  height: 2px;
  overflow: hidden;
  border-radius: 1px;
}
.search-progress::after {
  content: "";
  display: block;
  height: 100%;
  width: 40%;
  background: var(--accent);
  animation: indeterminate 1s infinite var(--ease);
}
@keyframes indeterminate {
  from { transform: translateX(-100%); }
  to { transform: translateX(280%); }
}

.search-listbox {
  position: absolute;
  z-index: 1100;
  top: calc(100% + 4px);
  left: 0; right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(26, 43, 34, 0.14);
  max-height: 380px;
  overflow-y: auto;
}

.search-listbox li {
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.search-listbox li.active, .search-listbox li:hover { background: #EEF3EE; }
.search-listbox .opt-name { font-weight: 500; }
.search-listbox .opt-prov { font-size: 13px; color: var(--ink-soft); }
.search-listbox .opt-msg { color: var(--ink-soft); cursor: default; }
.search-listbox .opt-fallback { cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.search-listbox .opt-fallback:hover { background: #EEF3EE; }

.search-inline-error { margin-top: 6px; font-size: 13px; color: var(--brown); }
.search-inline-error button { margin-left: 8px; }

/* -------------------------------------------------------------------- hero */

.hero {
  text-align: center;
  padding: 64px 16px 48px;
  max-width: 640px;
  margin: 0 auto;
}
.hero h2 { font-size: 28px; font-weight: 700; margin: 0 0 8px; }
.hero p { color: var(--ink-soft); margin: 0 0 24px; }
.hero .chips-hint { font-size: 13px; margin: 0 0 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.chip:hover { background: #EEF3EE; border-color: var(--accent); }

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

.controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 0;
}

.year-select {
  height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.vs-label { color: var(--ink-soft); }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.segmented button {
  height: 44px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.segmented button[aria-checked="true"] { background: var(--accent); color: #fff; }

.btn {
  height: 44px;
  padding: 0 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
/* anchor-as-button (WhatsApp share, spec §10): same box as .btn buttons */
a.btn { display: inline-flex; align-items: center; text-decoration: none; color: var(--ink); font-size: inherit; }
.helper-text { font-size: 13px; color: var(--brown); }

/* progress line (spec 4.6 loading state) */
.progress-line { padding: 0 0 12px; font-size: 13px; color: var(--ink-soft); }
.progress-track { height: 2px; background: var(--border); border-radius: 1px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 300ms var(--ease); }

/* ------------------------------------------------------------------- maps */

.maps-side { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.map-panel { position: relative; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(26,43,34,0.08); background: var(--surface); }
.map { height: 52vh; min-height: 320px; }
#map-diff-wrap .map { height: 56vh; min-height: 320px; }

.map-panel .leaflet-tile-pane .basemap { filter: grayscale(0.6) brightness(1.05); }

.year-chip {
  position: absolute;
  z-index: 1000;
  top: 10px; left: 10px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(26, 43, 34, 0.75);
  border-radius: 6px;
  pointer-events: none;
}

.map-panel.skeleton .map { visibility: hidden; }
.map-panel.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, #ECEFEA 40%, #F5F7F4 50%, #ECEFEA 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -80% 0; } }

/* legends */
.legend { display: flex; align-items: center; gap: 10px; padding: 10px 2px; font-size: 13px; color: var(--ink-soft); }
.legend-bar { flex: 0 1 260px; height: 10px; border-radius: 5px; border: 1px solid var(--border); }
.legend-bar.diff {
  background: linear-gradient(to right, #8C4A1F, rgba(255,255,255,0) 50%, #1E7A3C);
}

/* ----------------------------------------------------------------- verdict */

.verdict-row { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; padding: 8px 0 24px; }

.card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(26, 43, 34, 0.08);
  padding: 24px;
}
.verdict-card { max-width: 640px; flex: 1 1 480px; }

.verdict-headline {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 6px;
  opacity: 1;
  transform: translateY(0);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.verdict-headline.entering { opacity: 0; transform: translateY(4px); }
.verdict-headline.greener { color: var(--green); }
.verdict-headline.browner { color: var(--brown); }
.verdict-headline.same { color: var(--neutral); }

.verdict-subline { color: var(--ink-soft); margin: 0 0 12px; }

/* context stats row (spec §10, 2026-07-12 — embalses.net pattern) */
.verdict-context { display: flex; flex-wrap: wrap; gap: 6px 24px; margin: 0 0 12px; font-size: 13px; }
.ctx-stat { display: inline-flex; align-items: baseline; gap: 6px; }
.ctx-label { color: var(--ink-soft); }
.ctx-value { font-weight: 600; }
.ctx-value.greener { color: var(--green); }
.ctx-value.browner { color: var(--brown); }
.ctx-value.same { color: var(--neutral); }

.skeleton-bar {
  height: 30px;
  border-radius: 6px;
  margin-bottom: 10px;
  background: linear-gradient(100deg, #ECEFEA 40%, #F5F7F4 50%, #ECEFEA 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
.skeleton-bar.short { width: 60%; height: 16px; }

.lowconf-banner {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 0 0 12px;
}

.caveat { font-size: 13px; color: var(--ink-soft); margin: 0; }
.caveat a { color: var(--accent); }

/* brand.md F-B2: screenshot self-attribution inside the verdict card */
.watermark { font-size: 12px; color: var(--ink-soft); text-align: right; margin: 8px 0 0; }

.error-card p { margin: 0 0 12px; }

/* --------------------------------------------------------------- evolution */
/* Spec §10 (2026-07-12): on-demand year-by-year chart under the verdict. */

.evolution { padding: 0 0 24px; }
.evo-card { max-width: 720px; }
.evo-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.evo-title { font-size: 20px; font-weight: 600; margin: 0; }
.evo-confirm-text { margin: 0 0 12px; color: var(--ink-soft); }
.evo-progress { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--ink-soft); padding: 8px 0 12px; }

#evo-chart svg { display: block; width: 100%; height: auto; }
.evo-band { fill: rgba(91, 107, 98, 0.14); }
.evo-band-label { font-size: 11px; fill: var(--ink-soft); }
.evo-grid { stroke: var(--border); stroke-width: 1; }
.evo-line { fill: none; stroke: var(--accent); stroke-width: 2; }
.evo-point { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }
.evo-point-low { fill: var(--surface); stroke: var(--accent); stroke-width: 2; stroke-dasharray: 3 2; }
.evo-mode button { height: 34px; padding: 0 12px; font-size: 13px; }
.evo-leg { display: inline-flex; align-items: center; gap: 6px; margin-left: 14px; font-weight: 600; color: var(--ink); }
.evo-leg-sw { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.evo-event { stroke: var(--brown); stroke-width: 1.5; stroke-dasharray: 4 3; }
.evo-event-label { font-size: 10px; fill: var(--brown); font-weight: 700; }
.evo-tick { font-size: 11px; fill: var(--ink-soft); }
.evo-avg { stroke: var(--ink-soft); stroke-width: 1.5; stroke-dasharray: 6 4; }
.evo-avg-label { font-size: 11px; fill: var(--ink-soft); }
.evo-value-label { font-size: 11px; fill: var(--ink); }

.evo-table-toggle { margin-top: 12px; }
.evo-table table { border-collapse: collapse; margin-top: 12px; font-size: 13px; }
.evo-table caption { text-align: left; color: var(--ink-soft); padding-bottom: 6px; }
.evo-table th, .evo-table td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
.evo-table th { background: var(--bg); font-weight: 600; }

/* ------------------------------------------------------------------ footer */

footer {
  padding: 24px 16px 40px;
  font-size: 13px;
  color: var(--ink-soft);
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
footer a { color: var(--accent); }

/* ------------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(26, 43, 34, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(26, 43, 34, 0.25);
}
.modal h2 { margin-top: 0; font-size: 20px; }
.modal p { font-size: 15px; }
.modal .attribution { font-size: 13px; color: var(--ink-soft); }
.modal-close { float: right; }

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 3000;
  background: var(--warn-bg);
  color: var(--warn-ink);
  text-align: center;
  padding: 10px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

[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;
}

/* ------------------------------------------------------- national overview */

.overview-section { max-width: 1000px; margin: 0 auto; padding: 8px 16px 40px; }
.ov-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 2px;
}
.ov-title { font-size: 22px; font-weight: 700; margin: 0; }
.ov-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ov-status { font-size: 13px; color: var(--ink-soft); padding: 6px 0; min-height: 20px; }

.ov-map-wrap {
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(26, 43, 34, 0.08);
  background: var(--surface); border: 1px solid var(--border);
}
.ov-map { height: 60vh; min-height: 380px; background: var(--bg); }
#ov-map.leaflet-container { background: var(--bg); }
.ov-region { cursor: pointer; transition: fill-opacity var(--dur) var(--ease); }

/* Clean permanent region labels — strip Leaflet's tooltip box + pointer. */
.leaflet-tooltip.ov-tip {
  background: none; border: 0; box-shadow: none; padding: 0;
  text-align: center; white-space: nowrap; pointer-events: none;
  font-weight: 600; color: var(--ink);
  text-shadow: 0 1px 2px rgba(255,255,255,0.92), 0 0 2px rgba(255,255,255,0.92);
}
.leaflet-tooltip.ov-tip::before { display: none; }
/* Municipio choropleth: too many to label permanently, so names show on hover
   as a readable pill (overrides the transparent permanent-label style above). */
.leaflet-tooltip.ov-tip.ov-tip-hover {
  background: rgba(26, 43, 34, 0.92);
  color: #fff;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12px;
  text-shadow: none;
}
.ov-tip-name { display: block; font-size: 10px; line-height: 1.05; }
.ov-tip-pct { display: block; font-size: 11.5px; line-height: 1.1; }

.ov-legend {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px;
  padding: 12px 2px 4px; font-size: 12px; color: var(--ink-soft);
}
.ov-legend-title { font-weight: 600; color: var(--ink); margin-right: 2px; }
.ov-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.ov-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.12); }
.ov-note { max-width: none; margin-top: 6px; }

/* ------------------------------------------------------ hub / SEO pages */

.page-head { max-width: 1000px; margin: 0 auto; padding: 24px 16px 4px; }
.page-head h1 { font-size: 26px; font-weight: 700; margin: 0 0 8px; line-height: 1.2; }
.page-intro { color: var(--ink-soft); margin: 0 0 8px; max-width: 70ch; }
.breadcrumb { font-size: 13px; color: var(--ink-soft); margin: 0 0 10px; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { margin: 0 6px; opacity: 0.6; }
.child-links { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 10px 0 0; }
.child-links a {
  display: inline-block; padding: 6px 12px; border: 1px solid var(--border);
  border-radius: 18px; background: var(--surface); text-decoration: none; color: var(--ink);
}
.child-links a:hover { border-color: var(--accent); background: #EEF3EE; }

.muni-list { max-width: 1000px; margin: 8px auto 0; padding: 0 16px; }
.muni-heading { font-size: 18px; font-weight: 700; margin: 12px 0 8px; }
.muni-links { list-style: none; padding: 0; margin: 0; columns: 200px; column-gap: 24px; }
.muni-links li { break-inside: avoid; margin-bottom: 4px; }
.muni-links a { color: var(--accent); text-decoration: none; }
.muni-links a:hover { text-decoration: underline; }
.muni-more, .muni-loading { color: var(--ink-soft); font-size: 13px; margin: 10px 0 0; }

/* data-driven summary under the choropleth */
.insight {
  max-width: 1000px; margin: 12px auto 0; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.insight-title { font-size: 15px; font-weight: 700; margin: 0 0 6px; }
.insight p { margin: 0 0 6px; color: var(--ink); }
.insight p:last-child { margin-bottom: 0; }

/* context + official sources (bottom of every page) */
.context {
  max-width: 1000px; margin: 28px auto 8px; padding: 0 16px;
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 28px;
}
.context h2 { font-size: 16px; font-weight: 700; margin: 0 0 6px; }
.context p { color: var(--ink-soft); margin: 0 0 14px; }
.context-links { list-style: none; padding: 0; margin: 0 0 12px; }
.context-links li { margin-bottom: 6px; }
.context-links a { color: var(--accent); text-decoration: none; }
.context-links a:hover { text-decoration: underline; }
.context-note { font-size: 13px; }

/* --------------------------------------------------------------------- ads */

.ad-slot { margin: 16px auto; text-align: center; }
.ad-slot .adsbygoogle { display: block; }
.ad-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0.7;
  margin-bottom: 4px;
}
/* Reserve height so filled ads don't shove content (CLS). */
.ad-slot-side { margin: 12px 0 4px; min-height: 250px; }
.ad-slot-leader { max-width: 970px; padding: 12px 16px 4px; min-height: 120px; }

/* ----------------------------------------------------------------- mobile */

@media (max-width: 899px) {
  .maps-side { grid-template-columns: 1fr; }
  .ov-map { height: 54vh; min-height: 320px; }
  .ad-slot-side { display: none; } /* don't put a tall ad atop the mobile strip */
  .context { grid-template-columns: 1fr; gap: 4px; }
  .ov-head { align-items: flex-start; }
  .leaflet-tooltip.ov-tip .ov-tip-name { font-size: 9px; }
  .leaflet-tooltip.ov-tip .ov-tip-pct { font-size: 11px; }
  .map { height: 46vh; min-height: 280px; }
  .verdict-headline { font-size: 22px; }

  /* Sidebar collapses to a top strip; browse lists become horizontal chip
     rows so they don't push the search far down the page. */
  .layout { display: block; }
  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px 16px;
  }
  .side-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .side-list li { flex: 0 0 auto; }
  .side-link {
    width: auto;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 14px;
    white-space: nowrap;
  }
  .side-link:hover { border-color: var(--accent); }
  .side-cap { display: none; } /* chips show the region name only */
}

/* --------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
