/* ============================================================
   Cheapta Chat Widget
   Uses CSS variables from style.css for automatic theme support

   Layout:
     Top-left:     Theme toggle  (destinations.js, position: fixed)
     Top-right:    Chat FAB      (#chat-panel-wrapper, position: fixed)
     Bottom-right: Map FAB       (.fab-map-btn in style.css)
   ============================================================ */

/* ── Container — FAB anchored to bottom-right corner ──────── */
#chat-panel-wrapper {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 9999;
  font-family: var(--font-family);
}

/* ── Floating Action Button ─────────────────────────────── */
.chat-fab-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  padding: 0;
}

#chat-fab:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

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

.chat-fab-btn svg {
  width: 22px;
  height: 22px;
}

.chat-fab-btn.chat-fab--hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

/* ── Chat Panel ──────────────────────────────────────────── */
/* bottom: 92px = 24px (widget bottom) + 56px (FAB) + 12px (gap)  */
/* Or we can just use the flex layout and not fixed position. 
   Wait, earlier I made it fixed bottom: 24px but now I will just use fixed for bottom right. */
#chat-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  bottom: 24px;
  width: 370px;
  max-height: calc(100vh - 88px);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md), 0 20px 60px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  transform-origin: top right;
  transition: opacity var(--transition-normal), transform var(--transition-normal);
}

#chat-panel.chat-closed {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9) translateY(12px);
}

#chat-panel.chat-open {
  opacity: 1;
  pointer-events: all;
  transform: scale(1) translateY(0);
}

/* ── Header ─────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  height: 64px;
}

.chat-header-avatar {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-title {
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
}

.chat-header-subtitle {
  font-size: var(--text-xs);
  opacity: 0.85;
  margin-top: 1px;
}

.chat-header-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.chat-header-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ── Messages ────────────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.chat-bubble {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.5;
  word-break: break-word;
}

.chat-bubble-bot {
  align-self: flex-start;
  background: var(--bg-primary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
}

.chat-bubble-user {
  align-self: flex-end;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
  border: 1px solid var(--border-color);
}

.chat-bubble strong { font-weight: 600; }
.chat-bubble em { font-style: italic; }

.chat-bubble ul {
  list-style: none;
  padding: 0;
  margin: 6px 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-bubble li {
  padding: 5px 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-primary);
}

.chat-bubble-bot li {
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.chat-bubble-bot li:hover {
  background-color: var(--bg-tertiary);
  transform: translateX(2px);
}

.chat-bubble-user li {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.chat-bubble br + br { display: none; }

/* ── Typing Indicator ────────────────────────────────────── */
.chat-bubble-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
}

.chat-bubble-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  opacity: 0.5;
  animation: chat-typing-bounce 1.2s infinite ease-in-out;
}

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

@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Quick Replies ───────────────────────────────────────── */
#chat-quick-replies {
  padding: 6px 14px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  min-height: 0;
}

#chat-quick-replies:empty { padding: 0; }

.chat-chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent-color);
  background: transparent;
  color: var(--accent-color);
  font-size: var(--text-xs);
  font-family: var(--font-family);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
  line-height: 1.4;
}

.chat-chip:hover {
  background: var(--accent-color);
  color: #fff;
}

/* ── Booking Button ──────────────────────────────────────── */
.chat-booking-btn {
  display: block;
  margin: 4px 0;
  padding: 9px 16px;
  background: var(--success-color);
  color: #fff;
  font-family: var(--font-family);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  border-radius: var(--radius-md);
  transition: opacity var(--transition-fast);
  align-self: flex-start;
}

.chat-booking-btn:hover { opacity: 0.88; }

/* ── Input Row ───────────────────────────────────────────── */
.chat-input-row {
  padding: 12px 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: var(--text-md);
  font-family: inherit;
  height: 44px;
  transition: border-color var(--transition-fast);
}

#chat-input:focus {
  outline: none;
  border-color: var(--accent-color);
}
#chat-input::placeholder { color: var(--text-secondary); }

#chat-send-btn {
  background: var(--accent-color);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity var(--transition-fast);
}

#chat-send-btn:hover { background: var(--accent-hover); }
#chat-send-btn:active { transform: scale(0.92); }
#chat-send-btn svg { width: 16px; height: 16px; }

/* ── Error State ─────────────────────────────────────────── */
.chat-bubble-error {
  background: rgba(229, 62, 62, 0.1);
  border: 1px solid rgba(229, 62, 62, 0.25);
  color: var(--danger-color);
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Chat FAB — top-right at 16px */
  #chat-panel-wrapper {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 9999;
  font-family: var(--font-family);
}

  /* Make chat button look like the theme toggle icon */
  .chat-fab-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  padding: 0;
}
  
  #chat-fab:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

  .chat-fab-btn svg {
  width: 22px;
  height: 22px;
}

  /* Chat panel — true full screen, slides down from top */
  #chat-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  bottom: 24px;
  width: 370px;
  max-height: calc(100vh - 88px);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md), 0 20px 60px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  transform-origin: top right;
  transition: opacity var(--transition-normal), transform var(--transition-normal);
}

  #chat-panel.chat-closed {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-20px);
  }

  #chat-panel.chat-open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
  }
}

@media (min-width: 769px) {
  #chat-panel-wrapper {
    position: fixed !important;
    top: auto !important;
    bottom: 24px !important;
    right: 24px !important;
  }
  #chat-panel {
    top: auto !important;
    bottom: 24px !important;
    right: 24px !important;
    max-height: calc(100vh - 48px) !important;
    transform-origin: bottom right !important;
  }
}


@media (max-width: 768px) {
  #chat-panel {
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
    z-index: 9990 !important;
  }
  
  /* Make sure FAB sits above the full screen chat panel */
  .chat-fab-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  padding: 0;
}
}



/* Desktop chat fab */
#chat-fab-desktop {
  position: fixed !important;
  bottom: 24px !important;
  right: 24px !important;
  z-index: 9999 !important;
}

/* Mobile chat fab is inside panel header */
#chat-fab-mobile {
  position: absolute !important;
  right: 16px !important;
  top: 12px !important;
  z-index: 9998 !important;
}

@media (max-width: 768px) {
  #chat-fab-desktop {
    display: none !important;
  }
}
@media (min-width: 769px) {
  #chat-fab-mobile {
    display: none !important;
  }
}
