/* base.css — tokens, reset y componentes compartidos (landing, app y páginas legales).
   Móvil primero. Modo oscuro por prefers-color-scheme. Contraste AA verificado (ver README). */

:root {
  color-scheme: light dark;

  /* superficies y texto */
  --bg: #F7F5FB;
  --surface: #FFFFFF;
  --surface-2: #EFEBF8;
  --border: #D3CCE4;
  --text: #2B2738;
  --muted: #5F5A70;

  /* marca (morado de Valeria v1) */
  --brand: #7B68AE;          /* relleno de botones; texto blanco encima = 4.75:1 */
  --on-brand: #FFFFFF;
  --brand-strong: #5F4B96;   /* texto/enlaces sobre fondo claro */
  --brand-soft: #E8E3F3;

  /* estados */
  --danger: #B3342F;
  --on-danger: #FFFFFF;
  --danger-soft: #FBEAE9;
  --ok: #2A7355;
  --ok-soft: #E4F3EC;
  --warn: #7A4F00;
  --warn-soft: #FFF3D6;

  /* ayuda en crisis (banner permanente y discreto) */
  --crisis-bg: #FFF1E6;
  --crisis-text: #5A2A00;
  --crisis-border: #F0C9A8;

  /* foco */
  --focus: #3D2FA0;

  /* burbujas del chat */
  --b-yo-bg: #6A55A3;
  --b-yo-text: #FFFFFF;
  --b-otro-bg: #FFFFFF;
  --b-otro-text: #2B2738;
  --b-ia-bg: #EFEBF8;
  --b-ia-text: #2B2738;
  --b-sis-bg: transparent;
  --b-sis-text: #5F5A70;

  --radio: 14px;
  --radio-sm: 10px;
  --sombra: 0 2px 14px rgba(77, 58, 130, 0.09);
  --gutter: 16px;
  --medida: 40rem;
  --fuente: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15121C;
    --surface: #1F1B2A;
    --surface-2: #2A2538;
    --border: #3F3858;
    --text: #ECE9F5;
    --muted: #B7B1CB;

    --brand: #A596D6;
    --on-brand: #15121C;
    --brand-strong: #C2B6F2;
    --brand-soft: #2E2745;

    --danger: #FF9C97;
    --on-danger: #2A0907;
    --danger-soft: #3A1A19;
    --ok: #7FD1A9;
    --ok-soft: #14301F;
    --warn: #F2C56B;
    --warn-soft: #382A0B;

    --crisis-bg: #33210F;
    --crisis-text: #FFD9B8;
    --crisis-border: #5C3A1B;

    --focus: #CFC6FF;

    --b-yo-bg: #A596D6;
    --b-yo-text: #15121C;
    --b-otro-bg: #2A2538;
    --b-otro-text: #ECE9F5;
    --b-ia-bg: #2E2745;
    --b-ia-text: #ECE9F5;
    --b-sis-text: #B7B1CB;

    --sombra: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--fuente);
  font-size: 1rem;
  line-height: 1.55;
  overflow-wrap: anywhere;   /* nada fuerza scroll horizontal */
}

img, svg, video { max-width: 100%; height: auto; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 1.625rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.0625rem; }
p { margin: 0 0 .75rem; }
ul, ol { margin: 0 0 .75rem; padding-left: 1.25rem; }
li { margin-bottom: .35rem; }

