/* ────────────────────────────────────────────────────────────────────
   Kugamon Chatbot — v1 (UX prototype)
   Companion file: chatbot.js
   Brand vars (--ku-blue, --ku-blue-light, --bg, etc.) inherit from the host page.
   ──────────────────────────────────────────────────────────────────── */

/* ── Co-existence with the page's existing back-to-top button ─────
   Shift #back-to-top above the chat button so they don't overlap.
   !important is needed because the page's inline <style> loads after
   chatbot.css and would otherwise win. */
#back-to-top {
  bottom: 84px !important;
}
@media (max-width: 600px) {
  #back-to-top {
    bottom: 64px !important;
  }
}

/* ── Floating trigger button ─────────────────────────────────────── */
.kuga-chat-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9000;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--ku-blue, #014486);
  color: #ffffff;
  border: none;
  border-radius: 980px;
  padding: 12px 20px 12px 16px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.1px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(1, 68, 134, 0.32), 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease, opacity 0.25s ease;
}
.kuga-chat-btn:hover {
  background: var(--ku-blue-light, #1276d3);
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(1, 68, 134, 0.4), 0 4px 10px rgba(0, 0, 0, 0.12);
}
.kuga-chat-btn[aria-expanded="true"] {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}
.kuga-chat-btn svg {
  flex-shrink: 0;
}
.kuga-chat-btn-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 980px;
  background: var(--ku-blue, #014486);
  opacity: 0.4;
  z-index: -1;
  animation: kuga-pulse 2.4s ease-in-out infinite;
}
@keyframes kuga-pulse {
  0%, 100% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.15); opacity: 0; }
}

