/* ==========================================================================
   AI Assistant Chat Widget
   Fixed bottom-right launcher + slide-up panel.
   No external dependencies — all styles are namespaced under #ai-chat-root.
   ========================================================================== */

/* ── Custom properties (easy theming) ─────────────────────────────────────── */
#ai-chat-root {
  --ai-accent:        #2563eb;   /* launcher / send button / user bubble */
  --ai-accent-hover:  #1d4ed8;
  --ai-panel-bg:      #ffffff;
  --ai-header-bg:     #2563eb;
  --ai-header-text:   #ffffff;
  --ai-user-bg:       #2563eb;
  --ai-user-text:     #ffffff;
  --ai-bot-bg:        #f1f5f9;
  --ai-bot-text:      #1e293b;
  --ai-input-border:  #cbd5e1;
  --ai-shadow:        0 8px 32px rgba(0, 0, 0, 0.18);
  --ai-radius-panel:  16px;
  --ai-radius-bubble: 16px;
  --ai-font:          system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ai-z:             99999;
  --ai-panel-w:       360px;
  --ai-panel-h:       520px;
}

/* ── Launcher button ──────────────────────────────────────────────────────── */
.ai-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--ai-z);

  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--ai-accent);
  color: #fff;
  box-shadow: var(--ai-shadow);

  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
}

.ai-chat-launcher:hover,
.ai-chat-launcher:focus-visible {
  background: var(--ai-accent-hover);
  transform: scale(1.08);
  outline: none;
}

/* Icon swap — show chat icon by default, show × when open */
.ai-chat-icon { width: 26px; height: 26px; }
.ai-chat-icon--close { display: none; }

.ai-chat-launcher[aria-expanded="true"] .ai-chat-icon--open  { display: none; }
.ai-chat-launcher[aria-expanded="true"] .ai-chat-icon--close { display: block; }

/* ── Panel ────────────────────────────────────────────────────────────────── */
.ai-chat-panel {
  position: fixed;
  bottom: 92px;    /* sits above the launcher */
  right: 24px;
  z-index: var(--ai-z);

  width: var(--ai-panel-w);
  max-width: calc(100vw - 32px);
  height: var(--ai-panel-h);
  max-height: calc(100vh - 120px);

  background: var(--ai-panel-bg);
  border-radius: var(--ai-radius-panel);
  box-shadow: var(--ai-shadow);
  font-family: var(--ai-font);
  font-size: 14px;
  line-height: 1.55;

  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Hidden by default — toggled via JS */
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.ai-chat-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--ai-header-bg);
  color: var(--ai-header-text);
  flex-shrink: 0;
}

.ai-chat-header__title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-chat-header__close {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
  opacity: 0.85;
  transition: opacity 0.15s;
}
.ai-chat-header__close:hover { opacity: 1; }

/* ── Message list ─────────────────────────────────────────────────────────── */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

/* Shared message row */
.ai-chat-message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.ai-chat-message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.ai-chat-message--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

/* Bubbles */
.ai-chat-bubble {
  padding: 10px 14px;
  border-radius: var(--ai-radius-bubble);
  word-break: break-word;
  white-space: pre-wrap;
}

.ai-chat-message--user .ai-chat-bubble {
  background: var(--ai-user-bg);
  color: var(--ai-user-text);
  border-bottom-right-radius: 4px;
}

.ai-chat-message--assistant .ai-chat-bubble {
  background: var(--ai-bot-bg);
  color: var(--ai-bot-text);
  border-bottom-left-radius: 4px;
}

/* Inline links inside assistant / error bubbles */
.ai-chat-bubble__link {
  color: var(--ai-accent);
  text-decoration: underline;
  word-break: break-all;
}
.ai-chat-bubble__link:hover {
  color: var(--ai-accent-hover);
}

/* "Generated with AI" attribution tag */
.ai-chat-attribution {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  padding: 3px 8px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  font-size: 11px;
  color: #94a3b8;
  user-select: none;
}

.ai-chat-attribution__icon {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  color: var(--ai-accent);
}

.ai-chat-sources__link::before {
  content: '↗';
  flex-shrink: 0;
  font-size: 11px;
  opacity: 0.7;
}

.ai-chat-sources__link:hover {
  background: #dbeafe;
  border-color: var(--ai-accent);
  text-decoration: none;
}

/* ── Typing indicator ─────────────────────────────────────────────────────── */
.ai-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--ai-bot-bg);
  border-radius: var(--ai-radius-bubble);
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.ai-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: ai-bounce 1.2s infinite ease-in-out;
}

.ai-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-6px); }
}

/* ── Error message ────────────────────────────────────────────────────────── */
.ai-chat-message--error .ai-chat-bubble {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

/* ── Input area ───────────────────────────────────────────────────────────── */
.ai-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--ai-input-border);
  flex-shrink: 0;
  background: var(--ai-panel-bg);
}

.ai-chat-input {
  flex: 1;
  border: 1px solid var(--ai-input-border);
  border-radius: 24px;
  padding: 9px 16px;
  font-size: 14px !important;
  font-family: var(--ai-font);
  outline: none;
  background: #f8fafc;
  transition: border-color 0.15s;
}

.ai-chat-input:focus {
  border-color: var(--ai-accent);
  background: #fff;
}

.ai-chat-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--ai-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}

.ai-chat-send svg { width: 18px; height: 18px; }

.ai-chat-send:hover   { background: var(--ai-accent-hover); }
.ai-chat-send:active  { transform: scale(0.93); }

.ai-chat-send:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

/* ── Accessibility helper ─────────────────────────────────────────────────── */
.screen-reader-text {
  clip: rect(1px, 1px, 1px, 1px);
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #ai-chat-root {
    --ai-panel-w: 100vw;
    --ai-panel-h: 75vh;
  }

  .ai-chat-panel {
    right: 0;
    bottom: 76px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .ai-chat-launcher {
    bottom: 16px;
    right: 16px;
  }
}

/* ── Email capture card ───────────────────────────────────────────────────── */
.ai-chat-email-capture {
  background: var(--ai-bg, #f3f4f6);
  border: 1px solid var(--ai-border, #e5e7eb);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 0 4px;
  font-size: var(--ai-bot-text);
}

.ai-chat-email-capture__prompt {
  margin: 0 0 8px;
  color: var(--ai-bot-text);
  font-weight: 500;
  font-size: var(--ai-bot-text);
}

.ai-chat-email-capture__row {
  display: flex;
  gap: 6px;
}

.ai-chat-email-capture__input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--ai-border, #d1d5db);
  border-radius: 6px;
  font-size: 12px !important;
  background: #fff;
  color: var(--ai-bot-text, #111827);
  outline: none;
  transition: border-color 0.15s;
}

.ai-chat-email-capture__input:focus {
  border-color: var(--ai-brand, #2563eb);
}

.ai-chat-email-capture__btn {
  padding: 6px 14px;
  background: var(--ai-brand, #2563eb);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.ai-chat-email-capture__btn:hover:not(:disabled) {
  background: var(--ai-brand-hover, #1d4ed8);
}

.ai-chat-email-capture__btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ai-chat-email-capture__feedback {
  margin: 6px 0 0;
  color: #dc2626;
  font-size: 0.8125rem;
}

.ai-chat-email-capture__success {
  margin: 0;
  color: #16a34a;
  font-weight: 600;
  font-size: var(--ai-bot-text, #111827);

}
