:root {
  --bg: #FBF8F1;
  --surface: #FFFFFF;
  --ink: #2E2112;
  --muted: #6E6250;
  --line: #EDE5D3;
  --line-strong: #D9CCB0;
  --track: #F3EDDF;
  --primary: #4A3420;
  --primary-ink: #2E2112;
  --primary-soft: #FFF6DD;
  --accent: #F5C54A;
  --water-light: #F6E2A8;
  --water-mid: #EDC65C;
  --body-empty: #E4EBF2;
  --body-water: #3D8FE0;
  --body-water-deep: #1F5FB8;
  --orange: #D9692A;
  --orange-ink: #8A3A10;
  --orange-soft: #FDEFE3;
  --blue: #2F55B8;
  --blue-soft: #E8EEFB;
  --side: #FFF6DD;
  --side-2: #FBEBC4;
  --side-3: #F6DE9E;
  --side-muted: #8A7558;
  --danger: #B4432F;
  --display: "Fredoka", system-ui, sans-serif;
  --body: "Inter", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--body); }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -0.01em; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #F4B942; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
/* Lo de admin solo se ve con la sesión de admin (el servidor igual lo bloquea). */
body:not(.modo-admin) [data-solo-admin] { display: none !important; }

.app { display: flex; flex-wrap: wrap; min-height: 100vh; align-items: stretch; }

