:root {
  --bg: #f4f2ec;
  --card: #ffffff;
  --ink: #1d231f;
  --ink-2: #5a645d;
  --ink-3: #8b948d;
  --line: #e3e0d7;
  --accent: #2f5d3a;
  --accent-ink: #ffffff;
  --accent-soft: #e4ede4;
  --bien: #2e8b4f;
  --atencion: #c77a12;
  --alerta: #c8362f;
  --bien-soft: #e1f1e6;
  --atencion-soft: #fbeed8;
  --alerta-soft: #f8e0dd;
  --chart-now: #2463c9;
  --chart-prev: #e08a1e;
  --chart-band: rgba(110, 120, 112, .18);
  --chart-mid: #8b948d;
  --shadow: 0 1px 2px rgba(30, 35, 30, .06), 0 2px 8px rgba(30, 35, 30, .05);
  --tabs-h: 58px;
  --top-h: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1512;
    --card: #18201b;
    --ink: #e8ece8;
    --ink-2: #a7b1aa;
    --ink-3: #78837b;
    --line: #2a332d;
    --accent: #7fbf8e;
    --accent-ink: #0f1512;
    --accent-soft: #213027;
    --bien: #5cc27f;
    --atencion: #e9a23b;
    --alerta: #f06a5f;
    --bien-soft: #1c3124;
    --atencion-soft: #382a14;
    --alerta-soft: #3c1d1a;
    --chart-now: #6ea1ff;
    --chart-prev: #f0a34a;
    --chart-band: rgba(200, 210, 200, .14);
    --chart-mid: #78837b;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1512; --card: #18201b; --ink: #e8ece8; --ink-2: #a7b1aa; --ink-3: #78837b; --line: #2a332d;
  --accent: #7fbf8e; --accent-ink: #0f1512; --accent-soft: #213027;
  --bien: #5cc27f; --atencion: #e9a23b; --alerta: #f06a5f;
  --bien-soft: #1c3124; --atencion-soft: #382a14; --alerta-soft: #3c1d1a;
  --chart-now: #6ea1ff; --chart-prev: #f0a34a; --chart-band: rgba(200,210,200,.14); --chart-mid: #78837b;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; text-wrap: balance; }
p { margin: 0 0 .7em; }
p:last-child { margin-bottom: 0; }
.num { font-variant-numeric: tabular-nums; }

#top {
  position: sticky; top: 0; z-index: 900;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  display: flex; align-items: center; gap: 6px;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
#title { font-size: 17px; font-weight: 650; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 4px; }
.net { font-size: 12px; color: var(--atencion); background: var(--atencion-soft); padding: 2px 8px; border-radius: 99px; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; color: var(--accent); }
.icon-btn:active { background: var(--accent-soft); }

main { padding: 12px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); max-width: 720px; margin: 0 auto; outline: none; }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--card); border-top: 1px solid var(--line);
}
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--ink-3); font-size: 11.5px; font-weight: 550; }
#tabs a svg { width: 24px; height: 24px; }
#tabs a[aria-current="page"] { color: var(--accent); }

