:root {
  --azul: #2563eb;
  --azul-osc: #1e40af;
  --azul-claro: #eff6ff;
  --texto: #1c2733;
  --texto-suave: #64748b;
  --borde: #e2e8f0;
  --fondo: #f4f6f8;
  --blanco: #ffffff;
  --verde: #166534;
  --verde-bg: #dcfce7;
  --rojo: #991b1b;
  --rojo-bg: #fee2e2;
  --ambar: #92400e;
  --ambar-bg: #fef3c7;
  --radio: 14px;
  --sombra: 0 1px 3px rgba(0, 0, 0, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  overscroll-behavior-y: none;
}

.oculto { display: none !important; }

/* ------------------------------ cabecera ------------------------------ */

header {
  background: linear-gradient(135deg, var(--azul), var(--azul-osc));
  color: #fff;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 14px;
  text-align: center;
  position: relative;
}
header h1 { margin: 0; font-size: 1.25rem; font-weight: 600; }
header p { margin: 3px 0 0; font-size: 0.78rem; opacity: 0.85; }

.user-btn {
  position: absolute;
  right: 12px;
  top: calc(14px + env(safe-area-inset-top, 0px));
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

/* -------------------------------- tabs -------------------------------- */

.tabs {
  display: flex;
  background: var(--blanco);
  border-bottom: 1px solid var(--borde);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tab {
  flex: 1;
  padding: 11px 4px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--texto-suave);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  border-top: none;
  border-left: none;
  border-right: none;
  background: none;
  font-family: inherit;
}
.tab .ico { display: block; font-size: 1.1rem; margin-bottom: 2px; position: relative; }
.tab.active { color: var(--azul); border-bottom-color: var(--azul); }

/* Punto rojo sobre el icono cuando hay una toma pendiente. */
.tab .pin {
  position: absolute;
  top: -1px;
  right: 50%;
  margin-right: -14px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 8px;
  background: #dc2626;
  color: #fff;
  font-size: 0.6rem;
  line-height: 15px;
  font-weight: 700;
}

/* ------------------------------ contenedor ------------------------------ */

.container {
  padding: 16px 16px calc(24px + var(--safe-bottom));
  max-width: 520px;
  margin: 0 auto;
}

.card {
  background: var(--blanco);
  border-radius: var(--radio);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--sombra);
}

.field { margin-bottom: 14px; }
label { display: block; font-size: 0.82rem; font-weight: 600; color: #475569; margin-bottom: 5px; }

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d6dce3;
  border-radius: 10px;
  font-size: 1rem;
  background: #fbfcfd;
  font-family: inherit;
  color: var(--texto);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--azul); }
input[type="date"], input[type="time"] { min-height: 42px; }

.row { display: flex; gap: 10px; }
.row .field { flex: 1; }
.row3 { display: flex; gap: 8px; }
.row3 .field { flex: 1; }

