/**
 * AI Store Assistant - Chat Widget CSS
 * Responsive, Glassmorphism, Themeable Floating Assistant for PrestaShop 8
 */

:root {
  --aia-primary: #2563eb;
  --aia-primary-hover: #1d4ed8;
  --aia-hover: #1d4ed8;
  --aia-primary-light: #eff6ff;
  --aia-text-dark: #1e293b;
  --aia-text-muted: #64748b;
  --aia-bg-light: #f8fafc;
  --aia-border-color: #e2e8f0;
  --aia-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --aia-radius: 16px;
  --aia-z-index: 999999;
}

/* Floating Trigger Button */
.aia-floating-button {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--aia-z-index);
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  height: 56px;
  min-height: 56px;
  max-height: 56px;
  max-width: 320px;
  padding: 0;
  background: var(--aia-primary);
  color: #ffffff;
  border: 2.5px solid #ffffff;
  border-radius: 28px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2), 0 2px 6px rgba(0, 0, 0, 0.06);
  cursor: pointer;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  outline: none;
  box-sizing: border-box;
  overflow: visible;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: max-width 0.55s cubic-bezier(0.25, 1, 0.35, 1),
              min-width 0.55s cubic-bezier(0.25, 1, 0.35, 1),
              width 0.55s cubic-bezier(0.25, 1, 0.35, 1),
              box-shadow 0.3s ease,
              background 0.2s ease,
              transform 0.25s cubic-bezier(0.25, 1, 0.35, 1);
}

/* Status Online Indicator Dot on Floating Button */
.aia-btn-status-dot {
  display: block;
  position: absolute;
  top: 1px;
  right: 2px;
  width: 14px;
  height: 14px;
  min-width: 14px;
  min-height: 14px;
  background-color: #22c55e;
  border: 2.5px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  box-sizing: border-box;
  pointer-events: none;
  z-index: 5;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* Subtle Pulsing Ping Ring */
.aia-btn-status-dot::after {
  content: '';
  position: absolute;
  top: -2.5px;
  left: -2.5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: #22c55e;
  opacity: 0.75;
  animation: aiaStatusPing 2.2s cubic-bezier(0, 0, 0.2, 1) infinite;
  z-index: -1;
  pointer-events: none;
}

@keyframes aiaStatusPing {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }
  70%, 100% {
    transform: scale(2.1);
    opacity: 0;
  }
}

.aia-floating-button:hover {
  background: var(--aia-hover, var(--aia-primary-hover));
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}

.aia-floating-button:active {
  transform: translateY(0) scale(0.96);
}

.aia-floating-button.aia-position-left {
  right: auto;
  left: 24px;
}

/* Icon slot remains stable */
.aia-button-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 51px;
  height: 51px;
  min-width: 51px;
  min-height: 51px;
  max-width: 51px;
  max-height: 51px;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
}

.aia-button-icon svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  display: block;
}

.aia-btn-avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.aia-button-label {
  display: inline-block;
  max-width: 250px;
  padding-right: 18px;
  padding-left: 0;
  opacity: 1;
  white-space: nowrap;
  overflow: hidden;
  pointer-events: auto;
  transition: max-width 0.55s cubic-bezier(0.25, 1, 0.35, 1),
              padding-right 0.55s cubic-bezier(0.25, 1, 0.35, 1),
              opacity 0.4s ease 0.12s;
}

/* Perfect Circular Icon-Only Floating Button & Smooth Collapsed State on Open */
.aia-floating-button.aia-btn-icon-only,
.aia-floating-button.aia-btn-collapsed {
  width: 56px !important;
  min-width: 56px !important;
  max-width: 56px !important;
  height: 56px !important;
  min-height: 56px !important;
  max-height: 56px !important;
  padding: 0 !important;
  border-radius: 50% !important;
  justify-content: flex-start !important;
}

.aia-floating-button.aia-btn-collapsed .aia-button-label {
  max-width: 0 !important;
  padding-right: 0 !important;
  padding-left: 0 !important;
  margin: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transition: max-width 0.55s cubic-bezier(0.25, 1, 0.35, 1),
              padding-right 0.55s cubic-bezier(0.25, 1, 0.35, 1),
              opacity 0.3s ease;
}

/* Main Chat Modal Window */
.aia-chat-window {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: var(--aia-radius);
  box-shadow: var(--aia-shadow);
  border: 1px solid var(--aia-border-color);
  display: flex;
  flex-direction: column;
  z-index: var(--aia-z-index);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.aia-chat-window.aia-active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.aia-chat-window.aia-position-left {
  right: auto;
  left: 24px;
}

/* Header */
.aia-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--aia-primary);
  color: #ffffff;
}

.aia-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.aia-bot-avatar {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  box-sizing: border-box;
}