.card { background: var(--card); border-radius: 14px; padding: 14px 16px; margin: 0 0 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card > h2, .card > h3 { margin-bottom: 8px; }
.section-title { font-size: 13px; font-weight: 650; letter-spacing: .02em; text-transform: uppercase; color: var(--ink-2); margin: 22px 4px 8px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.tiny { font-size: 12.5px; color: var(--ink-3); }

.hero { padding: 6px 2px 4px; }
.hero .date { color: var(--ink-2); font-size: 14px; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hero h2 { font-size: 23px; margin: 4px 0 8px; }
.hero .lead { font-size: 17px; color: var(--ink); }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 650; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.bien { color: var(--bien); background: var(--bien-soft); }
.badge.atencion { color: var(--atencion); background: var(--atencion-soft); }
.badge.alerta { color: var(--alerta); background: var(--alerta-soft); }
.prio { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.prio.alta { color: var(--alerta); }
.prio.media { color: var(--atencion); }
.prio.baja { color: var(--ink-3); }

.md h3, .md h4 { margin: 14px 0 6px; font-size: 16px; }
.md ul, .md ol { margin: 0 0 .7em; padding-left: 1.25em; }
.md li { margin: .25em 0; }
.md strong { font-weight: 650; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; text-decoration: none; color: inherit; }
.row:first-child { padding-top: 2px; }
.row:last-child { padding-bottom: 2px; }
a.row:active { opacity: .7; }
.row .grow { flex: 1; min-width: 0; }
.row .chev { color: var(--ink-3); align-self: center; }
.zone-num { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff; }
.zone-num.alta { background: var(--alerta); }
.zone-num.media { background: var(--atencion); }
.zone-num.baja { background: #7b8a7f; }

.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; cursor: pointer; }
.check input { appearance: none; -webkit-appearance: none; flex: none; width: 24px; height: 24px; margin: 1px 0 0; border: 2px solid var(--ink-3); border-radius: 7px; display: grid; place-items: center; cursor: pointer; background: var(--card); }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--accent-ink); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
.check input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.check.done .title { text-decoration: line-through; color: var(--ink-3); }
.check .title { font-weight: 600; }
.check .meta { font-size: 13px; color: var(--ink-2); display: flex; gap: 8px; flex-wrap: wrap; margin: 1px 0 3px; }
.check details summary { font-size: 14px; color: var(--accent); cursor: pointer; list-style: none; }
.check details summary::-webkit-details-marker { display: none; }
.check details p { font-size: 15px; margin-top: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 8px 0 0; }
.stat { background: var(--bg); border-radius: 10px; padding: 9px 11px; }
.stat .v { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12.5px; color: var(--ink-2); line-height: 1.3; }

.sec-card { display: block; text-decoration: none; color: inherit; }
.sec-card .head { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 4px; }
.sec-card .head h3 { font-size: 17px; }
.sec-card .figs { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--ink-2); margin-top: 8px; }
.sec-card .figs b { color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; }

.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn { appearance: none; border: 0; border-radius: 11px; padding: 11px 16px; min-height: 44px; font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; cursor: pointer; background: var(--accent-soft); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .5; }
.btn.block { width: 100%; }

.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 2px; margin-bottom: 8px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; min-height: 34px; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--ink-3); font-size: 10.5px; font-family: inherit; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--ink-3); stroke-width: 1; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.chart-legend i.band { height: 10px; background: var(--chart-band); }

.dist { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 6px 0 8px; }
.dist span { display: block; height: 100%; }
.keyrow { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--ink-2); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

