@font-face { font-family: "Barlow"; src: url(fonts/barlow-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Barlow"; src: url(fonts/barlow-latin-500-normal.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow"; src: url(fonts/barlow-latin-600-normal.woff2) format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url(fonts/barlow-condensed-latin-500-normal.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url(fonts/barlow-condensed-latin-600-normal.woff2) format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --ink: #17242B;
  --muted: #56656B;
  --paper: #EEF1F0;
  --card: #FFFFFF;
  --line: rgba(23, 36, 43, .16);
  --signal: #F5C400;
  --signal-ink: #2B2300;
  --gps: #1E6BFF;
  --alert: #B8321F;
  --rec: #D7263D;
  --shadow: 0 1px 2px rgba(10, 20, 25, .18), 0 4px 14px rgba(10, 20, 25, .14);
  --sans: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --cond: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #E6ECEE;
    --muted: #9BA9AE;
    --paper: #0F1518;
    --card: #182227;
    --line: rgba(230, 236, 238, .16);
    --alert: #FF7A63;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 4px 14px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--paper); overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--gps); outline-offset: 2px; }
svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; background: #5f6b5a; }
.leaflet-container { font-family: var(--sans); }
.leaflet-control-attribution { font-size: 10px; margin-bottom: var(--sb) !important; }
.geoimg { position: absolute; left: 0; top: 0; max-width: none !important; pointer-events: none; user-select: none; }

/* Barra superior */
.topbar {
  position: fixed; z-index: 1000; left: calc(10px + var(--sl)); right: calc(10px + var(--sr)); top: calc(10px + var(--st));
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 5px;
}
.tb-btn { width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px; display: grid; place-items: center; }
.tb-btn:active { background: var(--paper); }
.tb-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
#mapName { font-family: var(--cond); font-weight: 600; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mapSub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.banner {
  position: fixed; z-index: 999; left: 50%; transform: translateX(-50%); top: calc(76px + var(--st));
  max-width: calc(100% - 24px); background: var(--alert); color: #fff; border-radius: 999px;
  padding: 7px 14px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recchip {
  position: fixed; z-index: 999; left: 50%; transform: translateX(-50%); top: calc(76px + var(--st));
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 10px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px; white-space: nowrap;
}
.banner:not([hidden]) ~ .recchip { top: calc(116px + var(--st)); }
.recdot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* Botones flotantes */
.rail { position: fixed; z-index: 1000; right: calc(12px + var(--sr)); bottom: calc(34px + var(--sb)); display: flex; flex-direction: column; gap: 12px; }
.fab {
  width: 54px; height: 54px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  box-shadow: var(--shadow); display: grid; place-items: center; position: relative;
}
.fab:active { transform: scale(.96); }
.fab[data-state="wait"] { color: var(--muted); }
.fab[data-state="wait"] svg { animation: blink 1.2s infinite; }
.fab[data-state="on"] { color: var(--gps); }
.fab[data-state="follow"] { background: var(--gps); color: #fff; border-color: var(--gps); }
.fab[data-state="follow"] .dot-c { fill: currentColor; }
.fab[data-state="rec"] { background: var(--rec); color: #fff; border-color: var(--rec); }

/* Placa de coordenadas */
.plate {
  position: fixed; z-index: 1000; left: calc(12px + var(--sl)); bottom: calc(34px + var(--sb));
  max-width: calc(100% - 100px - var(--sl) - var(--sr)); min-width: 200px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 0 14px 9px; text-align: left; display: grid; overflow: hidden;
}
.plate-k {
  justify-self: start; margin: 0 0 6px -14px; padding: 3px 10px 3px 14px; border-radius: 0 0 10px 0;
  background: var(--signal); color: var(--signal-ink); font-family: var(--cond); font-weight: 600; font-size: 13px; letter-spacing: .02em;
}
.plate-v { font-family: var(--cond); font-weight: 600; font-size: 23px; line-height: 1.12; font-variant-numeric: tabular-nums; white-space: nowrap; }
.plate-m { margin-top: 4px; font-size: 13px; color: var(--muted); }

.cross { position: fixed; z-index: 500; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; pointer-events: none; color: #fff; filter: drop-shadow(0 0 1.5px rgba(0,0,0,.9)); }

/* Marcador de ubicación */
.me { position: relative; width: 64px; height: 64px; }
.me-dot { position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; background: var(--gps); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); }
.me-cone {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0; margin-left: -20px; margin-top: -32px;
  border-left: 20px solid transparent; border-right: 20px solid transparent; border-bottom: 32px solid rgba(30, 107, 255, .38);
  transform-origin: 20px 32px; border-radius: 4px; transition: transform .15s linear;
}
.me.stale .me-dot { background: #8A979C; }

/* Puntos guardados */
.pin { width: 22px; height: 22px; transform: rotate(45deg); background: var(--signal); border: 2.5px solid #17242B; border-radius: 3px 50% 50% 50%; box-shadow: 0 1px 3px rgba(0,0,0,.45); }
.leaflet-popup-content-wrapper { border-radius: 12px; background: var(--card); color: var(--ink); }
.leaflet-popup-tip { background: var(--card); }
.leaflet-popup-content { margin: 12px 14px; font-size: 14px; line-height: 1.4; }
.pop-t { font-family: var(--cond); font-weight: 600; font-size: 18px; }
.pop-n { color: var(--muted); margin: 2px 0 6px; }
.pop-c { font-variant-numeric: tabular-nums; }
.pop-a { display: flex; gap: 8px; margin-top: 10px; }

/* Hojas inferiores */
.scrim { position: fixed; inset: 0; z-index: 1500; background: rgba(8, 14, 17, .42); }
.sheet {
  position: fixed; z-index: 1600; left: 0; right: 0; bottom: 0; max-height: 86%;
  background: var(--card); border-radius: 20px 20px 0 0; box-shadow: 0 -6px 30px rgba(0,0,0,.25);
  display: flex; flex-direction: column; padding-bottom: var(--sb);
  transform: translateY(105%); transition: transform .26s cubic-bezier(.2,.8,.2,1); visibility: hidden;
}
.sheet.open { transform: none; visibility: visible; }
@media (min-width: 720px) { .sheet { left: 50%; right: auto; width: 560px; margin-left: -280px; } }
.sh-head { display: flex; align-items: center; gap: 10px; padding: 16px 12px 8px 20px; }
.sh-head h2 { flex: 1; margin: 0; font-family: var(--cond); font-weight: 600; font-size: 24px; }
.sh-body { overflow-y: auto; padding: 4px 20px 20px; -webkit-overflow-scrolling: touch; }
.sh-body h3 { font-family: var(--cond); font-weight: 600; font-size: 17px; margin: 18px 0 8px; }
.hint { font-size: 13.5px; color: var(--muted); margin: 6px 0 0; line-height: 1.45; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 500; font-size: 15px;
}
.btn:active { background: var(--paper); }
.btn-main { background: var(--signal); color: var(--signal-ink); border-color: transparent; font-weight: 600; }
.btn-main:active { background: #E2B400; }
.btn-wide { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-danger { color: var(--alert); }

.seg { display: flex; background: var(--paper); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; font-weight: 500; font-size: 15px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.list { list-style: none; margin: 10px 0 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; display: flex; align-items: center; gap: 12px; }
.row-ico { width: 44px; height: 44px; border-radius: 10px; background: var(--paper); display: grid; place-items: center; flex: none; color: var(--ink); }
.row.active .row-ico { background: var(--signal); color: var(--signal-ink); }
.row-t { font-weight: 600; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.row-s { font-size: 13px; color: var(--muted); display: block; margin-top: 2px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--gps); color: #fff; margin-left: 6px; vertical-align: 1px; }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:active { background: var(--paper); }
.empty { text-align: center; padding: 26px 8px 8px; }
.empty p { margin: 0 0 4px; }
.empty .hint { margin-bottom: 18px; }

.field { display: block; margin: 12px 0 0; }
.field span { display: block; font-size: 13.5px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
}
.field textarea { min-height: 76px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }
.range { display: flex; align-items: center; gap: 12px; }
.range input { flex: 1; accent-color: var(--ink); }
.range output { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.actions .btn { flex: 1; }
.coordbox { margin-top: 10px; background: var(--paper); border-radius: 10px; padding: 10px 12px; font-family: var(--cond); font-weight: 500; font-size: 17px; font-variant-numeric: tabular-nums; }

.loading { position: fixed; inset: 0; z-index: 3000; background: rgba(8, 14, 17, .55); display: grid; place-items: center; }
.loading-card { background: var(--card); border-radius: 16px; padding: 22px 26px; display: flex; align-items: center; gap: 14px; max-width: 80%; box-shadow: var(--shadow); }
.loading-card p { margin: 0; font-weight: 500; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; z-index: 4000; left: 50%; top: calc(72px + var(--st)); transform: translate(-50%, -10px); opacity: 0; box-shadow: var(--shadow);
  max-width: calc(100% - 32px); background: var(--ink); color: var(--paper); padding: 11px 16px; border-radius: 12px;
  font-size: 14.5px; line-height: 1.4; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .sheet, .toast, .me-cone { transition: none; }
  .recdot, .fab[data-state="wait"] svg { animation: none; }
}

/* Medición */
.fab[data-state="measure"] { background: var(--signal); color: var(--signal-ink); border-color: var(--signal); }
.measpanel {
  position: fixed; z-index: 1000; left: calc(12px + var(--sl)); right: calc(78px + var(--sr)); bottom: calc(34px + var(--sb));
  max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 10px 12px 12px;
}
.mp-top { display: flex; align-items: center; gap: 6px; }
.mp-top .seg { flex: 1; }
.seg-sm button { min-height: 34px; font-size: 14px; }
.mp-val { font-family: var(--cond); font-weight: 600; font-size: 26px; line-height: 1.1; margin-top: 8px; font-variant-numeric: tabular-nums; }
.mp-sub { font-size: 13px; color: var(--muted); margin-top: 3px; line-height: 1.35; }
.mp-act { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.mp-act .btn { padding: 0 4px; font-size: 13px; }
.vtx { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid #17242B; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.vtx.first { background: var(--signal); }
.seglbl { background: rgba(23, 36, 43, .86); color: #fff; font-family: var(--cond); font-weight: 600; font-size: 13px; padding: 1px 6px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -50%); display: inline-block; pointer-events: none; }
.measuring .leaflet-interactive { cursor: crosshair; }
