/**
 * NILWALA CEYLON — Nilwala AI Standalone & Assistant Stylesheet
 * ===============================================================
 * Premium lightweight gold, cream, and cinnamon interface.
 * Typography: Playfair Display (headings) + Poppins (body & UI).
 */

:root {
  --color-gold-primary: #D4AF37;
  --color-gold-soft: #E6C76A;
  --color-gold-deep: #A67C28;
  --color-dark-espresso: #211813;
  --color-deep-charcoal: #191919;
  --color-cinnamon-brown: #503528;
  --color-warm-bronze: #99704A;
  --color-warm-ivory: #F4EBDD;
  --color-bg-primary: #120E0B;
  --color-bg-secondary: #191410;
  --color-bg-surface: #211813;
  --color-text-primary: #F4EBDD;
  --color-text-secondary: #DCD0BD;
  --color-text-muted: #A89B87;
  --color-text-dim: #8D806E;
  --glass-border: rgba(212, 175, 55, 0.30);
  --glass-border-subtle: rgba(212, 175, 55, 0.16);
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Sinhala', sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  --duration-fast: 180ms;
}

/* ==========================================================================
   1. STANDALONE FULL-SCREEN SHELL
   ========================================================================== */
html.ai-standalone-html,
body.ai-standalone-body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at top right, #261A13 0%, #140F0C 55%, #0E0A08 100%);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

*, *::before, *::after {
  box-sizing: border-box;
}

.ai-standalone-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  background: rgba(20, 15, 12, 0.96);
  border-left: 1px solid var(--glass-border-subtle);
  border-right: 1px solid var(--glass-border-subtle);
}

/* ==========================================================================
   2. HEADER (BRANDING & QUICK SUPPORT)
   ========================================================================== */
.ai-standalone-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem 1.25rem;
  background: linear-gradient(180deg, #241913 0%, #19130F 100%);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.ai-brand-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.ai-brand-logo-wrap {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  background: #140F0C;
  border: 1px solid var(--color-gold-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  padding: 3px;
}

.ai-brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.ai-header-text {
  min-width: 0;
}

.ai-header-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ai-header-text h1,
.ai-header-text h3 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-warm-ivory);
  margin: 0;
  line-height: 1.2;
}

.ai-status-indicator {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--color-text-muted);
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: #66BB6A;
  flex-shrink: 0;
}

.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.ai-header-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-full);
  font-family: var(--font-sans);
  font-size: 0.74rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast);
  white-space: nowrap;
}

.ai-header-btn-gold {
  background: linear-gradient(135deg, var(--color-gold-primary), var(--color-gold-soft));
  color: #14100D;
  border: 1px solid var(--color-gold-soft);
}

.ai-header-btn-gold:hover {
  filter: brightness(1.06);
}

.ai-header-btn-outline {
  background: rgba(37, 211, 102, 0.1);
  color: #7EE39F;
  border: 1px solid rgba(37, 211, 102, 0.38);
}

.ai-header-btn-outline:hover {
  background: rgba(37, 211, 102, 0.2);
}

/* Mode Banner */
.ai-mode-banner {
  padding: 0.4rem 1.25rem;
  background: rgba(33, 24, 19, 0.8);
  border-bottom: 1px solid var(--glass-border-subtle);
  font-size: 0.7rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}

.ai-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--color-gold-soft);
  font-weight: 500;
}

.ai-mode-badge.live {
  color: #81C784;
}

.ai-lang-tag {
  color: var(--color-text-secondary);
  font-size: 0.68rem;
}

/* ==========================================================================
   3. MESSAGES STREAM
   ========================================================================== */
.ai-messages-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.15rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

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

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

