/* ==================== ANGEL CHAT WIDGET ==================== */
/* Assistente Virtual - Construir Portugal */
/* Enhanced Version with improved organization and maintainability */

/* ==================== CSS VARIABLES ==================== */
:root {
  /* Angel Colors */
  --angel-primary: var(--blue-500);
  --angel-primary-dark: var(--blue-700);
  --angel-primary-darker: var(--blue-900);
  --angel-accent: var(--orange-500);
  --angel-accent-light: var(--orange-300);

  /* Angel Sizes (specific to widget) */
  --angel-avatar-sm: 44px;
  --angel-avatar-md: 54px;
  --angel-avatar-lg: 80px;

  /* Z-Index Stack */
  --angel-z-index-toggle: 1001;
  --angel-z-index-widget: 1001;
  --angel-z-index-modal: 1002;
}

/* ==================== FLOATING TOGGLE BUTTON ==================== */
.angel-toggle-btn {
  position: fixed;
  bottom: 40px;
  right: 40px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    var(--angel-primary) 0%,
    var(--angel-primary-dark) 100%
  );
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: var(--angel-z-index-toggle);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-base);
  animation: angelPulse 2s infinite;
}

.angel-toggle-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(33, 53, 119, 0.5);
}

.angel-toggle-btn img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  transition: transform var(--transition-base);
}

.angel-toggle-btn.active img {
  transform: rotate(90deg);
}

@keyframes angelPulse {
  0%,
  100% {
    box-shadow: var(--shadow-md);
  }
  50% {
    box-shadow:
      0 4px 30px rgba(33, 53, 119, 0.6),
      0 0 0 8px rgba(33, 53, 119, 0.1);
  }
}

/* Toggle Tooltip */
.angel-toggle-tooltip {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: var(--space-md);
  padding: 10px var(--space-lg);
  background: linear-gradient(
    135deg,
    var(--angel-primary-dark) 0%,
    var(--angel-primary-darker) 100%
  );
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  visibility: hidden;
  transform: translateY(var(--space-sm));
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: calc(var(--angel-z-index-toggle) + 1);
}

.angel-toggle-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 20px;
  border: var(--space-sm) solid transparent;
  border-top-color: var(--angel-primary-darker);
}

.angel-toggle-btn:hover .angel-toggle-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.angel-toggle-btn.active .angel-toggle-tooltip {
  opacity: 0;
  visibility: hidden;
}

/* ==================== WELCOME MODAL ==================== */
.angel-welcome-modal {
  position: fixed;
  bottom: 120px;
  right: 40px;
  width: 380px;
  max-height: 90vh;
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow:
    var(--shadow-lg),
    0 0 0 1px rgba(33, 53, 119, 0.1);
  z-index: var(--angel-z-index-modal);
  display: none;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: all var(--transition-base);
}

.angel-welcome-modal.show {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
}

.angel-welcome-header {
  background: linear-gradient(
    135deg,
    var(--angel-primary) 0%,
    var(--angel-primary-darker) 100%
  );
  padding: 24px;
  text-align: center;
  position: relative;
}

.angel-welcome-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--angel-accent),
    var(--angel-accent-light),
    var(--angel-accent)
  );
}

.angel-welcome-avatar {
  width: var(--angel-avatar-lg);
  height: var(--angel-avatar-lg);
  margin: 0 auto var(--space-lg);
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

.angel-welcome-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.angel-welcome-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--white);
  margin: 0;
}

.angel-welcome-body {
  padding: 24px;
  max-height: 300px;
  overflow-y: auto;
}

.angel-welcome-text {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--gray-700);
  margin-bottom: var(--space-lg);
}

.angel-welcome-disclaimer {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--gray-500);
  padding: var(--space-md);
  background: var(--gray-50);
  border-radius: var(--space-sm);
  border-left: 3px solid var(--angel-accent);
}

.angel-welcome-disclaimer a {
  color: var(--angel-primary);
  text-decoration: none;
  transition: all var(--transition-fast);
}

.angel-welcome-disclaimer a:hover {
  text-decoration: underline;
}

