/* ============================================================
   AI Order Assistant — Chat Widget CSS
   Premium floating chat UI for WooCommerce
   ============================================================ */

/* ── CSS Variables (Light Theme) ─────────────────────────────────────────── */
:root {
  --aoa-primary:          #6366f1;
  --aoa-primary-dark:     #4f46e5;
  --aoa-primary-light:    #e0e7ff;
  --aoa-primary-glow:     rgba(99, 102, 241, 0.3);

  --aoa-bg:               #ffffff;
  --aoa-bg-2:             #f8fafc;
  --aoa-bg-3:             #f1f5f9;

  --aoa-text:             #0f172a;
  --aoa-text-2:           #475569;
  --aoa-text-3:           #94a3b8;

  --aoa-border:           #e2e8f0;
  --aoa-border-2:         #cbd5e1;

  --aoa-bubble-user-bg:   var(--aoa-primary);
  --aoa-bubble-user-text: #ffffff;
  --aoa-bubble-ai-bg:     #f1f5f9;
  --aoa-bubble-ai-text:   #0f172a;

  --aoa-shadow-sm:  0 2px 8px rgba(0,0,0,0.08);
  --aoa-shadow-md:  0 8px 24px rgba(0,0,0,0.12);
  --aoa-shadow-lg:  0 20px 48px rgba(0,0,0,0.18);
  --aoa-shadow-xl:  0 32px 64px rgba(0,0,0,0.22);

  --aoa-radius-sm: 8px;
  --aoa-radius-md: 14px;
  --aoa-radius-lg: 20px;
  --aoa-radius-xl: 24px;
  --aoa-radius-full: 9999px;

  --aoa-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
  --aoa-font-arabic: 'Segoe UI', 'Tahoma', 'Arabic Typesetting', sans-serif;

  --aoa-transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --aoa-transition-spring: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);

  --aoa-z: 999999;
}

/* ── Dark Theme ──────────────────────────────────────────────────────────── */
#aoa-chat-container[data-theme="dark"] {
  --aoa-bg:               #0f172a;
  --aoa-bg-2:             #1e293b;
  --aoa-bg-3:             #293548;

  --aoa-text:             #f1f5f9;
  --aoa-text-2:           #94a3b8;
  --aoa-text-3:           #64748b;

  --aoa-border:           #334155;
  --aoa-border-2:         #475569;

  --aoa-bubble-ai-bg:     #1e293b;
  --aoa-bubble-ai-text:   #f1f5f9;

  --aoa-shadow-lg:  0 20px 48px rgba(0,0,0,0.5);
  --aoa-shadow-xl:  0 32px 64px rgba(0,0,0,0.6);
}

/* ── Container / Positioning ─────────────────────────────────────────────── */
#aoa-chat-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--aoa-z);
  font-family: var(--aoa-font);
  line-height: 1.5;
  font-size: 14px;
  color: var(--aoa-text);
  -webkit-font-smoothing: antialiased;
}

#aoa-chat-container.aoa-pos-left {
  right: auto;
  left: 24px;
}

/* ── Floating Bubble ─────────────────────────────────────────────────────── */
#aoa-chat-bubble {
  width: 60px;
  height: 60px;
  border-radius: var(--aoa-radius-full);
  background: linear-gradient(135deg, var(--aoa-primary) 0%, var(--aoa-primary-dark) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 20px var(--aoa-primary-glow), 0 8px 32px rgba(0,0,0,0.2);
  transition: transform var(--aoa-transition-spring), box-shadow var(--aoa-transition);
  position: relative;
  outline: none;
  animation: aoa-bubble-in 0.5s var(--aoa-transition-spring);
}

#aoa-chat-bubble:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 8px 32px var(--aoa-primary-glow), 0 12px 40px rgba(0,0,0,0.25);
}

#aoa-chat-bubble:active {
  transform: scale(0.95);
}

#aoa-chat-bubble::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: var(--aoa-radius-full);
  background: linear-gradient(135deg, var(--aoa-primary), var(--aoa-primary-dark));
  opacity: 0;
  z-index: -1;
  animation: aoa-pulse-ring 2.5s ease-in-out infinite;
}

.aoa-bubble-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--aoa-transition), opacity var(--aoa-transition);
}

.aoa-unread-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  background: #ef4444;
  color: #fff;
  border-radius: var(--aoa-radius-full);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: aoa-bounce 1s ease-in-out infinite;
}