button.primary {
  width: 100%;
  background: var(--azul);
  color: #fff;
  border: none;
  padding: 13px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
button.primary:active { background: #1d4ed8; }
button.primary:disabled { background: #93b4f5; cursor: default; }

button.secondary {
  background: var(--blanco);
  color: var(--azul);
  border: 1.5px solid var(--azul);
  padding: 10px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
button.secondary:disabled { opacity: 0.5; cursor: default; }

button.ghost {
  background: none;
  border: none;
  color: var(--texto-suave);
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  padding: 6px;
}

.msg {
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  font-size: 0.86rem;
  margin-bottom: 12px;
  display: none;
}
.msg.show { display: block; }
.msg.success { background: var(--verde-bg); color: var(--verde); }
.msg.error { background: var(--rojo-bg); color: var(--rojo); }
.msg.info { background: var(--ambar-bg); color: var(--ambar); }

/* ------------------------------ historial ------------------------------ */

.entry { border-bottom: 1px solid #eef1f4; padding: 12px 0; }
.entry:last-child { border-bottom: none; }
.entry-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.entry-date { font-weight: 600; font-size: 0.9rem; }
.entry-time { font-size: 0.76rem; color: var(--texto-suave); }
.entry-vals { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.85rem; }
.val-tag { color: #334155; }
.val-tag b { color: #1e293b; }
.entry-notes { font-size: 0.8rem; color: var(--texto-suave); margin-top: 4px; font-style: italic; }
.entry-foto { margin-top: 8px; }
.entry-foto img { max-width: 150px; border-radius: 8px; border: 1px solid var(--borde); cursor: pointer; }
.del-btn { background: none; border: none; color: #dc2626; font-size: 0.76rem; cursor: pointer; padding: 4px 6px; font-family: inherit; }

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  margin-right: 4px;
}
.badge.normal { background: var(--verde-bg); color: var(--verde); }
.badge.aviso { background: var(--ambar-bg); color: var(--ambar); }
.badge.alto { background: var(--rojo-bg); color: var(--rojo); }
.origen { font-size: 0.66rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.04em; }

.empty { text-align: center; color: #94a3b8; padding: 28px 10px; font-size: 0.9rem; }

.summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.summary-box { background: #f1f5f9; border-radius: 10px; padding: 10px; text-align: center; }
.summary-box .label { font-size: 0.7rem; color: var(--texto-suave); }
.summary-box .value { font-size: 1.05rem; font-weight: 700; color: #1e293b; margin-top: 2px; }
.summary-box .sub { font-size: 0.65rem; color: #94a3b8; margin-top: 1px; }

.section-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 10px; color: #1e293b; }

/* -------------------------------- chat -------------------------------- */

#view-chat .container { display: flex; flex-direction: column; }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 40vh;
  margin-bottom: 12px;
}
.burbuja {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.burbuja.user { align-self: flex-end; background: var(--azul); color: #fff; border-bottom-right-radius: 4px; }
.burbuja.assistant { align-self: flex-start; background: var(--blanco); color: var(--texto); border-bottom-left-radius: 4px; box-shadow: var(--sombra); }
.burbuja .adjunto { font-size: 0.75rem; opacity: 0.8; display: block; margin-bottom: 4px; }

.chat-form { display: flex; gap: 8px; align-items: flex-end; position: sticky; bottom: 0; padding-bottom: var(--safe-bottom); background: var(--fondo); }
.chat-form textarea { flex: 1; min-width: 0; resize: none; max-height: 120px; border-radius: 20px; padding: 11px 14px; overflow-x: hidden; text-overflow: ellipsis; }
.chat-form button {
  background: var(--azul);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-form button:disabled { background: #93b4f5; }

.sugerencias { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.sugerencia {
  background: var(--azul-claro);
  color: var(--azul-osc);
  border: 1px solid #c7dbfd;
  border-radius: 20px;
  padding: 7px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
}

.escribiendo { align-self: flex-start; color: var(--texto-suave); font-size: 0.85rem; padding: 8px 4px; }
.escribiendo span { animation: parpadeo 1.2s infinite; }
.escribiendo span:nth-child(2) { animation-delay: 0.2s; }
.escribiendo span:nth-child(3) { animation-delay: 0.4s; }
@keyframes parpadeo { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* --------------------------------- voz --------------------------------- */

/* -------------------------- modo conversación -------------------------- */

.conversacion {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 28px 20px calc(28px + var(--safe-bottom));
  min-height: 62vh;
}

.orbe {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--azul), var(--azul-osc));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.6rem;
  cursor: pointer;
  border: none;
  color: #fff;
  box-shadow: 0 8px 28px rgba(37, 99, 235, 0.32);
  transition: transform 0.2s, background 0.3s;
  user-select: none;
}
.orbe:active { transform: scale(0.96); }

/* Escuchando: late en rojo */
.orbe.escuchando {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  box-shadow: 0 8px 28px rgba(220, 38, 38, 0.4);
  animation: onda 1.5s ease-out infinite;
}
@keyframes onda {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55), 0 8px 28px rgba(220, 38, 38, 0.4); }
  70% { box-shadow: 0 0 0 34px rgba(220, 38, 38, 0), 0 8px 28px rgba(220, 38, 38, 0.4); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0), 0 8px 28px rgba(220, 38, 38, 0.4); }
}

/* Pensando: gira */
.orbe.pensando {
  background: linear-gradient(135deg, #f59e0b, #b45309);
  animation: girar-orbe 1.6s linear infinite;
}
@keyframes girar-orbe { to { transform: rotate(360deg); } }

/* Hablando: respira en verde */
.orbe.hablando {
  background: linear-gradient(135deg, #22c55e, #15803d);
  animation: respirar 1.8s ease-in-out infinite;
}
@keyframes respirar {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

.conv-titulo { font-size: 1.15rem; font-weight: 700; color: var(--texto); }
.conv-texto {
  font-size: 0.95rem;
  color: var(--texto-suave);
  line-height: 1.5;
  max-width: 340px;
  min-height: 3em;
  /* Un dictado largo no puede empujar el botón de salir fuera de la pantalla:
     el texto se queda en su caja y, si sobra, se desplaza dentro de ella. */
  max-height: 7.5em;
  overflow-y: auto;
  overscroll-behavior: contain;
  word-break: break-word;
}
.conv-texto b { color: var(--texto); }

/* Botón fijo en la barra de escribir: es lo único que se ve SIEMPRE, porque
   la tarjeta de abajo se va hacia arriba en cuanto hay conversación. */
.btn-conv {
  background: var(--blanco);
  color: var(--azul);
  border: 1.5px solid var(--azul);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.15rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* Tarjeta de presentación: solo mientras el chat está vacío.
   Es la función más útil para quien no ve bien la pantalla, así que tiene que
   verse. Y así deja de robarle sitio al campo de escribir. */
.conv-lanzador {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: linear-gradient(135deg, var(--azul), var(--azul-osc));
  color: #fff;
  border: none;
  border-radius: var(--radio);
  padding: 14px 16px;
  margin-bottom: 12px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.25);
}
.conv-lanzador:active { transform: scale(0.99); }
.conv-lanzador .ico {
  font-size: 1.5rem;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
}
.conv-lanzador .txt { flex: 1; font-size: 0.8rem; line-height: 1.35; opacity: 0.9; min-width: 0; }
.conv-lanzador .txt b { display: block; font-size: 0.98rem; opacity: 1; margin-bottom: 1px; }
.conv-lanzador .flecha { font-size: 1.5rem; opacity: 0.7; flex-shrink: 0; }

/* -------------------------------- foto -------------------------------- */

.foto-zona {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radio);
  padding: 26px 16px;
  text-align: center;
  color: var(--texto-suave);
  cursor: pointer;
  background: #fbfcfd;
}
.foto-zona .icono { font-size: 2.2rem; display: block; margin-bottom: 8px; }
.foto-preview { text-align: center; }
.foto-preview img { max-width: 100%; border-radius: 10px; border: 1px solid var(--borde); }

.lectura-item { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #eef1f4; font-size: 0.9rem; }
.lectura-item:last-child { border-bottom: none; }
.lectura-item input { width: 110px; text-align: right; padding: 6px 8px; font-size: 0.95rem; }

.confianza { font-size: 0.76rem; padding: 6px 10px; border-radius: 8px; display: inline-block; margin-bottom: 10px; }
.confianza.alta { background: var(--verde-bg); color: var(--verde); }
.confianza.media { background: var(--ambar-bg); color: var(--ambar); }
.confianza.baja { background: var(--rojo-bg); color: var(--rojo); }

/* ------------------------------- login ------------------------------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--azul), var(--azul-osc));
}
.auth-card { background: var(--blanco); border-radius: 18px; padding: 26px 22px; width: 100%; max-width: 400px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22); }
.auth-card h2 { margin: 0 0 4px; font-size: 1.3rem; text-align: center; }
.auth-card .sub { text-align: center; color: var(--texto-suave); font-size: 0.85rem; margin: 0 0 18px; }
.auth-switch { text-align: center; margin-top: 14px; font-size: 0.86rem; color: var(--texto-suave); }
.auth-switch button { background: none; border: none; color: var(--azul); font-weight: 600; cursor: pointer; font-size: 0.86rem; font-family: inherit; }

/* -------------------------------- modal -------------------------------- */

.modal-fondo {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}
.modal { background: var(--blanco); border-radius: 16px; padding: 20px; width: 100%; max-width: 380px; max-height: 85vh; overflow-y: auto; }
.modal h3 { margin: 0 0 12px; font-size: 1.05rem; }
.modal-foto { background: none; padding: 0; max-width: 92vw; }
.modal-foto img { width: 100%; border-radius: 12px; display: block; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(20px + var(--safe-bottom));
  background: #1e293b;
  color: #fff;
  padding: 11px 18px;
  border-radius: 22px;
  font-size: 0.86rem;
  z-index: 200;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
  text-align: center;
}

.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: girar 0.7s linear infinite;
  vertical-align: -2px;
}
.spinner.azul { border-color: rgba(37, 99, 235, 0.3); border-top-color: var(--azul); }
@keyframes girar { to { transform: rotate(360deg); } }

/* ------------------------------- familia ------------------------------- */

.miembro {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid #eef1f4;
}
.miembro:last-child { border-bottom: none; }
.miembro .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--azul-claro);
  color: var(--azul-osc);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  flex-shrink: 0;
}
.miembro .datos { flex: 1; min-width: 0; }
.miembro .datos .nom { font-weight: 600; font-size: 0.9rem; }
.miembro .datos .meta { font-size: 0.74rem; color: var(--texto-suave); overflow: hidden; text-overflow: ellipsis; }
.miembro .acciones { display: flex; gap: 6px; flex-shrink: 0; }
.miembro .acciones button { font-size: 0.74rem; padding: 6px 9px; }

.rol-chip {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  background: #e2e8f0;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.rol-chip.superadmin { background: #ede9fe; color: #5b21b6; }
.rol-chip.admin { background: #dbeafe; color: #1e40af; }

.codigo-invitacion {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--azul-claro);
  border: 1px dashed #93b4f5;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.codigo-invitacion code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--azul-osc);
  word-break: break-all;
}

/* Interruptor de compartir */
.switch-fila {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
}
.switch-fila .txt { flex: 1; }
.switch-fila .txt b { display: block; font-size: 0.88rem; }
.switch-fila .txt span { font-size: 0.76rem; color: var(--texto-suave); }
.switch {
  position: relative;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
  border: none;
  border-radius: 20px;
  background: #cbd5e1;
  cursor: pointer;
  transition: background 0.18s;
  padding: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.switch[aria-checked="true"] { background: #16a34a; }
.switch[aria-checked="true"]::after { transform: translateX(22px); }

.nota-privacidad {
  background: #f1f5f9;
  border-left: 3px solid var(--azul);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.78rem;
  color: #475569;
  line-height: 1.5;
  margin-bottom: 12px;
}

.aviso-auditoria {
  background: var(--ambar-bg);
  color: var(--ambar);
  padding: 12px 16px;
  font-size: 0.84rem;
  line-height: 1.45;
  border-bottom: 1px solid #fcd34d;
}
.aviso-auditoria button {
  background: none;
  border: none;
  color: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
  font-size: 0.8rem;
  padding: 4px 0 0;
}

.tabla-mini { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.tabla-mini th {
  text-align: left;
  font-size: 0.7rem;
  color: var(--texto-suave);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 6px;
  font-weight: 600;
}
.tabla-mini td { padding: 7px 6px 7px 0; border-top: 1px solid #eef1f4; }

/* ----------------------------- tratamientos ----------------------------- */

.trat {
  background: var(--blanco);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 14px;
  margin-bottom: 12px;
  border-left: 4px solid var(--borde);
}
.trat.pendiente { border-left-color: #dc2626; }
.trat.programado { border-left-color: var(--azul); }
.trat.libre { border-left-color: #0d9488; }
.trat.archivado { opacity: 0.62; border-left-color: #94a3b8; }

.trat-cabecera { display: flex; align-items: flex-start; gap: 10px; }
.trat-nombre { flex: 1; min-width: 0; }
.trat-nombre b { display: block; font-size: 1.02rem; line-height: 1.25; }
.trat-nombre span { display: block; font-size: 0.8rem; color: var(--texto-suave); margin-top: 2px; }

.trat-editar {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--texto-suave);
  cursor: pointer;
  padding: 2px 4px;
  font-family: inherit;
}

.trat-cuando {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--azul-claro);
  font-size: 0.86rem;
  line-height: 1.35;
}
.trat-cuando b { font-weight: 700; }
.trat.pendiente .trat-cuando { background: var(--rojo-bg); color: var(--rojo); }
.trat.libre .trat-cuando { background: #ccfbf1; color: #115e59; }
.trat.archivado .trat-cuando { background: var(--fondo); color: var(--texto-suave); }

.trat-acciones { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.trat-acciones button { flex: 1 1 120px; min-width: 0; }
.trat-acciones .tomar {
  background: #16a34a;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.trat-acciones .tomar:active { background: #15803d; }

.trat-ultima { font-size: 0.76rem; color: var(--texto-suave); margin-top: 8px; }

/* Panel de permiso de notificaciones */
.push-panel {
  background: var(--blanco);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 13px 14px;
  margin-bottom: 12px;
  font-size: 0.84rem;
  line-height: 1.45;
}
.push-panel.aviso { background: var(--ambar-bg); border-color: #fcd34d; color: var(--ambar); }
.push-panel b { display: block; margin-bottom: 4px; font-size: 0.9rem; }
.push-panel .fila { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.push-panel .fila button { flex: 1 1 130px; }

/* Selector de la forma de pautar. Tres opciones no caben en una fila a 320 px:
   se reparten en dos, con la primera ocupando el ancho entero. */
.pauta-modos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.pauta-modos button { width: 100%; padding: 11px 6px; font-size: 0.88rem; }
.pauta-modos button:first-child { grid-column: 1 / -1; }

/* Cada momento del día con su hora, editable en el sitio. */
.momentos-lista { display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.momento-fila {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--azul-claro);
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 7px 8px 7px 11px;
}
.momento-fila .nom {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--azul-osc);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.momento-fila input[type='time'] {
  flex: 0 0 auto;
  width: auto;
  min-width: 96px;
  padding: 6px 8px;
  font-size: 0.9rem;
  margin: 0;
}
.momento-fila .quitar {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--texto-suave);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 6px;
  font-family: inherit;
}

/* Días de la semana: L M X J V S D. Siete objetivos táctiles en una fila que
   tiene que caber en 320 px, así que reparto en grid y no en flex. */
.dias-fila {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-top: 4px;
}
.dia-chip {
  /* Alto fijo y ancho libre: con aspect-ratio, siete círculos de 38 px pedían
     266 px y el formulario se desbordaba en un móvil de 320. */
  height: 42px;
  min-width: 0;
  border-radius: 11px;
  border: 1px solid var(--borde);
  background: var(--blanco);
  color: var(--texto-suave);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}
.dia-chip.puesto {
  background: var(--azul);
  border-color: var(--azul);
  color: #fff;
}
.dia-chip:active { transform: scale(0.94); }

.libre-nota {
  background: #ccfbf1;
  border: 1px solid #5eead4;
  color: #115e59;
  border-radius: 10px;
  padding: 12px 13px;
  font-size: 0.84rem;
  line-height: 1.5;
  margin-bottom: 10px;
}
.libre-nota b { display: block; margin-bottom: 4px; font-size: 0.92rem; }
.libre-nota b + b, .libre-nota b:not(:first-child) { display: inline; margin: 0; font-size: inherit; }

.horas-elegidas { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 2px; }
.hora-chip {
  background: var(--azul-claro);
  color: var(--azul-osc);
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.hora-chip::after { content: ' ✕'; opacity: 0.6; font-size: 0.8em; }

.aviso-medico {
  font-size: 0.72rem;
  color: #94a3b8;
  text-align: center;
  padding: 4px 8px 16px;
  line-height: 1.4;
}

/* ------------------------- pantallas estrechas -------------------------
   Un iPhone SE o un Android básico tienen 320-375 px. Con cinco pestañas y
   dos botones redondos en la barra de escribir, el campo se quedaba en 132 px
   y el texto se salía. Aquí se aprieta todo lo justo. */
/* -------------------------------- comidas -------------------------------- */

.com-dia { margin-top: 14px; }
.com-fila {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #eef1f4;
}
.com-fila:last-child { border-bottom: none; }
.com-ico { font-size: 1.4rem; line-height: 1.2; width: 28px; text-align: center; flex: 0 0 auto; }
.com-cuerpo { flex: 1 1 auto; min-width: 0; }
.com-cab { font-size: 0.85rem; color: var(--texto-suave); }
.com-cab b { color: var(--texto); }
/* Una comida puede ser larga y traer un nombre sin espacios. Nunca se recorta
   con puntos suspensivos: es lo que la persona ha escrito. */
.com-texto { font-size: 0.92rem; margin-top: 2px; overflow-wrap: anywhere; }
/* Objetivos tactiles del tamano del resto de la app (~42 px) y SEPARADOS: el
   de borrar esta al lado del de editar, no hay deshacer, y el dedo que los
   busca es el de una persona mayor. El subrayado que trae .ghost sobra en un
   emoji. */
.com-botones { display: flex; gap: 6px; flex: 0 0 auto; }
.com-botones button {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
  text-decoration: none;
  border-radius: 10px;
}

/* Elegir entre dos mediciones que se solapan. Las dos cifras se ven a la vez:
   una persona mayor no tiene por qué acordarse de la de hace tres minutos. */
.elegir-opcion {
  border: 1px solid var(--borde);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--fondo);
}
.elegir-cab { font-size: 0.76rem; color: var(--texto-suave); }
.elegir-valores { font-size: 0.95rem; font-weight: 600; margin-top: 2px; }

/* Los dos botones de «Mi día», uno al lado del otro. A 320 px no caben en la
   misma línea sin quedarse en un renglón de letra pequeña: se apilan. */
.dia-botones { display: flex; gap: 8px; }
.dia-botones button { flex: 1 1 0; margin: 0; }

.dia-cab { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.dia-andado { font-size: 0.78rem; color: var(--texto-suave); white-space: nowrap; }

/* En el historial, cada cosa lleva su franja de color a la izquierda para
   distinguirla de un vistazo de una medicion. */
.entry-comida, .entry-toma, .entry-paseo { padding-left: 10px; border-left: 3px solid #f59e0b; }
.entry-toma { border-left-color: #7c3aed; }
.entry-paseo { border-left-color: #16a34a; }
.entry-clase { font-size: 0.74rem; color: var(--texto-suave); white-space: nowrap; }

/* -------------------------------- fin comidas -------------------------------- */

@media (max-width: 400px) {
  .tab { font-size: 0.66rem; padding: 8px 1px; letter-spacing: -0.01em; }
  .dia-cab { flex-wrap: wrap; gap: 2px; }
  .tab .ico { font-size: 0.98rem; margin-bottom: 1px; }

  .container { padding-left: 12px; padding-right: 12px; }

  .chat-form { gap: 6px; }
  .chat-form button, .btn-conv { width: 40px; height: 40px; font-size: 1rem; }
  .chat-form textarea { padding: 10px 12px; font-size: 0.95rem; }

  .orbe { width: 124px; height: 124px; font-size: 3rem; }
  .conversacion { gap: 14px; padding: 20px 14px calc(20px + var(--safe-bottom)); }
  .conv-titulo { font-size: 1.05rem; }
  .conv-texto { font-size: 0.9rem; }

  .conv-lanzador { padding: 12px 13px; gap: 10px; }
  .conv-lanzador .ico { font-size: 1.3rem; width: 38px; height: 38px; }
  .conv-lanzador .txt b { font-size: 0.92rem; }
  .conv-lanzador .txt { font-size: 0.75rem; }

  .miembro .acciones { flex-direction: column; gap: 4px; }
  .summary-box .value { font-size: 0.98rem; }

  .trat { padding: 12px; }
  .trat-nombre b { font-size: 0.96rem; }
  .trat-cuando { font-size: 0.82rem; padding: 8px 10px; }
  .trat-acciones button { flex: 1 1 100%; }
  .pauta-modos button { font-size: 0.82rem; padding: 10px 4px; }
  .dias-fila { gap: 4px; }
  .dia-chip { height: 40px; font-size: 0.84rem; border-radius: 10px; }
  .momento-fila { padding: 6px 6px 6px 9px; gap: 6px; }
  .momento-fila .nom { font-size: 0.82rem; }
  .momento-fila input[type='time'] { min-width: 88px; font-size: 0.85rem; padding: 5px 6px; }
}

/* A 320 px un campo de fecha y uno de hora no caben uno al lado del otro:
   los dos traen su propio ancho mínimo del navegador y el modal desbordaba
   por la derecha. Se ponen uno debajo del otro antes que recortarlos. */
@media (max-width: 359px) {
  .com-cuando { flex-wrap: wrap; }
  .com-cuando .field { flex: 1 1 100%; }
  /* Dos botones con emoji y texto no caben en 320 px sin encogerse. */
  .dia-botones { flex-direction: column; }
}

/* A 320 px el campo de hora y el nombre no caben en la misma línea: el nombre
   se quedaba en «☕ Desay…». Se pone en su propio renglón antes que recortarlo. */
@media (max-width: 359px) {
  .momento-fila { flex-wrap: wrap; padding: 8px 8px 8px 10px; }
  .momento-fila .nom { flex: 1 1 100%; white-space: normal; overflow: visible; }
  .momento-fila input[type='time'] { flex: 1 1 auto; }
}

/* Pantallas muy estrechas (320 px). Se aprieta la letra, pero NO se quita:
   un icono suelto no le dice nada a quien no ve bien. */
@media (max-width: 340px) {
  .tab { font-size: 0.6rem; padding: 8px 0; }
  .tab .ico { font-size: 0.94rem; }
  .container { padding-left: 10px; padding-right: 10px; }
  .card { padding: 13px; }
}

@media (min-width: 700px) {
  .container { max-width: 620px; }
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0f172a;
    --blanco: #1e293b;
    --texto: #e2e8f0;
    --texto-suave: #94a3b8;
    --borde: #334155;
    --azul-claro: #1e3a5f;
    --sombra: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
  input, textarea, select { background: #0f172a; border-color: #334155; color: var(--texto); }
  label { color: #cbd5e1; }
  .summary-box { background: #0f172a; }
  .summary-box .value { color: #e2e8f0; }
  .entry { border-color: #334155; }
  .val-tag { color: #cbd5e1; }
  .val-tag b { color: #f1f5f9; }
  .section-title { color: #e2e8f0; }
  .foto-zona { background: #0f172a; border-color: #475569; }
  button.secondary { background: var(--blanco); }
  .modal h3 { color: #e2e8f0; }
  .miembro { border-color: #334155; }
  .tabla-mini td { border-color: #334155; }
  .nota-privacidad { background: #0f172a; color: #cbd5e1; }
  .rol-chip { background: #334155; color: #cbd5e1; }
  .rol-chip.superadmin { background: #4c1d95; color: #ddd6fe; }
  .rol-chip.admin { background: #1e3a8a; color: #dbeafe; }
  .codigo-invitacion { background: #0f172a; border-color: #1e40af; }
  .codigo-invitacion code { color: #93b4f5; }
  .switch { background: #475569; }
  .aviso-auditoria { background: #422006; color: #fcd34d; border-color: #92400e; }
  .btn-conv { background: var(--blanco); }
  .conv-titulo { color: #e2e8f0; }
  .com-fila { border-color: #334155; }
  .trat-cuando { background: #0f172a; }
  .trat.pendiente .trat-cuando { background: #450a0a; color: #fecaca; }
  .trat.libre .trat-cuando { background: #042f2e; color: #99f6e4; }
  .libre-nota { background: #042f2e; border-color: #115e59; color: #99f6e4; }
  .momento-fila { background: #1e3a5f; border-color: #1e40af; }
  .momento-fila .nom { color: #dbeafe; }
  .dia-chip { background: #0f172a; border-color: #334155; }
  .dia-chip.puesto { background: var(--azul); border-color: var(--azul); color: #fff; }
  .push-panel.aviso { background: #422006; border-color: #92400e; color: #fcd34d; }
  .hora-chip { background: #1e3a5f; color: #dbeafe; border-color: #1e40af; }
}