.angel-welcome-footer {
  padding: var(--space-lg) 24px 24px;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.angel-accept-btn {
  width: 100%;
  padding: 14px 24px;
  background: linear-gradient(
    135deg,
    var(--angel-primary) 0%,
    var(--angel-primary-dark) 100%
  );
  color: var(--white);
  border: none;
  border-radius: var(--space-md);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.angel-accept-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.angel-decline-btn {
  width: 100%;
  padding: var(--space-md) 24px;
  background: transparent;
  color: var(--gray-500);
  border: 1px solid var(--gray-200);
  border-radius: var(--space-md);
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.angel-decline-btn:hover {
  background: var(--gray-50);
  color: var(--gray-700);
}

.angel-alternatives {
  display: none;
  padding: 24px;
  text-align: center;
}

.angel-alternatives.show {
  display: block;
}

.angel-alternatives-text {
  font-size: 0.95rem;
  color: var(--gray-600);
  margin-bottom: var(--space-lg);
}

.angel-alternatives-links {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
  flex-wrap: wrap;
}

.angel-alt-link {
  padding: 10px var(--space-xl);
  border-radius: var(--space-sm);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.angel-alt-link.faq {
  background: var(--gray-100);
  color: var(--gray-700);
}

.angel-alt-link.whatsapp {
  background: #25d366;
  color: var(--white);
}

.angel-alt-link:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

/* ==================== CHAT WIDGET ==================== */
.angel-chat-widget {
  position: fixed;
  bottom: 120px;
  right: 40px;
  width: 420px;
  height: 600px;
  display: none;
  flex-direction: column;
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: var(--white);
  box-shadow:
    var(--shadow-lg),
    0 0 0 1px rgba(33, 53, 119, 0.1);
  z-index: var(--angel-z-index-widget);
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: all var(--transition-base);
}

.angel-chat-widget.show {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Chat Header */
.angel-chat-header {
  background: linear-gradient(
    135deg,
    var(--angel-primary) 0%,
    var(--angel-primary-darker) 100%
  );
  color: var(--white);
  padding: 18px var(--space-xl);
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
}

.angel-chat-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--angel-accent),
    var(--angel-accent-light),
    var(--angel-accent)
  );
}

.angel-avatar {
  width: var(--angel-avatar-md);
  height: var(--angel-avatar-md);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  flex-shrink: 0;
}

.angel-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.angel-header-info {
  flex: 1;
  min-width: 0; /* Allow text truncation */
}

.angel-header-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.02em;
  color: var(--white);
}

.angel-header-status {
  font-size: 0.8rem;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.angel-status-dot {
  width: var(--space-sm);
  height: var(--space-sm);
  background: #10b981;
  border-radius: 50%;
  animation: statusPulse 2s infinite;
  flex-shrink: 0;
}

@keyframes statusPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.angel-close-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--space-sm);
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.angel-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ==================== MESSAGES AREA ==================== */
.angel-chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-xl);
  background: linear-gradient(180deg, var(--gray-50) 0%, var(--white) 100%);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.angel-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.angel-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.angel-chat-messages::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 3px;
}

/* Message Bubbles */
.angel-message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: messageSlide var(--transition-base);
}

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

.angel-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.angel-message.bot {
  align-self: flex-start;
}

.angel-message.system {
  align-self: center;
  max-width: 90%;
}

.angel-message-content {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--space-lg);
  font-size: 0.95rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.angel-message.user .angel-message-content {
  background: linear-gradient(
    135deg,
    var(--angel-primary) 0%,
    var(--angel-primary-dark) 100%
  );
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.angel-message.bot .angel-message-content {
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px var(--space-sm) rgba(0, 0, 0, 0.04);
}

.angel-message.bot .angel-message-content a {
  color: var(--angel-primary);
  text-decoration: none;
  font-weight: 500;
}

.angel-message.bot .angel-message-content a:hover {
  text-decoration: underline;
}

.angel-message.system .angel-message-content {
  background: var(--gray-100);
  color: var(--gray-600);
  border: 1px solid var(--gray-200);
  font-size: 0.85rem;
  font-style: italic;
  text-align: center;
}

/* Typing Indicator */
.angel-typing-indicator {
  display: flex;
  gap: 4px;
  padding: var(--space-md) var(--space-lg);
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--space-lg);
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.angel-typing-indicator span {
  width: var(--space-sm);
  height: var(--space-sm);
  background: var(--blue-300);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

.angel-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.angel-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-8px);
  }
}

/* ==================== QUICK ACTIONS ==================== */
.angel-quick-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  width: 100%;
}

.angel-quick-actions-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: center;
  padding: var(--space-sm) 0;
}

.angel-quick-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 18px;
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: 20px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  transition: all var(--transition-fast);
  animation: fadeInUp var(--transition-base);
  white-space: nowrap;
}

.angel-quick-btn:hover {
  background: var(--blue-50);
  border-color: var(--blue-300);
  color: var(--blue-700);
  transform: translateY(-1px);
}

.angel-quick-btn:active {
  transform: translateY(0);
}