/* ── Chat Window ─────────────────────────────────────────────────────────── */
.aoa-chat-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--aoa-bg);
  border-radius: var(--aoa-radius-xl);
  box-shadow: var(--aoa-shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--aoa-border);
  transform-origin: bottom right;
  transition: transform var(--aoa-transition-spring), opacity var(--aoa-transition);
}

#aoa-chat-container.aoa-pos-left .aoa-chat-window {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.aoa-chat-window.aoa-hidden {
  transform: scale(0.85) translateY(16px);
  opacity: 0;
  pointer-events: none;
}

.aoa-chat-window.aoa-visible {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.aoa-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--aoa-primary) 0%, var(--aoa-primary-dark) 100%);
  color: #fff;
  flex-shrink: 0;
  gap: 10px;
}

.aoa-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.aoa-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--aoa-radius-full);
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  position: relative;
  flex-shrink: 0;
  color: #fff;
  border: 2px solid rgba(255,255,255,0.3);
}

.aoa-avatar--sm {
  width: 28px;
  height: 28px;
  font-size: 10px;
  border: none;
  background: var(--aoa-primary-light);
  color: var(--aoa-primary);
}

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

.aoa-header-info { min-width: 0; }

.aoa-header-title {
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.aoa-header-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  margin-top: 1px;
}

.aoa-status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: var(--aoa-radius-full);
  animation: aoa-pulse-dot 2s ease-in-out infinite;
}

.aoa-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.aoa-lang-select {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  border-radius: var(--aoa-radius-sm);
  padding: 4px 6px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
  transition: background var(--aoa-transition);
}

.aoa-lang-select option { color: #0f172a; background: #fff; }
.aoa-lang-select:hover { background: rgba(255,255,255,0.25); }

.aoa-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--aoa-radius-sm);
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--aoa-transition);
  outline: none;
  padding: 0;
}

.aoa-icon-btn:hover { background: rgba(255,255,255,0.3); }
.aoa-icon-btn:active { background: rgba(255,255,255,0.1); }

/* ── Messages Area ───────────────────────────────────────────────────────── */
.aoa-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--aoa-bg);
  scroll-behavior: smooth;
}

.aoa-messages::-webkit-scrollbar { width: 4px; }
.aoa-messages::-webkit-scrollbar-track { background: transparent; }
.aoa-messages::-webkit-scrollbar-thumb { background: var(--aoa-border-2); border-radius: 4px; }
.aoa-messages::-webkit-scrollbar-thumb:hover { background: var(--aoa-text-3); }

/* ── Message Bubbles ─────────────────────────────────────────────────────── */
.aoa-message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: aoa-msg-in 0.3s var(--aoa-transition-spring);
}

.aoa-message--user {
  flex-direction: row-reverse;
}

.aoa-message--ai .aoa-avatar--sm {
  flex-shrink: 0;
  align-self: flex-end;
}

.aoa-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--aoa-radius-md);
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
  box-shadow: var(--aoa-shadow-sm);
}

.aoa-message--ai .aoa-bubble {
  background: var(--aoa-bubble-ai-bg);
  color: var(--aoa-bubble-ai-text);
  border-bottom-left-radius: 4px;
}

.aoa-message--user .aoa-bubble {
  background: var(--aoa-bubble-user-bg);
  color: var(--aoa-bubble-user-text);
  border-bottom-right-radius: 4px;
}

.aoa-bubble-time {
  font-size: 10px;
  color: var(--aoa-text-3);
  margin-top: 4px;
  text-align: right;
}

.aoa-message--ai .aoa-bubble-time {
  text-align: left;
  padding-left: 36px;
}

/* ── Typing Indicator ────────────────────────────────────────────────────── */
.aoa-typing-indicator {
  padding: 0 16px 8px;
  flex-shrink: 0;
}

.aoa-typing-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
}

.aoa-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--aoa-bubble-ai-bg);
  padding: 10px 14px;
  border-radius: var(--aoa-radius-md);
  border-bottom-left-radius: 4px;
}

.aoa-typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--aoa-text-3);
  border-radius: 50%;
  animation: aoa-typing 1.4s ease-in-out infinite;
}

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

/* ── Input Area ──────────────────────────────────────────────────────────── */
.aoa-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  background: var(--aoa-bg);
  border-top: 1px solid var(--aoa-border);
  flex-shrink: 0;
}

