/**
 * ACMEZ TECHNOLOGIES — INTERACTIVE CHATBOT ENGINE & WIDGET
 * Built on the Acmez Companion conversational architecture
 * Strictly Zero Em-Dashes and En-Dashes
 */

:root {
  --chat-primary: #163A70;
  --chat-secondary: #2563EB;
  --chat-accent: #3B82F6;
  --chat-emerald: #10B981;
  --chat-bg: #F8FAFC;
  --chat-card-bg: #FFFFFF;
  --chat-text: #0F172A;
  --chat-text-muted: #64748B;
  --chat-border: #E2E8F0;
  --chat-bg-bubble: #F1F5F9;
  --chat-brand-grad: linear-gradient(135deg, #163A70 0%, #1D4A8C 50%, #2563EB 100%);
  --chat-font-head: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  --chat-font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

/* Floating Root Container */
.acmez-chat-widget {
  position: fixed;
  bottom: 84px;
  right: 24px;
  z-index: 99999;
  font-family: var(--chat-font-body);
}

/* Launcher Button */
.chat-launcher-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--chat-brand-grad);
  border: none;
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(22, 58, 112, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

.chat-launcher-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 12px 30px rgba(22, 58, 112, 0.45);
}

.chat-launcher-btn:focus-visible {
  outline: 3px solid var(--chat-accent);
  outline-offset: 3px;
}

.chat-launcher-icon-wrap {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.chat-launcher-favicon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 50%;
}

.chat-pulse-indicator {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
}

.chat-pulse-ping {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: var(--chat-emerald);
  opacity: 0.75;
  animation: chat-ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.chat-pulse-dot {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background-color: var(--chat-emerald);
  border: 2px solid #ffffff;
}

@keyframes chat-ping {
  75%, 100% {
    transform: scale(2);
    opacity: 0;
  }
}

/* Launcher Tooltip */
.chat-launcher-tooltip {
  position: absolute;
  right: 68px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--chat-primary);
  color: #ffffff;
  padding: 7px 14px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--chat-font-head);
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.2);
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  animation: chat-fade-in 0.3s ease forwards;
}

.chat-launcher-tooltip svg {
  width: 14px;
  height: 14px;
  color: #F59E0B;
}

@keyframes chat-fade-in {
  from { opacity: 0; transform: translateY(-50%) translateX(6px); }
  to { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* Dialog Panel */
.chat-dialog-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(540px, calc(100vh - 130px));
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.25);
  border: 1px solid var(--chat-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  z-index: 999999;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.25s;
}

.chat-dialog-panel.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Panel Header */
.chat-header {
  background: var(--chat-brand-grad);
  color: #ffffff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.chat-header-favicon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.chat-header-status-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chat-emerald);
  border: 2px solid var(--chat-primary);
}

.chat-header-title {
  margin: 0;
  font-family: var(--chat-font-head);
  font-size: 0.9375rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
}

.chat-header-subtitle {
  margin: 2px 0 0 0;
  font-size: 0.6875rem;
  opacity: 0.85;
}

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

.chat-action-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #ffffff;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.chat-action-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Human WhatsApp Bar */
.chat-human-bar {
  background: #f0fdf4;
  border-bottom: 1px solid #bbf7d0;
  padding: 8px 16px;
  flex-shrink: 0;
}

.chat-human-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 7px 14px;
  background: #16a34a;
  color: #ffffff !important;
  border-radius: 8px;
  text-decoration: none !important;
  font-size: 0.7813rem;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.2);
  transition: background 0.15s ease, transform 0.15s ease;
}

.chat-human-btn:hover {
  background: #15803d;
  transform: translateY(-1px);
}

.chat-human-wa-icon {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.chat-human-arrow {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  margin-left: auto;
  transition: transform 0.15s ease;
}

.chat-human-btn:hover .chat-human-arrow {
  transform: translateX(3px);
}

/* Messages Area */
.chat-messages-container {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #ffffff;
  font-size: 0.8125rem;
  position: relative;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.chat-msg-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 88%;
  outline: none;
}

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

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

.chat-msg-category {
  font-size: 0.625rem;
  font-family: monospace;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--chat-primary);
  background: rgba(22, 58, 112, 0.08);
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
  border: 1px solid rgba(22, 58, 112, 0.2);
}

.chat-bubble {
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.55;
  word-break: break-word;
}

.chat-msg-row.assistant .chat-bubble {
  background: var(--chat-bg-bubble);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  border-bottom-left-radius: 2px;
}

.chat-msg-row.user .chat-bubble {
  background: var(--chat-brand-grad);
  color: #ffffff;
  font-weight: 500;
  border-bottom-right-radius: 2px;
  box-shadow: 0 4px 12px rgba(22, 58, 112, 0.25);
}

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

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

/* Callout Quote in Bot Answer */
.chat-quote-block {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(22, 58, 112, 0.05);
  border-left: 3px solid var(--chat-secondary);
  border-radius: 0 6px 6px 0;
  font-size: 0.75rem;
  font-style: italic;
  color: #334155;
}

.chat-quote-source {
  font-style: normal;
  font-family: monospace;
  font-size: 0.6875rem;
  color: var(--chat-text-muted);
  margin-top: 4px;
  display: block;
}

/* Action Links inside Bot Answer */
.chat-link-box {
  margin-top: 10px;
}

