/* ===========================================================
   AI assistant widget — uses the site's existing design tokens.
   Restyle here once a new visual direction is finalized.
   =========================================================== */

.chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 200;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #04070d;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, background-color 0.25s ease, border-color 0.25s ease;
}
.chat-launcher:hover { transform: translateY(-2px); }
.chat-launcher svg { display: block; }
.chat-launcher .icon-close { display: none; }
.chat-launcher.is-open .icon-chat { display: none; }
.chat-launcher.is-open .icon-close { display: block; }

.chat-launcher-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-2);
  border: 2px solid var(--bg);
}

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 199;
  width: min(380px, calc(100vw - 48px));
  height: min(560px, calc(100vh - 140px));
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, background-color 0.25s ease, border-color 0.25s ease;
}
.chat-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-panel-title { font-weight: 600; font-size: 0.94rem; line-height: 1.3; }
.chat-panel-subtitle { font-size: 0.76rem; color: var(--text-faint); font-family: var(--mono); }
.chat-panel-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-panel-close:hover { background: var(--bg-elevated); color: var(--text); }

.chat-disclosure {
  font-size: 0.74rem;
  color: var(--text-faint);
  padding: 8px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-message a { color: var(--accent); text-decoration: underline; }
.chat-message.from-assistant {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-message.from-user {
  align-self: flex-end;
  background: var(--accent);
  color: #04070d;
  border-bottom-right-radius: 4px;
}
.chat-message.from-error {
  align-self: stretch;
  background: transparent;
  border: 1px dashed var(--status-dev-border);
  color: var(--status-dev-color);
  font-size: 0.82rem;
}
.chat-message.from-error button {
  display: block;
  margin-top: 8px;
  background: none;
  border: 1px solid currentColor;
  color: inherit;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}

.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 13px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: chat-typing-bounce 1.1s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-typing span { animation: none; opacity: 0.8; }
}

.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 18px 12px;
  flex-shrink: 0;
}
.chat-quick-reply {
  font-family: var(--mono);
  font-size: 0.74rem;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.chat-quick-reply:hover { border-color: var(--border-hover); color: var(--text); }

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-input-row textarea {
  flex: 1;
  resize: none;
  max-height: 100px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.88rem;
  line-height: 1.4;
}
.chat-input-row textarea:focus { outline: none; border-color: var(--accent); }
.chat-send {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #04070d;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-footer-link {
  text-align: center;
  padding: 8px 18px 14px;
  font-size: 0.76rem;
  color: var(--text-faint);
  flex-shrink: 0;
}
.chat-footer-link a { color: var(--accent); }

@media (max-width: 480px) {
  .chat-panel {
    right: 12px;
    left: 12px;
    bottom: 88px;
    width: auto;
    height: min(70vh, 560px);
  }
  .chat-launcher { right: 16px; bottom: 16px; }
}