.ai-bubble {
  padding: 0.9rem 1.1rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.ai-msg-bot .ai-bubble {
  background: #211813;
  border: 1px solid var(--glass-border-subtle);
  border-left: 3px solid var(--color-gold-primary);
  color: var(--color-text-secondary);
  border-bottom-left-radius: 4px;
}

.ai-msg-bot .ai-bubble strong {
  color: var(--color-warm-ivory);
  font-weight: 600;
}

.ai-msg-bot .ai-bubble strong.ai-md-heading {
  display: inline-block;
  margin-top: 0.35rem;
  color: var(--color-gold-soft);
}

.ai-msg-bot .ai-bubble em {
  color: var(--color-gold-soft);
  font-style: italic;
}

.ai-msg-user .ai-bubble {
  background: linear-gradient(135deg, var(--color-gold-primary) 0%, var(--color-gold-soft) 100%);
  color: #14100D;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}

.ai-msg-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.3rem;
  padding: 0 0.25rem;
}

.ai-msg-source-tag {
  font-size: 0.64rem;
  letter-spacing: 0.03em;
  padding: 0.14rem 0.5rem;
  border-radius: var(--radius-full);
}

.ai-msg-source-tag.preview {
  color: var(--color-gold-soft);
  background: rgba(212, 175, 55, 0.1);
  border: 1px solid rgba(212, 175, 55, 0.25);
}

.ai-msg-source-tag.live {
  color: #81C784;
  background: rgba(129, 199, 132, 0.12);
  border: 1px solid rgba(129, 199, 132, 0.3);
}

.ai-msg-time {
  font-size: 0.66rem;
  color: var(--color-text-dim);
}

.ai-msg-user .ai-msg-meta-row {
  justify-content: flex-end;
}

/* Bot Action Button inside bubble */
.ai-msg-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.ai-msg-action-btn {
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-full);
  background: rgba(212, 175, 55, 0.14);
  border: 1px solid var(--color-gold-primary);
  color: var(--color-gold-soft);
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--duration-fast), color var(--duration-fast);
}

.ai-msg-action-btn:hover {
  background: var(--color-gold-primary);
  color: #14100D;
}

/* ==========================================================================
   4. LIGHTWEIGHT TEXT-BASED INTERACTIVE ORDER CARD
   ========================================================================== */
.ai-product-card {
  margin-top: 0.85rem;
  background: linear-gradient(160deg, #271C15 0%, #19130F 100%);
  border: 1px solid rgba(212, 175, 55, 0.42);
  border-radius: 16px;
  padding: 0.95rem 1.05rem;
  color: var(--color-text-primary);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: 440px;
}

.ai-product-text-header {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.ai-product-brand {
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-gold-soft);
}

.ai-product-title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-warm-ivory);
  margin: 0;
  line-height: 1.25;
}

.ai-product-meta {
  font-size: 0.78rem;
  color: var(--color-text-secondary);
  margin-top: 0.15rem;
}

.ai-product-controls {
  margin-top: 0.85rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--glass-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ai-qty-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-qty-label {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.ai-qty-stepper {
  display: inline-flex;
  align-items: center;
  background: #120E0B;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.ai-qty-btn {
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: var(--color-gold-soft);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--duration-fast), color var(--duration-fast);
}

.ai-qty-btn:hover:not(:disabled) {
  background: rgba(212, 175, 55, 0.18);
  color: var(--color-warm-ivory);
}

.ai-qty-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.ai-qty-value {
  min-width: 34px;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-warm-ivory);
  font-variant-numeric: tabular-nums;
}

.ai-subtotal-box {
  text-align: right;
}

.ai-subtotal-label {
  display: block;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.ai-subtotal-amount {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--color-gold-soft);
  font-variant-numeric: tabular-nums;
}

.ai-whatsapp-order-btn {
  margin-top: 0.8rem;
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #25D366 0%, #1DA851 100%);
  color: #081C0E;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  border: none;
  transition: filter var(--duration-fast);
}

.ai-whatsapp-order-btn:hover {
  filter: brightness(1.06);
}

.ai-product-note {
  margin-top: 0.55rem;
  font-size: 0.7rem;
  line-height: 1.45;
  color: var(--color-text-muted);
}

.ai-product-note.opened {
  color: #9CE7B6;
  background: rgba(37, 211, 102, 0.08);
  border: 1px solid rgba(37, 211, 102, 0.25);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}

/* Typing Indicator */
.ai-typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.75rem 1rem;
  background: #211813;
  border: 1px solid var(--glass-border-subtle);
  border-radius: 14px;
}

.ai-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-gold-primary);
  animation: aiDotPulse 1.2s infinite ease-in-out;
}

