/* ── TidalAI Chat Widget ─────────────────────────────────── */
/* Scoped under #tidalai-chat-widget to avoid Tailwind conflicts */

#tidalai-chat-widget {
  --chat-bg: #0f1117;
  --chat-surface: #14161e;
  --chat-card: #191b25;
  --chat-elevated: #1e2230;
  --chat-accent: #eab308;
  --chat-accent-glow: #facc15;
  --chat-accent-dark: #ca8a04;
  --chat-text: #f0f0f5;
  --chat-text-secondary: #8a8f9e;
  --chat-text-muted: #5c5f6e;
  --chat-border: rgba(255, 255, 255, 0.06);
  --chat-border-hover: rgba(255, 255, 255, 0.1);
  --chat-radius: 16px;
  --chat-radius-sm: 10px;
  --chat-font: 'Inter', system-ui, -apple-system, sans-serif;

  font-family: var(--chat-font);
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 9999;
  pointer-events: none;
}

#tidalai-chat-widget * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── FAB Button ──────────────────────────────────────────── */

.chat-fab {
  pointer-events: auto;
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  color: #08090d;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(234, 179, 8, 0.25), 0 0 0 1px rgba(234, 179, 8, 0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 10000;
}

.chat-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 32px rgba(234, 179, 8, 0.35), 0 0 0 1px rgba(234, 179, 8, 0.2);
}

.chat-fab:active {
  transform: scale(0.97);
}

.chat-fab svg {
  width: 24px;
  height: 24px;
  transition: transform 0.2s ease;
}

.chat-fab.open svg.icon-chat { display: none; }
.chat-fab:not(.open) svg.icon-close { display: none; }

.chat-fab-pulse {
  animation: chat-fab-pulse 2s ease-in-out 3;
}

@keyframes chat-fab-pulse {
  0%, 100% { box-shadow: 0 4px 24px rgba(234, 179, 8, 0.25), 0 0 0 1px rgba(234, 179, 8, 0.15); }
  50% { box-shadow: 0 4px 32px rgba(234, 179, 8, 0.45), 0 0 0 4px rgba(234, 179, 8, 0.1); }
}

/* ── Chat Panel ──────────────────────────────────────────── */

.chat-panel {
  pointer-events: auto;
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.03);
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  z-index: 9999;
}

.chat-panel.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--chat-surface);
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

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

.chat-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--chat-text);
}

.chat-header-status {
  font-size: 11px;
  color: var(--chat-text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

.chat-header-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--chat-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.chat-header-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--chat-text);
}

/* ── Messages Area ───────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}

/* ── Message Bubbles ─────────────────────────────────────── */

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: chat-msg-in 0.2s ease;
}

@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--chat-elevated);
  color: var(--chat-text-secondary);
  border-bottom-left-radius: 4px;
  border-left: 3px solid var(--chat-accent);
  margin-left: 4px;
}

.chat-msg.assistant strong {
  color: var(--chat-text);
  font-weight: 600;
}

.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  color: #08090d;
  border-bottom-right-radius: 4px;
}

.chat-msg.system {
  align-self: center;
  background: rgba(234, 179, 8, 0.08);
  border: 1px solid rgba(234, 179, 8, 0.15);
  color: var(--chat-text-secondary);
  font-size: 12px;
  text-align: center;
  border-radius: 8px;
  max-width: 90%;
}

/* ── Typing Indicator ────────────────────────────────────── */

.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
  background: var(--chat-card);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-text-muted);
  animation: chat-bounce 1.4s ease-in-out infinite;
}

.chat-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.32s; }

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

/* ── Quick Replies ───────────────────────────────────────── */

.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
  flex-shrink: 0;
}

.chat-quick-reply {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-text-secondary);
  font-size: 12px;
  font-family: var(--chat-font);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.chat-quick-reply:hover {
  border-color: var(--chat-accent);
  color: var(--chat-accent);
  background: rgba(234, 179, 8, 0.06);
}

/* ── Invoice Cards ───────────────────────────────────────── */

.chat-invoice-card {
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-sm);
  padding: 10px 12px;
  margin: 4px 0;
  font-size: 12px;
}

.chat-invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.chat-invoice-number {
  font-weight: 600;
  color: var(--chat-text);
}

