/* Red de Cuidado — señalética de emergencia: alto contraste, colores con significado fijo,
   botones grandes. Fuentes alojadas en el propio servidor (funcionan sin internet). */

@font-face { font-family: "Atkinson"; src: url("/fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("/fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); font-weight: 700; 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; }
@font-face { font-family: "Barlow Condensed"; src: url("/fonts/barlow-condensed-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --paper: #F3EEE4;
  --card: #FBF8F2;
  --ink: #161412;
  --muted: #5B5650;
  --line: #D8D0C2;
  --focus: #1F5FA8;
  /* Colores con significado: nunca se usan para otra cosa. */
  --ok: #1E7A3D;       --on-ok: #fff;
  --sep: #E3A400;      --on-sep: #161412;
  --med: #C42A1F;      --on-med: #fff;
  --comp: #1F5FA8;     --on-comp: #fff;
  --ret: #0E7472;      --on-ret: #fff;
  --help: #161412;     --on-help: #F3EEE4;
  --warn-bg: #FFF1C2;
  --radius: 14px;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --text: "Atkinson", "Verdana", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121110; --card: #1C1A18; --ink: #F2EDE3; --muted: #B4ADA2; --line: #36322D; --focus: #7FB2F0;
    --ok: #2B9A50; --sep: #F0B51C; --med: #E0392C; --comp: #3C7BC8; --ret: #19918E;
    --help: #F2EDE3; --on-help: #121110; --warn-bg: #3A2F0E;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--paper); color: var(--ink);
  font: 18px/1.45 var(--text); padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
main { max-width: 560px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .01em; line-height: 1.05; margin: 0; }
h1 { font-size: 34px; text-transform: uppercase; }
h2 { font-size: 26px; text-transform: uppercase; margin: 28px 0 10px; }
h3 { font-size: 21px; }
p { margin: 8px 0; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.pad { padding: 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
main:focus, main:focus-visible { outline: none; }

/* ── Franja de conexión: lo primero que se ve. Con rayas de advertencia cuando no hay red. ── */
.net {
  position: sticky; top: 0; z-index: 20; font: 600 17px/1.2 var(--display); letter-spacing: .03em;
  text-transform: uppercase; padding: 9px 16px calc(9px) 16px; text-align: center;
  background: var(--ink); color: var(--paper); padding-top: calc(9px + env(safe-area-inset-top));
}
.net[data-state="online"] { background: var(--card); color: var(--muted); border-bottom: 1px solid var(--line); }
.net[data-state="offline"], .net[data-state="unreachable"] {
  background: repeating-linear-gradient(-45deg, var(--sep) 0 14px, #161412 14px 28px); color: #161412;
}
.net span { background: var(--sep); padding: 2px 10px; border-radius: 6px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.net[data-state="online"] span { background: none; padding: 0; }

/* ── Botones ── */
button, .btn {
  font: 700 19px/1.1 var(--text); color: var(--ink); background: var(--card); border: 2px solid var(--ink);
  border-radius: var(--radius); padding: 14px 18px; min-height: 56px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
button:active, .btn:active { transform: translateY(1px); }
button[disabled] { opacity: .45; cursor: not-allowed; }
.btn.primary, button.primary { background: var(--ink); color: var(--paper); }
.btn.ghost, button.ghost { border-color: var(--line); }
.btn.danger, button.danger { border-color: var(--med); color: var(--med); }
.btn.block, button.block { width: 100%; }
.btn.small, button.small { min-height: 44px; padding: 8px 14px; font-size: 16px; }

/* Botones de estado: el corazón de la app. */
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.sbtn {
  min-height: 104px; border: 0; border-radius: 18px; padding: 14px; text-align: left; justify-content: flex-start;
  align-items: flex-end; font: 700 27px/0.95 var(--display); text-transform: uppercase; letter-spacing: .01em;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.18);
}
.sbtn small { display: block; font: 400 14px/1.2 var(--text); text-transform: none; letter-spacing: 0; margin-top: 6px; opacity: .92; }
.sbtn .lbl { display: block; }
.sbtn.wide { grid-column: 1 / -1; min-height: 112px; font-size: 34px; }
.sbtn.span { grid-column: 1 / -1; min-height: 84px; }
.k-medical { background: var(--med); color: var(--on-med); }
.k-separated { background: var(--sep); color: var(--on-sep); }
.k-accompaniment { background: var(--comp); color: var(--on-comp); }
.k-return_help { background: var(--ret); color: var(--on-ret); }
.k-ok { background: var(--ok); color: var(--on-ok); }
.k-safe_can_help { background: var(--help); color: var(--on-help); }
.k-arrived { background: var(--ok); color: var(--on-ok); }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; background: var(--line); }
.dot.k-ok, .dot.k-arrived, .dot.k-safe_can_help { background: var(--ok); }
.dot.k-medical { background: var(--med); }
.dot.k-separated { background: var(--sep); }
.dot.k-accompaniment { background: var(--comp); }
.dot.k-return_help { background: var(--ret); }
.dot.k-overdue { background: var(--med); box-shadow: 0 0 0 3px color-mix(in srgb, var(--med) 30%, transparent); }

/* ── Tarjetas ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card + .card { margin-top: 10px; }
.card.alert { border: 3px solid var(--med); }
.card.mine { border-left: 8px solid var(--ink); }
.card h3 { margin-bottom: 4px; }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.card .actions > * { flex: 1 1 130px; }
.badge {
  display: inline-block; font: 600 15px/1 var(--display); text-transform: uppercase; letter-spacing: .04em;
  padding: 5px 8px; border-radius: 6px; border: 1.5px solid currentColor;
}
.lifecycle { list-style: none; padding: 0; margin: 10px 0 0; font-size: 15px; }
.lifecycle li { display: flex; gap: 8px; align-items: baseline; color: var(--muted); }
.lifecycle li::before { content: "○"; font-weight: 700; }
.lifecycle li.done { color: var(--ink); }
.lifecycle li.done::before { content: "●"; }
.lifecycle li.now { font-weight: 700; color: var(--ink); }
.warn { background: var(--warn-bg); border: 2px solid var(--sep); border-radius: var(--radius); padding: 12px 14px; }
.emergency {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 18px; padding: 12px 14px;
  border: 2px dashed var(--med); border-radius: var(--radius); font-size: 15px;
}
.emergency a { font: 700 22px/1 var(--display); text-decoration: none; border: 2px solid var(--med); color: var(--med); border-radius: 10px; padding: 8px 12px; }

/* ── Listas de personas ── */
.person { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: start; }
.person .dot { margin-top: 7px; }
.person .who { font-weight: 700; }
.person .actions { grid-column: 1 / -1; }

/* ── Formularios ── */
label { display: block; font-weight: 700; margin: 14px 0 6px; }
input, textarea, select {
  width: 100%; font: 20px/1.3 var(--text); color: var(--ink); background: var(--card);
  border: 2px solid var(--ink); border-radius: 12px; padding: 12px 14px; min-height: 56px;
}
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"] { width: 28px; height: 28px; min-height: 0; flex: none; accent-color: var(--ink); }
.check { display: flex; gap: 12px; align-items: flex-start; font-weight: 400; }
.code-input { font: 700 34px/1 var(--display); letter-spacing: .35em; text-align: center; }
.big-code { font: 700 46px/1 var(--display); letter-spacing: .12em; text-align: center; padding: 18px; border: 3px solid var(--ink); border-radius: var(--radius); user-select: all; }
.hint { font-size: 15px; color: var(--muted); margin-top: 4px; }
.error { color: var(--med); font-weight: 700; }

/* ── Encabezado y pestañas ── */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 6px; }
.top select { width: auto; min-height: 44px; font-size: 17px; padding: 6px 10px; }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 10px; min-height: 64px;
  font: 600 15px/1 var(--display); text-transform: uppercase; letter-spacing: .03em; text-decoration: none; color: var(--muted);
}
.tabs a .ico { font-size: 20px; line-height: 1.2; }
.tabs a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 3px 0 var(--ink); }
.tabs .count { background: var(--med); color: #fff; border-radius: 9px; font: 700 12px/1 var(--text); padding: 2px 6px; }

/* ── Hoja inferior (confirmaciones) ── */
.backdrop { position: fixed; inset: 0; background: rgba(10,9,8,.55); z-index: 40; animation: fade .15s ease-out; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 92dvh; overflow: auto;
  animation: rise .2s cubic-bezier(.2,.8,.2,1); max-width: 600px; margin: 0 auto;
}
.sheet .head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.sheet .chip { width: 22px; height: 22px; border-radius: 6px; flex: none; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 12px; font-weight: 700;
  max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

/* Mensajes */
.msg { max-width: 86%; padding: 10px 14px; border-radius: 16px 16px 16px 4px; background: var(--card); border: 1px solid var(--line); }
.msg.me { margin-left: auto; border-radius: 16px 16px 4px 16px; background: var(--ink); color: var(--paper); border-color: var(--ink); }
.msg.p2 { border: 3px solid var(--med); }
.msg .meta { font-size: 13px; opacity: .8; margin-top: 4px; }
.thread > * + * { margin-top: 8px; }
.composer { position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); background: var(--paper); padding-top: 10px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (min-width: 420px) { .sbtn { min-height: 116px; } }