.chat-action-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--chat-brand-grad);
  color: #ffffff !important;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  text-decoration: none;
  box-shadow: 0 3px 10px rgba(22, 58, 112, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.chat-action-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(22, 58, 112, 0.4);
  filter: brightness(1.05);
}

.chat-action-link.whatsapp-link {
  background: #16a34a;
  box-shadow: 0 3px 10px rgba(22, 163, 74, 0.25);
}

.chat-action-link.whatsapp-link:hover {
  background: #15803d;
  box-shadow: 0 5px 15px rgba(22, 163, 74, 0.35);
}

/* Suggested Followup Chips */
.chat-followups-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.chat-chip-btn {
  background: #ffffff;
  border: 1px solid var(--chat-border);
  color: #334155;
  font-size: 0.7188rem;
  padding: 5px 10px;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.chat-chip-btn:hover {
  border-color: var(--chat-secondary);
  color: var(--chat-primary);
  background: rgba(37, 99, 235, 0.08);
}

/* Typing Indicator Animation */
.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--chat-bg-bubble);
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  border-bottom-left-radius: 2px;
  width: fit-content;
}

.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  opacity: 0.4;
  animation: chat-typing-pulse 1.4s infinite ease-in-out;
}

.chat-typing-dot:nth-child(1) {
  background: #163A70;
  animation-delay: 0s;
}

.chat-typing-dot:nth-child(2) {
  background: #2563EB;
  animation-delay: 0.2s;
}

.chat-typing-dot:nth-child(3) {
  background: #10B981;
  animation-delay: 0.4s;
}

@keyframes chat-typing-pulse {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Quick Topics Bar & Continuous Auto-Slider */
.chat-topics-bar {
  flex-shrink: 0;
  padding: 8px 12px;
  background: #f8fafc;
  border-top: 1px solid var(--chat-border);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  font-size: 0.6875rem;
  position: relative;
}

.chat-topics-label {
  color: var(--chat-text-muted);
  font-family: monospace;
  font-weight: 600;
  text-transform: uppercase;
  flex-shrink: 0;
  z-index: 2;
  background: #f8fafc;
  padding-right: 4px;
}

.chat-topics-overflow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  position: relative;
  mask-image: linear-gradient(to right, transparent 0%, black 10px, black calc(100% - 10px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, transparent 0%, black 10px, black calc(100% - 10px), transparent 100%);
}

.chat-topics-track {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  animation: chat-topics-auto-slide 20s linear infinite;
  will-change: transform;
}

.chat-topics-bar:hover .chat-topics-track,
.chat-topics-track:focus-within {
  animation-play-state: paused;
}

@keyframes chat-topics-auto-slide {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

.chat-topic-tag {
  background: #ffffff;
  border: 1px solid var(--chat-border);
  color: #475569;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.6875rem;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s, border-color 0.15s, transform 0.15s;
}

.chat-topic-tag:hover {
  color: var(--chat-primary);
  background: rgba(22, 58, 112, 0.08);
  border-color: var(--chat-secondary);
  transform: translateY(-1px);
}

.chat-topic-tag.chat-topic-human {
  color: #16a34a;
  border-color: #bbf7d0;
  background: #f0fdf4;
  font-weight: 600;
}

.chat-topic-tag.chat-topic-human:hover {
  color: #15803d;
  background: #dcfce7;
  border-color: #16a34a;
}

/* Input Form Area */
.chat-input-form {
  flex-shrink: 0;
  padding: 12px 14px;
  background: #ffffff;
  border-top: 1px solid var(--chat-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-text-input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  font-size: 0.8125rem;
  color: var(--chat-text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-text-input:focus {
  border-color: var(--chat-secondary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--chat-brand-grad);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(22, 58, 112, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.chat-send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 15px rgba(22, 58, 112, 0.4);
  filter: brightness(1.06);
}

.chat-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Mobile Responsiveness */
@media (max-width: 640px) {
  .acmez-chat-widget {
    bottom: 72px;
    right: 16px;
  }

  .acmez-chat-widget.chat-open {
    position: static;
  }

  .acmez-chat-widget.chat-open .chat-launcher-btn,
  .chat-launcher-btn.chat-launcher-hidden {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }

  .chat-dialog-panel {
    position: fixed;
    top: 10px;
    top: max(10px, env(safe-area-inset-top, 10px));
    bottom: 12px;
    bottom: max(12px, env(safe-area-inset-bottom, 12px));
    left: 10px;
    left: max(10px, env(safe-area-inset-left, 10px));
    right: 10px;
    right: max(10px, env(safe-area-inset-right, 10px));
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    border-radius: 18px;
    box-shadow: 0 12px 36px rgba(15, 23, 42, 0.35);
    z-index: 100000;
  }

  .chat-header {
    padding: 12px 14px;
  }

  .chat-header-avatar {
    width: 32px;
    height: 32px;
  }

  .chat-header-favicon {
    width: 20px;
    height: 20px;
  }

  .chat-header-title {
    font-size: 0.8125rem;
  }

  .chat-header-subtitle {
    font-size: 0.625rem;
  }

  .chat-human-bar {
    padding: 6px 12px;
  }

  .chat-human-btn {
    padding: 7px 12px;
    font-size: 0.75rem;
  }

  .chat-messages-container {
    padding: 12px;
    gap: 12px;
  }

  .chat-bubble {
    padding: 10px 12px;
  }

  .chat-topics-bar {
    padding: 6px 12px;
  }

  .chat-input-form {
    padding: 10px 12px;
  }
}
