/* ==========================================================================
   RAFI9 CHATBOT WIDGET - PREMIUM STYLES
   ========================================================================== */

/* Launcher Button */
#rafi9-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(99, 102, 241, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9999;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#rafi9-launcher:hover {
  transform: scale(1.05) translateY(-5px);
  box-shadow: 0 15px 40px rgba(99, 102, 241, 0.4), inset 0 0 30px rgba(99, 102, 241, 0.4);
}

#rafi9-launcher::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: var(--gradient-hero);
  z-index: -1;
  animation: pulseGlow 3s infinite alternate;
  opacity: 0.5;
}

@keyframes pulseGlow {
  0% { transform: scale(1); opacity: 0.3; }
  100% { transform: scale(1.15); opacity: 0.6; }
}

#rafi9-launcher .icon {
  font-size: 28px;
  filter: drop-shadow(0 2px 5px rgba(0,0,0,0.5));
}

#rafi9-launcher .badge {
  position: absolute;
  top: 0;
  right: 0;
  width: 14px;
  height: 14px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
  display: none;
}
#rafi9-launcher.has-unread .badge {
  display: block;
}

/* Chat Window */
#rafi9-widget {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: rgba(18, 18, 26, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6), 0 0 100px rgba(99, 102, 241, 0.15);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  font-family: var(--font-body);
}

#rafi9-widget.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Header */
.rafi9-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  background: rgba(10, 10, 15, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.rafi9-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rafi9-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--gradient-hero);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.rafi9-info h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 2px 0;
}

.rafi9-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
  animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

.rafi9-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.rafi9-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

/* Chat Body (Messages) */
.rafi9-messages {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

/* Custom Scrollbar for Chat */
.rafi9-messages::-webkit-scrollbar {
  width: 6px;
}
.rafi9-messages::-webkit-scrollbar-track {
  background: transparent;
}
.rafi9-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
}

/* Messages */
.message-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: messageSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
  transform: translateY(10px);
}

@keyframes messageSlide {
  to { opacity: 1; transform: translateY(0); }
}

.message-wrapper.bot {
  align-self: flex-start;
}

.message-wrapper.user {
  align-self: flex-end;
}

.message-bubble {
  padding: 0.875rem 1.25rem;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.message-wrapper.bot .message-bubble {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom-left-radius: 4px;
  position: relative;
}
/* Subtle accent on bot messages */
.message-wrapper.bot .message-bubble::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  background: var(--accent-primary);
  border-radius: 4px;
  opacity: 0.5;
}

/* Hide accent line when displaying full-width media */
.message-wrapper.bot .message-bubble.media-bubble::before {
  display: none;
}

.message-wrapper.user .message-bubble {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
  align-self: flex-end;
}

.message-wrapper.bot .message-time {
  align-self: flex-start;
  margin-left: 4px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.5rem 0.25rem;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-secondary);
  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); }
}

/* Input Area */
.rafi9-input-area {
  padding: 1rem 1.5rem;
  background: rgba(10, 10, 15, 0.8);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.rafi9-input-wrapper {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 0.75rem 1rem;
  display: flex;
  transition: border-color 0.3s;
}

.rafi9-input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

#rafi9-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px; /* 16px prevents iOS auto-zoom */
  resize: none;
  outline: none;
  max-height: 100px;
}

#rafi9-input::placeholder {
  color: var(--text-muted);
}

.rafi9-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--gradient-hero);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

.rafi9-send:hover {
  transform: scale(1.05);
  box-shadow: 0 5px 15px rgba(99, 102, 241, 0.4);
}
.rafi9-send:active {
  transform: scale(0.95);
}

.rafi9-send svg {
  width: 20px;
  height: 20px;
  margin-left: 2px;
}

/* Quick Replies */
.rafi9-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  margin-bottom: 8px;
}

.rafi9-chip {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
  
  /* Staggered animation setup */
  opacity: 0;
  transform: translateY(10px);
  animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUpFade {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.rafi9-chip::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--gradient-hero);
  opacity: 0;
  z-index: -1;
  transition: opacity 0.3s ease;
}

.rafi9-chip:hover {
  border-color: rgba(99, 102, 241, 0.5);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
}

.rafi9-chip:hover::before {
  opacity: 0.15;
}