.aoa-input {
  flex: 1;
  border: 1.5px solid var(--aoa-border);
  border-radius: var(--aoa-radius-md);
  padding: 10px 14px;
  font-family: var(--aoa-font);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  background: var(--aoa-bg-2);
  color: var(--aoa-text);
  transition: border-color var(--aoa-transition), box-shadow var(--aoa-transition);
  max-height: 100px;
  overflow-y: auto;
  display: block;
  box-sizing: border-box;
}

.aoa-input:focus {
  border-color: var(--aoa-primary);
  box-shadow: 0 0 0 3px var(--aoa-primary-glow);
  background: var(--aoa-bg);
}

.aoa-input::placeholder { color: var(--aoa-text-3); }

.aoa-send-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--aoa-radius-full);
  background: linear-gradient(135deg, var(--aoa-primary), var(--aoa-primary-dark));
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--aoa-transition-spring), box-shadow var(--aoa-transition), opacity var(--aoa-transition);
  outline: none;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--aoa-primary-glow);
}

.aoa-send-btn:hover { transform: scale(1.05); box-shadow: 0 6px 16px var(--aoa-primary-glow); }
.aoa-send-btn:active { transform: scale(0.95); }
.aoa-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Footer Bar ──────────────────────────────────────────────────────────── */
.aoa-footer-bar {
  padding: 7px 14px;
  text-align: center;
  font-size: 11px;
  color: var(--aoa-text-3);
  background: var(--aoa-bg-2);
  border-top: 1px solid var(--aoa-border);
  flex-shrink: 0;
}

/* ── Product Cards ───────────────────────────────────────────────────────── */
.aoa-products-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}

.aoa-product-card {
  display: flex;
  gap: 10px;
  background: var(--aoa-bg);
  border: 1.5px solid var(--aoa-border);
  border-radius: var(--aoa-radius-md);
  padding: 10px;
  cursor: pointer;
  transition: border-color var(--aoa-transition), transform var(--aoa-transition), box-shadow var(--aoa-transition);
  animation: aoa-card-in 0.3s var(--aoa-transition-spring) both;
  text-decoration: none;
  align-items: center;
}

.aoa-product-card:nth-child(2) { animation-delay: 0.05s; }
.aoa-product-card:nth-child(3) { animation-delay: 0.10s; }
.aoa-product-card:nth-child(4) { animation-delay: 0.15s; }

.aoa-product-card:hover {
  border-color: var(--aoa-primary);
  transform: translateX(2px);
  box-shadow: var(--aoa-shadow-sm), -3px 0 0 var(--aoa-primary);
}

.aoa-product-card.aoa-out-of-stock { opacity: 0.6; cursor: default; }

.aoa-product-img {
  width: 56px;
  height: 56px;
  border-radius: var(--aoa-radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--aoa-bg-3);
}

.aoa-product-info { flex: 1; min-width: 0; }

.aoa-product-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--aoa-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.aoa-product-price {
  font-weight: 700;
  color: var(--aoa-primary);
  font-size: 14px;
}

.aoa-product-meta {
  font-size: 11px;
  color: var(--aoa-text-3);
  margin-top: 2px;
}

.aoa-product-stock {
  font-size: 11px;
  margin-top: 2px;
}

.aoa-product-stock--in  { color: #16a34a; }
.aoa-product-stock--out { color: #dc2626; }

.aoa-product-select-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--aoa-radius-full);
  background: var(--aoa-primary-light);
  border: none;
  color: var(--aoa-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--aoa-transition), color var(--aoa-transition);
  font-size: 16px;
}

.aoa-product-card:hover .aoa-product-select-btn {
  background: var(--aoa-primary);
  color: #fff;
}

/* ── Order Summary Card ──────────────────────────────────────────────────── */
.aoa-order-summary {
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
  border: 1.5px solid #86efac;
  border-radius: var(--aoa-radius-md);
  padding: 14px;
  margin-top: 8px;
  animation: aoa-msg-in 0.35s var(--aoa-transition-spring);
}

#aoa-chat-container[data-theme="dark"] .aoa-order-summary {
  background: linear-gradient(135deg, #052e16 0%, #14532d 100%);
  border-color: #166534;
}

.aoa-order-summary h4 {
  margin: 0 0 10px;
  color: #15803d;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#aoa-chat-container[data-theme="dark"] .aoa-order-summary h4 { color: #4ade80; }

.aoa-order-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
  color: var(--aoa-text-2);
}

