/* PULSO3 — Estilos
   Mobile-first, minimalista. Sistema visual aprobado: navy profundo + verde pulso,
   fondos blanco/carbón, colores de estado verde/ámbar/rojo. Funcional y contenido,
   no decorativo. */

:root {
  --color-navy: #0b1f33;
  --color-navy-soft: #163a5c;
  --color-green: #72c89a;
  --color-green-dark: #4e9c74;
  --color-white: #ffffff; /* blanco puro fijo: texto sobre navy, nunca cambia con el tema */
  --color-surface: #ffffff; /* fondo de tarjetas/inputs: sí cambia con el tema */
  --color-bg: #f6f8fa;
  --color-text: #16233a;
  --color-text-muted: #5b6b82;
  --color-border: #e1e7ee;

  /* Colores de estado — versión "viva" para barras, puntos y bordes (elementos
     gráficos grandes; requieren 3:1 de contraste, no 4.5:1). */
  --color-critico: #d65353;
  --color-atencion: #d99a2b;
  --color-fuerte: #45b97c;

  /* Variantes "-text", más oscuras, para cuando el color de estado se usa como
     texto sobre un fondo claro (badges, etiquetas): garantizan >= 4.5:1 (AA)
     en vez del ~2-4:1 que dan los tonos vivos de arriba sobre blanco. */
  --color-critico-text: #b83a3a;
  --color-atencion-text: #8a5e0c;
  --color-fuerte-text: #1e7a4c;

  --color-critico-bg: #fbeaea;
  --color-atencion-bg: #fbf1de;
  --color-fuerte-bg: #e9f6ef;

  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(11, 31, 51, 0.08);
  --shadow-md: 0 8px 24px rgba(11, 31, 51, 0.12);

  --font-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- Modo oscuro ----------
   Fondo "carbón" en vez de invertir navy/blanco. Los colores de estado vivos
   (--color-critico/-atencion/-fuerte) ya tienen contraste >=4.4:1 sobre el
   carbón y se reutilizan tal cual para texto; solo el rojo necesita una
   variante más clara (--color-critico-text) para llegar a AA en modo oscuro,
   porque el rojo vivo por sí solo queda en ~4.4:1 contra el carbón. */
:root[data-theme='dark'] {
  --color-bg: #14181d;
  --color-surface: #1c2128;
  --color-text: #e8ecf0;
  --color-text-muted: #9aa7b5;
  --color-border: #2b323c;
  --color-navy: #0b1f33;
  --color-navy-soft: #1c3a5c;

  --color-critico-text: #e97575;
  --color-atencion-text: #d99a2b;
  --color-fuerte-text: #45b97c;

  --color-critico-bg: #2c1a1a;
  --color-atencion-bg: #2b2416;
  --color-fuerte-bg: #17281f;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --color-bg: #14181d;
    --color-surface: #1c2128;
    --color-text: #e8ecf0;
    --color-text-muted: #9aa7b5;
    --color-border: #2b323c;
    --color-navy: #0b1f33;
    --color-navy-soft: #1c3a5c;

    --color-critico-text: #e97575;
    --color-atencion-text: #d99a2b;
    --color-fuerte-text: #45b97c;

    --color-critico-bg: #2c1a1a;
    --color-atencion-bg: #2b2416;
    --color-fuerte-bg: #17281f;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-base);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button,
input,
select {
  font-family: inherit;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- Pantallas ---------- */

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 100vh;
  animation: fade-in 0.28s ease;
}

.screen.active {
  display: flex;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.screen-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 28px 24px 36px;
  width: 100%;
}

.screen-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-navy);
  margin: 0 0 6px;
}

.screen-subtitle {
  font-size: 0.95rem;
  color: var(--color-text-muted);
  margin: 0 0 24px;
}

/* ---------- Bienvenida ---------- */

.welcome-content {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 4px;
  background: linear-gradient(180deg, var(--color-navy) 0%, var(--color-navy-soft) 100%);
  color: var(--color-white);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  min-height: 100vh;
  padding: 40px 28px;
}

.welcome-logo-img {
  display: block;
  height: 46px;
  width: auto;
  margin-bottom: 28px;
}

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

.tagline {
  font-size: 1.05rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.88);
  max-width: 34ch;
  margin: 0 0 32px;
}

