/* ═══════════════════════════════════════════════════════════════════════
   AI Chat Widget + Landing AI Bar
   Uses existing design tokens from base.css
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Floating trigger button ──────────────────────────────────────────── */
.ai-chat-trigger {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-brand);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: var(--z-dropdown, 100);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, opacity 0.2s;
}
.ai-chat-trigger:hover { transform: scale(1.08); }
.ai-chat-trigger .material-symbols-rounded { font-size: 24px; }

/* Hide trigger when panel is open */
.ai-chat-widget.open .ai-chat-trigger { opacity: 0; pointer-events: none; }

/* ── Chat panel ───────────────────────────────────────────────────────── */
.ai-chat-panel {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 400px;
  max-height: 560px;
  background: var(--bg-card, hsl(220,18%,13%));
  border: 1px solid var(--border, hsl(220,14%,20%));
  border-radius: var(--radius-xl, 12px);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-modal, 1000);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: aiChatIn 0.15s ease-out;
}
.ai-chat-widget.open .ai-chat-panel { display: flex; }

@keyframes aiChatIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Header ───────────────────────────────────────────────────────────── */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-chat-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-chat-header-icon {
  color: var(--color-brand);
  font-size: 20px;
}
.ai-chat-header-title {
  font-weight: 600;
  font-size: var(--fs-md, 0.875rem);
  color: var(--text-primary);
}
.ai-chat-remaining {
  font-size: var(--fs-xs, 0.6875rem);
  color: var(--text-muted);
}
.ai-chat-header-actions {
  display: flex;
  gap: 4px;
}
.ai-chat-btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.ai-chat-btn-icon:hover { color: var(--text-primary); background: var(--bg-hover, hsla(0,0%,100%,0.06)); }
.ai-chat-btn-icon .material-symbols-rounded { font-size: 18px; }

/* ── Messages area ────────────────────────────────────────────────────── */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
  max-height: 360px;
}

/* Welcome state */
.ai-chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 0;
  text-align: center;
}
.ai-chat-welcome-icon {
  font-size: 32px;
  color: var(--color-brand);
  opacity: 0.6;
}
.ai-chat-welcome-text {
  color: var(--text-secondary);
  font-size: var(--fs-sm, 0.8125rem);
  max-width: 260px;
  line-height: 1.5;
}

/* Suggestion chips */
.ai-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.ai-chat-chip {
  background: var(--bg-hover, hsla(0,0%,100%,0.06));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: var(--fs-xs, 0.6875rem);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.ai-chat-chip:hover {
  border-color: var(--color-brand);
  color: var(--color-brand);
}

/* Message bubbles */
.ai-chat-msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: var(--fs-sm, 0.8125rem);
  line-height: 1.55;
  word-wrap: break-word;
}
.ai-chat-msg-user {
  align-self: flex-end;
  background: var(--color-brand-dim, hsla(25,100%,50%,0.12));
  color: var(--text-primary);
  border-radius: 12px 12px 4px 12px;
}
.ai-chat-msg-ai {
  align-self: flex-start;
  background: var(--bg-hover, hsla(0,0%,100%,0.06));
  color: var(--text-primary);
  border-radius: 12px 12px 12px 4px;
}

/* Markdown inside AI messages */
.ai-chat-msg-ai strong { font-weight: 600; }
.ai-chat-msg-ai code {
  background: var(--bg-input, hsl(220,16%,16%));
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.8em;
}
.ai-chat-msg-ai pre {
  background: var(--bg-input);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}
.ai-chat-msg-ai ul, .ai-chat-msg-ai ol {
  padding-left: 16px;
  margin: 4px 0;
}
.ai-chat-msg-ai table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: var(--fs-xs);
  width: 100%;
}
.ai-chat-msg-ai th, .ai-chat-msg-ai td {
  border: 1px solid var(--border);
  padding: 3px 6px;
  text-align: left;
}
.ai-chat-msg-ai th { font-weight: 600; }
.ai-chat-msg-ai a {
  color: var(--color-brand);
  text-decoration: none;
}
.ai-chat-msg-ai a:hover { text-decoration: underline; }