/* ── Side panel ──────────────────────────────────────────────────── */
.kuga-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 100vw;
  z-index: 9500;
  display: flex;
  flex-direction: column;
  background: var(--bg-card, #ffffff);
  border-left: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.kuga-chat-panel.open {
  transform: translateX(0);
}

/* ── Panel header ────────────────────────────────────────────────── */
.kuga-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  background: var(--bg-card, #ffffff);
  flex-shrink: 0;
}
.kuga-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.kuga-chat-avatar img {
  width: 22px;
  height: auto;
  display: block;
}
/* Dark mode: invert the SVG so the K stays visible (same trick as the nav logo) */
[data-resolved-theme="dark"] .kuga-chat-avatar img {
  filter: invert(1);
}
.kuga-chat-header-text {
  flex: 1;
  min-width: 0;
}
.kuga-chat-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary, #1d1d1f);
  line-height: 1.2;
}
.kuga-chat-subtitle {
  font-size: 12px;
  color: var(--text-tertiary, #86868b);
  margin-top: 2px;
  line-height: 1.3;
}
.kuga-chat-close,
.kuga-chat-reset {
  background: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-tertiary, #86868b);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.kuga-chat-close:hover,
.kuga-chat-reset:hover {
  background: var(--bg-secondary, #f5f5f7);
  color: var(--text-primary, #1d1d1f);
}
.kuga-chat-reset { margin-right: 2px; }
[data-resolved-theme="dark"] .kuga-chat-close:hover,
[data-resolved-theme="dark"] .kuga-chat-reset:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* ── Thread (message list) ───────────────────────────────────────── */
.kuga-chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.kuga-chat-thread::-webkit-scrollbar {
  width: 6px;
}
.kuga-chat-thread::-webkit-scrollbar-thumb {
  background: var(--border-strong, rgba(0, 0, 0, 0.15));
  border-radius: 3px;
}

/* ── Message bubbles ─────────────────────────────────────────────── */
.kuga-msg {
  max-width: 85%;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: kuga-msg-in 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes kuga-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.kuga-msg-bot {
  align-self: flex-start;
  background: var(--bg-secondary, #f5f5f7);
  color: var(--text-primary, #1d1d1f);
  border-radius: 16px 16px 16px 4px;
  padding: 12px 16px;
}
.kuga-msg-user {
  align-self: flex-end;
  background: var(--ku-blue, #014486);
  color: #ffffff;
  border-radius: 16px 16px 4px 16px;
  padding: 12px 16px;
}
.kuga-msg strong {
  font-weight: 600;
}
.kuga-msg a {
  color: inherit;
  text-decoration: underline;
}

/* Typing indicator (3 dots) */
.kuga-msg-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 16px;
}
.kuga-msg-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary, #86868b);
  animation: kuga-typing-bounce 1.2s ease-in-out infinite;
}
.kuga-msg-typing span:nth-child(2) { animation-delay: 0.15s; }
.kuga-msg-typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes kuga-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* "Schedule demo" CTA bubble */
.kuga-cta-bubble {
  align-self: flex-start;
  background: linear-gradient(135deg, var(--ku-blue, #014486) 0%, var(--ku-blue-light, #1276d3) 100%);
  color: #ffffff;
  border-radius: 16px;
  padding: 16px 18px;
  max-width: 85%;
  box-shadow: 0 4px 14px rgba(1, 68, 134, 0.22);
}
.kuga-cta-bubble-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}
.kuga-cta-bubble-sub {
  font-size: 13px;
  opacity: 0.9;
  margin-bottom: 12px;
  line-height: 1.4;
}
.kuga-cta-bubble button {
  background: rgba(255, 255, 255, 0.95);
  color: var(--ku-blue, #014486);
  border: none;
  border-radius: 980px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}
.kuga-cta-bubble button:hover {
  background: #ffffff;
  transform: scale(1.03);
}

/* ── Suggested-prompt chips ──────────────────────────────────────── */
.kuga-chips {
  padding: 0 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.kuga-chips-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary, #86868b);
  margin-bottom: 4px;
}
.kuga-chip {
  background: transparent;
  border: 1px solid var(--border-strong, rgba(0, 0, 0, 0.15));
  border-radius: 980px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary, #1d1d1f);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.kuga-chip:hover {
  border-color: var(--ku-blue-light, #1276d3);
  background: rgba(18, 118, 211, 0.06);
}

/* ── Input row ───────────────────────────────────────────────────── */
.kuga-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  background: var(--bg-card, #ffffff);
  flex-shrink: 0;
}
.kuga-chat-input {
  flex: 1;
  background: var(--bg-secondary, #f5f5f7);
  border: 1px solid transparent;
  border-radius: 18px;
  padding: 12px 16px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.45;
  color: var(--text-primary, #1d1d1f);
  outline: none;
  resize: none;
  overflow-y: auto;
  min-height: 64px;       /* roughly 2 rows — invites longer questions */
  max-height: 140px;
  transition: border-color 0.15s, background 0.15s;
}
.kuga-chat-input:focus {
  border-color: var(--ku-blue-light, #1276d3);
  background: var(--bg-card, #ffffff);
}
.kuga-chat-input::placeholder {
  color: var(--text-tertiary, #86868b);
}
.kuga-chat-send {
  background: var(--ku-blue, #014486);
  color: #ffffff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-bottom: 12px;   /* aligns the send button to the lower edge of the textarea */
  transition: background 0.15s, transform 0.15s;
}
.kuga-chat-send:hover {
  background: var(--ku-blue-light, #1276d3);
  transform: scale(1.05);
}
.kuga-chat-send:disabled {
  background: var(--text-tertiary, #86868b);
  cursor: not-allowed;
  transform: none;
}

/* ── Footer disclaimer ───────────────────────────────────────────── */
.kuga-chat-footer {
  padding: 8px 20px 14px;
  font-size: 11px;
  color: var(--text-tertiary, #86868b);
  text-align: center;
  line-height: 1.4;
  background: var(--bg-card, #ffffff);
  flex-shrink: 0;
}
.kuga-chat-footer a {
  color: var(--ku-blue-light, #1276d3);
  text-decoration: none;
}
.kuga-chat-footer a:hover {
  text-decoration: underline;
}
/* ── Mobile ──────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .kuga-chat-panel {
    width: 100vw;
    border-left: none;
  }
  .kuga-chat-btn {
    padding: 10px 14px;
    font-size: 13px;
    bottom: 16px;
    right: 16px;
  }
  .kuga-chat-btn-label {
    display: none;  /* icon-only on small screens */
  }
}

/* ── Dark mode (matches host page's [data-resolved-theme="dark"]) ─ */
[data-resolved-theme="dark"] .kuga-msg-bot {
  background: rgba(255, 255, 255, 0.06);
}
[data-resolved-theme="dark"] .kuga-chat-input {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}
[data-resolved-theme="dark"] .kuga-chat-input:focus {
  background: rgba(255, 255, 255, 0.10);
}
