/* ============ SOS Digital · app funcional · sistema "Dos mundos" ============
   luz  = producto en paz (inicio, registro)
   noche = emergencia (pánico, pre-bloqueo, crisis, cierre) */

:root {
  --noche: #0B0E14; --panel-n: #121721; --elev-n: #1A2130; --hair-n: #232C3D;
  --tinta-n: #E8ECF4; --tenue-n: #8A94A6;
  --luz: #F4F5F2; --panel-l: #FFFFFF; --tinta-l: #10131A; --tenue-l: #6A7180; --hair-l: #E2E4E0;
  --rojo: #FF4438; --rojo-prof: #C21F14; --rojo-glow: rgba(255, 68, 56, .32);
  --verde: #2FBF8F; --verde-fondo: rgba(47, 191, 143, .12);
  --ambar: #F0A93C; --ambar-fondo: rgba(240, 169, 60, .14);
  --mono: "Cascadia Code", ui-monospace, Consolas, monospace;
  --sans: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  font-family: var(--sans); line-height: 1.5; min-height: 100vh;
  transition: background .35s ease, color .35s ease;
}
body.luz { background: var(--luz); color: var(--tinta-l); }
body.noche { background: var(--noche); color: var(--tinta-n); }

/* foco visible y consistente en toda la app */
:focus-visible { outline: 2px solid var(--ambar); outline-offset: 2px; border-radius: 6px; }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px 16px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--hair-l);
}
body.noche .topbar { border-color: var(--hair-n); }
.logo { font-weight: 900; font-size: 19px; letter-spacing: -0.5px; text-decoration: none; color: inherit; }
.logo em { color: var(--rojo); font-style: normal; }
.topbar nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.topbar nav a {
  color: inherit; text-decoration: none; font-size: 13.5px; opacity: .75;
  display: inline-flex; align-items: center; min-height: 40px;   /* área táctil */
}
.topbar nav a:hover, .topbar nav a:focus-visible { opacity: 1; }
.btn-sos-mini {
  background: var(--rojo); color: #fff !important; opacity: 1 !important;
  font-weight: 800; font-size: 12px !important; letter-spacing: 1px;
  padding: 0 14px; border-radius: 999px; white-space: nowrap;
}

main { max-width: 1080px; margin: 0 auto; padding: 34px 20px 80px; }
section[hidden] { display: none; }

/* ---------------- piezas comunes ---------------- */
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: var(--tenue-l); margin: 0 0 10px; }
body.noche .eyebrow { color: var(--tenue-n); }
.eyebrow.rojo { color: var(--rojo) !important; }
.eyebrow.verde { color: var(--verde) !important; }
h1 { font-size: clamp(30px, 5vw, 50px); line-height: 1.06; font-weight: 900; letter-spacing: -1.2px; margin: 0 0 16px; text-wrap: balance; }
h2 { font-size: clamp(21px, 3.4vw, 30px); font-weight: 900; letter-spacing: -0.6px; margin: 0 0 10px; overflow-wrap: break-word; }
h3 { font-family: var(--mono); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; font-weight: 600; margin: 0 0 12px; color: var(--tenue-n); }
.lede { color: var(--tenue-l); max-width: 58ch; font-size: 15px; }
body.noche .lede { color: var(--tenue-n); }
.letra-chica { font-size: 11.5px; color: var(--tenue-l); }
body.noche .letra-chica { color: var(--tenue-n); }
.error { color: var(--rojo); font-size: 13px; font-weight: 600; }

