/* ============================================================================
 * YaTeLoAvisé Amplifier — Chat IA widget styles (F10-C02)
 *
 * Scope: visuales del widget de chat IA (botón flotante + panel lateral).
 * Convive con static/css/main.css. Sin frameworks externos.
 * ==========================================================================*/

/* --- Design tokens (scoped al widget) ------------------------------------- */
.chat-widget {
  --chat-color-bg: #ffffff;
  --chat-color-surface: #f7f8fa;
  --chat-color-border: #e2e5ea;
  --chat-color-text: #1f2430;
  --chat-color-muted: #6b7280;
  --chat-color-primary: #2260c7;
  --chat-color-primary-hover: #1a4ea6;
  --chat-color-primary-contrast: #ffffff;
  --chat-color-assistant-bg: #eef2f7;
  --chat-color-assistant-text: #1f2430;
  --chat-color-user-bg: #2260c7;
  --chat-color-user-text: #ffffff;
  --chat-color-shadow: rgba(15, 23, 42, 0.18);
  --chat-radius-md: 12px;
  --chat-radius-lg: 16px;
  --chat-radius-pill: 999px;
  --chat-space-1: 4px;
  --chat-space-2: 8px;
  --chat-space-3: 12px;
  --chat-space-4: 16px;
  --chat-space-5: 20px;
  --chat-space-6: 24px;
  --chat-panel-width: 400px;
  --chat-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* --- Contenedor raíz ------------------------------------------------------ */
.chat-widget,
.chat-widget *,
.chat-widget *::before,
.chat-widget *::after {
  box-sizing: border-box;
}

.chat-widget {
  font-family: var(--chat-font);
  color: var(--chat-color-text);
  line-height: 1.45;
}

/* --- Botón flotante ------------------------------------------------------- */
.chat-widget__toggle {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--chat-space-2);

  width: 56px;
  height: 56px;
  padding: 0;

  border: none;
  border-radius: var(--chat-radius-pill);
  background-color: var(--chat-color-primary);
  color: var(--chat-color-primary-contrast);

  box-shadow: 0 8px 24px var(--chat-color-shadow);
  cursor: pointer;

  transition: background-color 150ms ease-out,
              transform 150ms ease-out,
              box-shadow 150ms ease-out;
}

.chat-widget__toggle:hover {
  background-color: var(--chat-color-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 10px 28px var(--chat-color-shadow);
}

.chat-widget__toggle:focus-visible {
  outline: 3px solid rgba(34, 96, 199, 0.45);
  outline-offset: 2px;
}

.chat-widget__toggle:active {
  transform: translateY(0);
}

.chat-widget__toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-widget__toggle-label {
  /* Texto accesible; se mantiene fuera de vista por defecto para que el
     botón luzca circular en mobile/desktop sin depender de assets externos. */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- Panel lateral -------------------------------------------------------- */
.chat-widget__panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1001;

  display: flex;
  flex-direction: column;

  width: var(--chat-panel-width);
  max-width: 100%;
  height: 100vh;

  background-color: var(--chat-color-bg);
  border-left: 1px solid var(--chat-color-border);
  box-shadow: -12px 0 32px var(--chat-color-shadow);

  transform: translateX(100%);
  transition: transform 300ms ease-out;
  will-change: transform;
}

/* Estado abierto: se activa agregando la clase (o quitando [hidden]) desde JS
   en F10-C03. El HTML ya usa [hidden] por defecto. */
.chat-widget__panel[hidden] {
  display: none;
}

.chat-widget__panel.is-open,
.chat-widget[data-open="true"] .chat-widget__panel {
  transform: translateX(0);
}

/* --- Header --------------------------------------------------------------- */
.chat-widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--chat-space-3);

  padding: var(--chat-space-4) var(--chat-space-5);
  border-bottom: 1px solid var(--chat-color-border);
  background-color: var(--chat-color-bg);
}

.chat-widget__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--chat-color-text);
}

.chat-widget__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 36px;
  height: 36px;
  padding: 0;

  border: none;
  border-radius: var(--chat-radius-pill);
  background: transparent;
  color: var(--chat-color-muted);

  cursor: pointer;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}

.chat-widget__close:hover {
  background-color: var(--chat-color-surface);
  color: var(--chat-color-text);
}

.chat-widget__close:focus-visible {
  outline: 2px solid var(--chat-color-primary);
  outline-offset: 2px;
}

/* --- Body / área scrollable ---------------------------------------------- */
.chat-widget__body {
  flex: 1 1 auto;
  min-height: 0;

  display: flex;
  flex-direction: column;

  background-color: var(--chat-color-surface);
}

/* --- Mensajes ------------------------------------------------------------- */
.chat-widget__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;

  display: flex;
  flex-direction: column;
  gap: var(--chat-space-3);

  padding: var(--chat-space-4) var(--chat-space-5);
}

/* Burbujas. Las clases específicas las setea el JS al renderizar cada
   mensaje; se anticipan aquí variantes user / assistant. */