/* Feedback */
.ai-chat-feedback {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  justify-content: flex-end;
}
.ai-chat-fb-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  font-size: 14px;
}
.ai-chat-fb-btn:hover { color: var(--color-brand); }
.ai-chat-fb-btn.active { color: var(--color-brand); }

/* Streaming cursor */
.ai-chat-cursor {
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--color-brand);
  margin-left: 2px;
  animation: aiCursorBlink 0.8s step-end infinite;
  vertical-align: text-bottom;
}
@keyframes aiCursorBlink {
  50% { opacity: 0; }
}

/* ── Tool indicator ───────────────────────────────────────────────────── */
.ai-chat-tool {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: var(--fs-xs);
  color: var(--color-brand);
  flex-shrink: 0;
}
.ai-chat-tool-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-brand-dim, hsla(25,100%,50%,0.25));
  border-top-color: var(--color-brand);
  border-radius: 50%;
  animation: aiSpin 0.6s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }

/* ── Input area ───────────────────────────────────────────────────────── */
.ai-chat-input-area {
  border-top: 1px solid var(--border);
  padding: 10px 14px 8px;
  flex-shrink: 0;
}
.ai-chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.ai-chat-input {
  flex: 1;
  background: var(--bg-input, hsl(220,16%,16%));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: var(--fs-sm, 0.8125rem);
  font-family: inherit;
  resize: none;
  max-height: 72px;
  overflow-y: auto;
  line-height: 1.4;
}
.ai-chat-input:focus {
  outline: none;
  border-color: var(--color-brand);
}
.ai-chat-input::placeholder { color: var(--text-muted); }
.ai-chat-send {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--color-brand);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.ai-chat-send:disabled {
  opacity: 0.35;
  cursor: default;
}
.ai-chat-send .material-symbols-rounded { font-size: 18px; }
.ai-chat-input-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}
.ai-chat-hint {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.5;
}

/* ── Landing page AI bar ──────────────────────────────────────────────── */
.landing-search-mode-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  justify-content: center;
}
.landing-mode-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 14px;
  border-radius: 16px;
  border: 1px solid var(--border, hsl(220,14%,20%));
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s;
}
.landing-mode-btn .material-icons { font-size: 16px; }
.landing-mode-btn.active {
  background: var(--color-brand-dim, hsla(25,100%,50%,0.12));
  border-color: var(--color-brand);
  color: var(--color-brand);
}
.landing-mode-btn:hover:not(.active) {
  border-color: var(--text-muted);
}

/* Hide/show based on mode */
.landing-search--ai-mode .landing-search-bar { display: none; }
.landing-search--ai-mode .landing-ai-bar { display: flex; }
.landing-ai-bar { display: none; }

.landing-ai-bar {
  flex-direction: column;
  gap: 10px;
}
.landing-ai-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input, hsl(220,16%,16%));
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  height: 46px;
}
.landing-ai-input-row .material-icons {
  color: var(--color-brand);
  font-size: 20px;
}
.landing-ai-input-row input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.9375rem;
  outline: none;
}
.landing-ai-input-row input::placeholder { color: var(--text-muted); }
.landing-ai-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.landing-ai-send {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--color-brand);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.landing-ai-send:disabled { opacity: 0.35; cursor: default; }
.landing-ai-send .material-icons { font-size: 18px; }

.landing-ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.landing-ai-chip {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 5px 14px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.landing-ai-chip:hover {
  border-color: var(--color-brand);
  color: var(--color-brand);
}

/* Landing AI response area */
.landing-ai-response {
  background: var(--bg-card, hsl(220,18%,13%));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-primary);
}
.landing-ai-response:empty { display: none; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 48rem) {
  .ai-chat-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 70vh;
    border-radius: 12px 12px 0 0;
  }
}
