/* ════════════════════════════════════════════════════════════════════════════
   chatbot.css — Hoja de estilos INMUTABLE del cliente PHP.
   No edites este archivo: tus cambios se perderían en la próxima actualización.
   Para personalizar la apariencia, usá css/user.css (se carga después).
   Variables disponibles (todas se pueden sobreescribir desde user.css):
     --font, --bg, --surface, --text, --muted, --accent, --border,
     --link, --user-bubble, --bot-bubble, --user-accent, --bot-accent,
     --radius, --radius-lg, --shadow.
   ════════════════════════════════════════════════════════════════════════════ */

:root {
  --font: 'Open Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* Paleta light (default) — consistente con el backend */
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --text:         #0f172a;
  --muted:        #64748b;
  --accent:       #3b82f6;
  --border:       #e2e8f0;
  --link:         #2563eb;
  --user-bubble:  #e0e7ff;
  --bot-bubble:   #ffffff;
  --user-accent:  #4338ca;
  --bot-accent:   #0ea5e9;

  /* Métricas */
  --radius:    16px;
  --radius-lg: 22px;
  --shadow:    0 10px 30px rgba(2, 6, 23, 0.10);

  --maxw:      min(100%, 760px);
}

[data-theme="dark"] {
  --bg:           #0b1020;
  --surface:      #131a2c;
  --text:         #e7ecf5;
  --muted:        #8b97b1;
  --accent:       #60a5fa;
  --border:       #1e293b;
  --link:         #93c5fd;
  --user-bubble:  #1e293b;
  --bot-bubble:   #131a2c;
  --user-accent:  #c7d2fe;
  --bot-accent:   #38bdf8;
  --shadow:    0 10px 30px rgba(0, 0, 0, 0.45);
}

/* ── Reset mínimo ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Soporte para dark via prefers-color-scheme cuando el usuario no eligió nada. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
  }
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.chat-app {
  display: flex;
  flex-direction: column;
  width: var(--maxw);
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-header__text { min-width: 0; }

.chat-header__title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__subtitle {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Botones de icono (limpiar / tema) ────────────────────────────────────── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Área de mensajes ─────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 16px 24px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.chat-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}
.chat-empty p { margin: 0; }

/* ── Chips de sugerencias ─────────────────────────────────────────────────────── */
/* Mismo look que el backend (classic.css): pill borders, color muted, hover/active. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: min(100%, 520px);
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  font-family: var(--font);
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: color .2s, border-color .2s, background .2s, transform .12s;
}
.chip:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.chip:active { transform: scale(0.96); }
.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
[data-theme="dark"] .chip {
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}

/* Cada mensaje: usuario o bot */
.msg {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  max-width: 100%;
}
.msg.user { flex-direction: row-reverse; }

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  margin-top: 2px;
}
.avatar svg { width: 20px; height: 20px; display: block; }
.msg.user .avatar { background: var(--user-bubble); color: var(--user-accent); }
.msg.bot  .avatar { background: var(--bot-bubble);  color: var(--bot-accent); border-color: var(--border); }

.bubble {
  position: relative;
  padding: 11px 15px;
  border-radius: var(--radius);
  max-width: min(78%, 560px);
  font-size: 0.95rem;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--text);
  border-top-right-radius: 4px;
}
.msg.bot .bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}

/* Contenido Markdown dentro de la burbuja */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 8px; padding-left: 1.4em; }
.bubble li { margin: 2px 0; }
.bubble code {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  background: rgba(100, 116, 139, 0.16);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.88em;
}
.bubble pre {
  background: rgba(2, 6, 23, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  overflow-x: auto;
  margin: 8px 0;
}
[data-theme="dark"] .bubble pre { background: rgba(0, 0, 0, 0.32); }
.bubble pre code { background: transparent; padding: 0; }
.bubble a { color: var(--link); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--link) 40%, transparent); }
.bubble a:hover { border-bottom-color: var(--link); }
.bubble strong { font-weight: 700; }
.bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 6px 0;
  color: var(--muted);
}

/* ── Indicador de "escribiendo" ────────────────────────────────────────────── */
.typing .bubble { display: inline-flex; align-items: center; gap: 5px; padding: 13px 16px; }
.typing .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out both;
}
.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ── Mensaje de error / rate limit ────────────────────────────────────────── */
.msg.error .bubble {
  background: rgba(220, 38, 38, 0.08);
  border-color: rgba(220, 38, 38, 0.45);
  color: #b91c1c;
}
[data-theme="dark"] .msg.error .bubble {
  background: rgba(248, 113, 113, 0.10);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fca5a5;
}

/* ── Input ────────────────────────────────────────────────────────────────── */
.chat-input {
  display: flex;
  gap: 10px;
  padding: 12px 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.chat-input input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 12px 18px;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input input::placeholder { color: var(--muted); }
.chat-input input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.chat-input input:disabled { opacity: 0.6; cursor: not-allowed; }

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .12s, opacity .15s, background .15s;
}
.send-btn svg { width: 20px; height: 20px; }
.send-btn:hover { transform: scale(1.06); }
.send-btn:active { transform: scale(0.96); }
.send-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Utilidad accesibilidad ────────────────────────────────────────────────── */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
/* Móvil: ocupa todo el ancho, sin sombras laterales. */
@media (max-width: 600px) {
  .chat-app {
    border-left: none;
    border-right: none;
    box-shadow: none;
    --radius: 14px;
  }
  .chat-header { padding: 14px 14px; }
  .chat-header__title { font-size: 1rem; }
  .chat-header__subtitle { font-size: 0.78rem; }
  .chat-messages { padding: 14px 12px 20px; }
  .bubble { max-width: 84%; font-size: 0.92rem; }
  .chat-input { padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0px)); }
  .send-btn { width: 44px; height: 44px; }
}

/* Tablet / desktop amplio: límite superior del ancho. */
@media (min-width: 1024px) {
  body { padding: 24px 0; }
  .chat-app {
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }
}

/* Respeta la preferencia de menos movimiento. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