.chat-widget__message {
  max-width: 85%;
  padding: var(--chat-space-3) var(--chat-space-4);
  border-radius: var(--chat-radius-lg);
  font-size: 0.95rem;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.chat-widget__message--assistant {
  align-self: flex-start;
  background-color: var(--chat-color-assistant-bg);
  color: var(--chat-color-assistant-text);
  border-bottom-left-radius: var(--chat-space-1);
}

.chat-widget__message--user {
  align-self: flex-end;
  background-color: var(--chat-color-user-bg);
  color: var(--chat-color-user-text);
  border-bottom-right-radius: var(--chat-space-1);
}

/* --- Indicador de typing ------------------------------------------------- */
.chat-widget__typing {
  display: flex;
  align-items: center;
  gap: var(--chat-space-2);

  padding: var(--chat-space-2) var(--chat-space-5);
  color: var(--chat-color-muted);
  font-size: 0.85rem;
}

.chat-widget__typing[hidden] {
  display: none;
}

.chat-widget__typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--chat-color-muted);
  opacity: 0.4;
  animation: chat-widget-typing 1200ms infinite ease-in-out;
}

.chat-widget__typing-dot:nth-child(2) {
  animation-delay: 150ms;
}

.chat-widget__typing-dot:nth-child(3) {
  animation-delay: 300ms;
}

.chat-widget__typing-label {
  margin-left: var(--chat-space-1);
}

@keyframes chat-widget-typing {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40%           { opacity: 1;    transform: translateY(-2px); }
}

/* --- Form / input -------------------------------------------------------- */
.chat-widget__form {
  flex: 0 0 auto;
  padding: var(--chat-space-3) var(--chat-space-5);
  background-color: var(--chat-color-bg);
  border-top: 1px solid var(--chat-color-border);
}

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

.chat-widget__input-row {
  display: flex;
  align-items: center;
  gap: var(--chat-space-2);
}

.chat-widget__input {
  flex: 1 1 auto;
  min-width: 0;

  padding: var(--chat-space-3) var(--chat-space-4);
  border: 1px solid var(--chat-color-border);
  border-radius: var(--chat-radius-md);
  background-color: var(--chat-color-bg);
  color: var(--chat-color-text);

  font: inherit;
  font-size: 0.95rem;

  transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
}

.chat-widget__input::placeholder {
  color: var(--chat-color-muted);
}

.chat-widget__input:focus {
  outline: none;
  border-color: var(--chat-color-primary);
  box-shadow: 0 0 0 3px rgba(34, 96, 199, 0.18);
}

.chat-widget__input:disabled {
  background-color: var(--chat-color-surface);
  color: var(--chat-color-muted);
  cursor: not-allowed;
}

.chat-widget__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 40px;
  height: 40px;
  padding: 0;

  border: none;
  border-radius: var(--chat-radius-md);
  background-color: var(--chat-color-primary);
  color: var(--chat-color-primary-contrast);

  cursor: pointer;
  transition: background-color 150ms ease-out, transform 150ms ease-out;
}

.chat-widget__send:hover:not(:disabled) {
  background-color: var(--chat-color-primary-hover);
}

.chat-widget__send:focus-visible {
  outline: 2px solid var(--chat-color-primary);
  outline-offset: 2px;
}

.chat-widget__send:active:not(:disabled) {
  transform: scale(0.97);
}

.chat-widget__send:disabled {
  background-color: #a8b1bd;
  cursor: not-allowed;
}

/* --- Estado no autenticado ----------------------------------------------- */
.chat-widget__auth-gate {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--chat-space-3);

  margin: var(--chat-space-5);
  padding: var(--chat-space-4) var(--chat-space-5);

  background-color: var(--chat-color-bg);
  border: 1px solid var(--chat-color-border);
  border-radius: var(--chat-radius-md);
}

.chat-widget__auth-message {
  margin: 0;
  color: var(--chat-color-text);
  font-size: 0.95rem;
}

.chat-widget__auth-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: var(--chat-space-2) var(--chat-space-4);

  background-color: var(--chat-color-primary);
  color: var(--chat-color-primary-contrast);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;

  border-radius: var(--chat-radius-md);
  transition: background-color 150ms ease-out;
}

.chat-widget__auth-cta:hover {
  background-color: var(--chat-color-primary-hover);
}

.chat-widget__form--disabled {
  opacity: 0.75;
}

/* --- Footer / disclaimer -------------------------------------------------- */
.chat-widget__footer {
  flex: 0 0 auto;
  padding: var(--chat-space-2) var(--chat-space-5) var(--chat-space-3);
  background-color: var(--chat-color-bg);
  border-top: 1px solid var(--chat-color-border);
}

.chat-widget__disclaimer {
  margin: 0;
  color: var(--chat-color-muted);
  font-size: 0.75rem;
  line-height: 1.35;
  text-align: center;
}

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 767px) {
  .chat-widget__panel {
    width: 100%;
    border-left: none;
  }

  .chat-widget__toggle {
    right: 16px;
    bottom: 16px;
  }
}

/* --- Accesibilidad / reduced motion -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .chat-widget__panel,
  .chat-widget__toggle,
  .chat-widget__send,
  .chat-widget__typing-dot {
    transition: none;
    animation: none;
  }
}
