/**
 * Web24 AI Assistant — Chatbot Frontend Styles
 * Premium dark glassmorphism UI
 */

/* ─── CSS Variables ─────────────────────────────────────────────────────────── */
#web24-ai-wrapper {
  --web24-primary:      #6c63ff;
  --web24-primary-glow: rgba(108, 99, 255, 0.35);
  --web24-bg:           #0d0d14;
  --web24-surface:      #141420;
  --web24-surface-2:    #1c1c2e;
  --web24-surface-3:    #232336;
  --web24-border:       rgba(255, 255, 255, 0.08);
  --web24-text:         #e8e8f0;
  --web24-text-muted:   rgba(232, 232, 240, 0.5);
  --web24-user-bubble:  var(--web24-primary);
  --web24-bot-bubble:   var(--web24-surface-3);
  --web24-radius:       20px;
  --web24-radius-sm:    12px;
  --web24-shadow:       0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--web24-border);
  --web24-font:         -apple-system, 'Segoe UI', 'Inter', sans-serif;
  --web24-z:            999999;
  --web24-speed:        0.25s;
}

/* ─── Resets (scoped) ────────────────────────────────────────────────────────── */
#web24-ai-wrapper *,
#web24-ai-wrapper *::before,
#web24-ai-wrapper *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Wrapper ────────────────────────────────────────────────────────────────── */
#web24-ai-wrapper {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--web24-z);
  font-family: var(--web24-font);
}

/* ─── Trigger Button ─────────────────────────────────────────────────────────── */
.web24-trigger {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--web24-primary), color-mix(in srgb, var(--web24-primary) 70%, #ff6b9d));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--web24-primary-glow), 0 2px 8px rgba(0,0,0,0.3);
  transition: transform var(--web24-speed) cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow var(--web24-speed) ease;
  overflow: visible;
}

.web24-trigger:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 8px 30px var(--web24-primary-glow), 0 4px 12px rgba(0,0,0,0.4);
}

.web24-trigger:active {
  transform: scale(0.95);
}

/* Icon toggle */
.web24-trigger__icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--web24-speed) ease, transform var(--web24-speed) cubic-bezier(0.34, 1.56, 0.64, 1);
}

.web24-trigger__icon--close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.web24-trigger.is-open .web24-trigger__icon--open {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.web24-trigger.is-open .web24-trigger__icon--close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Pulse ring */
.web24-trigger__pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--web24-primary);
  opacity: 0;
  animation: web24-pulse 2.5s ease-out infinite;
}

@keyframes web24-pulse {
  0%   { transform: scale(1);    opacity: 0.7; }
  70%  { transform: scale(1.4);  opacity: 0;   }
  100% { transform: scale(1.4);  opacity: 0;   }
}

/* ─── Chat Window ────────────────────────────────────────────────────────────── */
.web24-chat {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  max-height: 580px;
  display: flex;
  flex-direction: column;
  background: var(--web24-surface);
  border-radius: var(--web24-radius);
  border: 1px solid var(--web24-border);
  box-shadow: var(--web24-shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity var(--web24-speed) ease,
              transform var(--web24-speed) cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: bottom right;
}

.web24-chat.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ─── Header ─────────────────────────────────────────────────────────────────── */
.web24-chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px;
  background: linear-gradient(135deg, var(--web24-primary), color-mix(in srgb, var(--web24-primary) 60%, #9c27b0));
  position: relative;
  flex-shrink: 0;
}

.web24-chat__header::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}

.web24-chat__avatar {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.25);
}

.web24-chat__avatar-text {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}

.web24-chat__status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  background: #22c55e;
  border-radius: 50%;
  border: 2px solid var(--web24-primary);
}

.web24-chat__header-info {
  flex: 1;
  min-width: 0;
}

.web24-chat__name {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.web24-chat__subtitle {
  font-size: 11px;
  color: rgba(255,255,255,0.75);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.web24-chat__header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 1;
}

/* ─── Icon Buttons ───────────────────────────────────────────────────────────── */
.web24-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.web24-icon-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.05);
}

.web24-icon-btn--voice.active {
  background: rgba(255, 255, 255, 0.25);
}

.web24-icon-btn--voice:not(.active) {
  opacity: 0.6;
}

.web24-icon-btn--whatsapp {
  background: rgba(37, 211, 102, 0.25);
}

.web24-icon-btn--whatsapp:hover {
  background: rgba(37, 211, 102, 0.4);
}

/* ─── Messages ───────────────────────────────────────────────────────────────── */
.web24-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.web24-chat__messages::-webkit-scrollbar {
  width: 4px;
}
.web24-chat__messages::-webkit-scrollbar-track {
  background: transparent;
}
.web24-chat__messages::-webkit-scrollbar-thumb {
  background: var(--web24-border);
  border-radius: 2px;
}

/* Message bubbles */
.web24-msg {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  animation: web24-msg-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes web24-msg-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1);     }
}

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

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

