.ai-chat {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 95;
  font-family: "Inter", system-ui, sans-serif;
}

.ai-chat-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  border: 0;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 10px 30px rgba(31, 77, 58, 0.28);
  transition: transform 0.22s ease, box-shadow 0.22s ease, background 0.22s ease;
}

.ai-chat-toggle:hover {
  transform: translateY(-3px);
  background: var(--brand-dark);
  box-shadow: 0 14px 36px rgba(31, 77, 58, 0.34);
}

.ai-chat-toggle svg {
  width: 1.45rem;
  height: 1.45rem;
}

.ai-chat-toggle.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.92);
}

.ai-chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.85rem);
  display: flex;
  flex-direction: column;
  width: min(24rem, calc(100vw - 2rem));
  max-height: min(32rem, calc(100vh - 7rem));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(28, 36, 33, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.24s ease, transform 0.24s ease, visibility 0.24s ease;
}

.ai-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.ai-chat-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f8fbf9 0%, #fff 100%);
}

.ai-chat-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-chat-status-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--brand);
  box-shadow: 0 0 0 3px rgba(60, 177, 121, 0.2);
}

.ai-chat-title {
  flex: 1;
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.3;
}

.ai-chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  transition: background 0.2s ease, color 0.2s ease;
}

.ai-chat-close:hover {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.ai-chat-close svg {
  width: 1.1rem;
  height: 1.1rem;
}

.ai-chat-messages {
  flex: 1;
  min-height: 11rem;
  padding: 1rem;
  overflow-y: auto;
  background: #fcfefd;
}

.ai-chat-message {
  max-width: 92%;
  margin-bottom: 0.75rem;
}

.ai-chat-message--bot {
  margin-right: auto;
}

.ai-chat-message--bot p {
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem 1rem 1rem 0.35rem;
  background: #fff;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.65;
  box-shadow: var(--shadow-sm);
}

.ai-chat-message--user {
  margin-left: auto;
}

.ai-chat-message--user p {
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--brand-dark);
  border-radius: 1rem 1rem 0.35rem 1rem;
  background: var(--brand);
  color: #fff;
  font-size: 0.88rem;
  line-height: 1.65;
  box-shadow: 0 6px 18px rgba(60, 177, 121, 0.22);
}

.ai-chat-typing {
  padding: 0;
}

.ai-chat-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem 1rem 1rem 0.35rem;
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.ai-chat-typing-dots span {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: var(--brand);
  opacity: 0.35;
  animation: ai-chat-dot-pulse 1.2s ease-in-out infinite;
}

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

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

@keyframes ai-chat-dot-pulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.ai-chat-send:disabled,
.ai-chat-input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.ai-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  padding: 0.85rem;
  border-top: 1px solid var(--border);
  background: #fff;
}

.ai-chat-input {
  flex: 1;
  min-height: 2.75rem;
  max-height: 6rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.45;
  resize: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-input::placeholder {
  color: #8a968f;
}

.ai-chat-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(60, 177, 121, 0.15);
}

.ai-chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  transition: background 0.2s ease, transform 0.2s ease;
}

.ai-chat-send:hover {
  background: var(--brand-dark);
  transform: translateY(-1px);
}

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

@media (max-width: 640px) {
  .ai-chat {
    right: 0;
    bottom: 0;
    left: 0;
    pointer-events: none;
  }

  .ai-chat-toggle {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    pointer-events: auto;
  }

  .ai-chat-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: min(88vh, 100%);
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transform-origin: bottom center;
  }

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

  .ai-chat-panel.is-open ~ .ai-chat-toggle,
  .ai-chat:has(.ai-chat-panel.is-open) .ai-chat-toggle {
    opacity: 0;
    pointer-events: none;
  }
}
