/* Interactive help overlay — bot tutor, golden borders, popover */

:root {
  --help-accent: var(--color-warning);
  --help-accent-glow: rgba(245, 158, 11, 0.35);
}

/* ── Bot flotante ──────────────────────────────────────────────── */

@keyframes helpFloat {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-4px); }
}

#help-tutor-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9000;
  width: 56px;
  height: 56px;
  cursor: pointer;
  opacity: 0.40;
  transition: opacity 0.2s, width 0.2s, height 0.2s;
  animation: helpFloat 3s ease-in-out infinite;
  border-radius: 50%;
}

@media (prefers-reduced-motion: reduce) {
  #help-tutor-btn { animation: none; }
}

#help-tutor-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#help-tutor-btn:hover {
  opacity: 1;
}

#help-tutor-btn.active {
  opacity: 1;
  width: 84px;
  height: 84px;
  box-shadow: 0 0 0 3px var(--help-accent-glow);
}

/* Touch: raise base opacity — hover doesn't exist on touch devices */
@media (hover: none) {
  #help-tutor-btn { opacity: 0.65; }
}

/* ── Splash de intro (animación de activación) ─────────────────── */

@keyframes tutorIntro {
  0%   { transform: scale(0.05); opacity: 0; }
  22%  { transform: scale(1);    opacity: 1; }
  72%  { transform: scale(1);    opacity: 1; }
  100% { transform: scale(1.06); opacity: 0; }
}

#tutor-splash {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 216px;
  height: 216px;
  margin: -108px 0 0 -108px;
  z-index: 9100;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 4px var(--help-accent), 0 0 28px 10px var(--help-accent-glow);
  animation: tutorIntro 2.21s ease-out forwards;
}

#tutor-splash img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@media (prefers-reduced-motion: reduce) {
  #tutor-splash { animation-duration: 0.01ms; }
}

/* ── Burbuja de inicio ─────────────────────────────────────────── */

#help-bubble-start {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 9001;
  background: var(--color-surface);
  border: 1px solid var(--help-accent);
  border-radius: 12px;
  padding: 10px 14px;
  max-width: 220px;
  display: none;
  color: var(--color-text);
  font-size: 0.875rem;
  gap: 8px;
  align-items: center;
}

#help-bubble-start.visible {
  display: flex;
  flex-direction: column;     /* texto+× arriba, "Preguntar" debajo */
  align-items: stretch;
}

.help-bubble-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Arrow pointing down toward the bot */
#help-bubble-start::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 20px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--help-accent);
}

#help-bubble-close {
  flex-shrink: 0;
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-tertiary);
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}

/* ── Modo ayuda — bordes dorados ───────────────────────────────── */

body.help-mode [data-help] {
  outline: 2px solid var(--help-accent);
  outline-offset: -2px;
  cursor: help;
}

body.help-mode [data-help]:hover {
  outline-width: 3px;
  background-color: rgba(245, 158, 11, 0.07);
}

/* outline on inline elements appears fragmented — force inline-block */
body.help-mode span[data-help] {
  display: inline-block;
}

/* ── Popover ───────────────────────────────────────────────────── */

#help-popover {
  position: fixed;
  z-index: 9002;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  padding: 16px 18px;
  max-width: 320px;
  min-width: 220px;
  /* Guard: an expanded "ver más" can grow tall; cap and scroll so it stays on
     screen. Short popovers never reach the cap → visually identical to before. */
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  display: none;
}

#help-popover.visible {
  display: block;
}

/* Avoid touching viewport edges on very narrow screens (e.g. iPhone SE ~320px) */
@media (max-width: 380px) {
  #help-popover { max-width: calc(100vw - 16px); }
}

#help-popover-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-tertiary);
  font-size: 1rem;
  line-height: 1;
  padding: 2px 4px;
}

#help-popover-title {
  font-weight: 600;
  color: var(--color-text-strong);
  margin: 0 0 6px;
  padding-right: 20px;
  font-size: 0.9375rem;
}

#help-popover-body {
  color: var(--color-text);
  font-size: 0.875rem;
  line-height: 1.5;
  margin: 0 0 12px;
}

/* ── "Ver más" — detalle de metodología (opcional, aditivo) ────── */

.help-popover-more {
  display: block;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 10px;
  color: var(--help-accent);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.help-popover-more:hover {
  text-decoration: underline;
}

.help-popover-details {
  display: none; /* colapsado por defecto; .expanded lo revela */
  white-space: pre-line;
  color: var(--color-text);
  font-size: 0.8125rem;
  line-height: 1.5;
  margin: 0 0 12px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border);
}

.help-popover-details.expanded {
  display: block;
}

#help-popover-exec {
  display: block;
  width: 100%;
  padding: 7px 12px;
  background: var(--help-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  opacity: 0.9;
  transition: opacity 0.15s;
}

#help-popover-exec:hover {
  opacity: 1;
}

/* ── Botón "Preguntar" en la burbuja ───────────────────────────── */

