/* ================================================
   Asistente Virtual — Municipalidad de Río Bravo
   ================================================ */

:root {
  --chat-primary:      #1e3a6e;
  --chat-primary-light:#2d5299;
  --chat-accent:       #FFD700;
  --chat-bg:           #f8fafc;
  --chat-white:        #ffffff;
  --chat-bot-bubble:   #ffffff;
  --chat-user-bubble:  linear-gradient(135deg, #1e3a6e, #2d5299);
  --chat-border:       #e2e8f0;
  --chat-text:         #1e293b;
  --chat-muted:        #94a3b8;
  --chat-shadow:       0 12px 48px rgba(0, 0, 0, 0.16);
  --chat-radius:       20px;
}

/* ── Container ─────────────────────────────────── */
#muni-chatbot {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 99999;
  font-family: 'Poppins', sans-serif;
}

/* ── Toggle Button ──────────────────────────────── */
#chat-toggle-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-light));
  border: 3px solid var(--chat-accent);
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(30, 58, 110, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.2s ease;
  position: relative;
  overflow: visible;
}

#chat-toggle-btn:hover {
  transform: scale(1.07);
  box-shadow: 0 8px 32px rgba(30, 58, 110, 0.55);
}

#chat-toggle-btn:active {
  transform: scale(0.97);
}

#chat-toggle-btn .icon-chat,
#chat-toggle-btn .icon-close {
  position: absolute;
  transition: opacity 0.2s, transform 0.2s;
}

#chat-toggle-btn .icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

#chat-toggle-btn.open .icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

#chat-toggle-btn.open .icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Notification pulse */
.chat-pulse {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e63946;
  border: 2px solid #fff;
  animation: chatPulse 2s infinite;
}

@keyframes chatPulse {
  0%   { box-shadow: 0 0 0 0 rgba(230, 57, 70, 0.7); }
  70%  { box-shadow: 0 0 0 10px rgba(230, 57, 70, 0); }
  100% { box-shadow: 0 0 0 0 rgba(230, 57, 70, 0); }
}

/* ── Chat Window ────────────────────────────────── */
.chat-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 375px;
  max-height: 590px;
  background: var(--chat-white);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(18px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s ease,
              transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-window.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ─────────────────────────────────────── */
.chat-header {
  background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-light) 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 11px;
}

.chat-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 215, 0, 0.12);
  border: 2px solid var(--chat-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.chat-header-avatar img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.chat-header-text h4 {
  color: #fff;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.chat-header-text .chat-subtitle {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.75);
  margin-top: 1px;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 3px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  animation: statusBlink 2.5s infinite;
}

@keyframes statusBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

.chat-close-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.chat-close-btn:hover  { background: rgba(255, 255, 255, 0.25); }
.chat-close-btn:active { background: rgba(255, 255, 255, 0.35); }

/* ── Messages Area ──────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--chat-bg);
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar        { width: 4px; }
.chat-messages::-webkit-scrollbar-track  { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb  { background: #cbd5e1; border-radius: 2px; }

/* ── Message Row ────────────────────────────────── */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msgFadeIn 0.24s ease;
}

@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0);    }
}

.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e2e8f0;
  overflow: hidden;
}

.msg-avatar.bot-avatar {
  background: rgba(30, 58, 110, 0.08);
  border: 1.5px solid rgba(30, 58, 110, 0.15);
}

.msg-avatar img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.msg-avatar.user-avatar {
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-light));
}

.msg-content {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg-row.bot .msg-bubble {
  background: var(--chat-bot-bubble);
  color: var(--chat-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
}

.msg-row.user .msg-bubble {
  background: linear-gradient(135deg, #1e3a6e, #2d5299);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-bubble strong { font-weight: 600; }

.msg-time {
  font-size: 10px;
  color: var(--chat-muted);
  margin-top: 4px;
  padding: 0 2px;
}

.msg-row.bot  .msg-time { text-align: left;  }
.msg-row.user .msg-time { text-align: right; }

/* ── Typing Indicator ───────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 0 16px 6px;
  animation: msgFadeIn 0.2s ease;
}

.typing-indicator.hidden { display: none; }

.typing-bubble {
  background: var(--chat-white);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 11px 16px;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: typingBounce 1.3s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.6; }
  30%           { transform: translateY(-7px); opacity: 1;   }
}

/* ── Quick Replies ──────────────────────────────── */
.quick-replies {
  padding: 8px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--chat-bg);
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.quick-replies:empty { display: none; }

.qr-btn {
  background: #fff;
  border: 1.5px solid #cbd5e1;
  color: var(--chat-primary);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: 'Poppins', sans-serif;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.qr-btn:hover {
  background: var(--chat-primary);
  border-color: var(--chat-primary);
  color: var(--chat-accent);
}

/* Botón especial para subir DPI */
.qr-btn.dpi-btn {
  background: linear-gradient(135deg, #1e3a6e, #2d5299);
  border-color: var(--chat-primary);
  color: var(--chat-accent);
  font-weight: 600;
  padding: 7px 16px;
  animation: dpiBtnPulse 2s infinite;
}

.qr-btn.dpi-btn:hover {
  background: linear-gradient(135deg, #2d5299, #1e3a6e);
  color: #fff;
}

@keyframes dpiBtnPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(30, 58, 110, 0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(30, 58, 110, 0); }
}

/* ── Input Area ─────────────────────────────────── */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: 1.5px solid var(--chat-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: 'Poppins', sans-serif;
  resize: none;
  max-height: 100px;
  min-height: 42px;
  outline: none;
  transition: border-color 0.2s;
  color: var(--chat-text);
  line-height: 1.45;
  overflow-y: auto;
  background: var(--chat-bg);
}

#chat-input:focus       { border-color: var(--chat-primary); background: #fff; }
#chat-input::placeholder { color: var(--chat-muted); font-size: 13px; }

#chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-light));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, opacity 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(30, 58, 110, 0.35);
}

#chat-send-btn:hover   { transform: scale(1.05); box-shadow: 0 4px 14px rgba(30, 58, 110, 0.45); }
#chat-send-btn:active  { transform: scale(0.95); }
#chat-send-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

#chat-send-btn svg { fill: #fff; width: 18px; height: 18px; }

/* ── Footer branding ────────────────────────────── */
.chat-footer-brand {
  text-align: center;
  font-size: 10px;
  color: var(--chat-muted);
  padding: 5px 0 7px;
  background: #fff;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}

.chat-footer-brand span { font-weight: 600; color: var(--chat-primary); }

/* ── Error state ────────────────────────────────── */
.msg-bubble.error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

/* ── Mobile ─────────────────────────────────────── */
@media (max-width: 430px) {
  #muni-chatbot {
    bottom: 16px;
    right: 16px;
  }

  .chat-window {
    width: calc(100vw - 32px);
    right: -4px;
    bottom: 76px;
    max-height: 72vh;
  }

  #chat-toggle-btn {
    width: 56px;
    height: 56px;
  }
}
