/* ============================================================
   CHATBOT.CSS — "Ask Roger" AI Chat Widget
   Depends on: theme.css (custom properties)
   ============================================================ */

/* ── Floating Button ───────────────────────────────────────── */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9500;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #c9a84c;
  color: #111;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(201, 168, 76, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: chatFabEntry 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 1s both,
             chatFabAttention 3s ease-in-out 2.5s infinite;
}

.chat-fab:hover {
  transform: scale(1.12);
  box-shadow: 0 6px 32px rgba(201, 168, 76, 0.6);
  animation: none;
}

.chat-fab.is-open {
  animation: none;
  transform: rotate(90deg);
}

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

/* Entry: bounce in from below */
@keyframes chatFabEntry {
  0% { opacity: 0; transform: translateY(40px) scale(0.5); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Attention: subtle wiggle + glow pulse */
@keyframes chatFabAttention {
  0%, 100% {
    transform: rotate(0deg);
    box-shadow: 0 4px 20px rgba(201, 168, 76, 0.35);
  }
  10% { transform: rotate(-8deg); }
  20% { transform: rotate(6deg); }
  30% { transform: rotate(-4deg); }
  40% { transform: rotate(0deg); }
  50% {
    box-shadow: 0 4px 32px rgba(201, 168, 76, 0.65);
  }
}

/* ── Notification Bubble ───────────────────────────────────── */
.chat-bubble {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 9500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 260px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  opacity: 0;
  transform: translateY(10px) scale(0.9);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

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

.chat-bubble::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 24px;
  width: 12px;
  height: 12px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: rotate(45deg);
}

.chat-bubble-text {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
  flex: 1;
}

.chat-bubble-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  display: flex;
  flex-shrink: 0;
  border-radius: 4px;
  transition: color 0.15s;
}

.chat-bubble-close:hover {
  color: var(--text-primary);
}

/* Unread dot on FAB */
.chat-fab::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff4444;
  border: 2px solid #c9a84c;
  opacity: 0;
  transition: opacity 0.3s;
}

.chat-fab.has-notification::after {
  opacity: 1;
  animation: notifPulse 2s ease-in-out infinite;
}

@keyframes notifPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* ── Chat Panel ────────────────────────────────────────────── */
.chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 9500;
  width: 400px;
  height: 520px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

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

/* ── Header ────────────────────────────────────────────────── */
.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
}

.chat-header-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.chat-beta {
  font-family: 'Courier New', monospace;
  font-size: 8px;
  letter-spacing: 0.1em;
  color: #111;
  background: #c9a84c;
  padding: 2px 6px;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 6px;
}

.chat-header-status {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-header-flight {
  color: #c9a84c;
}

.chat-header-sep {
  opacity: 0.4;
}

.chat-header-route {
  color: var(--text-muted);
}

.chat-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

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

.chat-close svg {
  width: 20px;
  height: 20px;
}

/* ── Messages ──────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
}

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

.chat-msg--user {
  align-self: flex-end;
  background: var(--accent-dim);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.chat-msg--limit {
  align-self: center;
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  text-align: center;
  max-width: 90%;
  font-size: 13px;
  color: var(--text-secondary);
}

.chat-msg--limit a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.chat-msg--limit a:hover {
  text-decoration: underline;
}

/* ── Chat Cards (book, product previews) ───────────────────── */
.chat-card {
  max-width: 85%;
  margin: 4px 0;
  animation: quickRepliesFadeIn 0.4s ease;
}

.chat-card-link {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

.chat-card-link:hover {
  border-color: var(--accent);
}

.chat-card-cover {
  width: 48px;
  height: 68px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.chat-card-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.chat-card-label {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #c9a84c;
}

.chat-card-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-card-desc {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-muted);
}

.chat-card-more {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: #c9a84c;
  text-decoration: none;
  margin-top: 4px;
  display: inline-block;
}

.chat-card-more:hover {
  text-decoration: underline;
}

/* Fallback links when offline */
.chat-fallback-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.chat-fallback-links a {
  display: block;
  color: #c9a84c;
  text-decoration: none;
  font-weight: 500;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  transition: border-color 0.15s;
}

.chat-fallback-links a:hover {
  border-color: var(--accent);
  text-decoration: none;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  padding: 12px 18px;
  background: var(--bg-secondary);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
}

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

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

@keyframes typingBounce {
  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: 4px 0;
  animation: quickRepliesFadeIn 0.4s ease;
}

.chat-quick-btn {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: #c9a84c;
  background: none;
  border: 1px solid #c9a84c;
  border-radius: 16px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.chat-quick-btn:hover {
  background: #c9a84c;
  color: #111;
}

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

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

.chat-input {
  flex: 1;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  outline: none;
  resize: none;
  max-height: 80px;
  line-height: 1.4;
  transition: border-color 0.15s;
}

.chat-input:focus {
  border-color: var(--accent);
}

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

.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: #c9a84c;
  color: #111;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.chat-send:hover {
  opacity: 0.85;
}

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

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

/* ── Counter ───────────────────────────────────────────────── */
.chat-counter {
  padding: 0 16px 8px;
  text-align: right;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-counter.is-low {
  color: var(--accent);
}

/* ── Sticky footer offset (book pages) ─────────────────────── */
body:has(.bk-sticky.is-visible) .chat-fab,
body:has(.bk-sticky.is-visible) .chat-bubble {
  bottom: 80px;
  transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

body:has(.bk-sticky.is-visible) .chat-panel {
  bottom: 152px;
  transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Mobile ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-panel {
    width: calc(100vw - 16px);
    height: calc(100dvh - 100px);
    bottom: 72px;
    right: 8px;
    border-radius: 12px;
  }

  .chat-fab {
    bottom: 12px;
    right: 12px;
    width: 46px;
    height: 46px;
  }

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

  .chat-bubble {
    bottom: 68px;
    right: 12px;
    max-width: 220px;
    font-size: 12px;
  }
}
