:root {
  --navy: #082862;
  --blue: #087caf;
  --sky: #d9effb;
  --teal: #008f8c;
  --orange: #f97316;
  --ink: #172033;
  --muted: #637083;
  --line: #dce4ed;
  --paper: #f4f7fb;
  --white: #fff;
  --shadow: 0 12px 30px rgba(18, 48, 84, .10);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--ink); background: var(--paper); font-family: Inter, "Segoe UI", Arial, sans-serif; }
button, select { font: inherit; }

.topbar { min-height: 82px; padding: 10px clamp(18px, 3vw, 48px); display: flex; align-items: center; justify-content: space-between; gap: 20px; background: var(--white); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 18px; }
.brand img { width: 128px; height: 62px; object-fit: contain; object-position: left center; }
.brand h1 { margin: 0; color: var(--navy); font-size: clamp(1.05rem, 2vw, 1.45rem); letter-spacing: -.02em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: .86rem; }
.institutional-logos { display: flex; align-items: center; justify-content: center; gap: 13px; padding: 4px 16px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.institution-logo { display: block; object-fit: contain; flex: 0 0 auto; }
.ufpb-mark { display: flex; align-items: center; gap: 5px; color: var(--navy); font-size: .78rem; font-weight: 850; }
.ufpb-mark img { width: 38px; height: 46px; object-fit: contain; }
.ppgecam-mark { width: 112px; height: 44px; }
.larhena-mark { width: 49px; height: 49px; border-radius: 50%; border: 1px solid var(--line); }
.sgb-mark { width: 102px; height: 42px; }
.freshness { width: 100%; color: var(--muted); font-size: .73rem; line-height: 1.35; text-align: right; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; max-width: 310px; }
.experimental-badge { display: inline-flex; align-items: center; width: fit-content; padding: 5px 9px; border-radius: 999px; background: #fff4e6; color: #9a4c08; border: 1px solid #f8c98f; font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.methodology-button { height: 34px; padding: 0 12px; border: 1px solid var(--navy); border-radius: 8px; color: var(--navy); background: var(--white); font-weight: 750; cursor: pointer; }
.methodology-button:hover { color: var(--white); background: var(--navy); }

main { width: min(1600px, 100%); margin: 0 auto; padding: 18px clamp(14px, 2.5vw, 38px) 34px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.municipality-search { display: grid; grid-template-columns: minmax(220px, .7fr) minmax(280px, 1.3fr); align-items: center; gap: 20px; margin-bottom: 12px; padding: 13px 16px; background: linear-gradient(110deg, #f8fbff, #eef8fb); border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 4px 16px rgba(18, 48, 84, .04); }
.municipality-search-copy { display: grid; gap: 2px; }
.municipality-search-copy strong { color: var(--navy); font-size: .96rem; }
.municipality-search-copy small { color: var(--muted); font-size: .76rem; }
.municipality-search-control { position: relative; }
.municipality-search-control input { width: 100%; height: 44px; padding: 0 42px; border: 1px solid #b9cbe0; border-radius: 10px; background: var(--white); color: var(--ink); font: inherit; font-size: .9rem; font-weight: 600; outline: none; box-shadow: 0 2px 7px rgba(18, 48, 84, .05); }
.municipality-search-control input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 136, 194, .13); }
.search-icon { position: absolute; z-index: 2; left: 14px; top: 50%; transform: translateY(-50%); color: var(--blue); font-size: 1.35rem; pointer-events: none; }
.city-suggestions { position: absolute; z-index: 1200; inset: calc(100% + 6px) 0 auto; max-height: 250px; overflow-y: auto; padding: 6px; background: var(--white); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(15, 42, 72, .18); }
.city-suggestions button { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; padding: 9px 11px; border: 0; border-radius: 7px; background: transparent; color: var(--ink); text-align: left; font: inherit; font-size: .86rem; cursor: pointer; }
.city-suggestions button small { min-width: 26px; color: var(--muted); font-size: .72rem; font-weight: 800; text-align: right; }
.city-suggestions button:hover, .city-suggestions button:focus { background: #eef7fc; color: var(--navy); outline: none; }
.city-suggestions .empty-suggestion { display: block; padding: 10px; color: var(--muted); font-size: .82rem; }
.filters { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)) auto; gap: 10px; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.filters select, .filters input, .filters button { height: 40px; min-width: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--white); color: var(--ink); padding: 0 11px; text-transform: none; letter-spacing: 0; font-weight: 600; font-size: .86rem; }
.filters button { align-self: end; cursor: pointer; color: var(--navy); }
.filters button:hover { border-color: var(--blue); background: #f7fcff; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.kpis article { position: relative; overflow: hidden; min-height: 112px; padding: 16px 18px; background: var(--white); border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 4px 16px rgba(18, 48, 84, .04); }
.kpis article::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--blue); }
.kpis article:nth-child(3)::before, .kpis article:nth-child(4)::before { background: var(--orange); }
.kpis span { display: block; color: var(--muted); font-size: .77rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kpis strong { display: block; margin-top: 7px; color: var(--navy); font-size: clamp(1.45rem, 2.5vw, 2rem); line-height: 1; }
.kpis small { display: block; margin-top: 7px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 14px; height: 620px; min-height: 0; }
.map-card, .details, .chart-card, .method-note { background: var(--white); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.map-card { position: relative; overflow: hidden; min-width: 0; min-height: 0; }
#map { width: 100%; height: 100%; min-height: 0; background: #dce9ef; }
.map-status { position: absolute; z-index: 700; top: 12px; left: 50%; transform: translateX(-50%); background: rgba(8, 40, 98, .91); color: #fff; padding: 8px 13px; border-radius: 20px; font-size: .78rem; pointer-events: none; }
.map-status:empty { display: none; }
.map-legend { position: absolute; z-index: 700; left: 12px; bottom: 22px; padding: 10px 12px; border-radius: 9px; background: rgba(255, 255, 255, .94); box-shadow: 0 4px 18px rgba(0,0,0,.16); font-size: .73rem; line-height: 1.55; }
.legend-row { display: flex; align-items: center; gap: 7px; }
.legend-dot { display: inline-block; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); }
.selected-station-symbol { width: 11px; height: 11px; background: #facc15; border: 2px solid #7c2d12; }
.event-station-marker-wrap { display: grid; place-items: center; pointer-events: auto !important; background: transparent; border: 0; }
.event-station-marker { display: block; border-radius: 50%; background: #facc15; border: 2px solid #7c2d12; box-shadow: 0 1px 5px rgba(0,0,0,.35); }

.details { height: 620px; min-height: 0; padding: 18px; overflow-x: hidden; overflow-y: auto; scrollbar-gutter: stable; }
.details-placeholder { height: 100%; min-height: 0; align-content: center; text-align: center; padding: 20px; color: var(--muted); }
.details-placeholder:not([hidden]) { display: grid; }
.details-placeholder[hidden], #event-details[hidden], #station-details[hidden] { display: none !important; }
.details-placeholder .drop { color: var(--teal); font-size: 2rem; }
.details h2 { margin: 5px 0 8px; color: var(--navy); font-size: 1.15rem; }
.details h3 { margin: 22px 0 8px; font-size: .9rem; color: var(--navy); }
.details p { line-height: 1.55; font-size: .86rem; }
.details-heading { display: flex; justify-content: space-between; gap: 10px; }
.details-heading button { border: 0; background: transparent; color: var(--muted); font-size: 1.6rem; cursor: pointer; }
.eyebrow { color: var(--teal); font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 14px 0; background: var(--line); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.detail-grid div { background: var(--white); padding: 10px; }
.detail-grid dt { color: var(--muted); font-size: .67rem; text-transform: uppercase; font-weight: 700; }
.detail-grid dd { margin: 4px 0 0; color: var(--ink); font-size: .85rem; font-weight: 700; overflow-wrap: anywhere; }
.station-detail-note { margin: 12px 2px 0; padding: 10px 12px; border-radius: 8px; background: #eef8fb; color: var(--muted); font-size: .76rem !important; }
.associated-event-button { width: 100%; padding: 0; border: 0; background: transparent; color: var(--blue); font: inherit; font-weight: 800; text-align: left; overflow-wrap: anywhere; cursor: pointer; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.associated-event-button:hover, .associated-event-button:focus { color: var(--navy); outline: none; }

.charts { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-top: 14px; }
.chart-card { min-width: 0; padding: 18px; box-shadow: 0 6px 22px rgba(18, 48, 84, .06); }
.chart-card.wide { display: flex; flex-direction: column; grid-row: span 2; }
.chart-card.wide .chart-wrap { flex: 1 1 auto; height: auto; min-height: 540px; }
.card-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 12px; }
.card-heading h2 { margin: 3px 0 0; color: var(--navy); font-size: 1rem; }
.card-heading p { max-width: 260px; margin: 0; color: var(--muted); font-size: .72rem; text-align: right; }
.chart-wrap { position: relative; height: 270px; }
.chart-wrap.compact { height: 260px; }

.method-note { margin-top: 14px; padding: 20px 24px; box-shadow: none; }
.method-note h2 { margin: 0 0 8px; color: var(--navy); font-size: 1rem; }
.method-note-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.method-note-heading span { color: #9a4c08; font-size: .7rem; font-weight: 800; text-transform: uppercase; }
.method-note p { margin: 6px 0; color: var(--muted); font-size: .82rem; line-height: 1.6; }
.method-note .source { font-size: .74rem; }
footer { padding: 18px; text-align: center; color: var(--muted); font-size: .75rem; }

.methodology-dialog { width: min(850px, calc(100vw - 32px)); max-height: min(84vh, 900px); padding: 0; border: 0; border-radius: 16px; color: var(--ink); background: var(--white); box-shadow: 0 24px 80px rgba(4, 24, 58, .28); }
.methodology-dialog::backdrop { background: rgba(5, 20, 45, .58); backdrop-filter: blur(2px); }
.dialog-heading { position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 20px 24px 14px; background: var(--white); border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 8px 0 0; color: var(--navy); font-size: 1.25rem; }
.dialog-heading button { border: 0; background: transparent; color: var(--muted); font-size: 1.8rem; line-height: 1; cursor: pointer; }
.dialog-lead { margin: 0; padding: 18px 24px 8px; color: var(--muted); font-size: .9rem; line-height: 1.6; }
.method-steps { margin: 0; padding: 8px 38px 10px 48px; }
.method-steps li { margin: 0 0 12px; padding-left: 5px; font-size: .86rem; line-height: 1.6; }
.method-steps strong { color: var(--navy); }
.limitations { margin: 6px 24px 24px; padding: 16px 18px; border-left: 4px solid var(--orange); border-radius: 8px; background: #fff9f3; }
.limitations h3 { margin: 0 0 8px; color: var(--navy); font-size: .9rem; }
.limitations ul { margin: 0; padding-left: 18px; }
.limitations li { margin: 5px 0; color: var(--muted); font-size: .8rem; line-height: 1.5; }

.leaflet-popup-content-wrapper { border-radius: 10px; }
.leaflet-popup-content { width: 340px !important; max-width: calc(100vw - 90px); margin: 14px 18px; }
.popup { min-width: 0; overflow: visible; }
.popup h3 { margin: 0 0 7px; color: var(--navy); font-size: .95rem; overflow-wrap: anywhere; }
.popup dl { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 5px 10px; margin: 0; align-items: start; }
.popup dt { color: var(--muted); }
.popup dd { min-width: 0; margin: 0; font-weight: 700; overflow-wrap: anywhere; word-break: break-word; }
.popup button { width: 100%; margin-top: 10px; border: 0; border-radius: 7px; padding: 7px; color: white; background: var(--navy); cursor: pointer; }
.leaflet-control-layers { border-radius: 9px; color: var(--ink); }
.leaflet-control-layers-expanded { min-width: 165px; }

@media (max-width: 1100px) {
  .topbar { flex-wrap: wrap; }
  .institutional-logos { order: 3; width: 100%; border: 0; border-top: 1px solid var(--line); padding-top: 8px; }
  .filters { grid-template-columns: repeat(4, 1fr); }
  .workspace { grid-template-columns: 1fr; height: auto; }
  .map-card { height: 620px; }
  .details { height: auto; min-height: 300px; max-height: 620px; }
  #map { height: 100%; }
}
@media (max-width: 760px) {
  .topbar { align-items: flex-start; }
  .brand img { width: 92px; height: 48px; }
  .brand p, .freshness { display: none; }
  .institutional-logos { justify-content: flex-start; gap: 9px; overflow-x: auto; }
  .ppgecam-mark { width: 95px; }
  .sgb-mark { width: 88px; }
  .experimental-badge { font-size: .6rem; }
  .methodology-button { height: 32px; padding: 0 9px; font-size: .75rem; }
  .filters { grid-template-columns: 1fr 1fr; }
  .municipality-search { grid-template-columns: 1fr; gap: 9px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .workspace { min-height: auto; }
  .map-card { height: 70vh; min-height: 520px; }
  #map { min-height: 0; height: 100%; }
  .charts { grid-template-columns: 1fr; }
  .chart-card.wide { grid-row: auto; }
  .chart-card.wide .chart-wrap { min-height: 430px; }
}
@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .leaflet-popup-content { width: 275px !important; max-width: calc(100vw - 70px); }
  .popup dl { grid-template-columns: 82px minmax(0, 1fr); }
}