.wx { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(52px, 1fr); gap: 4px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.wx::-webkit-scrollbar { display: none; }
.wx .d { text-align: center; font-size: 12px; color: var(--ink-2); background: var(--bg); border-radius: 9px; padding: 6px 2px; }
.wx .d b { display: block; color: var(--ink); font-size: 13px; }
.wx .d .t { font-variant-numeric: tabular-nums; }
.wx .d .r { color: var(--chart-now); font-weight: 600; font-variant-numeric: tabular-nums; }
.wx .d.alert { outline: 2px solid var(--atencion); outline-offset: -2px; }
.alert-box { display: flex; gap: 10px; background: var(--atencion-soft); color: var(--ink); border-radius: 11px; padding: 10px 12px; margin: 10px 0 0; font-size: 14.5px; }
.alert-box b { color: var(--atencion); }

.bar-h { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-h > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.cov { display: grid; grid-template-columns: 92px 1fr 44px; gap: 8px; align-items: center; font-size: 13.5px; padding: 3px 0; }

.banner { display: flex; gap: 10px; align-items: center; background: var(--accent-soft); color: var(--ink); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14.5px; }
.banner .grow { flex: 1; }

.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

textarea, input[type="text"], input[type="password"] { width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
textarea { min-height: 96px; resize: vertical; }
.error { color: var(--alerta); font-size: 14px; margin-top: 8px; }

/* Map */
#map-wrap { position: fixed; left: 0; right: 0; top: calc(var(--top-h) + env(safe-area-inset-top)); bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); z-index: 10; }
#map { position: absolute; inset: 0; background: #2a2f2b; }
.chips { position: absolute; top: 10px; left: 0; right: 0; z-index: 500; display: flex; gap: 6px; overflow-x: auto; padding: 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 0; border-radius: 99px; padding: 7px 13px; font-size: 13.5px; font-weight: 600; background: rgba(255,255,255,.92); color: #1d231f; box-shadow: 0 1px 4px rgba(0,0,0,.25); cursor: pointer; min-height: 36px; }
.chips button[aria-checked="true"] { background: #2f5d3a; color: #fff; }
.legend { position: absolute; left: 12px; bottom: 12px; z-index: 500; background: rgba(255,255,255,.94); color: #1d231f; border-radius: 10px; padding: 7px 10px; font-size: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.25); max-width: calc(100% - 90px); }
.legend .ramp { height: 8px; border-radius: 4px; margin: 4px 0 2px; min-width: 150px; }
.legend .ends { display: flex; justify-content: space-between; gap: 10px; color: #5a645d; }
.legend .keyrow { color: #1d231f; font-size: 12px; }
.fab { position: absolute; right: 12px; bottom: 12px; z-index: 500; width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgba(255,255,255,.95); color: #2f5d3a; display: grid; place-items: center; box-shadow: 0 1px 5px rgba(0,0,0,.3); cursor: pointer; }
.fab.on { background: #2463c9; color: #fff; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 800; background: var(--card); color: var(--ink); border-radius: 18px 18px 0 0; box-shadow: 0 -4px 18px rgba(0,0,0,.22); padding: 8px 16px 16px; max-height: 62%; overflow-y: auto; overscroll-behavior: contain; }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet .close { position: absolute; top: 8px; right: 8px; }
.zone-label { background: none; border: 0; }
/* names on the map: sections white on dark, the owner's marks on blue (a point also gets a dot on its spot) */
.map-name { background: none; border: 0; }
.map-name span { position: absolute; transform: translate(-50%, -50%); white-space: nowrap; padding: 1px 8px; border-radius: 9px; font-size: 12px; line-height: 16px; font-weight: 600; color: #fff; background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.35); pointer-events: none; }
.map-name.point span, .map-name.line span { background: rgba(10,132,255,.9); border-color: rgba(255,255,255,.9); }
.map-name.point span { transform: translate(-50%, calc(-100% - 8px)); }
.map-name i { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; box-sizing: border-box; border-radius: 50%; background: #0a84ff; border: 2px solid #fff; pointer-events: none; }
.zone-label span { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: #fff; font-weight: 700; font-size: 13px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #2463c9; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(36,99,201,.25); }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10px; }

/* Guide */
.guide { text-align: center; padding-top: 8px; }
.guide .target { font-size: 20px; font-weight: 650; margin-bottom: 2px; }
.guide .arrow-wrap { width: min(68vw, 280px); aspect-ratio: 1; margin: 18px auto 8px; position: relative; }
.guide .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--line); }
.guide .arrow { position: absolute; inset: 12%; transition: transform .25s ease-out; }
.guide .arrow.arrived { transform: none !important; }
.guide .distance { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.guide .hint { color: var(--ink-2); font-size: 15px; min-height: 1.5em; }
#guide-map { height: 190px; border-radius: 14px; overflow: hidden; margin-top: 16px; border: 1px solid var(--line); }

@media (prefers-reduced-motion: reduce) {
  .guide .arrow { transition: none; }
  .spinner { animation-duration: 2.5s; }
}
@media (hover: hover) {
  a.row:hover .grow h3, a.row:hover .grow .title { color: var(--accent); }
  .btn:hover { filter: brightness(.97); }
}