.rafi9-chip:active {
  transform: translateY(0) scale(0.96);
}

/* Booking Card inside Chat */
.booking-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 1.25rem;
  margin-top: 10px;
  text-align: center;
}
.booking-card h4 {
  font-size: 1.1rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}
.booking-card p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}
.booking-card .btn {
  width: 100%;
  font-size: 0.9rem;
  padding: 0.75rem;
}

/* ===== Service Cards (In-Widget) ===== */
.rafi9-service-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.rafi9-service-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-primary);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.rafi9-service-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(139, 92, 246, 0.05));
  opacity: 0;
  transition: opacity 0.25s;
}

.rafi9-service-card:hover {
  border-color: rgba(99, 102, 241, 0.4);
  transform: translateX(4px);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.15);
}

.rafi9-service-card:hover::before {
  opacity: 1;
}

.rafi9-service-card:active {
  transform: translateX(2px) scale(0.98);
}

.rafi9-service-card__icon {
  font-size: 24px;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 10px;
}

.rafi9-service-card__body {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.rafi9-service-card__body h4 {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 3px 0;
  line-height: 1.3;
}

.rafi9-service-card__body p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0 0 6px 0;
  line-height: 1.4;
}

.rafi9-service-card__tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent-glow);
  background: rgba(99, 102, 241, 0.12);
  padding: 2px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== Media Gallery (In-Widget) ===== */
.rafi9-media-gallery {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  width: 260px; /* Explicit concrete width to prevent flex collapse */
  max-width: 100%; 
}

.rafi9-media-card {
  flex: 0 0 100%;
  width: 100%;
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
}

.rafi9-media-card__visual {
  width: 100%;
  /* No absolute positioning so it defines the height naturally */
}

.rafi9-media-card__visual video,
.rafi9-media-card__visual img {
  width: 100%;
  height: auto;
  display: block;
}

.rafi9-media-card__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(10,10,15,0.95) 0%, rgba(10,10,15,0.4) 40%, transparent 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px;
}

.rafi9-media-card__overlay h5 {
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.95rem;
  margin: 0 0 4px 0;
  font-weight: 600;
}

.rafi9-media-card__overlay p {
  color: rgba(255,255,255,0.7);
  font-size: 0.75rem;
  margin: 0;
  line-height: 1.3;
}

/* ===== Fullscreen Media Lightbox ===== */
#rafi9-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#rafi9-lightbox.active {
  opacity: 1;
  pointer-events: auto;
}

.rafi9-lightbox__close {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  z-index: 10001;
  transition: all 0.3s;
}

.rafi9-lightbox__close:hover {
  background: var(--accent-primary);
  transform: rotate(90deg);
}

.rafi9-lightbox__content {
  max-width: 90vw;
  max-height: 90vh;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  transform: scale(0.95);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#rafi9-lightbox.active .rafi9-lightbox__content {
  transform: scale(1);
}

.rafi9-lightbox__content video,
.rafi9-lightbox__content img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  display: block;
}

/* ==========================================
   DATE/TIME PICKER WIDGET
   ========================================== */
.rafi9-dt-widget {
  background: var(--bg-elevated, #1A1A2E);
  border: 1px solid var(--border-glass, rgba(255,255,255,0.08));
  border-radius: 12px;
  padding: 1rem;
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.rafi9-dt-section h5 {
  font-size: 0.8rem;
  color: var(--text-secondary, #94A3B8);
  margin: 0 0 0.5rem 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.rafi9-dt-scroll {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: none;
}
.rafi9-dt-scroll::-webkit-scrollbar {
  display: none;
}
.rafi9-pill {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary, #F1F5F9);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}
.rafi9-pill:hover {
  background: rgba(255, 255, 255, 0.08);
}
.rafi9-pill.selected {
  background: var(--accent-primary, #6366F1);
  border-color: var(--accent-primary, #6366F1);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}
.rafi9-dt-submit {
  background: var(--accent-primary, #6366F1);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  opacity: 0.5;
  pointer-events: none;
}
.rafi9-dt-submit.ready {
  opacity: 1;
  pointer-events: auto;
}
.rafi9-dt-submit.ready:hover {
  background: var(--accent-secondary, #8B5CF6);
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
  #rafi9-widget {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  
  #rafi9-launcher {
    bottom: 20px;
    right: 20px;
  }
}