.angel-quick-btn-icon {
  font-size: 1em;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(var(--space-sm));
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Staggered animation delays */
.angel-quick-btn:nth-child(2) {
  animation-delay: 0.05s;
}
.angel-quick-btn:nth-child(3) {
  animation-delay: 0.1s;
}
.angel-quick-btn:nth-child(4) {
  animation-delay: 0.15s;
}
.angel-quick-btn:nth-child(5) {
  animation-delay: 0.2s;
}

/* ==================== INPUT AREA ==================== */
.angel-chat-input-area {
  padding: var(--space-lg) var(--space-xl);
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: var(--space-md);
  align-items: center;
}

.angel-chat-input {
  flex: 1;
  padding: var(--space-md) var(--space-lg);
  border: 2px solid var(--gray-200);
  border-radius: var(--space-md);
  font-family: var(--font-body);
  font-size: 0.95rem;
  outline: none;
  transition: all var(--transition-fast);
  background: var(--gray-50);
}

.angel-chat-input:focus {
  border-color: var(--angel-primary);
  background: var(--white);
  box-shadow: 0 0 0 4px rgba(33, 53, 119, 0.1);
}

.angel-chat-input::placeholder {
  color: var(--gray-400);
}

.angel-send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--space-md);
  background: linear-gradient(
    135deg,
    var(--angel-primary) 0%,
    var(--angel-primary-dark) 100%
  );
  border: none;
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.angel-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

.angel-send-btn:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.6;
}

.angel-send-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* ==================== RESPONSIVE DESIGN ==================== */
/* Tablet */
@media (max-width: 768px) {
  .angel-toggle-btn {
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
  }

  .angel-toggle-btn img {
    width: 32px;
    height: 32px;
  }

  .angel-chat-widget {
    width: 380px;
    height: 550px;
    bottom: 100px;
    right: 20px;
  }

  .angel-welcome-modal {
    width: 340px;
    right: 20px;
    bottom: 100px;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .angel-toggle-btn {
    bottom: var(--space-lg);
    right: var(--space-lg);
    width: 50px;
    height: 50px;
  }

  .angel-toggle-btn img {
    width: 28px;
    height: 28px;
  }

  .angel-chat-widget {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  .angel-chat-widget.show {
    transform: translateY(0);
  }

  .angel-welcome-modal {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 85vh;
    border-radius: 20px 20px 0 0;
  }

  .angel-chat-header {
    padding: 14px var(--space-lg);
  }

  .angel-avatar {
    width: var(--angel-avatar-sm);
    height: var(--angel-avatar-sm);
  }

  .angel-chat-input-area {
    padding: var(--space-md) var(--space-lg);
  }

  .angel-quick-btn {
    font-size: 0.85rem;
    padding: var(--space-sm) 14px;
  }
}

/* ==================== ACCESSIBILITY ==================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .angel-message.bot .angel-message-content {
    border-width: 2px;
  }

  .angel-quick-btn {
    border-width: 2px;
  }
}

/* ==================== PRINT STYLES ==================== */
@media print {
  .angel-toggle-btn,
  .angel-chat-widget,
  .angel-welcome-modal {
    display: none !important;
  }
}

/* ==================== CATALOG PAGE SPECIFIC STYLES ==================== */
/* Position Angel widget on the LEFT side only on catalog page */
.page-catalogo .angel-toggle-btn {
  left: 40px;
  right: auto;
}

/* Tooltip appears to the RIGHT of button */
.page-catalogo .angel-toggle-tooltip {
  left: 80px; /* Position to the right of button */
  right: auto;
  bottom: 10px;
  transform: translateX(-10px);
}

.page-catalogo .angel-toggle-tooltip::after {
  /* Arrow pointing left */
  left: 0;
  right: auto;
  top: 50%;
  transform: translateY(-50%) translateX(-100%);
  border: var(--space-sm) solid transparent;
  border-right-color: var(--angel-primary-darker);
  border-top-color: transparent;
}

.page-catalogo .angel-toggle-btn:hover .angel-toggle-tooltip {
  transform: translateX(0);
}

.page-catalogo .angel-chat-widget {
  left: 40px;
  right: auto;
}

.page-catalogo .angel-welcome-modal {
  left: 40px;
  right: auto;
}

/* Responsive adjustments for catalog */
@media (max-width: 768px) {
  .page-catalogo .angel-toggle-btn {
    left: 20px;
    right: auto;
    bottom: 100px;
  }

  .page-catalogo .angel-toggle-tooltip {
    left: 70px; /* Adjusted for smaller button */
    bottom: 8px;
  }

  .page-catalogo .angel-chat-widget {
    left: 20px;
    right: auto;
    bottom: 180px;
  }

  .page-catalogo .angel-welcome-modal {
    left: 20px;
    right: auto;
    bottom: 180px;
  }
}

@media (max-width: 480px) {
  .page-catalogo .angel-toggle-btn {
    left: 16px;
    right: auto;
    bottom: 80px;
  }

  .page-catalogo .angel-toggle-tooltip {
    left: 66px; /* Adjusted for mobile button size */
    bottom: 6px;
  }

  .page-catalogo .angel-chat-widget {
    /* Full screen on mobile */
    left: 0;
    right: 0;
    bottom: 0;
  }

  .page-catalogo .angel-welcome-modal {
    /* Full width on mobile */
    left: 0;
    right: 0;
    bottom: 0;
  }
}
