:root {
  --bg: #eef2f5;
  --surface: #ffffff;
  --ink: #0a1f44;
  --muted: #5b6b85;
  --line: #d9e0e8;
  --hivis: #ffd400;
  --sos: #d7263d;
  --ok: #0b8a5a;
  --warn: #b25e00;
  --radius: 16px;
  --display: "Bahnschrift", "DIN Alternate", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--body);
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); letter-spacing: 0.01em; line-height: 1.15; margin: 0; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
:focus-visible { outline: 3px solid var(--hivis); outline-offset: 2px; box-shadow: 0 0 0 5px var(--ink); }

/* Marca */
.brand { display: flex; align-items: center; gap: 10px; font: 700 1.35rem var(--display); }
.brand.big { font-size: 2.2rem; }
.mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  background: var(--hivis); color: var(--ink); border-radius: 9px; font-weight: 800;
}
.big .mark { width: 56px; height: 56px; border-radius: 14px; font-size: 1.9rem; }

/* Estructura */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--ink); color: #fff;
}
.topbar .mark { width: 30px; height: 30px; }
.content { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  appearance: none; border: 0; background: none; color: var(--muted);
  padding: 10px 4px 9px; font: 600 0.78rem var(--body);
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
  border-top: 3px solid transparent;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.on { color: var(--ink); border-top-color: var(--hivis); }

/* Tarjetas */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card.stack > h2 + .muted { margin-top: -8px; }
.section-title { font: 700 1.05rem var(--display); margin: 6px 2px -4px; color: var(--muted); }

/* Ficha de emergencia (elemento protagonista) */
.sos { background: var(--sos); color: #fff; border-radius: 22px; padding: 18px; }
.sos-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sos-head p { font-size: 0.9rem; opacity: 0.92; margin-bottom: 4px; }
.sos-head h2 { font-size: 1.7rem; word-break: break-word; }
.blood {
  background: #fff; color: var(--ink); border-radius: 14px; padding: 8px 14px;
  text-align: center; flex: none; min-width: 78px;
}
.blood small { display: block; font-size: 0.72rem; color: var(--muted); }
.blood b { font: 800 2.5rem/1 var(--display); }
.facts { margin: 14px 0 0; display: grid; gap: 8px; }
.facts div { background: rgba(255, 255, 255, 0.14); border-radius: 12px; padding: 10px 12px; }
.facts dt { font-size: 0.8rem; opacity: 0.9; }
.facts dd { margin: 2px 0 0; font-size: 1.05rem; font-weight: 600; white-space: pre-wrap; word-break: break-word; }
.callbtn {
  display: block; margin-top: 12px; background: var(--hivis); color: var(--ink);
  text-decoration: none; border-radius: 14px; padding: 14px 16px;
}
.callbtn span { display: block; font-size: 0.88rem; }
.callbtn b { font: 700 1.5rem var(--display); }

/* Conductor y vehículo */
.driver { display: flex; gap: 14px; align-items: center; }
.avatar {
  width: 76px; height: 76px; border-radius: 50%; object-fit: cover; flex: none;
  background: var(--line); display: grid; place-items: center; overflow: hidden;
  font: 700 1.6rem var(--display); color: var(--muted);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0 0; }
.kv dt { color: var(--muted); font-size: 0.9rem; }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.plate {
  display: inline-block; background: #fff; color: #111; border: 3px solid #111; border-radius: 10px;
  padding: 2px 14px; font: 800 2rem/1.25 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.12em;
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-btn {
  appearance: none; border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 6px 14px; font: 700 0.95rem ui-monospace, Menlo, Consolas, monospace; cursor: pointer;
}
.chip-btn.on { border-color: var(--ink); background: var(--ink); color: #fff; }

/* Documentos */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.tile {
  appearance: none; text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 8px;
  display: flex; flex-direction: column; gap: 8px;
}
.tile.missing { cursor: default; opacity: 0.8; border-style: dashed; }
.thumb {
  aspect-ratio: 4 / 3; border-radius: 10px; background: var(--line); display: grid; place-items: center;
  overflow: hidden; color: var(--muted); font-weight: 700;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .pdf { background: var(--ink); color: #fff; padding: 6px 12px; border-radius: 8px; font-family: var(--display); letter-spacing: 0.06em; }
.tile-body { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; font-size: 0.92rem; }
.tile-body small { color: var(--muted); }

.chip { display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; }
.chip.ok { background: #d9f2e7; color: var(--ok); }
.chip.warn { background: #ffe9c7; color: var(--warn); }
.chip.bad { background: #fbd9de; color: var(--sos); }
.chip.none { background: var(--line); color: var(--muted); }

.slot {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.slot:first-of-type { border-top: 0; }
.slot-info { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.slot-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Formularios y botones */
.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 0.92rem; }
.field input, .field select, .field textarea {
  font: 400 1rem var(--body); color: var(--ink); background: #fff;
  border: 1.5px solid #b9c4d3; border-radius: 12px; padding: 11px 12px; width: 100%;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.92rem; font-weight: 500; }
.check input { width: 22px; height: 22px; flex: none; margin-top: 1px; accent-color: var(--ink); }

.btn {
  appearance: none; cursor: pointer; font: 700 1rem var(--body); text-decoration: none; text-align: center;
  border: 2px solid var(--ink); background: var(--surface); color: var(--ink);
  border-radius: 12px; padding: 12px 18px; min-height: 46px; display: inline-flex; align-items: center; justify-content: center;
}
.btn.primary { background: var(--hivis); border-color: var(--hivis); }
.btn.small { padding: 7px 12px; min-height: 38px; font-size: 0.9rem; border-width: 1.5px; }
.btn.ghost { border-color: transparent; background: none; }
.btn.danger { color: var(--sos); border-color: var(--sos); }
.btn.ghost.danger { border-color: transparent; }
.btn.link { border: 0; background: none; text-decoration: underline; min-height: 0; padding: 6px; }
.btn:disabled { opacity: 0.55; cursor: progress; }

.pill { font-size: 0.8rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--hivis); color: var(--ink); }
.pill.none { background: var(--line); color: var(--muted); display: inline-block; width: fit-content; }
.notice { background: #fff3c4; border: 1px solid #e8cf5b; border-radius: 12px; padding: 10px 12px; font-size: 0.92rem; }
.linkbox { background: var(--bg); border: 1px dashed #9fb0c7; border-radius: 12px; padding: 10px 12px; overflow-wrap: anywhere; font-size: 0.88rem; }
.empty { text-align: left; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }

.vehicle-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.vehicle-row:first-of-type { border-top: 0; }

/* Acceso */
.auth { max-width: 420px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 18px 40px; display: flex; flex-direction: column; gap: 16px; }
.auth .tagline { font-size: 1.05rem; color: var(--muted); }

/* Modal, visor y avisos */
.modal {
  position: fixed; inset: 0; z-index: 20; background: rgba(10, 31, 68, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
}
.viewer { position: fixed; inset: 0; z-index: 30; background: #050d1f; display: flex; flex-direction: column; color: #fff; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
.viewer-bar .btn { color: #fff; border-color: #fff; background: none; }
.viewer-body { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 10px calc(14px + env(safe-area-inset-bottom)); align-items: center; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; margin: auto; touch-action: pinch-zoom; }
.viewer-body iframe { width: 100%; flex: 1; min-height: 60vh; border: 0; background: #fff; border-radius: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(12px);
  z-index: 40; background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 12px; max-width: 90vw;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; font-weight: 600; font-size: 0.95rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(3, 1fr); } }

.pw { display: flex; gap: 8px; align-items: center; }
.pw input { flex: 1; min-width: 0; }
