:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel2: #172238;
  --line: #22304a;
  --text: #e8eef9;
  --muted: #8a9bb8;
  --blue: #3b82f6;
  --blue2: #2563eb;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: #7fb0ff; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.mono { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.center { text-align: center; }
.ok { color: var(--green); }
.warn { color: var(--amber); }
.bad { color: var(--red); }

/* ---------- Barra superior ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(11,18,32,.94); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: calc(8px + var(--safe-t)) 14px 8px; }
.tb-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tb-title { display: flex; flex-direction: column; min-width: 0; }
.tb-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-badge { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 10px; font-size: 12px; color: var(--green); white-space: nowrap; }
.sync-badge.off { color: var(--amber); }
.sync-badge.pending { color: var(--amber); }
.tb-progress { margin-top: 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pbar-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.pbar { height: 6px; background: var(--panel2); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.pbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--green)); border-radius: 99px; transition: width .4s; }
.pbar.amber > i { background: var(--amber); }
.pbar.red > i { background: var(--red); }

/* ---------- Vista y navegación ---------- */
.view { padding: 12px 12px calc(var(--tabbar) + 24px + var(--safe-b)); max-width: 640px; margin: 0 auto; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; display: grid; grid-template-columns: repeat(5, 1fr); background: rgba(14,22,38,.97); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); backdrop-filter: blur(10px); }
.tabbar button { background: none; border: 0; padding: 7px 0 9px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); }
.tabbar button span { font-size: 20px; line-height: 1.1; filter: grayscale(.6); }
.tabbar button.active { color: #fff; }
.tabbar button.active span { filter: none; }

/* ---------- Tarjetas ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.kpi { background: var(--panel2); border-radius: 10px; padding: 8px; text-align: center; }
.kpi b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 11px; color: var(--muted); }
.meta { font-size: 10.5px; color: #6c7d9b; margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.meta .dot { width: 7px; height: 7px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 999px; padding: 7px 13px; font-size: 13px; }
.chip.active { background: var(--blue2); border-color: var(--blue2); color: #fff; }
.badge { display: inline-block; border-radius: 6px; padding: 1px 7px; font-size: 11px; font-weight: 600; }
.badge.green { background: rgba(16,185,129,.15); color: #34d399; }
.badge.amber { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge.red { background: rgba(239,68,68,.15); color: #f87171; }
.badge.blue { background: rgba(59,130,246,.15); color: #93c5fd; }
.badge.gray { background: rgba(138,155,184,.15); color: var(--muted); }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 10px 14px; min-height: 44px; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--text); cursor: pointer; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--blue2); border-color: var(--blue2); color: #fff; }
.btn.green { background: #059669; border-color: #059669; color: #fff; }
.btn.amber { background: #b45309; border-color: #b45309; color: #fff; }
.btn.danger { background: transparent; border-color: rgba(239,68,68,.5); color: #f87171; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; }
.btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.icon-btn { background: none; border: 0; padding: 6px; color: var(--muted); font-size: 16px; min-width: 34px; min-height: 34px; border-radius: 8px; }
.icon-btn:active { background: var(--panel2); }
.fab { position: fixed; right: 16px; bottom: calc(var(--tabbar) + 16px + var(--safe-b)); z-index: 35; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--blue2); color: #fff; font-size: 30px; box-shadow: 0 8px 24px rgba(0,0,0,.45); }

/* ---------- Línea de tiempo ---------- */
.timeline { position: relative; margin-top: 4px; }
.stop { position: relative; padding: 0 0 14px 34px; }
.stop::before { content: ""; position: absolute; left: 12px; top: 26px; bottom: 0; width: 2px; background: var(--line); }
.stop:last-child::before { display: none; }
.stop .pin { position: absolute; left: 0; top: 2px; width: 26px; height: 26px; border-radius: 50%; background: var(--panel2); border: 2px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.stop.done .pin { background: var(--green); border-color: var(--green); color: #04261b; }
.stop.here .pin { background: var(--amber); border-color: var(--amber); color: #2a1800; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(245,158,11,.18); } }
.stop-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stop-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.stop-name { font-weight: 600; }
.times { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; font-size: 12px; }
.times div { background: rgba(0,0,0,.18); border-radius: 8px; padding: 5px 6px; }
.times b { display: block; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.times span { color: var(--muted); font-size: 10.5px; }
.late { color: #fbbf24; }
.early { color: #34d399; }
.notes { font-size: 12.5px; color: #b9c6dc; margin-top: 6px; white-space: pre-line; }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .grow b { font-weight: 600; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.check { width: 26px; height: 26px; flex: none; border-radius: 8px; border: 2px solid #3a4a68; background: transparent; display: grid; place-items: center; color: #04261b; font-weight: 900; }
.check.on { background: var(--green); border-color: var(--green); }
.item.checked .grow b { color: var(--muted); text-decoration: line-through; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); }
.qty b { min-width: 22px; text-align: center; }
.group-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 16px 2px 6px; display: flex; justify-content: space-between; }
.cat-bar { margin: 8px 0; }
.cat-bar .pbar { height: 8px; }

/* ---------- Hoja inferior (formularios) ---------- */
.sheet { position: fixed; inset: 0; z-index: 1000; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; background: var(--panel); border-radius: 18px 18px 0 0; border-top: 1px solid var(--line); padding: 8px 16px calc(18px + var(--safe-b)); max-width: 640px; margin: 0 auto; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-grip { width: 42px; height: 5px; background: var(--line); border-radius: 9px; margin: 2px auto 10px; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 16px; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.big-amount { font-size: 30px; font-weight: 700; text-align: center; padding: 12px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.seg button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 8px 12px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--blue2); border-color: var(--blue2); color: #fff; }
.results { margin: 6px 0 10px; }
.results button { display: block; width: 100%; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; margin-bottom: 6px; font-size: 13px; }

/* ---------- Mapa ---------- */
.map-wrap { position: fixed; left: 0; right: 0; top: var(--topbar-h, 96px); bottom: calc(var(--tabbar) + var(--safe-b)); z-index: 10; }
#map { position: absolute; inset: 0; background: #0f172a; }
#mapUi { position: absolute; left: 10px; right: 10px; top: 10px; z-index: 500; pointer-events: none; }
#mapUi > * { pointer-events: auto; }
.map-panel { background: rgba(17,26,46,.95); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; font-size: 12.5px; }
.map-ctrls { position: absolute; right: 10px; bottom: 16px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.map-ctrls button { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: rgba(17,26,46,.95); font-size: 20px; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.map-ctrls button.on { background: var(--blue2); border-color: var(--blue2); }
.pick-banner { background: var(--amber); color: #2a1800; font-weight: 700; padding: 10px 12px; border-radius: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.num-icon { background: #1d4ed8; color: #fff; border: 2px solid #fff; border-radius: 50%; width: 26px !important; height: 26px !important; display: grid; place-items: center; font-weight: 700; font-size: 12px; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.num-icon.done { background: #059669; }
.num-icon.end { background: #dc2626; }
.toll-icon { background: #f59e0b; color: #2a1800; border: 2px solid #fff; border-radius: 6px; width: 22px !important; height: 22px !important; display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.me-icon { width: 20px !important; height: 20px !important; border-radius: 50%; background: #3b82f6; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(59,130,246,.3); }
.leaflet-container { font: inherit; }
.leaflet-popup-content { font-size: 13px; }
.leaflet-control-attribution { font-size: 9px; }

/* ---------- Avisos ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + 18px + var(--safe-b)); z-index: 2000; background: #1e293b; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.err { border-color: rgba(239,68,68,.6); }
.alert { border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 10px; border: 1px solid; }
.alert.amber { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.4); color: #fcd34d; }
.alert.red { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.4); color: #fca5a5; }
.alert.green { background: rgba(16,185,129,.1); border-color: rgba(16,185,129,.4); color: #6ee7b7; }
.empty { text-align: center; color: var(--muted); padding: 24px 10px; }

/* ---------- Ingreso / instalación ---------- */
.page-auth { display: flex; align-items: center; justify-content: center; padding: 20px; min-height: 100vh; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 24px; }
.auth-card.wide { max-width: 520px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card h2 { font-size: 15px; margin: 20px 0 8px; color: #93c5fd; }
.auth-logo { font-size: 42px; }
.auth-card form { margin-top: 16px; }
.auth-card fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 4px; margin: 0 0 10px; }
.auth-card fieldset input { margin-bottom: 8px; }
.auth-card legend { font-size: 13px; padding: 0 6px; display: flex; align-items: center; gap: 6px; }
.hint { font-size: 12px; color: var(--muted); margin-top: -4px; }
.err-box { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.4); color: #fca5a5; border-radius: 10px; padding: 10px; font-size: 13px; }
.ok-box { background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.4); color: #6ee7b7; border-radius: 10px; padding: 10px; font-size: 14px; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
