/* ─── AI ASSISTANT ─── */

/* Floating button */
.chat-fab {
  position: fixed;
  bottom: clamp(1.25rem, 3vw, 2rem);
  right: clamp(1.25rem, 3vw, 2rem);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1.5px solid var(--brand);
  background: var(--brand);
  color: var(--dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: all 0.35s var(--ease-out);
  box-shadow: 0 8px 24px rgba(252, 170, 45, 0.25);
}

.chat-fab:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(252, 170, 45, 0.35);
}

.chat-fab:active {
  transform: translateY(-1px);
}

.chat-fab svg {
  width: 24px;
  height: 24px;
  transition: transform 0.3s var(--ease-out);
}

.chat-fab.is-open svg {
  transform: rotate(90deg);
}

/* Panel overlay */
.chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(24, 19, 18, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease-out);
}

.chat-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* Chat panel */
.chat-panel {
  position: fixed;
  bottom: clamp(5rem, 10vw, 6.5rem);
  right: clamp(1.25rem, 3vw, 2rem);
  width: min(420px, calc(100vw - 2rem));
  height: min(600px, calc(100vh - 8rem));
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  z-index: 1001;
  overflow: hidden;
  transform: translateY(12px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s var(--ease-out), opacity 0.35s var(--ease-out);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
}

.chat-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--card-border);
  flex-shrink: 0;
}

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

.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(252, 170, 45, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  flex-shrink: 0;
}

.chat-header-avatar svg {
  width: 18px;
  height: 18px;
}

.chat-header-info h4 {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.2;
}

.chat-header-info p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s var(--ease-out);
  flex-shrink: 0;
}

.chat-close:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.chat-close svg {
  width: 16px;
  height: 16px;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
  scroll-behavior: smooth;
  background: var(--bg);
}

.chat-messages > .chat-msg:first-child .chat-bubble {
  background: rgba(252, 170, 45, 0.08);
  border-color: rgba(252, 170, 45, 0.2);
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--card-border);
  border-radius: 2px;
}

/* Message bubbles */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: chatMsgIn 0.3s var(--ease-out) forwards;
}

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

.chat-msg-user {
  align-self: flex-end;
}

.chat-msg-assistant {
  align-self: flex-start;
}

.chat-bubble {
  padding: 0.875rem 1.125rem;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  line-height: 1.7;
  word-wrap: break-word;
}

.chat-msg-user .chat-bubble {
  background: var(--brand);
  color: var(--dark);
  border-bottom-right-radius: 0.25rem;
}

.chat-msg-assistant .chat-bubble {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-left: 3px solid var(--brand);
  border-bottom-left-radius: 0.25rem;
}

.chat-msg-label {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  padding: 0 0.25rem;
  letter-spacing: 0.02em;
}

.chat-msg-user .chat-msg-label {
  text-align: right;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.125rem;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 0.25rem;
  align-self: flex-start;
  animation: chatMsgIn 0.3s var(--ease-out) forwards;
}

.chat-typing-dots {
  display: flex;
  gap: 4px;
}

.chat-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chatDotPulse 1.4s ease-in-out infinite;
}

.chat-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes chatDotPulse {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Links in bubbles */
.chat-bubble a {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: opacity 0.2s var(--ease-out);
}

.chat-bubble a:hover {
  opacity: 0.8;
}

.chat-msg-user .chat-bubble a {
  color: var(--dark);
}

/* Error message */
.chat-error {
  padding: 0.75rem 1rem;
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: #ef4444;
  align-self: center;
  text-align: center;
  max-width: 90%;
  animation: chatMsgIn 0.3s var(--ease-out) forwards;
}

/* Input area */
.chat-input-area {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--card-border);
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--card-border);
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(252, 170, 45, 0.1);
}

.chat-send {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--brand);
  background: var(--brand);
  color: var(--dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.25s var(--ease-out);
}

.chat-send:hover:not(:disabled) {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  transform: translateY(-1px);
}

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

.chat-send svg {
  width: 18px;
  height: 18px;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .chat-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }

  .chat-fab {
    bottom: 1.25rem;
    right: 1.25rem;
  }
}
