/* KIROS-TERAPIA — PWA paciente
   Base cálida y oscura (marca personal del terapeuta): fondo marrón oscuro,
   texto crema, serif para títulos + sans para cuerpo. El azul/violeta de
   KIROS queda reservado casi en exclusiva para el búho mascota y un puñado
   de acentos puntuales (botón primario, anillo de progreso semanal). El
   dorado hace de color de racha/logro; el salvia, de "completado".
   Mobile-first; en desktop el contenido queda centrado como una tarjeta. */

:root {
  /* ---- Base cálida y oscura ---- */
  --bg: #1a150e;
  --bg-2: #221b12;
  --bg-3: #2c2216;
  --bg-4: #372a19;
  --cream: #f7efdd;
  --cream-2: #ddcfb1;
  --cream-3: #a99c81;
  --gold: #d6a55c;
  --gold-2: #f0cb8c;
  --gold-dim: #8a6a3a;
  --sage: #8a9678;
  --sage-2: #a9b596;
  --line: rgba(247, 239, 221, 0.13);
  --line-soft: rgba(247, 239, 221, 0.08);
  --danger: #e0897a;
  --danger-soft: rgba(224, 137, 122, 0.14);

  /* ---- Azul/violeta KIROS: búho + acentos puntuales ---- */
  --accent: #2563eb;
  --accent-2: #0ea5e9;
  --accent-deep: #0b69b0;
  --violet: #6d28d9;
  --navy: #0b1221;
  --navy-2: #14223a;
  --navy-3: #1a3560;

  --serif: "Cormorant Garamond", "Times New Roman", serif;
  --sans: "Sora", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --hand: "Caveat", cursive;

  --radius: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-soft: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition: 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);

  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 20px 44px -14px rgba(0, 0, 0, 0.55);

  /* Compat: nombres usados por el CSS heredado de la v1 */
  --color-bg: var(--bg);
  --color-surface: var(--bg-3);
  --color-surface-soft: var(--bg-4);
  --color-border: var(--line);
  --color-text: var(--cream);
  --color-text-soft: var(--cream-3);
  --color-primary: var(--accent);
  --color-primary-dark: var(--accent-deep);
  --color-primary-contrast: #f5f8ff;
  --color-accent: var(--gold-2);
  --color-accent-soft: rgba(214, 165, 92, 0.16);
  --color-danger: var(--danger);
  --color-danger-soft: var(--danger-soft);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--cream-2);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

h1, h2, h3 {
  line-height: 1.2;
  margin: 0 0 0.4em;
  font-family: var(--serif);
  color: var(--cream);
  font-weight: 500;
}
h1 { font-size: 1.7rem; font-style: italic; }
h2 { font-size: 1.2rem; font-style: italic; }
p { margin: 0 0 1em; }
a { color: var(--gold-2); }

button, input, textarea { font-family: inherit; font-size: 1rem; color: inherit; }

::selection { background: var(--gold); color: var(--bg); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 4px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Fondo ambiente (marca del terapeuta, tonos cálidos) ---------- */

.ambient-wash {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 60% at 20% 0%, rgba(214, 165, 92, 0.14), transparent 62%),
    radial-gradient(90% 55% at 88% 10%, rgba(138, 150, 120, 0.12), transparent 60%),
    radial-gradient(100% 55% at 50% 100%, rgba(214, 165, 92, 0.10), transparent 65%),
    linear-gradient(180deg, #201911 0%, var(--bg) 45%, #1c160e 100%);
}
.ambient-wash .bulb {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  mix-blend-mode: screen;
  animation: bulbBreathe 11s ease-in-out infinite;
}
.ambient-wash .bulb-1 { top: 4%; left: 10%; width: 280px; height: 280px; background: radial-gradient(circle, rgba(214,165,92,.32), transparent 70%); }
.ambient-wash .bulb-2 { top: 55%; right: -6%; width: 320px; height: 320px; background: radial-gradient(circle, rgba(138,150,120,.24), transparent 70%); animation-delay: 3s; }
.ambient-wash .bulb-3 { bottom: -6%; left: 30%; width: 300px; height: 300px; background: radial-gradient(circle, rgba(240,203,140,.22), transparent 70%); animation-delay: 6s; }
@keyframes bulbBreathe {
  0%, 100% { opacity: .6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.12); }
}

.screen, .app-shell { position: relative; z-index: 1; }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.85em 1.5em;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  transition: transform 0.4s var(--ease-bounce), box-shadow 0.4s var(--ease-soft), opacity 0.15s ease, background 0.25s ease, border-color 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-block { width: 100%; }
.btn-small { padding: 0.55em 1.1em; font-size: 0.88rem; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent) 55%, var(--violet));
  color: #f5f8ff;
  box-shadow: 0 10px 26px -8px rgba(37, 99, 235, 0.55);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px -10px rgba(37, 99, 235, 0.65);
}
.btn-primary.is-done {
  background: linear-gradient(135deg, var(--sage-2), var(--sage));
  color: #14200f;
  box-shadow: 0 10px 26px -8px rgba(138, 150, 120, 0.5);
}