.pill { font-family: var(--mono); font-size: 10px; letter-spacing: 1.5px; padding: 4px 10px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.pill.ambar { color: var(--ambar); border-color: var(--ambar); background: var(--ambar-fondo); }
.pill.verde { color: var(--verde); border-color: var(--verde); background: var(--verde-fondo); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; cursor: pointer; text-decoration: none; text-align: center;
  font: inherit; font-weight: 700; font-size: 14px; border-radius: 12px;
  padding: 12px 20px; min-height: 44px;                 /* área táctil cómoda */
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: wait; transform: none; }
.btn.primario { background: var(--tinta-l); color: var(--luz); }
body.noche .btn.primario { background: var(--tinta-n); color: var(--noche); }
.btn.linea { background: transparent; color: inherit; border: 1.5px solid var(--hair-l); }
body.noche .btn.linea { border-color: var(--hair-n); }
.btn.sos {
  background: var(--rojo); color: #fff; font-weight: 900; letter-spacing: 1px;
  padding: 15px 22px; width: 100%;
  box-shadow: 0 8px 24px -8px var(--rojo-glow);
}
.btn.sos:hover { background: var(--rojo-prof); }
.btn.mini { font-size: 11.5px; padding: 6px 12px; min-height: 36px; background: var(--elev-n); color: var(--tinta-n); border: 1px solid var(--hair-n); border-radius: 8px; }

/* ---------------- inicio ---------------- */
.hero-inicio { text-align: center; padding-top: 26px; }
.hero-inicio .lede { margin: 0 auto 30px; }
.sos-ring {
  display: inline-flex; align-items: center; justify-content: center;
  width: 172px; height: 172px; max-width: 60vw; max-height: 60vw;
  border-radius: 50%; text-decoration: none;
  background: var(--rojo); color: #fff;
  box-shadow: 0 0 0 14px rgba(255, 68, 56, .12), 0 18px 40px -12px var(--rojo-glow);
  animation: latido 2.4s ease-in-out infinite;
}
.sos-core { display: flex; flex-direction: column; align-items: center; font-size: 34px; }
.sos-core b { font-size: 13px; letter-spacing: 2px; margin-top: 2px; }
@keyframes latido {
  0%, 100% { box-shadow: 0 0 0 10px rgba(255,68,56,.10), 0 18px 40px -12px var(--rojo-glow); }
  50% { box-shadow: 0 0 0 20px rgba(255,68,56,.16), 0 18px 40px -12px var(--rojo-glow); }
}
.acciones-inicio { display: flex; gap: 12px; justify-content: center; margin: 30px 0 10px; flex-wrap: wrap; }
.nota-contacto { max-width: 56ch; margin: 10px auto 0; font-size: 13px; color: var(--tenue-l); background: var(--panel-l); border: 1px solid var(--hair-l); border-radius: 12px; padding: 12px 16px; text-align: left; }
.tarjetas-inicio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 40px; text-align: left; }
.tarjeta { background: var(--panel-l); border: 1px solid var(--hair-l); border-radius: 14px; padding: 16px 18px; }
.tarjeta b { display: block; font-size: 14px; margin-bottom: 5px; }
.tarjeta span { font-size: 12.5px; color: var(--tenue-l); }

/* ---------------- chat ---------------- */
.panel-chat {
  max-width: 640px; margin: 0 auto; background: var(--panel-l);
  border: 1px solid var(--hair-l); border-radius: 18px; padding: 22px 22px 16px;
  box-shadow: 0 14px 34px -18px rgba(0,0,0,.18);
  min-width: 0;                                  /* que no empuje el grid en móvil */
}
.panel-chat.noche { background: var(--panel-n); border-color: var(--hair-n); box-shadow: 0 20px 44px -20px rgba(0,0,0,.6); max-width: none; }
.chat-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.chat {
  display: flex; flex-direction: column; gap: 10px;
  min-height: 240px; max-height: 52vh; max-height: 52dvh;   /* dvh: el teclado móvil no lo rompe */
  overflow-y: auto; overscroll-behavior: contain; padding: 4px 2px;
}
.burb {
  max-width: 88%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.45;
  overflow-wrap: anywhere;                       /* URLs y palabras largas no desbordan */
}
.burb.yo { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--rojo); color: #fff; white-space: pre-wrap; }
.burb.ia { align-self: flex-start; border-bottom-left-radius: 4px; background: var(--luz); border-left: 3px solid var(--ambar); }
body.noche .burb.ia, .panel-chat.noche .burb.ia { background: var(--elev-n); }
.burb .firma { display: block; font-family: var(--mono); font-size: 9px; letter-spacing: 1.5px; color: var(--ambar); margin-bottom: 4px; }
.burb.typing { display: inline-flex; gap: 5px; align-items: center; }
.burb.typing i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .35; animation: puntito 1.2s infinite; }
.burb.typing i:nth-child(2) { animation-delay: .2s; }
.burb.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes puntito { 0%, 100% { opacity: .25; } 50% { opacity: .9; } }

