:root {
  --fondo: #f6f7fb;
  --superficie: #ffffff;
  --texto: #10151c;
  --texto-suave: #46505f;
  --acento: #0b57d0;
  --acento-oscuro: #083d94;
  --rojo: #b3261e;
  --rojo-oscuro: #8c1d16;
  --verde: #1b6b3a;
  --borde: #d5dae3;
  --sombra: 0 6px 18px rgba(15, 23, 42, .14);
  --radio: 26px;
  --escala: 1;
}

body.letra-grande { --escala: 1.22; }

body.alto-contraste {
  --fondo: #000000;
  --superficie: #0a0a0a;
  --texto: #ffffff;
  --texto-suave: #e6e6e6;
  --acento: #ffd400;
  --acento-oscuro: #ffe873;
  --rojo: #ff5a4d;
  --rojo-oscuro: #ff8a80;
  --borde: #565656;
  --sombra: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { font-size: calc(22px * var(--escala)); touch-action: manipulation; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  /* tableta fija en casa: sin rebote ni selección accidental al tocar */
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

input, textarea, .seleccionable { -webkit-user-select: text; user-select: text; }

.oculto { display: none !important; }

/* ---------- cabecera ---------- */
.cabecera {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem;
  padding: calc(1rem + env(safe-area-inset-top)) 1.1rem .6rem;
}
.fecha { margin: 0; font-size: .9rem; color: var(--texto-suave); }
.saludo { margin: .15rem 0 0; font-size: 1.5rem; line-height: 1.15; }

.boton-ajustes {
  font: inherit; font-weight: 700;
  min-width: 3.2rem; height: 3.2rem; border-radius: 50%;
  background: var(--superficie); color: var(--texto);
  border: 2px solid var(--borde); box-shadow: var(--sombra);
  cursor: pointer;
}

/* ---------- vistas ---------- */
main { flex: 1; display: flex; flex-direction: column; }
.vista { display: none; flex-direction: column; padding: 0 1.1rem 1rem; gap: 1rem; }
.vista.activa { display: flex; }

.cabecera-vista { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.cabecera-vista h2 { font-size: 1.4rem; margin: 0; }

/* ---------- micrófono ---------- */
.micro {
  margin: .4rem auto 0;
  width: min(72vw, 380px); aspect-ratio: 1;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 35% 25%, #3b82f6, var(--acento) 55%, var(--acento-oscuro));
  color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .3rem;
  box-shadow: 0 16px 40px rgba(11, 87, 208, .38);
  cursor: pointer;
  transition: transform .12s ease;
}
.micro:active { transform: scale(.97); }
.micro-icono { font-size: 5rem; line-height: 1; }
.micro-texto { font-size: 1.5rem; font-weight: 800; letter-spacing: .12em; }

.micro.escuchando {
  background: radial-gradient(circle at 35% 25%, #ef4444, var(--rojo) 55%, var(--rojo-oscuro));
  animation: latido 1.15s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(179, 38, 30, .6);
}
@keyframes latido {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179, 38, 30, .55); }
  50% { box-shadow: 0 0 0 26px rgba(179, 38, 30, 0); }
}
@media (prefers-reduced-motion: reduce) { .micro.escuchando { animation: none; } }

.pista { text-align: center; color: var(--texto-suave); font-size: 1rem; line-height: 1.35; margin: .2rem 0; }

/* ---------- conversación ---------- */
.conversacion {
  background: var(--superficie); border: 2px solid var(--borde); border-radius: var(--radio);
  padding: 1rem; box-shadow: var(--sombra);
  display: flex; flex-direction: column; gap: .7rem;
}
.conversacion .dicho { margin: 0; color: var(--texto-suave); font-size: 1rem; }
.conversacion .dicho::before { content: "Has dicho: "; font-weight: 700; }
.conversacion .respuesta { margin: 0; font-size: 1.2rem; line-height: 1.4; font-weight: 600; }
.acciones-respuesta { display: flex; flex-wrap: wrap; gap: .6rem; }

/* ---------- botones ---------- */
.boton-primario, .boton-secundario, .boton-escuchar, .boton-volver {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: 18px;
  padding: .9rem 1.1rem; line-height: 1.2;
}
.boton-primario {
  background: var(--acento); color: #fff; border: none; box-shadow: var(--sombra);
  font-size: 1.1rem;
}
.boton-secundario {
  background: var(--superficie); color: var(--texto);
  border: 2px solid var(--borde); font-size: 1rem;
}
.boton-escuchar {
  background: var(--superficie); color: var(--texto);
  border: 2px solid var(--borde); font-size: 1.05rem; width: 100%;
}
.boton-volver { background: transparent; border: none; color: var(--acento); font-size: 1rem; }
.escribir { margin: .2rem auto 0; font-size: .85rem; opacity: .8; border-style: dashed; }

/* ---------- barra inferior ---------- */
.barra {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem;
  padding: .7rem 1rem calc(.8rem + env(safe-area-inset-bottom));
  background: var(--superficie); border-top: 2px solid var(--borde);
  position: sticky; bottom: 0;
}
.boton-barra {
  font: inherit; font-weight: 800; font-size: .82rem; letter-spacing: .03em;
  border-radius: 18px; border: 2px solid var(--borde); background: var(--fondo);
  color: var(--texto); padding: .6rem .3rem;
  display: flex; flex-direction: column; align-items: center; gap: .2rem;
  cursor: pointer; min-height: 4.6rem; justify-content: center;
}
.boton-barra span[aria-hidden] { font-size: 1.6rem; line-height: 1; }
.boton-barra-ayuda { border-color: var(--rojo); color: var(--rojo); }

/* ---------- listas ---------- */
.lista { display: flex; flex-direction: column; gap: .7rem; }
.tarjeta {
  background: var(--superficie); border: 2px solid var(--borde); border-radius: 20px;
  padding: .9rem 1rem; box-shadow: var(--sombra);
  display: flex; flex-direction: column; gap: .55rem;
}
.tarjeta .titulo { font-size: 1.12rem; font-weight: 700; margin: 0; }
.tarjeta .detalle { font-size: .95rem; color: var(--texto-suave); margin: 0; }
.tarjeta .fila-botones { display: flex; gap: .6rem; flex-wrap: wrap; }
.tarjeta .fila-botones > * { flex: 1 1 45%; }

.estado { display: inline-block; font-size: .8rem; font-weight: 800; padding: .18rem .6rem; border-radius: 999px; }
.estado.pendiente { background: #fff4d6; color: #6b4b00; }
.estado.tomada { background: #d9f2e1; color: var(--verde); }
.estado.omitida { background: #ffe0dc; color: var(--rojo-oscuro); }
body.alto-contraste .estado.pendiente { background: #4a3a00; color: #ffe9a8; }
body.alto-contraste .estado.tomada { background: #0d3d22; color: #b8f6cc; }
body.alto-contraste .estado.omitida { background: #4d0f0b; color: #ffc9c4; }

.boton-tomada {
  background: var(--verde); color: #fff; border: none; border-radius: 16px;
  font: inherit; font-weight: 800; font-size: 1rem; padding: .85rem; cursor: pointer;
}
.boton-no-tomada {
  background: var(--superficie); color: var(--rojo); border: 2px solid var(--rojo);
  border-radius: 16px; font: inherit; font-weight: 700; font-size: .95rem; padding: .8rem; cursor: pointer;
}

/* ---------- SOS ---------- */
.boton-sos {
  width: 100%; border: none; border-radius: var(--radio); cursor: pointer;
  background: linear-gradient(180deg, #d93a2c, var(--rojo) 60%, var(--rojo-oscuro));
  color: #fff; padding: 1.6rem 1rem; display: flex; flex-direction: column;
  gap: .35rem; align-items: center; box-shadow: 0 14px 30px rgba(179, 38, 30, .35);
}
.boton-sos span { font-size: 3rem; line-height: 1; }
.boton-sos strong { font-size: 2rem; letter-spacing: .08em; }
.boton-sos small { font-size: .9rem; opacity: .95; }

.aviso-pie { font-size: .8rem; color: var(--texto-suave); line-height: 1.35; margin: .4rem 0 0; }

/* ---------- capas (diálogos) ---------- */
.capa {
  position: fixed; inset: 0; background: rgba(8, 12, 20, .72);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50;
}
.capa-caja {
  background: var(--superficie); color: var(--texto);
  border-radius: 28px; padding: 1.4rem; width: min(560px, 100%);
  max-height: 92dvh; overflow: auto; display: flex; flex-direction: column; gap: .9rem;
}
.capa-caja h2 { margin: 0; font-size: 1.4rem; }
.capa-acciones { display: flex; flex-direction: column; gap: .7rem; }
.cuenta-atras { font-size: 3.4rem; font-weight: 800; text-align: center; margin: 0; color: var(--rojo); }
.ajuste { display: flex; flex-direction: column; gap: .4rem; font-size: 1rem; }
.ajuste input[type="range"] { width: 100%; height: 2.4rem; }
.ajuste-fila { display: flex; align-items: center; justify-content: space-between; gap: 1rem; font-size: 1.05rem; }
.ajuste-fila input[type="checkbox"] { width: 2rem; height: 2rem; }

.aviso-flotante {
  position: fixed; left: 1rem; right: 1rem; bottom: 6.4rem;
  background: var(--texto); color: var(--fondo); font-weight: 700;
  border-radius: 18px; padding: 1rem 1.2rem; z-index: 60; box-shadow: var(--sombra);
}

/* ---------- sugerencias (solo tableta) ---------- */
.bloque-conversacion { display: contents; }
.bloque-micro { display: contents; }
.sugerencias { display: none; }
.sugerencias-titulo { margin: 0 0 .2rem; font-size: 1rem; font-weight: 800; color: var(--texto-suave); }
.sugerencia {
  font: inherit; font-size: 1rem; text-align: left; cursor: pointer;
  background: var(--superficie); color: var(--texto);
  border: 2px solid var(--borde); border-radius: 16px; padding: .7rem .9rem;
}
.sugerencia:active { background: var(--fondo); }
.sugerencias-pie { margin: .2rem 0 0; font-size: .82rem; color: var(--texto-suave); line-height: 1.3; }
#conversacion:not(.oculto) ~ .sugerencias { display: none; }

/* tablet / kiosco */
@media (min-width: 760px) {
  body { align-items: center; }
  .cabecera, main, .barra { width: min(1100px, 100%); }
  .barra { position: sticky; border-radius: 26px 26px 0 0; }
  .micro { width: min(46vh, 380px); }
  .boton-barra { min-height: 5.4rem; font-size: .9rem; }
  .sugerencias {
    display: flex; flex-direction: column; gap: .55rem;
    background: var(--superficie); border: 2px solid var(--borde);
    border-radius: var(--radio); padding: 1rem; box-shadow: var(--sombra);
  }
}

/* tableta en horizontal: micrófono grande a la izquierda, conversación a la derecha */
@media (min-width: 900px) and (min-height: 520px) and (orientation: landscape) {
  #vista-hablar.activa {
    display: grid;
    grid-template-columns: minmax(300px, 400px) 1fr;
    grid-template-areas: "micro bloque";
    align-items: center;
    column-gap: 2.4rem;
    padding: 0 1.6rem 1.2rem;
  }
  #vista-hablar .bloque-micro {
    grid-area: micro; display: flex; flex-direction: column; align-items: center; gap: .5rem;
  }
  #vista-hablar .micro { margin: 0 auto; width: min(36vh, 340px); }
  #vista-hablar .bloque-conversacion {
    grid-area: bloque; display: flex; flex-direction: column; gap: 1rem; justify-content: center;
  }
  #vista-hablar .escribir { margin: 0; }
  #vista-hablar .sugerencias { max-height: 66vh; overflow: auto; }
}

/* listas en dos columnas cuando hay sitio */
@media (min-width: 1000px) and (min-height: 520px) and (orientation: landscape) {
  #vista-dia .lista, #vista-medicacion .lista, #vista-ayuda .lista {
    display: grid; grid-template-columns: 1fr 1fr; align-items: start;
  }
  #vista-medicacion .aviso-pie, #vista-ayuda .pista { grid-column: 1 / -1; }
}

/* ---------------- tableta fija: ni zoom accidental ni gestos que saquen de la app ---------------- */
html, body { overscroll-behavior: none; }
body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input, textarea, .seleccionable {
  -webkit-user-select: text;
  user-select: text;
}
button, .micro, .sugerencia, .contacto {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------------- lista de la compra (Fase 3) ---------------- */
.bolsa {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-top: .7rem;
}
.bolsa-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 1.05em;
  padding: .85rem 1rem;
  border: 2px solid #d7dbe6;
  border-radius: 14px;
  background: #fff;
  color: var(--texto, #1b1f2a);
  cursor: pointer;
}
.bolsa-item:active { background: #eef3ff; border-color: var(--acento, #0b57d0); }
body.alto-contraste .bolsa-item { background: #000; color: #fff; border-color: #fff; }

/* Lista de la compra: si hay muchas cosas, se desplaza dentro de la tarjeta. */
.bolsa { max-height: 42vh; overflow-y: auto; }

/* Acceso discreto al panel de la familia, al final de los ajustes. */
.acceso-familia {
  margin: 1.4rem 0 .2rem;
  font-size: .78em;
  color: var(--texto-suave, #5f6675);
  text-align: center;
}

.acceso-familia a {
  color: inherit;
  text-decoration: underline;
}

/* Ajustes nuevos: nombre del asistente y escucha sin tocar. */
.ajuste-columna {
  flex-direction: column;
  align-items: stretch;
  gap: .4rem;
}

.ajuste-columna input {
  width: 100%;
  font: inherit;
  padding: .7rem .9rem;
  border-radius: 12px;
  border: 2px solid #d5dae3;
}

.ajuste-nota {
  margin: .9rem 0 .2rem;
  font-size: .72em;
  line-height: 1.45;
  color: var(--texto-suave, #5f6675);
}

/* Micrófono en modo manos libres: halo suave para indicar que escucha. */
#btn-micro.libre {
  box-shadow: 0 0 0 14px rgba(11, 87, 208, .10), 0 18px 40px rgba(11, 87, 208, .22);
}
