/* ==========================================================================
   PREMIUM AI CHATBOT SYSTEM - MEL THE MASTER BARBER
   ========================================================================== */

/* Variables that hook into existing dark/light theme */
:root {
  --chat-launcher-size: 60px;
  --chat-panel-width: 380px;
  --chat-panel-max-height: 600px;
  --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  --chat-border: var(--accent-border);
  --chat-radius: 16px;
  --chat-zindex: 2000; /* Must be above navbar */
}

[data-theme="light"] {
  --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

/* --------------------------------------------------------------------------
   1. FLOATING LAUNCHER BUTTON
   -------------------------------------------------------------------------- */
.mel-ai-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: var(--chat-launcher-size);
  height: var(--chat-launcher-size);
  border-radius: 50%;
  background-color: var(--bg-card);
  border: 1px solid var(--accent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: var(--chat-zindex);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  transition: all var(--transition-smooth);
  opacity: 1;
}

[data-theme="light"] .mel-ai-launcher {
  background-color: #FFFFFF;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.mel-ai-launcher:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 25px var(--accent-glow);
  background-color: var(--accent);
  color: #0A0A0A;
}

.mel-ai-launcher svg {
  transition: stroke var(--transition-fast), fill var(--transition-fast);
}

.mel-ai-launcher.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.9);
}

/* --------------------------------------------------------------------------
   2. CHAT PANEL OVERALL CONTAINER
   -------------------------------------------------------------------------- */
.mel-ai-panel {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: var(--chat-panel-width);
  height: 65vh;
  max-height: var(--chat-panel-max-height);
  background-color: var(--bg-card);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  z-index: calc(var(--chat-zindex) + 1);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  
  /* Initial hidden state animation */
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.mel-ai-panel.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

@media (max-width: 575.98px) {
  .mel-ai-launcher {
    bottom: 16px;
    right: 16px;
  }
  
  .mel-ai-panel {
    bottom: 16px;
    right: 16px;
    width: calc(100% - 32px);
    height: calc(100vh - 4rem); /* Responsive tall height avoiding browser mobile bars */
    max-height: 800px;
  }
}

/* --------------------------------------------------------------------------
   3. HEADER
   -------------------------------------------------------------------------- */
.mel-ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.mel-ai-header-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.mel-ai-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: rgba(198, 161, 91, 0.1);
  border: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.mel-ai-title-wrap {
  display: flex;
  flex-direction: column;
}

.mel-ai-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: 0.05em;
  margin: 0;
}

.mel-ai-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mel-ai-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  transition: color var(--transition-fast), transform var(--transition-fast);
  line-height: 1;
}

.mel-ai-close:hover {
  color: var(--accent);
  transform: rotate(90deg);
}

/* --------------------------------------------------------------------------
   4. MESSAGES AREA
   -------------------------------------------------------------------------- */
.mel-ai-messages {
  flex-grow: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  background-color: var(--bg-primary);
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--accent-border) transparent;
}

.mel-ai-messages::-webkit-scrollbar {
  width: 6px;
}
.mel-ai-messages::-webkit-scrollbar-track {
  background: transparent;
}
.mel-ai-messages::-webkit-scrollbar-thumb {
  background-color: var(--accent-border);
  border-radius: 4px;
}

.mel-ai-msg-row {
  display: flex;
  width: 100%;
}

.mel-ai-msg-row.ai {
  justify-content: flex-start;
}

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

.mel-ai-bubble {
  max-width: 85%;
  padding: 0.85rem 1.15rem;
  font-size: 0.95rem;
  line-height: 1.5;
  border-radius: 12px;
}

.mel-ai-msg-row.ai .mel-ai-bubble {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}

.mel-ai-msg-row.user .mel-ai-bubble {
  background-color: var(--accent);
  color: #0A0A0A; /* Always dark text on gold */
  border: 1px solid var(--accent);
  border-bottom-right-radius: 2px;
  font-weight: 500;
}

/* Links inside AI messages (e.g. for booking) */
.mel-ai-msg-row.ai .mel-ai-bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}

.mel-ai-msg-row.ai .mel-ai-bubble a:hover {
  text-decoration: none;
}

/* Quick Question Buttons */
.mel-ai-quick-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.mel-ai-quick-btn {
  background-color: transparent;
  border: 1px solid var(--accent-border);
  color: var(--accent);
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
  white-space: normal;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mel-ai-quick-btn:hover {
  background-color: rgba(198, 161, 91, 0.1);
  border-color: var(--accent);
  transform: translateX(4px);
}

.mel-ai-quick-btn::before {
  content: '›';
  font-size: 1.1rem;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   5. TYPING INDICATOR
   -------------------------------------------------------------------------- */
.mel-ai-typing {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem;
}

.mel-ai-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent);
  border-radius: 50%;
  animation: melTypingBounce 1.4s infinite ease-in-out both;
  opacity: 0.6;
}

.mel-ai-dot:nth-child(1) { animation-delay: -0.32s; }
.mel-ai-dot:nth-child(2) { animation-delay: -0.16s; }

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

/* --------------------------------------------------------------------------
   6. INPUT AREA
   -------------------------------------------------------------------------- */
.mel-ai-input-wrapper {
  padding: 1.25rem 1.5rem;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.mel-ai-input {
  flex-grow: 1;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-pill);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  resize: none;
  max-height: 100px;
  min-height: 44px;
}

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

.mel-ai-input:focus {
  border-color: var(--accent);
  background-color: var(--bg-card);
  box-shadow: 0 0 0 2px rgba(198, 161, 91, 0.15);
}

.mel-ai-send {
  background-color: var(--accent);
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0A0A0A;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.mel-ai-send:hover {
  background-color: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.mel-ai-send:disabled {
  background-color: var(--border-subtle);
  color: var(--text-secondary);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Reduced Motion Override */
@media (prefers-reduced-motion: reduce) {
  .mel-ai-launcher, .mel-ai-panel, .mel-ai-dot, .mel-ai-quick-btn, .mel-ai-send {
    transition: none !important;
    animation: none !important;
    transform: none !important;
  }
}