#help-ask-open {
  flex-shrink: 0;
  background: var(--help-accent);
  color: var(--color-primary-contrast);
  border: none;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

#help-ask-open:hover {
  filter: brightness(1.05);
}

/* ── Panel de pregunta (Tutor IA) ──────────────────────────────── */

#help-ask {
  position: fixed;
  right: 24px;
  bottom: 90px;
  z-index: 9002;
  width: 320px;
  max-width: calc(100vw - 16px);
  /* Ancla en bottom:90 y crece hacia arriba; tope al 50% del alto de pantalla para que nunca
     domine el viewport. El cuerpo (#help-ask-result) scrollea dentro (flex). Patrón guía §13. */
  max-height: 50vh;
  overflow: hidden;            /* clip al border-radius; el scroll vive en #help-ask-result */
  background: var(--color-surface);
  border: 1px solid var(--help-accent);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  display: none;
}

#help-ask.visible {
  display: flex;
  flex-direction: column;
}

#help-ask-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  font-weight: 600;
  color: var(--color-text-strong);
  border-bottom: 1px solid var(--color-border);
}

#help-ask-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-tertiary);
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}

#help-ask-form {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
}

#help-ask-input {
  flex: 1;
  min-width: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--color-text);
  font-size: 0.875rem;
}

#help-ask-input:focus {
  outline: none;
  border-color: var(--help-accent);
}

#help-ask-input:disabled {
  opacity: 0.6;
}

#help-ask-send {
  flex-shrink: 0;
  background: var(--help-accent);
  color: var(--color-primary-contrast);
  border: none;
  border-radius: 8px;
  padding: 0 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

#help-ask-send:disabled {
  opacity: 0.6;
  cursor: default;
}

#help-ask-result {
  flex: 1 1 auto;       /* ocupa el resto del panel acotado… */
  min-height: 0;        /* …y scrollea en lugar de empujar la altura (clave del flex) */
  overflow-y: auto;
  padding: 0 12px 12px;
}

#help-ask-result:empty {
  display: none;
}

.help-ask-line {
  color: var(--color-text);
  font-size: 0.875rem;
  line-height: 1.5;
  margin: 0 0 4px;
}

.help-ask-line strong {
  color: var(--color-text-strong);
}

.help-ask-option {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 8px;
  color: var(--color-text);
  font-size: 0.875rem;
  cursor: pointer;
}

.help-ask-option:hover {
  background: var(--color-surface-muted);
}

/* Enlace "ver sugerencias de esta sección" / "volver a la lista" — estilo texto, no botón sólido */
.help-ask-suglink {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 2px;
  margin-top: 6px;
  color: var(--help-accent);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.help-ask-suglink:hover {
  text-decoration: underline;
}

@media (max-width: 380px) {
  #help-ask { right: 8px; left: 8px; width: auto; }
}

/* ── Bienvenida de la demo — modal de opciones (aparte del splash del logo, abajo-centrado) ──── */
/* El logo grande es el #tutor-splash de siempre (arriba, centrado, 8 s). Este modal es el otro
   elemento: mensaje + preguntas, abajo, con borde TRANSLÚCIDO (no un recuadro duro sobrepuesto) y
   un halo suave que hereda la "magia" del splash. NO lleva backdrop ni auto-cierre. */

@keyframes tutorWelcomeIn {
  0%   { transform: translateX(-50%) translateY(12px); opacity: 0; }
  100% { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

#tutor-welcome {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 9101;
  width: calc(100vw - 32px);
  max-width: 420px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--color-surface);
  border: none;                                    /* sin línea dura: el halo define el borde */
  border-radius: 18px;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.20), 0 0 34px 6px var(--help-accent-glow);
  padding: 20px 20px 18px;
  animation: tutorWelcomeIn 0.3s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  #tutor-welcome { animation: none; }
}

#tutor-welcome-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-tertiary);
  font-size: 1.25rem;
  line-height: 1;
  padding: 2px 6px;
}

#tutor-welcome-msg {
  color: var(--color-text);
  margin-bottom: 6px;
}

#tutor-welcome-msg .help-ask-line {
  line-height: 1.55;
}

#tutor-welcome-chips {
  margin-top: 10px;
}

/* ── Resaltado fuerte (spotlight) — capa sobre el outline base ──── */
/* Igual/mayor especificidad que body.help-mode [data-help] (0,2,0) y
   declarada DESPUÉS para ganar el empate (R6/F-D). */

[data-help].help-spotlight,
body.help-mode [data-help].help-spotlight {
  outline: 3px solid var(--help-accent);
  outline-offset: -2px;
  background-color: var(--help-accent-glow);
  box-shadow: 0 0 0 4px var(--help-accent-glow);
  animation: helpSpotlightPulse 1.6s ease-in-out infinite;
}

@keyframes helpSpotlightPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--help-accent-glow); }
  50%      { box-shadow: 0 0 0 7px var(--help-accent-glow); }
}

@media (prefers-reduced-motion: reduce) {
  .help-spotlight { animation: none; }
}