a { color: var(--brand-strong); text-decoration: underline; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.saltar {
  position: absolute; left: var(--gutter); top: -100px;
  background: var(--surface); color: var(--text);
  padding: .75rem 1rem; border-radius: var(--radio-sm); border: 2px solid var(--focus);
  z-index: 1000;
}
.saltar:focus { top: 8px; }

/* ---------- utilidades ---------- */
.muted { color: var(--muted); }
.chico { font-size: .875rem; }
.centrado { text-align: center; }
.pila { display: flex; flex-direction: column; gap: 1rem; }
.pila-sm { display: flex; flex-direction: column; gap: .5rem; }
.fila { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.fila-sep { display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.oculto { display: none !important; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ---------- botones (táctil ≥ 44 px) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .6rem 1.1rem;
  border: 2px solid transparent; border-radius: var(--radio-sm);
  font: inherit; font-weight: 600; line-height: 1.2; text-align: center; text-decoration: none;
  cursor: pointer; background: transparent; color: var(--brand-strong);
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn--primario { background: var(--brand); color: var(--on-brand); }
.btn--primario:hover:not(:disabled) { filter: brightness(.94); }
.btn--secundario { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn--secundario:hover:not(:disabled) { border-color: var(--brand); }
.btn--peligro { background: var(--danger); color: var(--on-danger); }
.btn--peligro-suave { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--texto { padding-inline: .5rem; text-decoration: underline; text-underline-offset: 2px; }
.btn--bloque { width: 100%; }
.btn--chico { min-height: 44px; padding: .4rem .8rem; font-size: .9375rem; }
.btn .cargando-punto {
  width: 1rem; height: 1rem; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: giro .8s linear infinite;
}
@keyframes giro { to { transform: rotate(360deg); } }

/* ---------- formularios ---------- */
.campo { display: flex; flex-direction: column; gap: .35rem; }
.campo > label, .campo > .etiqueta-campo, legend { font-weight: 600; font-size: .9375rem; }
.campo .ayuda { color: var(--muted); font-size: .875rem; }
.campo .error { color: var(--danger); font-size: .875rem; font-weight: 600; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="tel"], input[type="number"], select, textarea {
  width: 100%; min-height: 48px; padding: .7rem .85rem;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radio-sm);
  font: inherit; font-size: 1rem;          /* 16 px: iOS no hace zoom al enfocar */
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .9; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: .35rem; }

/* casillas y radios con área táctil grande */
.opcion {
  display: flex; align-items: flex-start; gap: .75rem;
  min-height: 44px; padding: .55rem .75rem;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radio-sm);
  cursor: pointer;
}
.opcion input { width: 1.25rem; height: 1.25rem; margin: .15rem 0 0; flex: none; accent-color: var(--brand); }
.opcion:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.opcion:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.opcion .opcion-texto { flex: 1; }

/* ---------- tarjetas / etiquetas ---------- */
.tarjeta {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radio); padding: 1rem; box-shadow: var(--sombra);
}
.tarjeta > :last-child { margin-bottom: 0; }
.tarjeta--aviso { background: var(--warn-soft); border-color: var(--warn); }
.tarjeta--ok { background: var(--ok-soft); border-color: var(--ok); }
.tarjeta--peligro { background: var(--danger-soft); border-color: var(--danger); }
.tarjeta--suave { background: var(--brand-soft); box-shadow: none; }

.etiqueta {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .1rem .55rem; border-radius: 999px; font-size: .8125rem; font-weight: 650;
  background: var(--brand-soft); color: var(--brand-strong); border: 1px solid transparent;
}
.etiqueta--ok { background: var(--ok-soft); color: var(--ok); }
.etiqueta--aviso { background: var(--warn-soft); color: var(--warn); }
.etiqueta--peligro { background: var(--danger-soft); color: var(--danger); }
.etiqueta--gris { background: var(--surface-2); color: var(--muted); }

/* ---------- aviso fijo de IA (Sala y Mi espacio) ---------- */
.aviso-ia { margin: 0; padding: .35rem .75rem; font-size: .75rem; color: var(--muted); text-align: center; border-bottom: 1px solid var(--crisis-border); }

/* ---------- banner de crisis (Sala y Mi espacio) ---------- */
.crisis {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px;
  background: var(--crisis-border);
  border-bottom: 1px solid var(--crisis-border);
}
.crisis a {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  min-height: 46px; padding: .2rem .25rem;
  background: var(--crisis-bg); color: var(--crisis-text);
  text-decoration: none; text-align: center; line-height: 1.2;
}
.crisis .crisis-nombre { font-size: .75rem; }
.crisis .crisis-num { font-size: .8125rem; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.crisis a:focus-visible { outline-offset: -3px; }

/* lista de recursos (ruta humana, landing, bloqueos) */
.recursos { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.recursos li { margin: 0; }
.recurso {
  display: flex; flex-direction: column; gap: .1rem;
  padding: .65rem .85rem; min-height: 44px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radio-sm);
  text-decoration: none; color: var(--text);
}
.recurso:hover { border-color: var(--brand); }
.recurso .r-nombre { font-weight: 650; }
.recurso .r-num { font-weight: 700; color: var(--brand-strong); font-size: 1.0625rem; text-decoration: underline; text-underline-offset: 2px; }
.recurso .r-nota { color: var(--muted); font-size: .875rem; }

/* ---------- diálogos ---------- */
dialog.modal {
  width: min(32rem, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100dvh - 2 * var(--gutter));
  padding: 0; border: 1px solid var(--border); border-radius: var(--radio);
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
  overflow: auto;
}
dialog.modal::backdrop { background: rgba(20, 14, 34, .55); }
.modal-cuerpo { padding: 1.1rem 1.1rem .5rem; }
.modal-cuerpo h2 { margin-bottom: .6rem; }
.modal-acciones { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: flex-end; padding: .75rem 1.1rem 1.1rem; }
.modal-acciones .btn { flex: 1 1 8rem; }

/* ---------- toasts ---------- */
#toasts {
  position: fixed; left: var(--gutter); right: var(--gutter);
  top: max(var(--gutter), env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: .5rem; align-items: center;
  z-index: 2000; pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 32rem; width: 100%;
  padding: .75rem 1rem; border-radius: var(--radio-sm);
  background: var(--text); color: var(--bg);
  font-weight: 600; font-size: .9375rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
}
.toast--error { background: var(--danger); color: var(--on-danger); }
.toast--ok { background: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) {
  .toast--ok { background: var(--ok); color: #0B1E14; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