.btn-secondary { background: rgba(214, 165, 92, 0.14); color: var(--gold-2); }
.btn-secondary:hover:not(:disabled) { background: rgba(214, 165, 92, 0.22); }

.btn-ghost {
  background: transparent;
  color: var(--cream-2);
  border: 1px solid var(--line);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--gold-dim); background: var(--bg-3); }

.btn-text { background: transparent; color: var(--cream-3); padding: 0.55em 0.8em; }
.btn-round { border-radius: 50%; width: 46px; height: 46px; padding: 0; flex: 0 0 auto; }

/* ---------- Formularios ---------- */

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4em;
  font-size: 0.95rem;
  color: var(--cream-2);
}

input[type="text"], input[type="email"], input[type="tel"], textarea {
  width: 100%;
  padding: 0.9em 1.05em;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-3);
  color: var(--cream);
  margin-bottom: 1em;
  transition: border-color 0.3s var(--ease-out);
}
input::placeholder, textarea::placeholder { color: var(--cream-3); opacity: 0.8; }
input:focus, textarea:focus, button:focus-visible {
  outline: none;
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 3px rgba(214, 165, 92, 0.16);
}

.field-error {
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-md);
  padding: 0.7em 1em;
  margin: -0.4em 0 1em;
  font-size: 0.92rem;
}

/* ---------- Spinner ---------- */

.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-lg { width: 34px; height: 34px; border-width: 3px; margin-bottom: 0.8em; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pantallas de auth ---------- */

.screen-center {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.card {
  background: linear-gradient(180deg, var(--bg-3), var(--bg-2));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  padding: 34px 26px;
  width: 100%;
  max-width: 400px;
}

.auth-card { text-align: left; }
.brand-mark {
  margin-bottom: 16px;
  color: var(--accent-2);
  animation: owlBobSmall 5s ease-in-out infinite;
}
@keyframes owlBobSmall {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.lede { color: var(--cream-3); }
.fine-print { color: var(--cream-3); font-size: 0.85rem; margin-top: 1.2em; margin-bottom: 0; }

.mock-box {
  margin-top: 1.4em;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-4);
  border: 1px dashed var(--gold-dim);
  font-size: 0.9rem;
}
.mock-box p { margin-bottom: 0.7em; color: var(--cream-2); }

/* ---------- App shell ---------- */

.app-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  background: transparent;
  overflow: hidden;
}

@media (min-width: 561px) {
  .app-shell {
    min-height: 100dvh;
    box-shadow: var(--shadow-lift);
    border-left: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-soft);
  }
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  background: linear-gradient(180deg, rgba(34, 27, 18, 0.92), rgba(34, 27, 18, 0.7));
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.app-header-title { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 1.2rem; color: var(--cream); }
.patient-chip {
  font-size: 0.78rem;
  color: var(--cream-3);
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-pill);
  padding: 0.35em 0.9em;
  white-space: nowrap;
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 16px 16px;
  overflow-y: auto;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8em;
  color: var(--cream-3);
  text-align: center;
  padding: 40px 20px;
}

/* ---------- Mascota: Kiro el búho ---------- */

.owl-mascot { display: block; overflow: visible; }

.owl-eye { transform-box: fill-box; transform-origin: 50% 50%; animation: owlBlink 6.5s ease-in-out infinite; }
.owl-eye-r { animation-delay: 0.05s; }
@keyframes owlBlink {
  0%, 92%, 100% { transform: scaleY(1); }
  94% { transform: scaleY(0.08); }
  96% { transform: scaleY(1); }
}

.owl-bob { transform-box: fill-box; transform-origin: 50% 50%; animation: owlFloat 4.5s ease-in-out infinite; }
@keyframes owlFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-5px) rotate(-0.6deg); }
}

.owl-wing { transform-box: fill-box; animation: owlWingSway 3.6s ease-in-out infinite; }
.owl-wing-l { transform-origin: 90% 10%; }
.owl-wing-r { transform-origin: 10% 10%; animation-delay: 0.4s; }
@keyframes owlWingSway {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(4deg); }
}

@media (prefers-reduced-motion: reduce) {
  .owl-eye, .owl-bob, .owl-wing, .brand-mark { animation: none; }
}

/* ---------- Cabecera "Hola, soy Kiro" + estadísticas ---------- */

.coach-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 16px;
  margin: 6px 0 16px;
  background: linear-gradient(160deg, var(--bg-3), var(--bg-2));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}
.coach-hero .owl-mascot--lg { width: 76px; height: 84px; flex: 0 0 auto; }
.coach-hero-text { min-width: 0; }
.coach-hero-hi {
  font-family: var(--hand);
  color: var(--gold-2);
  font-size: 1.5rem;
  line-height: 1;
  margin: 0 0 0.25em;
}
.coach-hero-sub { margin: 0; font-size: 0.88rem; color: var(--cream-3); }