/* ---- markdown dentro de la burbuja del agente ---- */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md h4 { font-size: 14.5px; font-weight: 900; letter-spacing: -0.2px; margin: 12px 0 6px; }
.md strong { font-weight: 800; }
.md em { font-style: italic; }
.md ul, .md ol { margin: 6px 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md li::marker { color: var(--ambar); }
.md code {
  font-family: var(--mono); font-size: .88em; padding: 1px 5px; border-radius: 5px;
  background: rgba(127, 137, 155, .18); overflow-wrap: anywhere;
}
.md pre {
  margin: 8px 0; padding: 10px 12px; border-radius: 10px; overflow-x: auto;
  background: rgba(127, 137, 155, .16);
}
.md pre code { background: none; padding: 0; font-size: 12px; line-height: 1.5; }
.md blockquote {
  margin: 8px 0; padding: 4px 0 4px 12px; border-left: 3px solid var(--ambar);
  color: inherit; opacity: .9; font-style: italic;
}
.md a { color: inherit; text-underline-offset: 2px; }
.panel-chat.noche .md a, body.noche .md a { color: var(--ambar); }

.chat-form { display: flex; gap: 10px; margin-top: 14px; }
.chat-form input {
  flex: 1; min-width: 0;                          /* sin esto el input desborda el flex */
  font: inherit; font-size: 16px;                 /* 16px: iOS no hace zoom al enfocar */
  padding: 11px 16px; border-radius: 12px;
  border: 1.5px solid var(--hair-l); background: transparent; color: inherit;
}
.panel-chat.noche .chat-form input { border-color: var(--hair-n); }
.chat-form input:focus-visible { outline: 2px solid var(--ambar); outline-offset: 1px; }
.chat-form .btn { white-space: nowrap; flex: 0 0 auto; }

/* ---------------- pánico / pre-bloqueo ---------------- */
.panel-panico {
  max-width: 460px; margin: 20px auto 0; background: var(--panel-n);
  border: 1px solid var(--hair-n); border-radius: 18px; padding: 28px 26px;
  box-shadow: 0 0 60px -18px var(--rojo-glow), 0 24px 48px -20px rgba(0,0,0,.6);
}
.panel-panico form { display: flex; flex-direction: column; gap: 14px; margin: 20px 0 14px; }
.panel-panico label { font-size: 12.5px; color: var(--tenue-n); display: flex; flex-direction: column; gap: 6px; }
.panel-panico input {
  font: inherit; font-size: 16px;                 /* 16px: evita el zoom de iOS */
  padding: 12px 15px; border-radius: 12px; width: 100%;
  border: 1.5px solid var(--hair-n); background: var(--elev-n); color: var(--tinta-n);
}
.panel-panico input:focus-visible { outline: 2px solid var(--rojo); outline-offset: 1px; }
.checks { display: flex; flex-direction: column; gap: 8px; margin: 18px 0; }
.check {
  display: flex; gap: 10px; align-items: center; font-family: var(--mono); font-size: 12px;
  padding: 10px 12px; border-radius: 10px; background: var(--verde-fondo); color: var(--verde);
  opacity: 0; animation: aparecer .5s ease forwards; overflow-wrap: anywhere;
}
@keyframes aparecer { to { opacity: 1; } }

/* ---------------- crisis ---------------- */
.crisis-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; align-items: start; }
.panel-lateral {
  background: var(--panel-n); border: 1px solid var(--hair-n); border-radius: 18px;
  padding: 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.timeline { display: flex; flex-direction: column; gap: 7px; max-height: 46vh; overflow-y: auto; overscroll-behavior: contain; }
.tl-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: baseline;
  font-size: 12px; padding: 8px 10px; border-radius: 9px; background: var(--elev-n);
}
.tl-hora { font-family: var(--mono); font-size: 10px; color: var(--tenue-n); }
.tl-txt { min-width: 0; overflow-wrap: anywhere; }
.tl-est { font-family: var(--mono); font-size: 9.5px; letter-spacing: 1px; color: var(--verde); white-space: nowrap; }

/* ---------------- cierre ---------------- */
.panel-cierre { max-width: 760px; margin: 0 auto; }
.docs-botones { display: flex; gap: 12px; margin: 22px 0; flex-wrap: wrap; }
.docs-botones .btn { flex: 1 1 240px; }
.doc-salida { background: var(--panel-n); border: 1px solid var(--hair-n); border-radius: 16px; padding: 16px 18px; }
.doc-acciones { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.doc-salida pre {
  font-family: var(--mono); font-size: 12px; line-height: 1.6; white-space: pre-wrap;
  overflow-wrap: anywhere;                        /* la denuncia no desborda a lo ancho */
  margin: 0; max-height: 55vh; overflow-y: auto; color: var(--tinta-n);
}

/* ---------------- responsive ---------------- */
@media (max-width: 860px) {
  .crisis-grid { grid-template-columns: 1fr; }
  /* en el celular el protocolo va ARRIBA y compacto: se ve el avance sin tapar el chat */
  .panel-lateral { order: -1; padding: 16px; }
  .timeline { max-height: 32vh; }
}
@media (max-width: 720px) { .tarjetas-inicio { grid-template-columns: 1fr; } }
@media (max-width: 560px) {
  main { padding: 24px 14px 64px; }
  .topbar { padding: 10px 14px; }
  .topbar nav { gap: 12px; }
  .panel-chat { padding: 16px 14px 12px; border-radius: 16px; }
  .panel-panico { padding: 22px 18px; margin-top: 8px; }
  .chat { max-height: 46vh; max-height: 46dvh; min-height: 200px; }
  .burb { max-width: 94%; }
  .hero-inicio { padding-top: 12px; }
  .acciones-inicio .btn { width: 100%; }
  .docs-botones .btn { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .sos-ring, .burb.typing i, .check { animation: none; }
  .check { opacity: 1; }
  .btn:hover { transform: none; }
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------------- pie ---------------- */
.pie {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  max-width: 1080px; margin: 0 auto; padding: 18px 20px 26px;
  font-size: 11.5px; color: var(--tenue-l); border-top: 1px solid var(--hair-l);
}
body.noche .pie { color: var(--tenue-n); border-color: var(--hair-n); }
.pie a { color: inherit; text-decoration: none; opacity: .6; min-height: 32px; display: inline-flex; align-items: center; }
.pie a:hover, .pie a:focus-visible { opacity: 1; }