.ai-typing-dot:nth-child(2) { animation-delay: 0.18s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes aiDotPulse {
  0%, 80%, 100% { transform: scale(0.65); opacity: 0.45; }
  40% { transform: scale(1.05); opacity: 1; }
}

/* ==========================================================================
   5. QUICK-ACTION SUGGESTIONS BAR
   ========================================================================== */
.ai-suggestions-tray {
  padding: 0.6rem 1.25rem;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  flex-shrink: 0;
  background: #140F0C;
  border-top: 1px solid var(--glass-border-subtle);
  scrollbar-width: none;
}

.ai-suggestions-tray::-webkit-scrollbar {
  display: none;
}

.ai-chip {
  padding: 0.42rem 0.85rem;
  border-radius: var(--radius-full);
  background: #211813;
  border: 1px solid var(--glass-border-subtle);
  color: var(--color-text-secondary);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: border-color var(--duration-fast), color var(--duration-fast), background-color var(--duration-fast);
}

.ai-chip:hover {
  border-color: var(--color-gold-primary);
  color: var(--color-gold-soft);
  background: rgba(212, 175, 55, 0.1);
}

.ai-chip-primary {
  border-color: rgba(212, 175, 55, 0.5);
  color: var(--color-gold-soft);
  background: rgba(212, 175, 55, 0.1);
}

.ai-chip-whatsapp {
  border-color: rgba(37, 211, 102, 0.38);
  color: #7EE39F;
}

/* ==========================================================================
   6. COMPOSER INPUT & FOOTER
   ========================================================================== */
.ai-input-wrapper {
  padding: 0.75rem 1.25rem 0.4rem;
  background: #16110E;
  border-top: 1px solid var(--glass-border-subtle);
  flex-shrink: 0;
}

.ai-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #0F0C0A;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  padding: 0.3rem 0.4rem 0.3rem 1.05rem;
}

.ai-form:focus-within {
  border-color: var(--color-gold-primary);
}

.ai-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  min-width: 0;
}

.ai-input::placeholder {
  color: var(--color-text-dim);
}

.ai-send-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--color-gold-primary);
  border: none;
  color: #14100D;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--duration-fast);
}

.ai-send-btn:hover:not(:disabled) {
  background: var(--color-gold-soft);
}

.ai-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-footer-disclaimer {
  font-size: 0.67rem;
  color: var(--color-text-dim);
  text-align: center;
  padding: 0.35rem 1rem 0.65rem;
  background: #16110E;
  line-height: 1.4;
  flex-shrink: 0;
}

/* ==========================================================================
   7. FLOATING DOCK FALLBACK (RETAINED FOR REVERSIBLE FULL-WEBSITE MODE)
   ========================================================================== */
.nilwala-ai-dock {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 990;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 1.25rem 0.75rem 0.95rem;
  background: rgba(26, 20, 16, 0.92);
  border: 1px solid var(--color-gold-primary);
  border-radius: var(--radius-full);
  color: var(--color-warm-ivory);
  font-family: var(--font-sans);
  cursor: pointer;
}

.nilwala-ai-window {
  position: fixed;
  bottom: 84px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 590px;
  max-height: calc(100vh - 110px);
  z-index: 995;
  background: rgba(22, 17, 14, 0.96);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.nilwala-ai-window.open {
  display: flex;
}

/* ==========================================================================
   8. RESPONSIVE MOBILE & TABLET TUNING
   ========================================================================== */
@media (max-width: 640px) {
  .ai-standalone-shell {
    border-left: none;
    border-right: none;
  }

  .ai-standalone-header {
    padding: 0.7rem 0.9rem;
  }

  .ai-brand-logo-wrap {
    width: 36px;
    height: 36px;
  }

  .ai-header-text h1 {
    font-size: 1.02rem;
  }

  .ai-header-btn-outline .ai-btn-label-long {
    display: none;
  }

  .ai-mode-banner {
    padding: 0.35rem 0.9rem;
  }

  .ai-messages-body {
    padding: 0.85rem 0.85rem;
  }

  .ai-msg {
    max-width: 94%;
  }

  .ai-bubble {
    padding: 0.8rem 0.95rem;
    font-size: 0.86rem;
  }

  .ai-product-card {
    padding: 0.85rem;
  }

  .ai-product-thumb {
    width: 72px;
    height: 72px;
  }

  .ai-suggestions-tray {
    padding: 0.5rem 0.85rem;
  }

  .ai-input-wrapper {
    padding: 0.6rem 0.85rem 0.35rem;
  }

  .ai-footer-disclaimer {
    padding: 0.25rem 0.85rem 0.55rem;
    font-size: 0.63rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-messages-body {
    scroll-behavior: auto;
  }
  .ai-typing-dot {
    animation: none;
  }
}