.coach-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 2px 16px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.stat-ring { position: relative; width: 72px; height: 72px; flex: 0 0 auto; }
.stat-ring svg { transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--line); stroke-width: 8; }
.ring-fill {
  fill: none;
  stroke: url(#ringGrad);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.7s var(--ease-soft);
}
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-label-pct { font-weight: 700; font-size: 1.02rem; color: var(--cream); font-family: var(--sans); }
.ring-label-sub { font-size: 0.62rem; color: var(--cream-3); text-transform: uppercase; letter-spacing: 0.05em; }

.stat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  flex: 1 1 auto;
  min-width: 150px;
}
.stat-chip-icon { font-size: 1.35rem; line-height: 1; filter: drop-shadow(0 0 6px rgba(214,165,92,.5)); }
.stat-chip-text { display: flex; flex-direction: column; }
.stat-chip-value { font-weight: 700; color: var(--gold-2); font-size: 1rem; }
.stat-chip-label { font-size: 0.76rem; color: var(--cream-3); }

/* ---------- Banner de push ---------- */

.push-banner {
  background: linear-gradient(135deg, rgba(37,99,235,0.14), rgba(109,40,217,0.14));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.push-banner p { margin: 0 0 0.7em; font-size: 0.92rem; color: var(--cream-2); }
.push-banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Tareas ---------- */

.tasks-list {
  list-style: none;
  margin: 0;
  padding: 4px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.task-card {
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-soft);
  transition: border-color 0.4s var(--ease-out), transform 0.3s var(--ease-soft);
}
.task-card:has(.task-complete-btn.is-done) { border-color: var(--sage); }

.task-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}
.task-title { font-size: 1.08rem; margin: 0; color: var(--cream); }
.task-freq {
  flex: 0 0 auto;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--gold-2);
  background: rgba(214, 165, 92, 0.12);
  border: 1px solid rgba(214, 165, 92, 0.28);
  border-radius: var(--radius-pill);
  padding: 0.3em 0.8em;
  white-space: nowrap;
}
.task-desc { color: var(--cream-3); margin-bottom: 0.6em; }

.task-why summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--accent-2);
  font-weight: 600;
  margin-bottom: 0.4em;
  list-style: none;
}
.task-why summary::-webkit-details-marker { display: none; }
.task-why[open] summary { margin-bottom: 0.5em; }
.task-justificacion { color: var(--cream-3); font-size: 0.92rem; margin-bottom: 0; }

.task-progress-track {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-4);
  overflow: hidden;
  margin-top: 12px;
}
.task-progress-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  width: var(--pct, 0%);
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  transition: width 0.6s var(--ease-soft);
}
.task-progress-track.is-complete .task-progress-fill {
  background: linear-gradient(90deg, var(--sage), var(--sage-2));
}

.task-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.task-progress { font-size: 0.85rem; color: var(--cream-3); }

/* ---------- Confeti de micro-celebración ---------- */

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  opacity: 0.95;
  animation: confettiFall 900ms var(--ease-out) forwards;
}
@keyframes confettiFall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx, 0px), var(--dy, 140px)) rotate(var(--rot, 200deg)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .confetti-piece { display: none; }
}

/* ---------- Chat ---------- */

.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 6px 0 12px;
  overflow-y: auto;
}

.chat-row { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.chat-row.from-coach { align-self: flex-start; }
.chat-row.from-patient { align-self: flex-end; }

.chat-avatar { flex: 0 0 auto; width: 32px; height: 34px; }

.chat-bubble {
  max-width: 78vw;
  padding: 0.7em 1em;
  border-radius: 18px;
  font-size: 0.96rem;
  line-height: 1.5;
}
@media (min-width: 400px) { .chat-bubble { max-width: 320px; } }
.chat-bubble-time {
  display: block;
  font-size: 0.72rem;
  margin-top: 0.35em;
  opacity: 0.7;
}
.chat-bubble.from-coach {
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
  border-bottom-left-radius: 4px;
  color: var(--cream-2);
}
.chat-bubble.from-patient {
  background: linear-gradient(135deg, var(--accent-2), var(--accent) 60%, var(--violet));
  color: #f5f8ff;
  border-bottom-right-radius: 4px;
}
.chat-bubble.is-pending { opacity: 0.6; }

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-top: 8px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(0deg, var(--bg) 60%, transparent);
}
.chat-composer textarea {
  margin-bottom: 0;
  resize: none;
  max-height: 120px;
}

/* ---------- Navegación inferior ---------- */

.bottom-nav {
  display: flex;
  border-top: 1px solid var(--line-soft);
  background: var(--bg-2);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  padding: 8px 4px;
  border-radius: var(--radius-md);
  color: var(--cream-3);
  cursor: pointer;
  position: relative;
  transition: color 0.25s var(--ease-out), background 0.25s var(--ease-out);
}
.nav-btn span:not(.nav-dot) { font-size: 0.78rem; font-weight: 600; }
.nav-btn.is-active { color: var(--gold-2); background: rgba(214, 165, 92, 0.1); }
.nav-dot {
  position: absolute;
  top: 4px;
  right: 30%;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 2px var(--bg-2);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--bg-4);
  color: var(--cream);
  border: 1px solid var(--line);
  padding: 0.8em 1.2em;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  box-shadow: var(--shadow-lift);
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}

/* ---------- Utilidad ---------- */

[hidden] { display: none !important; }