.web24-msg__bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.web24-msg--user .web24-msg__bubble {
  background: linear-gradient(135deg, var(--web24-primary), color-mix(in srgb, var(--web24-primary) 75%, #ff6b9d));
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 12px var(--web24-primary-glow);
}

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

.web24-msg__time {
  font-size: 10px;
  color: var(--web24-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* Navigation card */
.web24-nav-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 14px;
  background: linear-gradient(135deg, var(--web24-primary), color-mix(in srgb, var(--web24-primary) 70%, #9c27b0));
  border-radius: 10px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 2px 12px var(--web24-primary-glow);
}

.web24-nav-card:hover {
  opacity: 0.88;
  transform: translateY(-1px);
  color: #fff;
  text-decoration: none;
}

.web24-nav-card svg {
  flex-shrink: 0;
}

/* ─── Typing Indicator ───────────────────────────────────────────────────────── */
.web24-chat__typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 8px;
  flex-shrink: 0;
}

.web24-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--web24-surface-3);
  border-radius: 14px;
  border: 1px solid var(--web24-border);
}

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

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

@keyframes web24-typing-dot {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.5; }
  30%            { transform: translateY(-5px); opacity: 1;   }
}

.web24-typing-label {
  font-size: 11px;
  color: var(--web24-text-muted);
  font-style: italic;
}

/* ─── Input Area ─────────────────────────────────────────────────────────────── */
.web24-chat__input-area {
  padding: 12px;
  background: var(--web24-surface-2);
  border-top: 1px solid var(--web24-border);
  flex-shrink: 0;
}

.web24-chat__input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--web24-surface-3);
  border: 1px solid var(--web24-border);
  border-radius: var(--web24-radius-sm);
  padding: 8px 8px 8px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.web24-chat__input-wrapper:focus-within {
  border-color: var(--web24-primary);
  box-shadow: 0 0 0 3px var(--web24-primary-glow);
}

.web24-chat__input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--web24-text);
  font-size: 14px;
  font-family: var(--web24-font);
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  scrollbar-width: none;
}

.web24-chat__input::placeholder {
  color: var(--web24-text-muted);
}

.web24-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--web24-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 2px 8px var(--web24-primary-glow);
}

.web24-send-btn:hover {
  transform: scale(1.08);
}

.web24-send-btn:active {
  transform: scale(0.93);
}

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

.web24-chat__footer-bar {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

.web24-powered {
  font-size: 10px;
  color: var(--web24-text-muted);
  letter-spacing: 0.3px;
}

.web24-powered strong {
  color: var(--web24-primary);
}

/* ─── Error Message ──────────────────────────────────────────────────────────── */
.web24-msg--error .web24-msg__bubble {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* ─── Mobile Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #web24-ai-wrapper {
    bottom: 16px;
    right: 16px;
  }

  .web24-chat {
    width: calc(100vw - 32px);
    right: -16px;
    bottom: 72px;
    max-height: calc(100vh - 120px);
    border-radius: var(--web24-radius) var(--web24-radius) 0 0;
  }
}

@media (max-height: 600px) {
  .web24-chat {
    max-height: calc(100vh - 100px);
  }
}

/* ─── Accessibility ──────────────────────────────────────────────────────────── */
.web24-trigger:focus-visible,
.web24-send-btn:focus-visible,
.web24-icon-btn:focus-visible {
  outline: 2px solid var(--web24-primary);
  outline-offset: 2px;
}

/* ─── Quick Reply Chips ───────────────────────────────────────────────────────── */
.web24-chat__quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 4px;
  border-top: 1px solid var(--web24-border);
  background: var(--web24-surface-2);
  flex-shrink: 0;
}

.web24-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--web24-border);
  border-radius: 20px;
  color: var(--web24-text-muted);
  font-size: 12px;
  font-family: var(--web24-font);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.web24-chip:hover {
  background: var(--web24-surface-3);
  border-color: var(--web24-primary);
  color: var(--web24-text);
}

.web24-chat__quick-replies.is-hidden {
  display: none;
}

/* ─── Left Position Support ──────────────────────────────────────────────────── */
#web24-ai-wrapper.web24-pos-left {
  right: auto !important;
  left: 24px;
}

.web24-chat--left {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

/* ─── WooCommerce Product Card ───────────────────────────────────────────────── */
.web24-product-card {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  padding: 10px;
  background: var(--web24-surface-2);
  border: 1px solid var(--web24-border);
  border-radius: 10px;
  text-decoration: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.web24-product-card:hover {
  border-color: var(--web24-primary);
  background: var(--web24-surface-3);
  text-decoration: none;
}

.web24-product-card__img {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.web24-product-card__info {
  flex: 1;
  min-width: 0;
}

.web24-product-card__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--web24-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.web24-product-card__price {
  font-size: 12px;
  color: var(--web24-primary);
  margin-top: 2px;
}

.web24-product-card__btn {
  flex-shrink: 0;
  padding: 5px 10px;
  background: var(--web24-primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--web24-font);
  transition: opacity 0.2s ease;
}

.web24-product-card__btn:hover {
  opacity: 0.85;
}

/* ─── Navigation countdown bar ──────────────────────────────────────────────── */
.web24-nav-countdown {
  height: 3px;
  background: var(--web24-primary);
  border-radius: 2px;
  margin-top: 6px;
  animation: web24-countdown 3s linear forwards;
  transform-origin: left;
}

@keyframes web24-countdown {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}
