/* ==============================================================================
   Widget de Chatbot Asistente RAG para Geofirma (geofirma.es)
   Paleta corporativa: Verde Geofirma (#5f9a46 / #7eb564) y Azul Marino (#2d4668 / #40608f)
   ============================================================================== */

:root {
  --chat-green: #5f9a46;
  --chat-green-hover: #4f8639;
  --chat-green-soft: #eef6e5;
  --chat-green-border: #c8dfb8;
  --chat-navy: #2d4668;
  --chat-navy-light: #40608f;
  --chat-bg: #ffffff;
  --chat-surface: #f4f7fb;
  --chat-border: #e1e7ef;
  --chat-text: #13203a;
  --chat-text-muted: #64748b;
  --chat-online: #22c55e;
}

.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: var(--text, 'Inter', system-ui, -apple-system, sans-serif);
}

.chat-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--chat-green);
  border: 2px solid #ffffff;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(45, 70, 104, 0.35);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.2s, box-shadow 0.2s;
}

.chat-toggle:hover {
  transform: translateY(-2px) scale(1.04);
  background: var(--chat-green-hover);
  box-shadow: 0 14px 30px rgba(45, 70, 104, 0.45);
}

.chat-toggle svg {
  width: 26px;
  height: 26px;
  stroke: #ffffff;
}

.chat-toggle .chat-icon-close {
  display: none;
  font-size: 28px;
  line-height: 1;
  color: #ffffff;
}

.chat-widget.is-open .chat-toggle .chat-icon-open { display: none; }
.chat-widget.is-open .chat-toggle .chat-icon-close { display: block; }

.chat-toggle-badge {
  position: absolute;
  right: 68px;
  white-space: nowrap;
  background: #ffffff;
  border: 1px solid var(--chat-border);
  color: var(--chat-navy);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(19, 32, 58, 0.12);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}

.chat-widget.is-open .chat-toggle-badge,
.chat-toggle-badge.is-hidden {
  opacity: 0;
  transform: translateX(10px);
  pointer-events: none;
}

.chat-window {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 550px;
  max-height: calc(100vh - 100px);
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(19, 32, 58, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.22s ease-out, transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.chat-widget.is-open .chat-window {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--chat-navy);
  color: #ffffff;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chat-online);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.chat-title {
  font-family: var(--display, 'Outfit', sans-serif);
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  color: #ffffff;
  line-height: 1.2;
}

.chat-subtitle {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.8);
  margin: 0;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.chat-expand {
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 7px;
  border-radius: 6px;
  transition: color 0.15s, background-color 0.15s;
}

.chat-expand:hover,
.chat-expand:focus-visible {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

.chat-expand-off,
.chat-widget.is-expanded .chat-expand-on {
  display: none;
}

.chat-widget.is-expanded .chat-expand-off {
  display: block;
}

/* Expanded: the assistant takes the screen (a centred panel on wide screens). */
.chat-widget.is-expanded .chat-window {
  position: fixed;
  inset: 16px;
  width: auto;
  height: auto;
  max-width: 960px;
  max-height: none;
  margin: 0 auto;
  z-index: 2147483000;
}

.chat-widget.is-expanded .chat-video-wrap video {
  max-height: 70vh;
}

.chat-close {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s, background-color 0.15s;
}

.chat-close:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #ffffff;
  scroll-behavior: smooth;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: chatMsgFadeIn 0.2s ease-out;
}

@keyframes chatMsgFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg-user {
  align-self: flex-end;
}

.chat-msg-bot {
  align-self: flex-start;
}

.chat-msg-user .chat-bubble {
  background: var(--chat-navy);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.chat-msg-bot .chat-bubble {
  background: var(--chat-surface);
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
}

.chat-bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.5;
  word-break: break-word;
}

.chat-bubble p {
  margin: 0 0 8px 0;
}

.chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-bubble ul {
  margin: 6px 0 6px 18px;
  padding: 0;
  list-style: disc;
}

.chat-bubble li {
  margin-bottom: 4px;
}

.chat-bubble a {
  color: var(--chat-green);
  text-decoration: underline;
  font-weight: 600;
}

.chat-msg-user .chat-bubble a {
  color: #ffffff;
}

/* ==============================================================================
   Elementos Multimedia Interactivos en el Chat (Vídeos Clips e Imágenes)
   ============================================================================== */

.chat-media {
  margin: 8px 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid var(--chat-border);
  background: #0f172a;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-media:hover {
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.22);
}

.chat-video-wrap video {
  width: 100%;
  /* Phone clips are portrait (390×844): show them whole, not a cropped strip. */
  max-height: min(420px, 60vh);
  display: block;
  object-fit: contain;
  background: #000000;
  border-radius: 10px 10px 0 0;
}

.chat-img-wrap img {
  width: 100%;
  max-height: 200px;
  display: block;
  object-fit: cover;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chat-img-wrap img:hover {
  opacity: 0.92;
}

.chat-media-caption {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--chat-text-muted);
  padding: 6px 10px;
  background: var(--chat-surface);
  border-top: 1px solid var(--chat-border);
}

.chat-media-title {
  flex: 1;
  min-width: 0;
}

.chat-media-full {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  padding: 4px 9px;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  background: transparent;
  color: var(--chat-green);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.chat-media-full:hover,
.chat-media-full:focus-visible {
  background: var(--chat-green);
  border-color: var(--chat-green);
  color: #fff;
}

/* Full screen: the whole clip, centred, on black. */
.chat-video-wrap video:fullscreen {
  max-height: none;
  object-fit: contain;
  border-radius: 0;
  background: #000;
}

.chat-media-caption::before {
  content: '▶';
  color: var(--chat-green);
  font-size: 0.7rem;
}

.chat-img-wrap .chat-media-caption::before {
  content: '🔍';
}

.chat-bubble strong {
  font-weight: 700;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.chat-chip {
  background: var(--chat-green-soft);
  color: #2e591e;
  border: 1px solid var(--chat-green-border);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.chat-chip:hover {
  background: #e2f0d4;
  border-color: var(--chat-green);
  transform: translateY(-1px);
}

.chat-form {
  border-top: 1px solid var(--chat-border);
  background: #ffffff;
  padding: 10px 14px 12px;
}

.chat-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-wrap:focus-within {
  border-color: var(--chat-green);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(126, 181, 100, 0.2);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--chat-text);
  font-size: 0.88rem;
  outline: none;
  padding: 6px 0;
  min-width: 0;
}

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

.chat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--chat-green);
  color: #ffffff;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.chat-send:hover {
  background: var(--chat-green-hover);
  transform: scale(1.05);
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chat-send svg {
  width: 17px;
  height: 17px;
  stroke: #ffffff;
}

.chat-footer-note {
  font-size: 0.72rem;
  color: var(--chat-text-muted);
  text-align: center;
  margin-top: 8px;
}

.chat-footer-note a {
  color: var(--chat-navy);
  font-weight: 600;
  text-decoration: none;
}

.chat-footer-note a:hover {
  text-decoration: underline;
}

/* Indicador de escritura animado */
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-text-muted);
  animation: chatDotPulse 1.4s infinite ease-in-out both;
}

.chat-typing span:nth-child(1) { animation-delay: -0.32s; }
.chat-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes chatDotPulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

@media (max-width: 480px) {
  .chat-widget {
    bottom: 16px;
    right: 16px;
  }
  .chat-window {
    width: calc(100vw - 32px);
    height: calc(100vh - 90px);
    bottom: 68px;
  }
}