.aia-bot-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Force uploaded SVG or logo icons to be crisp pure white and centered */
.aia-avatar-svg,
.aia-bot-avatar img[src*=".svg"],
.aia-btn-avatar-img.aia-avatar-svg,
.aia-floating-button .aia-btn-avatar-img[src*=".svg"] {
  width: 24px !important;
  height: 24px !important;
  max-width: 24px !important;
  max-height: 24px !important;
  object-fit: contain !important;
  filter: brightness(0) invert(1) !important;
  margin: auto !important;
  display: block !important;
}

.aia-bot-avatar svg {
  width: 24px;
  height: 24px;
  fill: #ffffff;
  display: block;
}

.aia-header-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.aia-header-title {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  color: #ffffff;
  margin: 0;
  padding: 0;
}

.aia-online-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  line-height: 1;
  opacity: 0.92;
  color: #ffffff;
  margin: 0;
}

.aia-online-dot {
  width: 7px;
  height: 7px;
  min-width: 7px;
  min-height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.4);
}

.aia-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.aia-header-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.aia-header-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.aia-header-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Chat Messages Container */
.aia-chat-body {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--aia-bg-light);
  scroll-behavior: smooth;
}

.aia-message {
  display: flex;
  gap: 10px;
  max-width: 95%;
  animation: aiaFadeIn 0.3s ease-out;
  box-sizing: border-box;
}

.aia-message.aia-bot {
  align-self: flex-start;
  width: 100%;
}

.aia-message.aia-user {
  align-self: flex-end;
  display: flex;
  justify-content: flex-end;
  width: auto;
  max-width: 85%;
  margin-left: auto;
}

.aia-msg-bubble {
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: normal;
  box-sizing: border-box;
}

.aia-message.aia-bot .aia-msg-bubble {
  background: #ffffff;
  color: var(--aia-text-dark);
  border: 1px solid var(--aia-border-color);
  border-top-left-radius: 4px;
  width: 100%;
}

.aia-message.aia-user .aia-msg-bubble {
  background: var(--aia-primary);
  color: #ffffff;
  border-top-right-radius: 4px;
  width: auto;
  min-width: min-content;
  max-width: 100%;
  white-space: pre-wrap;
  display: inline-block;
}

.aia-msg-bubble p {
  margin: 0 0 8px 0;
}

.aia-msg-bubble p:last-child {
  margin-bottom: 0;
}

.aia-msg-bubble ul, .aia-msg-bubble ol {
  margin: 6px 0 6px 18px;
  padding: 0;
}

.aia-msg-bubble strong {
  font-weight: 600;
}

/* Product Cards 2-Column Responsive Grid */
.aia-products-carousel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 0 2px 0;
  margin-top: 8px;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.aia-product-card {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  border: 1px solid var(--aia-border-color);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
  transition: transform 0.2s, box-shadow 0.2s;
}

.aia-product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
}

.aia-card-image {
  width: 100%;
  height: 105px;
  background: #f8fafc;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.aia-card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
  box-sizing: border-box;
}

.aia-card-discount {
  position: absolute;
  top: 4px;
  left: 4px;
  background: #ef4444;
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
}

.aia-card-info {
  padding: 8px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.aia-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--aia-text-dark);
  margin: 0 0 4px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.25;
  min-height: 30px;
}

.aia-card-pricing {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  margin-bottom: 6px;
}

.aia-card-price {
  font-size: 13px;
  font-weight: 700;
  color: var(--aia-primary);
  line-height: 1.2;
}

.aia-card-old-price {
  font-size: 10px;
  color: var(--aia-text-muted);
  text-decoration: line-through;
}

.aia-card-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
  width: 100%;
}

.aia-card-btn {
  display: block;
  width: 100%;
  text-align: center;
  background: var(--aia-primary-light);
  color: var(--aia-primary);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 6px;
  text-decoration: none !important;
  border: none;
  cursor: pointer;
  box-sizing: border-box;
  transition: all 0.2s ease;
  line-height: 1.3;
}

.aia-card-btn:hover {
  background: var(--aia-hover, var(--aia-primary));
  color: #ffffff !important;
}

.aia-card-add-btn {
  background: var(--aia-primary);
  color: #ffffff !important;
}

.aia-card-add-btn:hover {
  background: var(--aia-hover, var(--aia-primary)) !important;
  color: #ffffff !important;
}

.aia-card-add-btn.aia-btn-success {
  background: #10b981 !important;
  color: #ffffff !important;
}

/* Typing indicator (Compact Floating Bubble with Only Dots) */
#aia-typing-indicator,
.aia-typing-container {
  width: auto !important;
  max-width: fit-content !important;
  align-self: flex-start !important;
}