/* ---------- Barra lateral ---------- */
.sidebar {
  flex: 1 1 232px; max-width: 260px; min-width: 210px;
  background: var(--side); color: var(--ink); border-right: 1px solid var(--line);
  padding: 24px 16px; display: flex; flex-direction: column; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark { width: 40px; height: 40px; display: block; flex: none; }
.brand-mark img { width: 100%; height: 100%; display: block; }
.brand-name { font-family: var(--display); font-weight: 600; font-size: 22px; line-height: 1.1; color: var(--ink); display: block; }
.brand-sub { font-size: 12px; color: var(--side-muted); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav button {
  min-height: 44px; display: flex; align-items: center; gap: 12px; padding: 0 12px;
  border: none; border-radius: 10px; background: transparent; color: var(--muted);
  font-weight: 500; text-align: left;
}
.nav button::before { content: ""; width: 8px; height: 8px; border-radius: 4px; background: var(--line-strong); }
.nav button:hover { background: var(--side-2); }
.nav button[aria-current="page"] { background: var(--side-3); color: var(--ink); font-weight: 600; }
.nav button[aria-current="page"]::before { background: var(--primary); }

.side-label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--side-muted); font-weight: 600; padding: 0 8px; }
.people { display: flex; flex-direction: column; gap: 2px; list-style: none; margin: 8px 0 0; padding: 0; }
.people button {
  width: 100%; min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  border: none; border-radius: 10px; background: transparent; text-align: left;
}
.people button:hover { background: var(--side-2); }
.people button[aria-current="true"] { background: var(--side-3); }
.avatar { width: 32px; height: 32px; border-radius: 16px; background: #F2DFAE; color: var(--ink); display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.people button[aria-current="true"] .avatar { background: var(--primary); color: var(--side); }
.people .who { display: flex; flex-direction: column; min-width: 0; }
.people .who b { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .who small { color: var(--side-muted); font-size: 12px; }
.add-person { display: flex; gap: 6px; padding: 8px 8px 0; }
.add-person input {
  flex: 1 1 auto; min-width: 0; min-height: 40px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
}
.add-person input::placeholder { color: var(--side-muted); }
.add-person button { min-height: 40px; padding: 0 12px; border-radius: 8px; border: none; background: var(--primary); color: var(--side); font-weight: 600; }

/* ---------- Contenido ---------- */
.main { flex: 999 1 560px; min-width: 0; padding: 28px 32px 120px; }
.container { max-width: 1160px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
.demo-banner { margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--orange-soft); color: var(--orange-ink); font-weight: 500; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.page-head .date { font-size: 13px; color: var(--muted); }
.page-head h1 { font-size: 30px; font-weight: 700; }
.head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; font-weight: 600; font-size: 13px; }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 4px; background: currentColor; }
.chip.ok { background: var(--primary-soft); color: var(--primary-ink); }
.chip.off { background: var(--orange-soft); color: var(--orange-ink); }
.btn { min-height: 44px; padding: 0 18px; border-radius: 10px; border: none; background: var(--primary); color: var(--side); font-weight: 600; }
.btn:hover { background: var(--primary-ink); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-ghost { min-height: 44px; padding: 0 12px; border: none; background: transparent; color: var(--primary); font-weight: 600; border-radius: 10px; }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--danger); background: #fff; color: var(--danger); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 12px; }
.card-head h2 { font-size: 18px; font-weight: 600; }
.card-head .hint, .hint { font-size: 13px; color: var(--muted); margin: 0; }
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-state h2 { color: var(--ink); font-size: 20px; margin-bottom: 8px; }

/* KPIs */
.kpi { gap: 12px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-top span:first-child { color: var(--muted); font-weight: 500; }
.tag { font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 999px; }
.kpi-value { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.kpi-value b { font-family: var(--display); font-size: 32px; font-weight: 700; line-height: 1.1; }
.kpi-value span { color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; transition: width 0.4s ease; }

/* Gráfico de barras (agua) */
.bars { position: relative; height: 200px; display: flex; align-items: flex-end; gap: 12px; padding: 0 4px; border-bottom: 1px solid var(--line); }
.bars .goal { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--side-muted); }
.bars .goal span { position: absolute; right: 0; top: -18px; font-size: 11px; color: var(--muted); background: var(--surface); padding: 0 4px; }
.bars .col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; }
.bars .col b { font-size: 12px; font-weight: 600; }
.bars .col i { display: block; width: 100%; max-width: 40px; border-radius: 8px 8px 0 0; background: var(--water-light); transition: height 0.4s ease; }
.bars .col i.full { background: var(--water-mid); }
.bars .col i.today { background: var(--primary); }
.axis { display: flex; gap: 12px; padding: 0 4px; }
.axis span { flex: 1 1 0; text-align: center; font-size: 12px; color: var(--muted); }
.axis span b { display: block; color: var(--ink); font-weight: 600; }

/* Cuerpo que se llena de agua (prueba) */
.water-wrap { display: flex; align-items: flex-end; gap: 20px; }
.water-wrap #water-chart { flex: 1 1 auto; min-width: 0; }
.water-body { flex: none; width: 96px; margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.water-body svg { width: 100%; height: auto; display: block; overflow: visible; }
.water-body .nivel { transition: transform 0.9s cubic-bezier(0.22, 1, 0.36, 1); }
.water-body .ola { animation: ola 2.4s linear infinite; }
.water-body .marca { stroke: #fff; stroke-opacity: 0.45; stroke-width: 0.8; stroke-dasharray: 2 3; }
.water-body figcaption { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.3; }
.water-body figcaption b { display: block; font-family: var(--display); font-size: 18px; color: var(--body-water-deep); }
.water-body.lleno svg { filter: drop-shadow(0 0 6px rgba(61, 143, 224, 0.45)); }
@keyframes ola { from { transform: translateX(0); } to { transform: translateX(-40px); } }
@media (prefers-reduced-motion: reduce) {
  .water-body .ola { animation: none; }
  .water-body .nivel { transition: none; }
}
/* ---------- Bienvenida ---------- */
.splash {
  position: fixed; inset: 0; z-index: 30; padding: 24px 16px;
  background: radial-gradient(circle at 50% 40%, var(--primary-soft), var(--bg) 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  color: var(--ink);
}
/* Solo Kero es clicable; el fondo y el texto no hacen nada. */
.splash-kero {
  display: block; line-height: 0; border: none; background: transparent; padding: 0; margin: 0;
  border-radius: 50%; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.splash-kero.fuera { cursor: default; } /* esquinas del cuadrado, fuera del círculo de Kero */
.splash-kero:focus-visible { outline-offset: 4px; }
.splash-kero .kero-face { width: min(50vh, 50dvh, 85vw); height: min(50vh, 50dvh, 85vw); animation: kero-flota 3s ease-in-out infinite; }
.splash-texto { margin: 0; font: 600 clamp(26px, 3vw, 36px)/1.2 var(--display); text-align: center; animation: kero-pulso 1.8s ease-in-out infinite; }
/* Se ríe al pasar el mouse (desktop) y al tocarlo, igual que la burbuja */
.splash-kero:is(:not(.fuera):hover, :focus-visible, .feliz) .kero-eyes, .splash-kero:is(:not(.fuera):hover, :focus-visible, .feliz) .kero-mouth { opacity: 0; }
.splash-kero:is(:not(.fuera):hover, :focus-visible, .feliz) .kero-happy, .splash-kero:is(:not(.fuera):hover, :focus-visible, .feliz) .kero-laugh { opacity: 1; }
.splash-kero:is(:not(.fuera):hover, .feliz) .kero-laugh { animation: kero-jaja 0.32s ease-in-out infinite alternate; }
.splash-kero:is(:not(.fuera):hover, :focus-visible, .feliz) .kero-blush { transform: scale(1.15); opacity: 1; }
.splash-kero:is(:not(.fuera):hover, :focus-visible, .feliz) .kero-face { animation: kero-giggle 0.6s ease-in-out infinite; }
.splash.saliendo { opacity: 0; transition: opacity 0.25s ease; }
@keyframes kero-flota { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes kero-pulso { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) {
  .splash-kero .kero-face, .splash-texto, .splash-kero.feliz .kero-face, .splash-kero.feliz .kero-laugh { animation: none; }
}

@media (max-width: 720px) {
  .water-wrap { gap: 12px; }
  .water-body { width: 72px; }
}

/* Kero hidratado */
.kero-card { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: center; margin-top: 16px; }
.kero-figura { margin: 0; }
.kero-figura svg { width: 100%; height: auto; display: block; }
.kero-figura .kero-bob { animation: kero-bob 3.2s ease-in-out infinite; transform-origin: 120px 200px; }
.kero-figura.feliz .kero-bob { animation: kero-salto 1.1s ease-in-out infinite; }
.kero-figura.sediento .kero-bob { animation-duration: 5s; }
/* Parpadea siempre, esté como esté; el doble parpadeo cada tanto lo hace ver vivo. */
.kero-figura .kero-ojos { transform-box: fill-box; transform-origin: center; animation: kero-parpadeo 5.2s infinite; }
.kero-info { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.kero-animo { margin: 0; font-family: var(--display); font-size: 20px; font-weight: 600; }
.kero-semana { list-style: none; margin: 6px 0 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.kero-semana li { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.kero-semana i { width: 26px; height: 26px; border-radius: 50%; border: 2px dashed var(--line-strong, #CBD5D2); display: grid; place-items: center; font-style: normal; font-size: 13px; }
.kero-semana .ok i { border: 2px solid var(--body-water); background: var(--body-water); color: #fff; }
.kero-semana .hoy i { border-style: solid; border-color: var(--body-water); }
.kero-semana .fuera i { opacity: 0.35; }
.kero-coleccion { list-style: none; margin: 6px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.kero-coleccion li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); font-size: 12px; line-height: 1.2; }
.kero-coleccion li span { font-size: 18px; }
/* Ganados: botón que pone o saca el accesorio */
.kero-coleccion li:has(button) { padding: 0; }
.kero-coleccion button { all: unset; box-sizing: border-box; width: 100%; min-height: 40px; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; cursor: pointer; }
.kero-coleccion button:hover { background: var(--primary-soft); }
.kero-coleccion button:focus-visible { outline: 3px solid #F4B942; outline-offset: 2px; }
.kero-coleccion button:disabled { cursor: progress; opacity: 0.6; }
.kero-coleccion li.puesto { border: 2px solid var(--primary); background: var(--primary-soft); }
.kero-coleccion li.puesto button::after { content: "✓"; margin-left: auto; font-weight: 700; color: var(--primary); }
.kero-coleccion li.no { opacity: 0.4; filter: grayscale(1); border-style: dashed; }
.kero-coleccion li.grande { border-color: #F5B700; background: #FFF7DA; }
.kero-coleccion li.grande.puesto { border-color: #C99400; }
.kero-coleccion li.grande.no { background: none; }
@keyframes kero-parpadeo { 0%, 44%, 50%, 88%, 91.5%, 95%, 100% { transform: scaleY(1); } 47%, 89.8%, 93.3% { transform: scaleY(0.1); } }
@keyframes kero-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes kero-salto { 0%, 100% { transform: translateY(0) scale(1, 1); } 30% { transform: translateY(-12px) scale(0.98, 1.02); } 60% { transform: translateY(0) scale(1.03, 0.97); } }
@media (prefers-reduced-motion: reduce) { .kero-figura .kero-bob, .kero-figura .kero-ojos { animation: none !important; } }
@media (max-width: 720px) {
  .kero-card { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .kero-figura { width: 180px; }
  .kero-info { width: 100%; }
}

/* Gráfico de línea (calorías) */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .ln { width: 14px; height: 3px; border-radius: 2px; background: var(--orange); }
.legend .ln.dash { height: 0; border-top: 2px dashed var(--muted); background: none; }
.line-chart { width: 100%; height: 200px; display: block; overflow: visible; }

/* Agenda */
.agenda { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.agenda li { display: grid; grid-template-columns: 52px 10px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid #F0F3F2; }
.agenda li:last-child { border-bottom: none; }
.agenda time { font-variant-numeric: tabular-nums; font-weight: 600; }
.agenda .dot { width: 10px; height: 10px; border-radius: 5px; }
.agenda .txt { overflow: hidden; text-overflow: ellipsis; }
.agenda li.past .txt, .agenda li.past time { color: var(--muted); }
.st { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.st-enviado { background: var(--primary-soft); color: var(--primary-ink); }
.st-pendiente { background: var(--bg); color: var(--muted); }
.st-omitido, .st-sin_enviar { background: var(--orange-soft); color: var(--orange-ink); }
.st-error { background: #FBE7E3; color: var(--danger); }

/* Semana */
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week-grid div { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.week-grid b { width: 100%; max-width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-weight: 600; font-size: 13px; background: var(--bg); color: var(--muted); border: 1px dashed var(--line-strong); }
.week-grid b.hecho { background: var(--primary); color: var(--side); border-color: transparent; }
.week-grid b.no_pude { background: var(--orange-soft); color: var(--orange-ink); border-color: transparent; }
.week-grid b.today { outline: 2px solid var(--ink); outline-offset: 2px; }
.week-grid small { font-size: 12px; color: var(--muted); }
.habits { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; border-top: 1px solid #F0F3F2; }
.habit-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.habit-row b { font-weight: 600; }

/* ---------- Rutinas ---------- */
.routine-head { display: flex; align-items: center; gap: 12px; }
.routine-head .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.routine-head > div:nth-child(2) { flex: 1 1 auto; min-width: 0; }
.routine-head h2 { font-size: 18px; font-weight: 600; }
.routine-head p { margin: 0; color: var(--muted); font-size: 13px; }
.field-label { font-weight: 500; margin-bottom: 8px; display: block; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); font-weight: 600; }
.pill.day { padding: 0 10px; min-width: 52px; }
.pill[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--side); }
.pill:disabled { cursor: default; }
.times { display: flex; flex-wrap: wrap; gap: 6px; }
.times span { padding: 6px 10px; border-radius: 8px; background: var(--bg); font-variant-numeric: tabular-nums; font-size: 13px; }
.switch {
  flex: none; width: 52px; height: 32px; border-radius: 16px; border: none; padding: 3px;
  background: var(--line-strong); display: flex; align-items: center; justify-content: flex-start; transition: background 0.2s;
}
.switch::after { content: ""; width: 26px; height: 26px; border-radius: 13px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.switch[aria-checked="true"] { background: var(--primary); justify-content: flex-end; }
.time-input { min-height: 44px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 10px; font-size: 15px; background: #fff; }
.time-field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.base-card { flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 24px; }
.base-card > div:first-child { flex: 1 1 260px; }
.meals { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.meals li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid #F0F3F2; }
.meals li:last-child { border-bottom: none; }
.meals .name { flex: 1 1 auto; font-weight: 500; }
.save-bar { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 12px; }
.save-msg { font-weight: 600; color: var(--primary-ink); }
.save-msg.err { color: var(--danger); }
.off-section { opacity: 0.55; }

/* ---------- Perfil y plan ---------- */
.targets { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 0; }
.targets div { background: var(--bg); border-radius: 12px; padding: 12px; }
.targets dt { font-size: 12px; color: var(--muted); }
.targets dd { margin: 0; font-family: var(--display); font-size: 22px; font-weight: 700; }
.targets dd small { font-size: 13px; color: var(--muted); font-family: var(--body); font-weight: 500; }
.profile { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.profile dt { color: var(--muted); }
.profile dd { margin: 0; font-weight: 500; }
.plan-days { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.plan-days li { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.plan-days li.today { border-color: var(--accent); background: var(--primary-soft); }
.plan-days h3 { font-size: 15px; margin-bottom: 4px; }
.plan-days p { margin: 2px 0; color: var(--muted); }
.plan-days p b { color: var(--ink); font-weight: 600; }
.notice { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--orange-soft); color: var(--orange-ink); }

/* ---------- Widget de chat ---------- */
.chat-widget {
  position: fixed; right: 24px; bottom: 24px; z-index: 20;
  width: 400px; max-width: calc(100vw - 32px); height: 600px; max-height: calc(100vh - 48px);
  background: #fff; border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 18px 48px rgba(74, 52, 32, 0.16);
  display: flex; flex-direction: column; overflow: hidden;
}
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 16px; background: var(--side); color: var(--ink); border-bottom: 1px solid var(--line); }
.chat-head .avatar { width: 36px; height: 36px; border-radius: 18px; }
.avatar.kero { background: transparent; padding: 0; overflow: hidden; }
.avatar.kero img { width: 100%; height: 100%; display: block; }
.chat-head .who { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.chat-head .who b { font-weight: 600; }
.icon-btn { width: 44px; height: 44px; border: none; border-radius: 10px; background: transparent; color: inherit; display: grid; place-items: center; flex: none; }
.chat-head .icon-btn:hover { background: var(--side-2); }
.sim-bar { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; border-bottom: 1px solid var(--line); background: #FFFCF3; align-items: center; }
.sim-bar span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sim-bar button { min-height: 32px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-strong); background: #fff; font-size: 12px; font-weight: 600; white-space: nowrap; }
.sim-bar button:hover { border-color: var(--primary); color: var(--primary-ink); }
.chat { flex: 1 1 auto; overflow-y: auto; padding: 16px; background: var(--bg); display: flex; flex-direction: column; gap: 10px; list-style: none; margin: 0; }
.msg { display: flex; flex-direction: column; gap: 6px; max-width: 85%; }
.msg.in { align-self: flex-end; align-items: flex-end; }
.msg.out { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 10px 12px; line-height: 1.45; font-size: 14px; border-radius: 14px; word-wrap: break-word; }
.msg.in .bubble { background: var(--side); border-bottom-right-radius: 4px; }
.msg.out .bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.typing .bubble { color: var(--muted); font-style: italic; }
.msg .sticker { width: 140px; height: 140px; display: block; }
.msg-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.msg-buttons button { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--primary); background: #fff; color: var(--primary-ink); font-weight: 600; }
.msg-buttons button:hover { background: var(--primary-soft); }
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 260px; }
.chat-notice { margin: 0; padding: 8px 12px; font-size: 13px; background: var(--orange-soft); color: var(--orange-ink); }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: #fff; }
.composer input[type="text"] { flex: 1 1 auto; min-width: 0; min-height: 44px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 10px; }
.composer .attach { width: 44px; height: 44px; border: 1px solid var(--line-strong); border-radius: 10px; display: grid; place-items: center; color: var(--muted); cursor: pointer; flex: none; }
.composer .send { width: 44px; height: 44px; border: none; border-radius: 10px; background: var(--primary); color: var(--side); display: grid; place-items: center; flex: none; }
.chat-launcher {
  position: fixed; right: 24px; bottom: 24px; z-index: 20; height: 56px; padding: 0 20px 0 16px;
  border: none; border-radius: 28px; background: var(--primary); color: var(--side); font-weight: 600;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 12px 32px rgba(74, 52, 32, 0.25);
}
/* Kero animado en el botón (solo con el chat cerrado) */
.chat-launcher { padding-left: 6px; }
.kero-face { width: 44px; height: 44px; flex: none; display: block; position: relative; }
.kero-tilt { position: absolute; inset: 0; display: block; transition: transform 0.25s ease-out; transform: translate(var(--kx, 0px), var(--ky, 0px)) rotate(var(--kr, 0deg)); }
.kero-tilt img, .kero-tilt svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.kero-eyes { transform: translate(var(--ex, 0px), var(--ey, 0px)); transition: transform 0.12s ease-out; }
.kero-blink { transform-box: fill-box; transform-origin: center; animation: kero-blink 4.5s infinite; }
.kero-blush { transform-box: fill-box; transform-origin: center; transition: transform 0.25s ease, opacity 0.25s ease; opacity: 0.9; }
.kero-happy, .kero-laugh { opacity: 0; transition: opacity 0.15s ease; }
.kero-laugh { transform-box: fill-box; transform-origin: center top; }
.kero-mouth { transition: opacity 0.15s ease; }
.chat-launcher:hover .kero-eyes, .chat-launcher:focus-visible .kero-eyes,
.chat-launcher:hover .kero-mouth, .chat-launcher:focus-visible .kero-mouth { opacity: 0; }
.chat-launcher:hover .kero-happy, .chat-launcher:focus-visible .kero-happy,
.chat-launcher:hover .kero-laugh, .chat-launcher:focus-visible .kero-laugh { opacity: 1; }
.chat-launcher:hover .kero-laugh { animation: kero-jaja 0.32s ease-in-out infinite alternate; }
.chat-launcher:hover .kero-blush, .chat-launcher:focus-visible .kero-blush { transform: scale(1.15); opacity: 1; }
.chat-launcher:hover .kero-face, .chat-launcher:focus-visible .kero-face { animation: kero-giggle 0.6s ease-in-out infinite; }
.chat-launcher:active .kero-face { transform: scale(0.9); }
@keyframes kero-blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(0.1); } }
@keyframes kero-jaja { from { transform: scaleY(0.75); } to { transform: scaleY(1.05); } }
@keyframes kero-giggle {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1.08); }
  25% { transform: translateY(-3px) rotate(-8deg) scale(1.08); }
  50% { transform: translateY(0) rotate(0deg) scale(1.08); }
  75% { transform: translateY(-3px) rotate(8deg) scale(1.08); }
}
@media (prefers-reduced-motion: reduce) {
  .kero-tilt, .kero-eyes { transition: none; transform: none; }
  .kero-blink, .chat-launcher:hover .kero-face, .chat-launcher:hover .kero-laugh { animation: none; }
}

@media (max-width: 720px) {
  .sidebar { max-width: none; flex-basis: 100%; gap: 16px; padding: 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 20px 16px 120px; }
  .page-head h1 { font-size: 24px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  /* En el celular el chat ocupa toda la pantalla, como una app de mensajería. */
  .chat-widget {
    inset: 0; width: auto; max-width: none;
    height: 100vh; height: var(--chat-h, 100dvh); max-height: none;
    border: none; border-radius: 0; box-shadow: none;
  }
  .chat-head { padding-top: max(12px, env(safe-area-inset-top)); }
  .composer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .composer input[type="text"] { font-size: 16px; } /* evita el zoom de iOS al enfocar */
  .msg { max-width: 90%; }
  .chat-launcher { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
  html.chat-lock, html.chat-lock body { overflow: hidden; }
}

/* ---------- Ejercicios ---------- */
.ej-config { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 16px 24px; }
.ej-config > div:first-child { flex: 1 1 280px; }
.ej-config h2 { font-size: 18px; font-weight: 600; }
.ej-dia { display: inline-flex; flex-direction: column; justify-content: center; line-height: 1.2; padding: 6px 12px; }
.ej-dia small { font-size: 11px; font-weight: 500; opacity: 0.75; }
.ej-sesion { display: flex; flex-direction: column; gap: 12px; }
.ej-sesion-head h3 { font-size: 17px; }
.ej-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ej-items > li { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; }
.ej-items > li.cambiando { border-color: var(--accent); background: var(--primary-soft); }
.ej-mini { width: 96px; height: 85px; display: block; background: #FFFDF8; border-radius: 10px; }
.ej-item-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ej-item-info b { font-weight: 600; }
.ej-dosis { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.ej-dosis label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.ej-dosis input { width: 64px; min-height: 40px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; font-size: 15px; }
.ej-item-acc { display: flex; flex-direction: column; gap: 2px; }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost[aria-pressed="true"] { background: var(--primary-soft); }
.ej-agregar { align-self: flex-start; }
.ej-agregar[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: 2px; }
.ej-pick { margin: 0; padding: 8px 8px 8px 14px; border-radius: 10px; background: var(--primary-soft); border: 1px solid var(--accent); font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.ej-filtros { display: flex; flex-direction: column; gap: 8px; }
.ej-filtros .pill { min-height: 36px; padding: 0 12px; font-size: 13px; }
.ej-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.ej-card { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.ej-card.foco { border-color: #F2A595; }
.ej-card svg { width: 100%; height: auto; aspect-ratio: 260 / 230; display: block; background: #FFFDF8; border-radius: 10px; }
.ej-card h3 { font-size: 16px; margin-top: 4px; }
.ej-meta { margin: 0; font-size: 12px; color: var(--muted); }
.ej-pasos { margin: 2px 0 0; padding-left: 18px; font-size: 13px; color: var(--ink); }
.ej-card-foot { margin-top: auto; padding-top: 6px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid #F3EEE3; }
.ej-card-foot .hint { white-space: nowrap; }
.ej-zonas { display: flex; flex-wrap: wrap; gap: 4px; }
.ej-zonas mark { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.ej-zonas mark.z1 { background: #FDE1DB; color: #9C2F1F; }
.ej-zonas mark.z2 { background: #FFF1EC; color: #A5543F; }
@media (max-width: 720px) {
  .ej-items > li { grid-template-columns: 72px minmax(0, 1fr); }
  .ej-mini { width: 72px; height: 64px; }
  .ej-item-acc { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
}

/* Sesión de Google (abajo en la barra lateral) */
.sesion { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding: 12px 8px 0; border-top: 1px solid var(--side-3); }
.sesion-email { font-size: 12px; color: var(--side-muted); overflow-wrap: anywhere; }
.sesion-salir { display: inline-flex; align-items: center; align-self: flex-start; min-height: 36px; padding: 0 8px; margin-left: -8px; text-decoration: none; }

/* Conectar WhatsApp */
.wa-cuenta { display: flex; flex-direction: column; gap: 6px; padding-bottom: 12px; }
.wa-estado { font-size: 13px; color: var(--ink); }
/* Mismos colores que el botón de WhatsApp de Globot */
.btn-wa { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; padding: 0 16px; border: none;
  border-radius: 10px; background: #25D366; color: #fff; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn-wa:hover { background: #128C7E; }
.btn-wa:focus-visible { outline-color: #128C7E; }
.wa-dialog { width: min(440px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--surface); color: var(--ink); }
.wa-dialog::backdrop { background: rgb(46 33 18 / 0.45); }
.wa-dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 24px; margin: 0; }
.wa-dialog h2 { font-size: 22px; font-weight: 600; }
.wa-pasos { margin: 0; padding-left: 20px; }
.wa-codigo { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.wa-copiar { display: inline-flex; align-items: center; gap: 6px; }
.wa-codigo code { display: inline-block; font: 600 26px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.06em; padding: 12px 18px; border-radius: 12px; background: var(--primary-soft); border: 1px dashed var(--accent); user-select: all; }
.wa-abrir { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.wa-error { margin: 0; color: var(--danger); font-size: 13px; }
.wa-acciones { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }

/* En pantallas anchas la barra lateral queda fija a la altura de la ventana: así
   "Cerrar sesión" siempre está a la vista, aunque la página sea larga. */
@media (min-width: 721px) {
  .sidebar { position: sticky; top: 0; align-self: flex-start; height: 100vh; height: 100dvh; overflow-y: auto; }
}