.aoa-order-row strong { color: var(--aoa-text); }

.aoa-order-total {
  border-top: 1px solid #86efac;
  margin-top: 8px;
  padding-top: 8px;
  font-weight: 700;
  font-size: 15px;
  color: #15803d;
}

#aoa-chat-container[data-theme="dark"] .aoa-order-total { color: #4ade80; }

/* ── Quick Replies / Chips ────────────────────────────────────────────────── */
.aoa-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.aoa-quick-reply {
  padding: 6px 12px;
  background: var(--aoa-bg);
  border: 1.5px solid var(--aoa-primary);
  color: var(--aoa-primary);
  border-radius: var(--aoa-radius-full);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--aoa-transition);
  white-space: nowrap;
  outline: none;
}

.aoa-quick-reply:hover {
  background: var(--aoa-primary);
  color: #fff;
  transform: translateY(-1px);
}

/* ── Date Divider ────────────────────────────────────────────────────────── */
.aoa-date-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--aoa-text-3);
  text-align: center;
}

.aoa-date-divider::before,
.aoa-date-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--aoa-border);
}

/* ── Welcome Screen ──────────────────────────────────────────────────────── */
.aoa-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 24px;
  gap: 12px;
  flex: 1;
}

.aoa-welcome-avatar {
  width: 64px;
  height: 64px;
  border-radius: var(--aoa-radius-full);
  background: linear-gradient(135deg, var(--aoa-primary), var(--aoa-primary-dark));
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px var(--aoa-primary-glow);
  margin-bottom: 4px;
}

.aoa-welcome h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--aoa-text);
}

.aoa-welcome p {
  margin: 0;
  font-size: 13px;
  color: var(--aoa-text-2);
  line-height: 1.6;
}

.aoa-welcome-btn {
  margin-top: 8px;
  padding: 10px 24px;
  background: linear-gradient(135deg, var(--aoa-primary), var(--aoa-primary-dark));
  color: #fff;
  border: none;
  border-radius: var(--aoa-radius-full);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--aoa-transition-spring), box-shadow var(--aoa-transition);
  box-shadow: 0 4px 12px var(--aoa-primary-glow);
  outline: none;
}

.aoa-welcome-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px var(--aoa-primary-glow);
}

/* ── RTL Support ─────────────────────────────────────────────────────────── */
.aoa-rtl .aoa-bubble { font-family: var(--aoa-font-arabic); direction: rtl; text-align: right; }
.aoa-rtl .aoa-input  { direction: rtl; text-align: right; font-family: var(--aoa-font-arabic); }

/* ── Hidden utility ──────────────────────────────────────────────────────── */
.aoa-hidden { display: none !important; }

/* ── Animations ──────────────────────────────────────────────────────────── */
@keyframes aoa-bubble-in {
  from { transform: scale(0) rotate(-15deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes aoa-msg-in {
  from { transform: translateY(8px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes aoa-card-in {
  from { transform: translateX(-8px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes aoa-typing {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1; }
}

@keyframes aoa-pulse-ring {
  0%   { transform: scale(1); opacity: 0.6; }
  70%  { transform: scale(1.5); opacity: 0; }
  100% { transform: scale(1.5); opacity: 0; }
}

@keyframes aoa-pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

@keyframes aoa-bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-3px); }
}

/* ── Mobile Responsive ───────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #aoa-chat-container {
    bottom: 0;
    right: 0;
    left: 0;
  }

  #aoa-chat-container.aoa-pos-left {
    right: 0;
    left: 0;
  }

  #aoa-chat-bubble {
    right: 16px;
    bottom: 16px;
    position: fixed;
  }

  #aoa-chat-container.aoa-pos-left #aoa-chat-bubble {
    right: auto;
    left: 16px;
  }

  .aoa-chat-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
    transform-origin: bottom center;
  }

  #aoa-chat-container.aoa-pos-left .aoa-chat-window {
    right: 0;
    left: 0;
    transform-origin: bottom center;
  }

  .aoa-chat-window.aoa-hidden {
    transform: translateY(100%);
  }

  .aoa-chat-window.aoa-visible {
    transform: translateY(0);
  }
}

@media (max-width: 360px) {
  .aoa-bubble { max-width: 88%; font-size: 13px; }
  .aoa-product-img { width: 46px; height: 46px; }
}
