/* ---------- AI chat host (wraps hero robot) ---------- */
.ai-chat-host {
  position: absolute;
  right: max(var(--hero-gutter), 2vw);
  bottom: clamp(100px, 14vh, 160px);
  width: min(360px, calc(100vw - var(--hero-gutter) * 2));
  z-index: 20;
}

.ai-chat-host.is-open::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: 100%;
  width: min(360px, 100%);
  height: calc(min(440px, 58vh) + 14px);
  pointer-events: auto;
}

.ai-chat-trigger {
  all: unset;
  box-sizing: border-box;
  display: block;
  width: min(160px, 18vw);
  margin-left: auto;
  cursor: pointer;
  pointer-events: auto;
  position: relative;
}

.ai-chat-trigger:focus-visible {
  outline: 2px solid #54b4dc;
  outline-offset: 4px;
  border-radius: 12px;
}

.ai-chat-hint {
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%) translateY(100%);
  padding: 4px 10px;
  border-radius: 999px;
  background: #0a0a0a;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}

.ai-chat-host:not(.is-open):hover .ai-chat-hint {
  opacity: 1;
  transform: translateX(-50%) translateY(calc(100% + 4px));
}

.ai-chat-host.is-open .ai-chat-hint {
  opacity: 0;
}

/* ---------- Chat panel ---------- */
.ai-chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  width: min(360px, calc(100vw - var(--hero-gutter) * 2));
  height: min(440px, 58vh);
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.16),
    0 8px 20px rgba(84, 180, 220, 0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.96);
  transform-origin: bottom right;
  transition:
    opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0.3s;
  pointer-events: none;
  overflow: hidden;
}

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

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background: linear-gradient(180deg, #fafafa 0%, #fff 100%);
  flex-shrink: 0;
}

.ai-chat-header__meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-chat-header__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15);
}

.ai-chat-header__title {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #0a0a0a;
}

.ai-chat-header__status {
  font-size: 0.75rem;
  font-weight: 600;
  color: #888;
}

.ai-chat-close {
  all: unset;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 1.4rem;
  line-height: 1;
  color: #666;
  transition: background 0.2s ease, color 0.2s ease;
}

.ai-chat-close:hover {
  background: #f0f0f0;
  color: #0a0a0a;
}

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

.ai-chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.55;
  font-weight: 500;
  word-break: break-word;
}

.ai-chat-msg--bot {
  align-self: flex-start;
  background: #f3f4f6;
  color: #111;
  border-bottom-left-radius: 4px;
}

.ai-chat-msg--user {
  align-self: flex-end;
  background: #0a0a0a;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-chat-msg--typing {
  align-self: flex-start;
  background: #f3f4f6;
  color: #888;
  font-style: italic;
}

.ai-chat-form {
  padding: 12px 14px 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
}

.ai-chat-form__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.ai-chat-form__row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ai-chat-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1.5px solid #e5e5e5;
  border-radius: 12px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  color: #0a0a0a;
  background: #fafafa;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.ai-chat-input:focus {
  outline: none;
  border-color: #54b4dc;
  background: #fff;
}

.ai-chat-send {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #0a0a0a;
  color: #fff;
  transition: transform 0.2s ease, background 0.2s ease;
}

.ai-chat-send:hover {
  background: #222;
  transform: scale(1.04);
}

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

.ai-chat-host.is-visible .hero__robot-lottie {
  animation: robot-float 4.5s ease-in-out infinite 0.8s;
}

@media (max-width: 1600px) {
  .ai-chat-host {
    bottom: clamp(96px, 13vh, 150px);
  }
}

@media (max-width: 1200px) {
  .ai-chat-host {
    width: min(340px, calc(100vw - var(--hero-gutter) * 2));
  }

  .ai-chat-panel {
    width: min(340px, calc(100vw - var(--hero-gutter) * 2));
    height: min(420px, 54vh);
  }
}

@media (max-width: 984px) {
  .ai-chat-host {
    width: min(320px, calc(100vw - 32px));
    bottom: clamp(88px, 12vh, 130px);
  }

  .ai-chat-trigger {
    width: min(120px, 22vw);
  }

  .ai-chat-host.is-open::after {
    width: min(320px, 100%);
    height: calc(min(400px, 52vh) + 14px);
  }

  .ai-chat-panel {
    width: min(320px, calc(100vw - 32px));
    height: min(400px, 52vh);
  }
}

@media (max-width: 763px) {
  .ai-chat-host {
    bottom: clamp(80px, 11vh, 120px);
  }

  .ai-chat-trigger {
    width: min(104px, 24vw);
  }

  .ai-chat-panel {
    height: min(380px, 50vh);
  }
}

@media (max-width: 640px) {
  .ai-chat-host {
    right: var(--hero-gutter);
    width: min(300px, calc(100vw - 28px));
    bottom: clamp(76px, 10vh, 108px);
  }

  .ai-chat-trigger {
    width: 88px;
  }

  .ai-chat-host.is-open::after {
    width: min(300px, 100%);
  }

  .ai-chat-panel {
    right: 0;
    width: min(300px, calc(100vw - 28px));
    height: min(360px, 48vh);
  }
}

@media (max-width: 420px) {
  .ai-chat-host {
    width: min(100%, calc(100vw - 28px));
    bottom: clamp(68px, 9vh, 96px);
  }

  .ai-chat-panel {
    width: min(100%, calc(100vw - 28px));
    height: min(340px, 46vh);
    border-radius: 16px;
  }
}

@media (hover: none) {
  .ai-chat-hint {
    opacity: 1;
    transform: translateX(-50%) translateY(calc(100% + 4px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat-panel,
  .ai-chat-hint {
    transition: none;
  }

  .ai-chat-host.is-visible .hero__robot-lottie {
    animation: none !important;
  }
}
