/* ─── AI Chat Widget ─────────────────────────────────────── */
.ai-chat-widget *,
.ai-chat-widget *::before,
.ai-chat-widget *::after {
  box-sizing: border-box;
}

.ai-chat-widget {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ── Chat window ──────────────────────────────────── */
.ai-chat-window {
  width: min(420px, calc(100vw - 2.5rem));
  margin-bottom: 0.75rem;
  overflow: hidden;
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(2, 6, 23, 0.95);
  box-shadow: 0 24px 90px -28px rgba(45, 212, 191, 0.5);
  backdrop-filter: blur(24px);
  display: none;
}

.ai-chat-window.open {
  display: block;
}

/* ── Header ───────────────────────────────────────── */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.75rem 1rem;
}

.ai-chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ai-chat-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(45, 212, 191, 0.2);
  background: rgba(45, 212, 191, 0.1);
  color: #99f6e4;
}

.ai-chat-avatar svg {
  width: 1.25rem;
  height: 1.25rem;
}

.ai-chat-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.25rem;
}

.ai-chat-subtitle {
  font-size: 0.75rem;
  color: #64748b;
  line-height: 1rem;
}

.ai-chat-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: #94a3b8;
  cursor: pointer;
  transition: color 0.15s;
}

.ai-chat-collapse-btn:hover {
  color: #fff;
}

.ai-chat-collapse-btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* ── Messages area ────────────────────────────────── */
.ai-chat-messages {
  max-height: 380px;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 2px;
}

.ai-msg {
  border-radius: 1rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.5rem;
  animation: aiMsgFadeIn 0.2s ease-out;
}

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

.ai-msg--user {
  margin-left: 2rem;
  background: #5eead4;
  color: #020617;
}

.ai-msg--assistant {
  margin-right: 2rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
}

.ai-msg--thinking {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: 2rem;
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: #94a3b8;
}

.ai-chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-right: 2rem;
}

.ai-chat-quick-reply {
  min-height: 2.25rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(45, 212, 191, 0.25);
  background: rgba(45, 212, 191, 0.08);
  padding: 0.45rem 0.75rem;
  color: #ccfbf1;
  font-size: 0.8125rem;
  line-height: 1.125rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.ai-chat-quick-reply:hover {
  border-color: rgba(45, 212, 191, 0.45);
  background: rgba(45, 212, 191, 0.14);
  color: #fff;
}

.ai-spinner {
  width: 1rem;
  height: 1rem;
  animation: aiSpin 1s linear infinite;
}

@keyframes aiSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ── Error bar ────────────────────────────────────── */
.ai-chat-error {
  border-top: 1px solid rgba(251, 113, 133, 0.15);
  background: rgba(251, 113, 133, 0.1);
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  line-height: 1.25rem;
  color: #ffe4e6;
}

/* ── Form ─────────────────────────────────────────── */
.ai-chat-form {
  display: flex;
  gap: 0.375rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.75rem;
}

.ai-chat-input {
  flex: 1;
  min-width: 0;
  height: 2.75rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(15, 23, 42, 0.8);
  padding: 0 0.75rem;
  font-size: 0.875rem;
  color: #fff;
  outline: none;
  transition: border-color 0.15s;
}

.ai-chat-input::placeholder {
  color: #64748b;
}

.ai-chat-input:focus {
  border-color: rgba(45, 212, 191, 0.4);
}

.ai-chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.75rem;
  border: none;
  background: #5eead4;
  color: #020617;
  cursor: pointer;
  transition: background 0.15s;
}

.ai-chat-send-btn:hover:not(:disabled) {
  background: #99f6e4;
}

.ai-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-chat-send-btn svg {
  width: 1rem;
  height: 1rem;
}

/* ── Microphone button ────────────────────────────── */
.ai-chat-mic-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.2s;
}

.ai-chat-mic-btn:hover {
  color: #5eead4;
  border-color: rgba(45, 212, 191, 0.3);
  background: rgba(45, 212, 191, 0.08);
}

.ai-chat-mic-btn.is-recording {
  color: #f43f5e;
  border-color: rgba(244, 63, 94, 0.4);
  background: rgba(244, 63, 94, 0.12);
  animation: aiMicPulse 1.2s ease-in-out infinite;
}

.ai-chat-mic-btn svg {
  width: 1rem;
  height: 1rem;
}

@keyframes aiMicPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.4);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(244, 63, 94, 0);
  }
}

/* ── Message wrapper & speak button ───────────────── */
.ai-msg-wrapper {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.375rem;
}

.ai-msg-wrapper > .ai-msg {
  flex: 1;
  min-width: 0;
}

.ai-msg-speak-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  margin-top: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  color: #64748b;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s;
}

.ai-msg-wrapper:hover .ai-msg-speak-btn {
  opacity: 1;
}

.ai-msg-speak-btn:hover {
  color: #5eead4;
  border-color: rgba(45, 212, 191, 0.3);
  background: rgba(45, 212, 191, 0.08);
  opacity: 1;
}

.ai-msg-speak-btn.is-speaking {
  color: #f43f5e;
  border-color: rgba(244, 63, 94, 0.3);
  background: rgba(244, 63, 94, 0.1);
  opacity: 1;
  animation: aiSpeakPulse 1s ease-in-out infinite;
}

.ai-msg-speak-btn svg {
  width: 0.875rem;
  height: 0.875rem;
}

@keyframes aiSpeakPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.3);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(244, 63, 94, 0);
  }
}

/* ── Toggle button ────────────────────────────────── */
.ai-chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  height: 3.5rem;
  border-radius: 1rem;
  border: 1px solid rgba(45, 212, 191, 0.25);
  background: rgba(2, 6, 23, 0.9);
  padding: 0 1rem;
  font-weight: 600;
  font-size: 0.875rem;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 18px 60px -22px rgba(45, 212, 191, 0.75);
  backdrop-filter: blur(24px);
  transition: border-color 0.15s, background 0.15s;
}

.ai-chat-toggle:hover {
  border-color: rgba(45, 212, 191, 0.45);
  background: rgba(15, 23, 42, 0.9);
}

.ai-chat-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
  color: #99f6e4;
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 480px) {
  .ai-chat-widget {
    bottom: 0.75rem;
    right: 0.75rem;
  }

  .ai-chat-window {
    width: calc(100vw - 1.5rem);
  }

  .ai-msg--user {
    margin-left: 1rem;
  }

  .ai-msg--assistant {
    margin-right: 1rem;
  }
}