.micro-note {
  margin-top: 16px;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.65);
}

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

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1rem;
  min-height: 52px;
  padding: 14px 20px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  width: 100%;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-green);
  color: var(--color-navy);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--color-green-dark);
  color: var(--color-navy); /* navy da ~5:1 sobre este verde; blanco solo da ~3.3:1 (falla AA) */
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  padding: 10px;
  margin-top: 8px;
  cursor: pointer;
  align-self: flex-start;
}

.btn-link:hover {
  color: var(--color-navy);
}

.btn-cta {
  font-size: 1.05rem;
}

/* ---------- Formularios (intake / email) ---------- */

#form-intake,
#form-email {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-navy);
  margin: 18px 0 8px;
}

.field-label:first-of-type {
  margin-top: 4px;
}

.field-input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 1rem;
  color: var(--color-text);
  background: var(--color-surface);
}

.field-input:focus {
  outline: none;
  border-color: var(--color-green);
  box-shadow: 0 0 0 3px rgba(124, 179, 66, 0.18);
}

.field-input.field-invalid {
  border-color: var(--color-critico);
}

.field-hidden {
  display: none;
}

.field-error {
  min-height: 18px;
  color: var(--color-critico);
  font-size: 0.8rem;
  margin: 6px 0 0;
}

#form-intake .btn,
#form-email .btn {
  margin-top: auto;
  padding-top: 14px;
}

#form-intake .btn {
  margin-top: 32px;
}

/* ---------- Quiz ---------- */

.quiz-header {
  padding: 20px 24px 0;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-green);
  border-radius: 999px;
  width: 0%;
  transition: width 0.25s ease;
}

.quiz-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.question-counter {
  font-weight: 700;
  color: var(--color-navy);
}

.quiz-content {
  justify-content: center;
  flex: 1;
  padding-top: 12px;
}

.question-text {
  font-size: 1.3rem;
  line-height: 1.4;
  font-weight: 700;
  color: var(--color-navy);
  margin: 0 0 32px;
}

.answer-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-answer {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  color: var(--color-text);
  text-align: left;
  font-size: 1.05rem;
  min-height: 56px;
}

.btn-answer:hover {
  border-color: var(--color-green);
}

.btn-answer.selected {
  background: var(--color-navy);
  border-color: var(--color-navy);
  color: var(--color-white);
}

/* ---------- Resultado ---------- */

.result-content {
  padding-top: 24px;
}

.result-eyebrow {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-green-dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 6px;
}

.areas-summary {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 20px 0 32px;
}

.area-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.area-row-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-navy);
}

.area-status {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

/* Texto (badges, etiquetas): usa las variantes "-text", más oscuras, para
   cumplir WCAG AA (>=4.5:1) sobre su fondo claro. */
.status-critico {
  color: var(--color-critico-text);
  background: var(--color-critico-bg);
}

.status-atencion {
  color: var(--color-atencion-text);
  background: var(--color-atencion-bg);
}

.status-fuerte {
  color: var(--color-fuerte-text);
  background: var(--color-fuerte-bg);
}

.area-bar-track {
  width: 100%;
  height: 10px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.area-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.area-bar-fill.status-critico {
  background: var(--color-critico);
}

.area-bar-fill.status-atencion {
  background: var(--color-atencion);
}

.area-bar-fill.status-fuerte {
  background: var(--color-fuerte);
}

.priorities-heading {
  font-size: 1.1rem;
  color: var(--color-navy);
  margin: 0 0 14px;
}

.priorities-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 28px;
}

.priority-card {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  background: var(--color-surface);
}

.priority-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.priority-rank {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--color-navy);
  color: var(--color-white);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.priority-title {
  font-weight: 700;
  color: var(--color-navy);
  font-size: 1rem;
}

.priority-score {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-left: auto;
}

.priority-text {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--color-text);
  margin: 0;
}

.cta-box {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  text-align: center;
  margin-top: 4px;
}

/* Bloque 7: intro de cotización — mismo lenguaje tipográfico del documento
   (navy para la afirmación, texto muted para la invitación), sin verse como
   un banner aparte pegado al final. */
.cta-intro {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--color-navy);
  margin: 0 0 6px;
}

.cta-lead {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin: 0 0 16px;
}

