/* ==========================================================================
   Botón flotante + chat con el asistente (ver chat-widget.js).
   Usa las variables de color de index.html (modo claro y oscuro).
   ========================================================================== */
.chat-widget {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 80;
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
  pointer-events: none;
}
.chat-widget > * { pointer-events: auto; }
/* Lo que el JS oculta con `hidden` (panel, burbuja, sugerencias) debe ocultarse
   aunque su regla le ponga display: flex. */
.chat-widget [hidden] { display: none !important; }
@media (min-width: 768px) { .chat-widget { right: 24px; bottom: 24px; } }

.chat-widget__button {
  width: 60px; height: 60px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 10px 26px rgba(35, 54, 240, .38);
  transition: transform .15s, background-color .15s;
}
.chat-widget__button:hover { transform: scale(1.06); background: var(--accent-hover); }
.chat-widget__button svg { width: 28px; height: 28px; }
.chat-widget__button--wa { background: #1FA855; box-shadow: 0 10px 26px rgba(31, 168, 85, .35); }
.chat-widget__button--wa:hover { background: #188A45; }

.chat-widget__bubble {
  position: relative; max-width: 250px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 16px 16px 4px 16px;
  padding: 14px 34px 14px 16px; box-shadow: var(--shadow);
  font-size: .88rem; line-height: 1.4;
}
.chat-widget__bubble strong { display: block; font-family: var(--font-display); text-transform: uppercase; font-size: 1.05rem; letter-spacing: .02em; }
.chat-widget__bubble-close {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; border: 0; background: none; color: var(--ink-2); cursor: pointer;
}
.chat-widget__bubble-close:hover { background: var(--surface-2); }
.chat-widget__bubble-close svg { width: 14px; height: 14px; }

.chat-widget__ico { display: grid; place-items: center; }
.chat-widget__ico--close { display: none; }
.chat-widget.is-open .chat-widget__ico--open { display: none; }
.chat-widget.is-open .chat-widget__ico--close { display: grid; }

/* ---------- Panel ---------- */
.chat-panel {
  display: flex; flex-direction: column;
  width: min(380px, calc(100vw - 32px)); height: min(600px, calc(100vh - 120px));
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 20px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(13, 16, 32, .28);
}
@media (max-width: 599px) {
  .chat-widget.is-open { inset: 0; }
  .chat-widget.is-open .chat-widget__button { display: none; }
  .chat-panel { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; border: 0; }
}
body.chat-no-scroll { overflow: hidden; }

.chat-panel__head {
  display: flex; align-items: center; gap: 10px; padding: 12px 10px 12px 14px;
  background: #0D1020; color: #fff; border-bottom: 3px solid var(--accent);
}
.chat-panel__avatar {
  width: 40px; height: 40px; flex: none; border-radius: 12px;
  display: grid; place-items: center; background: var(--accent); color: #fff;
  font-family: var(--font-display); font-weight: 900; font-size: 1.4rem;
}
.chat-panel__who { flex: 1; min-width: 0; line-height: 1.25; }
.chat-panel__who strong { display: block; font-family: var(--font-display); text-transform: uppercase; font-size: 1.2rem; letter-spacing: .03em; }
.chat-panel__who span { display: flex; align-items: center; gap: 6px; font-size: .75rem; color: rgba(255, 255, 255, .72); }
.chat-panel__online { width: 8px; height: 8px; border-radius: 50%; background: #3DDC84; flex: none; }
.chat-panel__icon-btn {
  width: 38px; height: 38px; border-radius: 10px; flex: none; border: 0; background: none; cursor: pointer;
  display: grid; place-items: center; font-size: 1.15rem; color: #fff;
}
.chat-panel__icon-btn:hover { background: rgba(255, 255, 255, .12); }
.chat-panel__icon-btn svg { width: 20px; height: 20px; }
.chat-panel :focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.chat-panel__head :focus-visible { outline-color: #fff; }

.chat-panel__body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; background: var(--bg);
}
.chat-msg { display: flex; flex-direction: column; gap: 6px; max-width: 86%; }
.chat-msg--bot { align-self: flex-start; }
.chat-msg--user { align-self: flex-end; align-items: flex-end; }
.chat-msg__bubble { padding: 10px 13px; border-radius: 16px; font-size: .92rem; line-height: 1.45; overflow-wrap: anywhere; }
.chat-msg--bot .chat-msg__bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-msg--user .chat-msg__bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.chat-msg__bubble a { color: inherit; text-decoration: underline; }
.chat-msg__acciones { display: flex; flex-direction: column; gap: 6px; }
.chat-accion {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 14px; border-radius: 12px; text-decoration: none;
  font-weight: 700; font-size: .88rem; color: #fff; background: #1FA855;
}
.chat-accion:hover { background: #188A45; }
.chat-accion--persona { background: var(--ink); color: var(--bg); }
.chat-accion--persona:hover { background: var(--ink-2); }
.chat-accion svg { width: 18px; height: 18px; }

.chat-cita {
  background: var(--surface); border: 1.5px dashed var(--accent); border-radius: 12px;
  padding: 10px 12px; font-size: .85rem; display: grid; gap: 4px;
}
.chat-cita strong { font-family: var(--font-display); text-transform: uppercase; font-size: 1.1rem; letter-spacing: .02em; }
.chat-cita div { display: flex; justify-content: space-between; gap: 12px; }
.chat-cita div span:first-child { color: var(--ink-2); }
.chat-cita div span:last-child { text-align: right; font-weight: 600; }
.chat-cita__code { font-family: var(--font-display); font-weight: 900; font-size: 1.3rem; letter-spacing: .12em; color: var(--accent); }
.chat-cita--off { border-color: var(--line); opacity: .8; }
.chat-cita--off strong { color: var(--danger); }
.chat-cita__total { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; }
.chat-cita__total span:last-child { color: var(--accent); font-family: var(--font-display); font-size: 1.3rem; font-weight: 900; }

.chat-typing { display: flex; gap: 4px; padding: 14px 16px; }
.chat-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-2); animation: chat-typing 1.2s infinite ease-in-out; }
.chat-typing i:nth-child(2) { animation-delay: .15s; }
.chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-typing { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .chat-typing i { animation: none; opacity: .7; } }

.chat-panel__chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 2px; background: var(--bg); }
.chat-chip {
  padding: 7px 12px; border-radius: 999px; font-size: .82rem; font-weight: 600; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--accent); color: var(--accent);
}
.chat-chip:hover { background: var(--accent); color: var(--accent-ink); }

.chat-panel__form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--line); }
.chat-panel__form textarea {
  flex: 1; resize: none; max-height: 120px;
  font: inherit; font-size: 16px; line-height: 1.35; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 12px; background: var(--bg);
}
.chat-panel__form textarea:focus-visible { outline: 0; border-color: var(--accent); }
.chat-panel__form button {
  width: 44px; height: 44px; border-radius: 50%; flex: none; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-ink);
}
.chat-panel__form button svg { width: 20px; height: 20px; }
.chat-panel__form button:disabled, .chat-panel__form textarea:disabled { opacity: .55; cursor: default; }
.chat-panel__foot {
  display: flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  padding: 8px 12px 10px; font-size: .78rem; color: var(--ink-2); background: var(--surface);
}
.chat-panel__foot svg { width: 14px; height: 14px; color: #1FA855; }
.chat-panel__foot:hover { color: var(--ink); }
