:root {
  /* Fallback color variables for the chatbot if not defined by the theme */
  --primary-bg: #FFFFFF;
  --secondary-bg: #F9F6F0;
  --dark-bg: #1A1816;
  --accent-bg: #C5A880;
  --black-bg: #000000;
  --text-dark: #1A1816;
  --text-light: #FFFFFF;
  --text-muted: rgba(255, 255, 255, 0.7);
  --text-muted-dark: rgba(26, 24, 22, 0.65);
  --border-light: rgba(197, 168, 128, 0.25);
  --border-dark: rgba(26, 24, 22, 0.08);
  --font-family: 'Cairo', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ==========================================================================
   CHAT WIDGET SYSTEM
   ========================================================================== */
.chat-widget-container {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

/* Auto-Greet Bubble */
.auto-greet-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(26, 24, 22, 0.96);
  border: 1px solid var(--accent-bg);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  animation: greetSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transition: opacity 0.4s ease;
  max-width: 260px;
}
.auto-greet-bubble:hover {
  border-color: #fff;
  box-shadow: 0 10px 35px rgba(197, 168, 128, 0.3);
}
.auto-greet-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: #fff;
  line-height: 1.4;
  font-family: var(--font-family);
}
.auto-greet-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.2s ease;
}
.auto-greet-close:hover { color: #fff; }
@keyframes greetSlideIn {
  from { opacity: 0; transform: translateY(15px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Floating Toggle Button */
.chat-toggle-btn {
  background-color: rgba(30, 26, 23, 0.95);
  border: 1px solid var(--accent-bg);
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background-color 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
  font-family: var(--font-family);
}
.chat-toggle-btn:hover {
  background-color: #26211d;
  transform: translateY(-2px);
  box-shadow: 0 15px 35px rgba(212, 175, 55, 0.2);
}
.chat-btn-avatar {
  position: relative;
  width: 32px;
  height: 32px;
  background-color: var(--accent-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-btn-avatar-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  background-color: #5cb85c;
  border: 2px solid rgba(30, 26, 23, 0.95);
  border-radius: 50%;
}
.chat-btn-icon {
  color: var(--dark-bg);
  font-size: 14px;
}
.chat-btn-text {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Chat Dialog Panel */
.chat-panel-card {
  width: 400px;
  height: 600px;
  background-color: rgba(20, 18, 16, 0.95);
  backdrop-filter: blur(10px) saturate(120%);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: absolute;
  bottom: 70px;
  right: 0;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: bottom right;
}
.chat-panel-card.active {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
.chat-header {
  background-color: rgba(30, 26, 23, 0.85);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
}
.chat-header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-avatar-wrapper {
  position: relative;
}
.chat-status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background-color: #5cb85c;
  border: 2px solid rgba(30, 26, 23, 1);
  border-radius: 50%;
}
.chat-avatar {
  width: 40px;
  height: 40px;
  background-color: var(--accent-bg);
  color: var(--dark-bg);
  font-family: var(--font-family);
  font-size: 18px;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-header-info {
  display: flex;
  flex-direction: column;
}
.chat-agent-name {
  font-family: var(--font-family);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}
.chat-agent-role {
  font-size: 11px;
  color: var(--text-muted);
}
.chat-header-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}
.chat-header-btn:hover {
  color: var(--accent-bg);
}
.chat-header-actions { display: flex; align-items: center; gap: 6px; }
.chat-language-btn { background: transparent; border: 1px solid var(--border-light); border-radius: 999px; color: #fff; cursor: pointer; font: inherit; font-size: 11px; padding: 4px 9px; }
.chat-language-btn:hover { border-color: var(--accent-bg); color: var(--accent-bg); }

/* Body / Message List */
.chat-messages-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* Message Bubbles */
.message-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  animation: messageSlideIn 0.25s ease-out forwards;
}

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

.message-bubble.user {
  background-color: var(--accent-bg);
  color: var(--dark-bg);
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.message-bubble.assistant {
  background-color: rgba(30, 26, 23, 0.95);
  color: #fff;
  border: 1px solid var(--border-light);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

.message-bubble.system {
  background-color: rgba(212, 175, 55, 0.08);
  border: 1px dashed var(--accent-bg);
  color: #fff;
  max-width: 95%;
  align-self: center;
  border-radius: 8px;
  font-size: 12.5px;
  text-align: center;
}

/* Attachment preview inside bubble */
.bubble-img-attachment {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 6px;
  margin-top: 8px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

/* Recommended Door Card Media Styling */
.door-card-media {
  display: block;
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: 6px;
  margin-top: 10px;
  border: 1px solid rgba(212, 175, 55, 0.35);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}
.door-card-media:hover {
  border-color: var(--accent-bg);
  transform: scale(1.01);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  align-self: flex-start;
}
.typing-status-label {
  margin-inline-end: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.typing-dot {
  width: 6px;
  height: 6px;
  background-color: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Attachment Preview Bar */
.attachment-preview-bar {
  background-color: rgba(30, 26, 23, 0.95);
  border-top: 1px solid var(--border-light);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 15px;
}
.preview-thumbnail-container {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: 6px;
  border: 1px solid var(--accent-bg);
  overflow: hidden;
}
.preview-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.remove-preview-btn {
  position: absolute;
  top: -2px;
  right: -2px;
  background: transparent;
  border: none;
  color: #ff5e5b;
  font-size: 16px;
  cursor: pointer;
  background-color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-filename {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Footer / Input Container */
.chat-input-footer {
  background-color: rgba(30, 26, 23, 0.85);
  border-top: 1px solid var(--border-light);
  padding: 12px 16px;
}
.chat-input-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: rgba(10, 9, 8, 0.85);
  border: 1px solid var(--border-light);
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
}
.chat-input-controls input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-family: var(--font-family);
  font-size: 13px;
  padding: 8px 0;
}
.chat-input-controls input:focus {
  outline: none;
}
.chat-widget-credit {
  margin-top: 8px;
  color: var(--text-muted);
  font-family: var(--font-family);
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: 0.03em;
  text-align: center;
}
.chat-media-btn {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  transition: all 0.3s ease;
}
.chat-media-btn:hover {
  color: var(--accent-bg);
}
.chat-media-btn:disabled {
  cursor: wait;
  opacity: 0.55;
}
.chat-send-action {
  background-color: var(--accent-bg);
  border: none;
  color: var(--dark-bg);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}
.chat-send-action:hover {
  background-color: #b8924d;
  transform: scale(1.05);
}
.hidden-input {
  display: none !important;
}

/* Handoff Lock Overlay */
.handoff-overlay-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 12, 10, 0.95);
  backdrop-filter: blur(12px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  animation: overlayFadeIn 0.3s ease-out;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.handoff-card-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 300px;
}
.handoff-icon-wrapper {
  width: 70px;
  height: 70px;
  background-color: rgba(197, 168, 128, 0.12);
  border: 1px solid var(--accent-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  font-size: 32px;
  color: var(--accent-bg);
  animation: pulseGold 2s infinite;
}

@keyframes pulseGold {
  0% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.4); }
  70% { box-shadow: 0 0 0 15px rgba(212, 175, 55, 0); }
  100% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0); }
}

.handoff-title {
  font-family: var(--font-family);
  font-size: 22px;
  margin-bottom: 12px;
}
.handoff-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 25px;
}
.handoff-details-badge {
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-bg);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 30px;
}
.btn-restart-chat {
  background-color: transparent;
  border: 1px solid var(--accent-bg);
  color: var(--accent-bg);
  padding: 10px 20px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.3s ease;
}
.btn-restart-chat:hover {
  background-color: var(--accent-bg);
  color: var(--dark-bg);
}

.hidden {
  display: none !important;
}

/* Mobile Responsive Styling (Preventing Viewport Overflow) */
@media (max-width: 576px) {
  .chat-panel-card {
    width: calc(100vw - 40px);
    right: 20px;
    left: 20px;
    bottom: 90px;
    height: calc(100vh - 120px);
    max-height: 520px;
  }
}

/* Quick Replies Styling */
.quick-replies-container {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  background-color: rgba(20, 18, 16, 0.95);
  border-top: 1px solid var(--border-light);
  white-space: nowrap;
}
.btn-quick-reply {
  background: rgba(197, 168, 128, 0.1);
  border: 1px solid var(--accent-bg);
  color: var(--accent-bg);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-family);
  transition: all 0.2s ease;
}
.btn-quick-reply:hover {
    background: var(--accent-bg);
    color: var(--dark-bg);
  }
  .message-contact-actions { margin-top: 12px; }
  .btn-message-contact {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--accent-bg);
    border-radius: 8px;
    background: var(--accent-bg);
    color: var(--dark-bg);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }
  .btn-message-contact:hover { filter: brightness(1.08); }
  .btn-message-contact:disabled { opacity: .65; cursor: default; }

/* Product Cards Row & Card Styling */
.product-cards-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
  width: 100%;
}
.product-showroom-card {
  background: rgba(30, 26, 23, 0.95);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.product-card-img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-bottom: 1px solid var(--border-light);
}
.product-card-details {
  padding: 12px;
}
.product-card-title {
  font-family: var(--font-family);
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}
.product-match-label {
  display: inline-flex;
  width: fit-content;
  margin: 2px 0 6px;
  padding: 3px 7px;
  border: 1px solid rgba(212, 175, 55, .55);
  border-radius: 999px;
  color: var(--accent-bg);
  font-size: 10px;
  line-height: 1.2;
}

.chat-failure-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.product-card-price {
  font-size: 12px;
  color: var(--accent-bg);
  font-weight: bold;
  display: block;
  margin-bottom: 6px;
}
.product-card-stock {
  display: block;
  margin: -2px 0 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.product-card-desc {
  margin: 0 0 10px 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}
.product-card-specs {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  margin: 0 0 10px 0;
  font-size: 11px;
  line-height: 1.4;
}
.product-card-specs dt {
  color: var(--text-muted);
  font-weight: 600;
}
.product-card-specs dd {
  margin: 0;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}
.product-card-actions {
  display: flex;
  gap: 8px;
}
.btn-view-product,
.btn-select-product {
  flex: 1;
  text-align: center;
  padding: 6px;
  font-size: 11px;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font-family);
  transition: all 0.2s ease;
}
.btn-view-product {
  background: transparent;
  border: 1px solid var(--border-light);
  color: #fff;
}
.btn-view-product:hover {
  border-color: #fff;
}
.btn-select-product {
  background: var(--accent-bg);
  border: 1px solid var(--accent-bg);
  color: var(--dark-bg);
}
.btn-select-product:hover {
  background: #b8924d;
}

/* Accessibility Focus States */
.chat-toggle-btn:focus-visible,
.chat-language-btn:focus-visible,
.chat-header-btn:focus-visible,
.chat-input-controls input:focus-visible,
.chat-send-action:focus-visible,
.btn-quick-reply:focus-visible,
  .btn-message-contact:focus-visible,
.btn-select-product:focus-visible,
.btn-view-product:focus-visible,
.chat-messages-body:focus-visible {
  outline: 2px solid var(--accent-bg);
  outline-offset: 2px;
}

/* Runtime language direction is isolated to the widget. */
.chat-widget-container[dir="rtl"] { right: auto; left: 30px; align-items: flex-start; }
.chat-widget-container[dir="rtl"] .chat-panel-card { right: auto; left: 0; transform-origin: bottom left; }
.chat-widget-container[dir="rtl"] .chat-header-user,
.chat-widget-container[dir="rtl"] .chat-input-controls,
.chat-widget-container[dir="rtl"] .product-card-actions { flex-direction: row-reverse; }
.chat-widget-container[dir="rtl"] .chat-header-info,
.chat-widget-container[dir="rtl"] .message-bubble,
.chat-widget-container[dir="rtl"] .product-card-details,
.chat-widget-container[dir="rtl"] .rwa-contact-form { text-align: right; }
.chat-widget-container[dir="rtl"] .message-bubble.user { align-self: flex-start; border-bottom-right-radius: 12px; border-bottom-left-radius: 2px; }
.chat-widget-container[dir="rtl"] .message-bubble.assistant { align-self: flex-end; border-bottom-left-radius: 12px; border-bottom-right-radius: 2px; }
.chat-widget-container[dir="rtl"] .rwa-consent-label { grid-template-columns: 1fr auto; }

.rwa-contact-form { padding: 16px; background: var(--light-bg, #fff); color: var(--text-color, #222); overflow-y: auto; }
.rwa-contact-form h3 { margin: 0 0 10px; font-size: 1rem; }
.rwa-contact-form label { display: block; margin: 8px 0; font-size: .85rem; }
.rwa-contact-form input:not([type="checkbox"]):not([type="radio"]),
.rwa-contact-form select { width: 100%; box-sizing: border-box; padding: 9px; border: 1px solid var(--border-light); border-radius: 6px; }
.rwa-contact-image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  padding: 8px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-size: 12px;
}
.rwa-contact-image-preview img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.rwa-consent-label { display: grid !important; grid-template-columns: auto 1fr; gap: 8px; align-items: start; line-height: 1.35; }
.chat-privacy-notice { display: grid; grid-template-columns: auto 1fr; gap: 6px 8px; padding: 8px 12px; font-size: 11px; line-height: 1.35; color: #d8d2ca; border-top: 1px solid var(--border-light); }
.chat-privacy-notice a { grid-column: 2; color: var(--accent-bg); }
.rwa-contact-purpose { border: 1px solid var(--border-light); border-radius: 6px; padding: 8px 10px; }
.rwa-contact-purpose label { display: inline-flex; align-items: center; gap: 5px; margin-right: 14px; }
.rwa-form-error { min-height: 1.25em; color: #a21d1d; font-size: .8rem; margin-top: 6px; }
.rwa-contact-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.rwa-contact-actions button { padding: 8px 12px; border-radius: 6px; cursor: pointer; }

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .chat-panel-card,
  .message-bubble,
  .handoff-overlay-card,
  .chat-toggle-btn,
  .auto-greet-bubble {
    animation: none !important;
    transition: none !important;
  }
}

/* Layout contract: one fixed header, one conversation scroller, one composer. */
.chat-toggle-btn.is-hidden { visibility: hidden; pointer-events: none; }
.chat-panel-card { min-height: 0; background-color: #141210; color: #fff; position: fixed; }
.chat-messages-body { min-height: 0; overscroll-behavior: contain; }
.quick-replies-container { overflow: hidden; flex-wrap: wrap; }
.rwa-contact-form { flex: 0 0 auto; width: 100%; box-sizing: border-box; margin: 4px 0; padding: 12px; background: rgba(30,26,23,.98); color: #fff; border: 1px solid var(--border-light); border-radius: 10px; overflow: visible; }
.rwa-contact-form input:not([type="checkbox"]):not([type="radio"]), .rwa-contact-form textarea, .rwa-contact-form select { width: 100%; box-sizing: border-box; padding: 8px; border: 1px solid var(--border-light); border-radius: 6px; background: rgba(10,9,8,.9); color: #fff; }
.rwa-contact-purpose { background: rgba(10,9,8,.5); }
.rwa-form-error { color: #ffb4a8; }
.rwa-contact-actions button[type="submit"] { background: var(--accent-bg); color: var(--dark-bg); border: 1px solid var(--accent-bg); }
.rwa-contact-actions button[type="button"] { background: transparent; color: #fff; border: 1px solid var(--border-light); }
@media (max-width: 576px) { .chat-panel-card { width: auto; right: 10px; left: 10px; height: min(680px, calc(100vh - 80px)); bottom: 60px; } .chat-widget-container { right: 10px; bottom: 10px; } .chat-widget-container[dir="rtl"] { right: auto; left: 10px; } }
