:root {
  color-scheme: dark;
  --bg: #08111f;
  --surface: rgba(10, 23, 41, .9);
  --surface-strong: #0d1b2e;
  --line: rgba(202, 221, 255, .16);
  --text: #f4f8ff;
  --muted: #aab9ce;
  --normal: #35d895;
  --affected: #ff6474;
  --daf: #61a8ff;
  --waiting: #b69aff;
  --missing: #f5c84c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body, .app-shell, #map { width: 100%; min-height: 100%; margin: 0; }
body { min-height: 100vh; overflow: hidden; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

#map { height: 100dvh; background: #0b1829; }
.leaflet-container { font: inherit; background: #0b1829; }
.leaflet-tile-pane { filter: brightness(.43) saturate(.72) contrast(1.12); }
.leaflet-top.leaflet-left { top: 125px; }
.leaflet-control-zoom { border: 1px solid var(--line) !important; border-radius: 12px !important; overflow: hidden; box-shadow: 0 12px 30px rgba(0,0,0,.32); }
.leaflet-control-zoom a { background: var(--surface-strong) !important; border-color: var(--line) !important; color: var(--text) !important; }
.leaflet-tooltip { border: 1px solid var(--line); border-radius: 10px; background: #102139; color: var(--text); box-shadow: 0 8px 22px rgba(0,0,0,.25); }
.leaflet-tooltip-top:before { border-top-color: #102139; }

.topbar { position: fixed; z-index: 1000; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; align-items: center; gap: 12px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.wordmark { flex: 0 0 auto; color: var(--text); text-decoration: none; font-size: 1.05rem; letter-spacing: -.02em; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); backdrop-filter: blur(14px); }
.wordmark strong { color: #65e5c2; }
.hud { flex: 1 1 auto; display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.hud::-webkit-scrollbar { display: none; }
.hud-item { flex: 0 0 auto; display: grid; grid-template-columns: auto auto; gap: 0 6px; align-items: center; min-width: 82px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--muted); text-align: left; backdrop-filter: blur(14px); transition: .18s ease; }
.hud-item:hover, .hud-item.active { border-color: var(--status); background: color-mix(in srgb, var(--status) 16%, #0d1b2e); color: var(--text); }
.hud-dot { grid-row: span 2; width: 8px; height: 8px; border-radius: 50%; background: var(--status); box-shadow: 0 0 12px var(--status); }
.hud-item strong { font-size: 1.08rem; line-height: 1; color: var(--text); }
.hud-item span { font-size: .67rem; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 7px; }
.updated-at { display: none; color: var(--muted); font-size: .72rem; white-space: nowrap; }
.icon-button, .main-menu summary { width: 39px; height: 39px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); backdrop-filter: blur(14px); font-size: 1.12rem; }
.main-menu { position: relative; }
.main-menu summary { list-style: none; }
.main-menu summary::-webkit-details-marker { display: none; }
.main-menu nav { position: absolute; right: 0; top: calc(100% + 8px); display: grid; min-width: 205px; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #102039; box-shadow: 0 18px 40px rgba(0,0,0,.4); }
.main-menu a { padding: 12px 14px; color: var(--text); text-decoration: none; font-size: .9rem; }
.main-menu a + a { border-top: 1px solid var(--line); }
.main-menu a:hover { background: rgba(255,255,255,.07); }

.map-tools { position: fixed; z-index: 900; top: 70px; left: 12px; display: flex; gap: 8px; pointer-events: auto; }
.search-box, .municipio-select select { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 8px 22px rgba(0,0,0,.2); backdrop-filter: blur(14px); }
.search-box { display: flex; overflow: hidden; }
.search-box input { width: 215px; border: 0; outline: 0; padding: 10px 11px; background: transparent; color: var(--text); }
.search-box input::placeholder { color: var(--muted); }
.search-box button { border: 0; border-left: 1px solid var(--line); padding: 0 12px; background: transparent; color: #72e6c5; font-weight: 700; }
.municipio-select select { height: 41px; max-width: 210px; padding: 0 31px 0 11px; color: var(--text); outline: 0; }

.map-controls { position: fixed; z-index: 900; right: 12px; bottom: 32px; display: grid; gap: 8px; }
.map-control { position: relative; }
.map-control summary { list-style: none; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); font-size: .82rem; font-weight: 700; box-shadow: 0 8px 22px rgba(0,0,0,.2); backdrop-filter: blur(14px); cursor: pointer; }
.map-control summary::-webkit-details-marker { display: none; }
.control-content { position: absolute; right: 0; bottom: calc(100% + 7px); min-width: 172px; padding: 11px; border: 1px solid var(--line); border-radius: 12px; background: #102039; box-shadow: 0 18px 40px rgba(0,0,0,.4); font-size: .84rem; }
.control-content label { display: flex; align-items: center; gap: 8px; }
.legend { display: grid; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.legend i { width: 9px; height: 9px; border-radius: 50%; background: var(--status); box-shadow: 0 0 10px var(--status); }

.power-gauge { --gauge-tone: var(--affected); position: fixed; z-index: 900; bottom: 30px; left: 12px; width: 156px; padding: 10px 10px 8px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 10px 28px rgba(0,0,0,.28); backdrop-filter: blur(14px); }
.gauge-label { display: block; color: var(--muted); font-size: .7rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.gauge-dial { position: relative; width: 118px; height: 59px; margin: 10px auto 0; overflow: hidden; }
.gauge-dial::before { content: ""; position: absolute; inset: 0; width: 118px; height: 118px; border-radius: 50%; background: conic-gradient(from 270deg, var(--affected) 0deg 49deg, var(--missing) 49deg 131deg, var(--normal) 131deg 180deg, transparent 180deg 360deg); }
.gauge-dial::after { content: ""; position: absolute; width: 92px; height: 92px; left: 13px; top: 13px; border-radius: 50%; background: #0c1a2d; }
.gauge-needle { position: absolute; z-index: 2; bottom: 0; left: 57px; width: 3px; height: 47px; border-radius: 99px; background: var(--gauge-tone); box-shadow: 0 0 8px var(--gauge-tone); transform-origin: 50% 100%; transform: rotate(var(--needle-angle, -90deg)); transition: transform .35s ease, background .25s ease; }
.gauge-needle::after { content: ""; position: absolute; width: 9px; height: 9px; bottom: -3px; left: -3px; border: 2px solid #0c1a2d; border-radius: 50%; background: var(--gauge-tone); }
.gauge-value { position: absolute; z-index: 3; bottom: 1px; left: 0; right: 0; display: grid; justify-items: center; line-height: 1; }
.gauge-value strong { font-size: 1.48rem; letter-spacing: -.05em; }
.gauge-value span { margin-top: 3px; color: var(--gauge-tone); font-size: .72rem; font-weight: 800; }
.gauge-scale { display: flex; justify-content: space-between; margin: 4px 2px 0; color: var(--muted); font-size: .62rem; font-style: normal; }
.gauge-scale i { font-style: normal; }

.hospital-marker { display: grid; place-items: center; width: 26px !important; height: 26px !important; border: 1px solid rgba(255,255,255,.48); border-radius: 50% 50% 50% 8%; transform: rotate(-45deg); background: #e9f3ff; box-shadow: 0 6px 15px rgba(0,0,0,.4); }
.hospital-marker span { color: #173254; font-size: 17px; font-weight: 800; transform: rotate(45deg); line-height: 1; }

.empty-state { position: fixed; z-index: 1100; top: 50%; left: 50%; width: min(360px, calc(100% - 32px)); padding: 20px; border: 1px solid rgba(255,100,116,.5); border-radius: 18px; background: #172036; box-shadow: 0 20px 50px rgba(0,0,0,.45); transform: translate(-50%, -50%); text-align: center; }
.empty-state strong, .empty-state span { display: block; }
.empty-state span { margin: 7px 0 15px; color: var(--muted); font-size: .9rem; }
.empty-state button { border: 0; border-radius: 10px; padding: 9px 13px; background: #65e5c2; color: #06121d; font-weight: 800; }

.sheet { position: fixed; z-index: 1100; left: 50%; bottom: 0; width: min(640px, 100%); max-height: min(72dvh, 620px); padding: 8px 18px calc(20px + env(safe-area-inset-bottom)); overflow: auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 23px 23px 0 0; background: #0b1729; box-shadow: 0 -16px 45px rgba(0,0,0,.38); transform: translate(-50%, 110%); transition: transform .28s cubic-bezier(.2,.8,.2,1), max-height .25s ease; }
.sheet.open { transform: translate(-50%, 0); }
.sheet.expanded { max-height: 100dvh; border-radius: 0; }
.sheet-handle { width: 38px; height: 4px; margin: 1px auto 12px; border-radius: 99px; background: #4d5f78; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.sheet-kicker { margin: 0 0 3px; color: var(--muted); font-size: .78rem; }
.sheet h1 { margin: 0; font-size: 1.55rem; letter-spacing: -.03em; }
.close-sheet { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--text); font-size: 1.4rem; line-height: 1; }
.status-row { display: flex; align-items: center; gap: 9px; margin: 15px 0; }
.state-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; color: var(--status); background: color-mix(in srgb, var(--status) 15%, transparent); font-size: .82rem; font-weight: 800; }
.state-pill i { width: 7px; height: 7px; border-radius: 99px; background: currentColor; }
.duration { margin-left: auto; color: var(--muted); font-size: .83rem; text-align: right; }
.duration strong { display: block; color: var(--text); font-size: 1rem; }
.location-note { margin: 0 0 13px; padding: 10px 11px; border: 1px solid rgba(245,200,76,.36); border-radius: 11px; color: #f9db82; background: rgba(245,200,76,.08); font-size: .83rem; }
.history-title { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 8px; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.timeline-key { display: flex; flex-wrap: wrap; gap: 6px 10px; margin: 0 0 9px; color: var(--muted); font-size: .68rem; }
.timeline-key span { display: inline-flex; align-items: center; gap: 4px; }
.timeline-key i { width: 7px; height: 7px; border-radius: 2px; }
.timeline-key .normal, .day-track .normal { background: var(--normal); }
.timeline-key .affected, .day-track .affected { background: var(--affected); }
.timeline-key .daf, .day-track .daf { background: var(--daf); }
.timeline-key .waiting, .day-track .waiting { background: var(--waiting); }
.timeline-hours { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 9px; margin: 0 0 3px; color: var(--muted); font-size: .6rem; }
.timeline-hours div { display: flex; justify-content: space-between; }
.timeline-hours i { font-style: normal; }
.day-timeline { display: grid; gap: 7px; }
.day-bar { display: grid; grid-template-columns: 58px minmax(0, 1fr); align-items: center; gap: 9px; }
.day-label { display: grid; line-height: 1.05; }
.day-label strong { color: var(--text); font-size: .74rem; }
.day-label span { margin-top: 3px; color: var(--muted); font-size: .66rem; text-transform: capitalize; }
.day-track { position: relative; height: 17px; overflow: hidden; border: 1px solid rgba(210,226,255,.22); border-radius: 99px; background: #18263a; }
.day-track::after { content: ""; position: absolute; z-index: 2; inset: 0; opacity: .52; background: repeating-linear-gradient(90deg, transparent 0 calc(4.166% - 1px), rgba(255,255,255,.48) calc(4.166% - 1px) 4.166%); pointer-events: none; }
.day-track i { position: absolute; z-index: 1; top: 0; bottom: 0; min-width: 1px; }
.day-track .missing { background: #48566a; }
.sheet-button { width: 100%; margin-top: 14px; padding: 11px; border: 1px solid rgba(101,229,194,.46); border-radius: 11px; background: rgba(101,229,194,.1); color: #83efd1; font-weight: 800; }
.no-history { padding: 13px; border: 1px dashed var(--line); border-radius: 11px; color: var(--muted); font-size: .86rem; text-align: center; }

.toast { position: fixed; z-index: 1200; bottom: 27px; left: 50%; padding: 11px 14px; border: 1px solid rgba(101,229,194,.45); border-radius: 12px; background: #12332f; color: #d8fff3; box-shadow: 0 12px 30px rgba(0,0,0,.36); transform: translateX(-50%); font-size: .87rem; }

@media (min-width: 760px) {
  .updated-at { display: block; }
  .sheet { bottom: 18px; border-bottom: 1px solid var(--line); border-radius: 20px; }
  .sheet.expanded { bottom: 0; max-height: calc(100dvh - 36px); border-radius: 20px; }
}
@media (max-width: 650px) {
  .topbar { align-items: flex-start; gap: 7px; }
  .wordmark { font-size: .9rem; padding: 10px; }
  .hud { max-width: calc(100vw - 158px); }
  .hud-item { min-width: 76px; padding: 7px 8px; }
  .top-actions { gap: 5px; }
  .icon-button, .main-menu summary { width: 36px; height: 36px; }
  .map-tools { top: 63px; right: 12px; display: grid; }
  .search-box input { width: calc(100vw - 112px); }
  .municipio-select select { width: 100%; max-width: none; }
  .map-controls { bottom: 24px; }
  .power-gauge { bottom: 23px; width: 143px; }
  .leaflet-top.leaflet-left { top: 172px; }
}