.aia-msg-bubble.aia-typing {
  width: auto !important;
  max-width: fit-content !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px 16px;
  background: #ffffff;
  border: 1px solid var(--aia-border-color);
  border-radius: 16px;
  border-top-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.aia-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--aia-primary);
  opacity: 0.65;
  animation: aiaBounce 1.4s infinite ease-in-out both;
}

.aia-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.aia-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.aia-typing-dot:nth-child(3) { animation-delay: 0s; }

/* Input Bar */
.aia-chat-footer {
  padding: 12px 16px;
  background: #ffffff;
  border-top: 1px solid var(--aia-border-color);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.aia-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.aia-input-field {
  flex: 1;
  border: 1px solid var(--aia-border-color);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
  background: #f8fafc;
}

.aia-input-field:focus {
  border-color: var(--aia-primary);
  background: #ffffff;
}

.aia-send-btn {
  background: var(--aia-primary);
  color: #ffffff;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.aia-send-btn:hover {
  background: var(--aia-hover, var(--aia-primary-hover));
  transform: scale(1.05);
}

.aia-send-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  transform: translateX(1px);
}

.aia-footer-disclaimer {
  font-size: 10px;
  text-align: center;
  color: var(--aia-text-muted);
}

/* Animations */
@keyframes aiaFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes aiaBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Links and WhatsApp Call-to-Action */
.aia-chat-link {
  color: var(--aia-primary);
  font-weight: 600;
  text-decoration: underline;
  word-break: break-word;
  transition: opacity 0.2s;
}

.aia-chat-link:hover {
  opacity: 0.8;
}

.aia-whatsapp-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #25d366;
  color: #ffffff !important;
  font-weight: 600;
  font-size: 13.5px;
  line-height: 1.2;
  padding: 9px 16px;
  border-radius: 24px;
  text-decoration: none !important;
  margin: 6px 0;
  box-shadow: 0 3px 8px rgba(37, 211, 102, 0.3);
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  vertical-align: middle;
}

.aia-whatsapp-link:hover {
  background: #20ba5a;
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(37, 211, 102, 0.45);
  color: #ffffff !important;
}

.aia-wa-icon {
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  flex-shrink: 0;
  fill: currentColor;
  display: inline-block;
  vertical-align: middle;
}

/* Responsive Mobile View (Floating Compact Card) */
@media (max-width: 480px) {
  .aia-chat-window {
    bottom: 76px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: 390px;
    height: 480px;
    max-height: calc(100vh - 96px);
    max-height: calc(100dvh - 96px);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .aia-chat-window.aia-position-left {
    right: 12px;
    left: 12px;
  }

  .aia-floating-button {
    bottom: 16px;
    right: 16px;
    height: 50px;
    min-height: 50px;
    max-height: 50px;
    padding: 0;
    border-radius: 25px;
    font-size: 13.5px;
    border: 2px solid #ffffff !important;
  }

  .aia-floating-button .aia-button-icon {
    width: 46px !important;
    height: 46px !important;
    min-width: 46px !important;
    min-height: 46px !important;
    max-width: 46px !important;
    max-height: 46px !important;
    margin: 0 !important;
  }

  .aia-floating-button .aia-button-icon svg {
    width: 22px !important;
    height: 22px !important;
  }

  .aia-floating-button .aia-button-label {
    padding-right: 14px;
    font-size: 13px;
  }

  .aia-floating-button.aia-btn-icon-only,
  .aia-floating-button.aia-btn-collapsed {
    width: 50px !important;
    height: 50px !important;
    min-width: 50px !important;
    min-height: 50px !important;
    max-width: 50px !important;
    max-height: 50px !important;
    padding: 0 !important;
    border: 2px solid #ffffff !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 0 !important;
  }

  .aia-floating-button.aia-position-left {
    left: 16px;
    right: auto;
  }

  .aia-chat-header {
    padding: 10px 14px;
    position: sticky;
    top: 0;
    z-index: 20;
    flex-shrink: 0;
  }

  .aia-bot-avatar {
    width: 30px;
    height: 30px;
  }

  .aia-header-title {
    font-size: 13px;
  }

  .aia-chat-body {
    padding: 10px 12px;
    gap: 10px;
    flex: 1 1 0%;
    min-height: 0;
  }

  .aia-chat-footer {
    padding: 8px 10px;
    position: sticky;
    bottom: 0;
    z-index: 20;
    flex-shrink: 0;
  }

  .aia-input-field {
    padding: 8px 14px;
    font-size: 13px;
  }

  .aia-send-btn {
    width: 34px;
    height: 34px;
  }

  .aia-btn-status-dot {
    top: 0;
    right: 0;
    width: 13px;
    height: 13px;
    border-width: 2px;
  }

  .aia-btn-status-dot::after {
    top: -2px;
    left: -2px;
    width: 13px;
    height: 13px;
  }
}