.cta-subtext {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin: 10px 0 0;
}

.cta-confirmation {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-green-dark);
  margin: 12px 0 0;
  min-height: 1em;
}

/* ---------- Responsive: pantallas más anchas ---------- */

@media (min-width: 540px) {
  body {
    background: var(--color-bg);
  }

  #app {
    margin: 24px auto;
    min-height: calc(100vh - 48px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
  }

  .welcome-content {
    min-height: calc(100vh - 48px);
  }
}

/* ---------- Bloque 6: escritorio (responsive simple) ----------
   Mismo flujo, mismo diseño (una pregunta por pantalla) — solo se ensancha
   un poco el contenedor y se escala la tipografía/espaciado para que no se
   sienta angosto en pantallas grandes. Sin layout de escritorio distinto. */
@media (min-width: 860px) {
  #app {
    max-width: 560px;
  }

  .screen-content {
    padding: 40px 40px 48px;
  }

  .screen-title {
    font-size: 1.7rem;
  }

  .tagline {
    font-size: 1.15rem;
  }

  .question-text {
    font-size: 1.5rem;
  }

  .btn-answer {
    font-size: 1.1rem;
  }

  .welcome-logo-img {
    height: 48px;
  }
}

/* ---------- Toggle de modo oscuro (Bloque 4) ---------- */

.theme-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
  width: 40px;
  height: 40px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-navy);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
}

#screen-welcome .theme-toggle {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-white);
}

/* ---------- Bloque 5: header compacto con el ícono de marca ---------- */

.hidden {
  display: none !important;
}

.app-header {
  padding: 14px 24px 0;
}

.app-header-logo {
  display: block;
  height: 26px;
  width: auto;
}

/* Por defecto (tema claro) se ve el ícono navy; el ícono blanco solo se
   muestra cuando el modo oscuro está activo, para no perder legibilidad
   sobre el fondo carbón. */
.app-header-logo-dark {
  display: none;
}

:root[data-theme='dark'] .app-header-logo-light {
  display: none;
}

:root[data-theme='dark'] .app-header-logo-dark {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .app-header-logo-light {
    display: none;
  }

  :root:not([data-theme='light']) .app-header-logo-dark {
    display: block;
  }
}

/* ---------- Bloque 2: dato extra por rubro ---------- */

.rubro-insight {
  margin: 4px 0 24px;
  padding: 12px 14px;
  border-left: 3px solid var(--color-green);
  background: var(--color-bg);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--color-text-muted);
}

.rubro-insight:empty {
  display: none;
  margin: 0;
}

/* ---------- Encabezado de resultado + botón de PDF ---------- */

.result-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.btn-pdf {
  flex-shrink: 0;
  min-height: 36px;
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-navy);
  cursor: pointer;
}

.btn-pdf:hover {
  border-color: var(--color-green);
}

/* ---------- Exportación a PDF (A4) ----------
   El resultado se imprime tal cual se ve en pantalla, forzado a tema claro
   (independiente del modo oscuro activo) y ajustado para caber en una sola
   página A4: se ocultan elementos interactivos (toggle de tema, botón de
   descarga) y se recorta el espaciado vertical del contenedor. */
@media print {
  @page {
    size: A4;
    margin: 14mm 12mm;
  }

  :root {
    --color-bg: #f6f8fa;
    --color-surface: #ffffff;
    --color-white: #ffffff;
    --color-text: #16233a;
    --color-text-muted: #5b6b82;
    --color-border: #e1e7ee;
    --color-critico-text: #b83a3a;
    --color-atencion-text: #8a5e0c;
    --color-fuerte-text: #1e7a4c;
    --color-critico-bg: #fbeaea;
    --color-atencion-bg: #fbf1de;
    --color-fuerte-bg: #e9f6ef;
  }

  body {
    background: #ffffff;
  }

  .screen {
    display: none !important;
  }

  #screen-result.active {
    display: flex !important;
  }

  #app {
    max-width: none;
    margin: 0;
    box-shadow: none;
    border-radius: 0;
  }

  .no-print,
  .theme-toggle,
  .app-header {
    display: none !important;
  }

  .result-content {
    padding: 0;
  }

  .priority-card {
    break-inside: avoid;
  }

  .area-row {
    break-inside: avoid;
  }
}