.chat-invoice-status {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-invoice-status.paid { background: rgba(34, 197, 94, 0.1); color: #22c55e; }
.chat-invoice-status.sent { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.chat-invoice-status.past_due { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.chat-invoice-status.draft { background: rgba(255, 255, 255, 0.05); color: var(--chat-text-muted); }

.chat-invoice-details {
  color: var(--chat-text-muted);
  display: flex;
  justify-content: space-between;
}

.chat-invoice-amount {
  font-weight: 600;
  color: var(--chat-text);
}

/* ── Booking Confirmation Card ───────────────────────────── */

.chat-booking-card {
  background: var(--chat-surface);
  border: 1px solid rgba(234, 179, 8, 0.15);
  border-radius: var(--chat-radius-sm);
  padding: 12px;
  margin: 4px 0;
}

.chat-booking-card h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--chat-accent);
  margin-bottom: 8px;
}

.chat-booking-detail {
  font-size: 12px;
  color: var(--chat-text-secondary);
  margin-bottom: 3px;
}

.chat-booking-detail strong {
  color: var(--chat-text);
}

.chat-booking-status {
  margin-top: 8px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(234, 179, 8, 0.1);
  color: var(--chat-accent);
  display: inline-block;
}

/* ── Slot Picker ─────────────────────────────────────────── */

.chat-slots-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 6px 0;
}

.chat-slot-btn {
  padding: 6px 4px;
  border-radius: 8px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-text-secondary);
  font-size: 12px;
  font-family: var(--chat-font);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.chat-slot-btn:hover {
  border-color: var(--chat-accent);
  color: var(--chat-accent);
  background: rgba(234, 179, 8, 0.06);
}

.chat-slot-btn.unavailable {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── OTP Input ───────────────────────────────────────────── */

.chat-otp-container {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 8px 0;
}

.chat-otp-digit {
  width: 40px;
  height: 48px;
  border-radius: 8px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-text);
  font-size: 20px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
}

.chat-otp-digit:focus {
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.15);
}

/* ── Tool Loading ────────────────────────────────────────── */

.chat-tool-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(234, 179, 8, 0.06);
  border-radius: 8px;
  font-size: 12px;
  color: var(--chat-text-muted);
  align-self: flex-start;
  animation: chat-msg-in 0.2s ease;
}

.chat-tool-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(234, 179, 8, 0.2);
  border-top-color: var(--chat-accent);
  border-radius: 50%;
  animation: chat-spin 0.8s linear infinite;
}

@keyframes chat-spin {
  to { transform: rotate(360deg); }
}

/* ── Input Area ──────────────────────────────────────────── */

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: var(--chat-surface);
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  min-height: 36px;
  max-height: 100px;
  padding: 8px 12px;
  border-radius: var(--chat-radius-sm);
  border: 1px solid var(--chat-border);
  background: var(--chat-bg);
  color: var(--chat-text);
  font-size: 13.5px;
  font-family: var(--chat-font);
  resize: none;
  outline: none;
  line-height: 1.4;
  transition: border-color 0.15s;
}

.chat-input:focus {
  border-color: rgba(255, 255, 255, 0.12);
}

.chat-input::placeholder {
  color: var(--chat-text-muted);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--chat-radius-sm);
  border: none;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  color: #08090d;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.chat-send-btn:hover { opacity: 0.9; }
.chat-send-btn:active { transform: scale(0.95); }

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

.chat-send-btn svg {
  width: 18px;
  height: 18px;
}

/* ── Markdown in Messages ────────────────────────────────── */

.chat-msg.assistant p { margin-bottom: 6px; }
.chat-msg.assistant p:last-child { margin-bottom: 0; }
.chat-msg.assistant ul, .chat-msg.assistant ol { padding-left: 16px; margin: 4px 0; }
.chat-msg.assistant li { margin-bottom: 2px; }
.chat-msg.assistant code {
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
}

/* ── Mobile ──────────────────────────────────────────────── */

@media (max-width: 640px) {
  .chat-panel {
    width: 100vw;
    height: calc(100vh - 80px);
    max-height: none;
    bottom: 0;
    right: 0;
    border-radius: var(--chat-radius) var(--chat-radius) 0 0;
  }

  .chat-fab {
    bottom: 16px;
    right: 16px;
  }

  .chat-panel.visible + .chat-fab {
    display: none;
  }
}
