/* AI chat popup — stable layout, always-visible close */
.ai-chat-modal {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.ai-chat-modal.is-open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  touch-action: none;
}

.ai-chat-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 2, 8, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
}

.ai-chat-modal__dialog {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  height: min(720px, 90vh);
  height: min(720px, 90dvh);
  max-height: 90vh;
  max-height: 90dvh;
  background: #000205;
  border: 1px solid rgba(0, 247, 255, 0.28);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 32px rgba(0, 247, 255, 0.1);
  overflow: hidden;
  transform: translateY(12px) scale(0.98);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  touch-action: auto;
}

.ai-chat-modal.is-open .ai-chat-modal__dialog {
  transform: translateY(0) scale(1);
}

/* Header: title left, close always top-right */
.ai-chat-modal__header {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 14px 14px 12px 18px;
  border-bottom: 1px solid rgba(0, 247, 255, 0.15);
  background: rgba(0, 8, 28, 0.98);
  flex-shrink: 0;
  overflow: visible;
}

.ai-chat-modal__title-wrap {
  grid-column: 1;
  min-width: 0;
}

.ai-chat-modal__title-wrap .contact-panel-label {
  margin-bottom: 4px;
}

.ai-chat-modal__header h2 {
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  font-family: "Ubuntu", sans-serif;
  line-height: 1.25;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat-modal__title-wrap .contact-chat-status {
  display: inline-flex;
  margin-top: 4px;
}

.ai-chat-modal__close {
  position: relative;
  z-index: 5;
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0, 247, 255, 0.45);
  border-radius: 8px;
  background: rgba(0, 247, 255, 0.12);
  color: #00f7ff;
  font-family: "Poppins", sans-serif;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.ai-chat-modal__close-glyph {
  display: block;
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  margin-top: -2px;
  pointer-events: none;
}

.ai-chat-modal__close:hover,
.ai-chat-modal__close:focus-visible {
  background: rgba(0, 247, 255, 0.22);
  border-color: #00f7ff;
  color: #fff;
  outline: none;
}

.ai-chat-modal__close:active {
  transform: scale(0.94);
}

/* Body — flex fill, no min-height conflicts */
.ai-chat-modal__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 16px 16px;
  overflow: hidden;
}

.ai-chat-modal .contact-chat-messages {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  margin-bottom: 12px;
  padding: 12px;
  user-select: text;
  -webkit-user-select: text;
}

.ai-chat-modal .contact-chat-input-wrap {
  flex-shrink: 0;
  width: 100%;
  min-width: 0;
}

.ai-chat-modal .contact-chat-input-wrap textarea {
  font-size: 15px;
  min-width: 0;
}

.ai-chat-modal .contact-chat-send {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
}

.ai-chat-modal .chat-msg {
  max-width: 92%;
}

.ai-chat-modal .chat-msg-bot {
  max-width: 96%;
}

.ai-chat-modal .chat-bubble {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.contact-ai-launch {
  display: flex;
  flex-direction: column;
  gap: 16px;
  justify-content: center;
  min-height: 100%;
}

.contact-ai-trigger {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
  padding: 8px 22px 8px 8px;
  border: none;
  background: transparent;
  color: #fbff00;
  font-family: "Poppins", sans-serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: color 0.3s ease;
}

.contact-ai-trigger:hover,
.contact-ai-trigger:focus-visible {
  color: #00f7ff;
}

.contact-ai-trigger__label {
  color: inherit;
}

body.ai-chat-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  left: 0;
  right: 0;
  touch-action: none;
}

body.ai-chat-open .contact-icons,
body.ai-chat-open #site-header .site-nav-burger {
  visibility: hidden;
  pointer-events: none;
}

@media (min-width: 1200px) {
  .ai-chat-modal {
    padding: 24px;
  }

  .ai-chat-modal__dialog {
    width: min(900px, calc(100vw - 48px));
    height: min(780px, 90dvh);
  }
}

/* Full screen on mobile */
@media (max-width: 768px) {
  .ai-chat-modal {
    padding: 0;
  }

  .ai-chat-modal__dialog {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
  }

  .ai-chat-modal .chat-msg,
  .ai-chat-modal .chat-msg-bot {
    max-width: 92%;
  }

  .ai-chat-modal__header {
    padding: 12px 12px 10px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .ai-chat-modal__close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .ai-chat-modal__body {
    padding: 10px 12px 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .ai-chat-modal .contact-chat-messages {
    padding: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat-modal,
  .ai-chat-modal__dialog {
    transition: none;
  }

  .ai-chat-modal__dialog {
    transform: none;
  }
}
