/* Floating launcher button */
.chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #2a2a2a;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-transition: -webkit-transform 0.3s ease, box-shadow 0.3s ease;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  z-index: 100000001;
  border: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.chat-launcher:hover {
  -webkit-transform: scale(1.05);
  -ms-transform: scale(1.05);
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.chat-launcher img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center;
}

/* Chat window container */
.chat-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  height: 580px;
  max-height: calc(100vh - 140px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  display: none;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  overflow: hidden;
  z-index: 100000002;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.chat-window.open {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-animation: slideIn 0.3s ease-out;
  animation: slideIn 0.3s ease-out;
}

@-webkit-keyframes slideIn {
  from {
    opacity: 0;
    -webkit-transform: translateY(20px);
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    -webkit-transform: translateY(0);
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    -webkit-transform: translateY(20px);
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    -webkit-transform: translateY(0);
    transform: translateY(0);
  }
}

/* Header */
.chat-header {
  background: -webkit-gradient(linear, left top, right bottom, from(#2a2a2a), to(#1a1a1a));
  background: -webkit-linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
  background: -o-linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
  background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
  color: #f5f5f0;
  padding: 20px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  border-bottom: 1px solid rgba(218, 195, 165, 0.1);
  gap: 12px;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

.chat-header-content {
  display: flex;
  align-items: center;
  flex: 1;
}

.chat-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  margin-right: 12px;
  object-fit: cover;
  object-position: center;
  border: 2px solid rgba(218, 195, 165, 0.3);
}

.chat-header-text h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 2px;
  color: #f5f5f0;
}

.chat-header-text p {
  font-size: 13px;
  color: #dac3a5;
  font-weight: 400;
}

.chat-close-button {
  background: none;
  border: none;
  color: #f5f5f0;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

.chat-close-button:hover {
  opacity: 1;
}

.pro-button {
  background: rgba(218, 195, 165, 0.15);
  border: 1px solid rgba(218, 195, 165, 0.4);
  color: #dac3a5;
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.pro-button:hover {
  background: rgba(218, 195, 165, 0.25);
  border-color: #dac3a5;
}

/* Messages container */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #fafaf8;
  scroll-behavior: smooth;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
  background: #d0d0d0;
  border-radius: 3px;
}

/* Message bubbles */
.message {
  margin-bottom: 16px;
  display: flex;
  animation: messageIn 0.4s ease-out;
  align-items: flex-end;
  gap: 8px;
}

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

.message.bot {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.message.user {
  justify-content: flex-end;
}

.message-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message.bot .message-bubble {
  background: #2a2a2a;
  color: #f5f5f0;
  border-bottom-left-radius: 4px;
}

.message.user .message-bubble {
  background: #e8e3db;
  color: #2a2a2a;
  border-bottom-right-radius: 4px;
}

/* Suggested questions */
.suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  animation: messageIn 0.5s ease-out;
}

.suggestion-button {
  background: #ffffff;
  border: 1px solid #dac3a5;
  color: #2a2a2a;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  font-family: inherit;
}

.suggestion-button:hover {
  background: #dac3a5;
  border-color: #dac3a5;
  color: #ffffff;
  transform: translateX(2px);
}

/* CTA Button */
.cta-button-container {
  display: flex;
  align-items: center;
  animation: messageIn 0.5s ease-out;
}

.cta-button {
  display: inline-flex;
  align-items: center;
  background: linear-gradient(135deg, #dac3a5 0%, #c9b194 100%);
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(218, 195, 165, 0.3);
  white-space: nowrap;
}

.cta-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(218, 195, 165, 0.4);
}

/* Input area */
.chat-input-container {
  padding: 16px 20px;
  background: #ffffff;
  border-top: 1px solid #e8e3db;
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 24px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
  background: #fafaf8;
}

.chat-input:focus {
  border-color: #dac3a5;
  background: #ffffff;
}

.chat-send-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #2a2a2a;
  border: none;
  color: #f5f5f0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-send-button:hover {
  background: #1a1a1a;
  transform: scale(1.05);
}

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

/* Loading indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f5f5f0;
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

/* Contact form */
.contact-form-container {
  padding: 24px;
  display: none;
  flex-direction: column;
  gap: 16px;
  background: #fafaf8;
  overflow-y: auto;
  flex: 1;
}

.contact-form-container.active {
  display: flex;
}

.contact-form-title {
  font-size: 18px;
  font-weight: 600;
  color: #2a2a2a;
  margin-bottom: 8px;
}

.contact-form-subtitle {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.contact-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.contact-form-label {
  font-size: 13px;
  font-weight: 500;
  color: #2a2a2a;
}

.contact-form-input {
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
  background: #ffffff;
}

.contact-form-select {
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
  background: #ffffff;
  cursor: pointer;
}

.contact-form-select:focus {
  border-color: #dac3a5;
}

.contact-form-textarea {
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
  background: #ffffff;
  resize: vertical;
  min-height: 80px;
}

.contact-form-textarea:focus {
  border-color: #dac3a5;
}

.contact-form-input:focus {
  border-color: #dac3a5;
}

.contact-form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.contact-form-button {
  flex: 1;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  font-family: inherit;
}

.contact-form-button.primary {
  background: linear-gradient(135deg, #dac3a5 0%, #c9b194 100%);
  color: #ffffff;
}

.contact-form-button.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(218, 195, 165, 0.4);
}

.contact-form-button.secondary {
  background: #ffffff;
  color: #2a2a2a;
  border: 1px solid #e0e0e0;
}

.contact-form-button.secondary:hover {
  background: #fafaf8;
}

.contact-form-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Success page */
.success-page {
  padding: 40px 24px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #fafaf8;
  gap: 24px;
}

.success-page.active {
  display: flex;
}

.success-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #dac3a5 0%, #c9b194 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  animation: scaleIn 0.5s ease-out;
}

@keyframes scaleIn {
  from {
    transform: scale(0);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.success-title {
  font-size: 22px;
  font-weight: 600;
  color: #2a2a2a;
  margin-bottom: -8px;
}

.success-message {
  font-size: 15px;
  color: #666;
  line-height: 1.6;
  max-width: 280px;
}

.success-button {
  padding: 14px 32px;
  border-radius: 24px;
  background: linear-gradient(135deg, #dac3a5 0%, #c9b194 100%);
  color: #ffffff;
  border: none;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(218, 195, 165, 0.3);
  font-family: inherit;
}

.success-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(218, 195, 165, 0.4);
}

/* Teaser message */
.chat-teaser {
  position: fixed;
  bottom: 100px;
  right: 24px;
  max-width: 280px;
  background: #ffffff;
  padding: 16px 20px;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  display: none;
  animation: slideIn 0.4s ease-out;
  z-index: 100000000;
}

.chat-teaser.show {
  display: block;
}

.chat-teaser-content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.chat-teaser-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center;
  flex-shrink: 0;
}

.chat-teaser-text {
  flex: 1;
}

.chat-teaser-name {
  font-size: 13px;
  font-weight: 600;
  color: #2a2a2a;
  margin-bottom: 4px;
}

.chat-teaser-message {
  font-size: 14px;
  color: #2a2a2a;
  line-height: 1.4;
}

.chat-teaser-close {
  background: none;
  border: none;
  color: #999;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  margin-left: 4px;
}

.chat-teaser-close:hover {
  color: #666;
}

/* Responsive adjustments (consolidated)
 * - One block for <=768px and one for <=480px
 * - Use 100dvh, env(safe-area-inset-*) and calc()
 * - Do NOT add padding-top on .chat-window
 * - Do NOT use position: sticky inside the fixed .chat-window
 */
@media (max-width: 768px) {
  .chat-window {
    right: 12px;
    left: 12px;
    width: calc(100% - 24px);
    height: calc(100dvh - 140px);
    max-height: none;
    bottom: calc(env(safe-area-inset-bottom, 12px) + 12px);
    border-radius: 12px;
    overflow: hidden;
  }

  .chat-launcher {
    right: 12px;
    bottom: 12px;
    width: 56px;
    height: 56px;
  }

  .chat-launcher img {
    width: 56px;
    height: 56px;
  }

  .chat-teaser {
    right: 12px;
    bottom: calc(env(safe-area-inset-bottom, 12px) + 80px);
    max-width: calc(100vw - 90px);
    padding: 14px 16px;
  }

  .chat-header {
    /* safe-area handled in header only (no padding-top on .chat-window) */
    padding: 16px;
    padding-top: calc(env(safe-area-inset-top, 12px) + 8px);
    flex-wrap: wrap;
    gap: 8px;
    position: relative;
    z-index: 100000004; /* above cookie/admin bars */
  }

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

  .chat-header-text h3 { font-size: 15px; }
  .chat-header-text p { font-size: 12px; }

  .pro-button {
    font-size: 11px;
    padding: 5px 12px;
    order: 3;
    flex-basis: 100%;
    margin-top: 4px;
  }

  .chat-messages {
    padding: 16px;
    -webkit-overflow-scrolling: touch;
    /* leave space for input + safe-area */
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
    flex: 1;
    max-height: none;
  }

  .message-bubble { max-width: 85%; font-size: 13px; padding: 10px 14px; }
  .suggestion-button { font-size: 12px; padding: 9px 14px; }
  .cta-button { font-size: 12px; padding: 9px 18px; }

  .contact-form-container { padding: 20px; gap: 14px; }
  .contact-form-title { font-size: 17px; }
  .contact-form-subtitle { font-size: 13px; }
  .contact-form-input, .contact-form-select, .contact-form-textarea { font-size: 16px; }

  .success-page { padding: 32px 20px; }
  .success-icon { width: 70px; height: 70px; font-size: 42px; }
  .success-title { font-size: 20px; }
  .success-message { font-size: 14px; }

  /* input area: absolute inside fixed .chat-window to avoid sticky inside fixed
   * keeps it above keyboards and cookie banners using env(safe-area-inset-bottom)
   */
  .chat-input-container {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(env(safe-area-inset-bottom, 12px) + 8px);
    padding: 12px 16px;
    background: #ffffff;
    border-top: 1px solid #e8e3db;
    display: flex;
    gap: 10px;
    align-items: center;
    z-index: 100000003;
  }

  .chat-input { font-size: 16px; }
  .chat-send-button { z-index: 100000005; }

  /* make sure close button is clickable and has a good hit area */
  .chat-close-button {
    position: relative;
    z-index: 100000005;
    padding: 8px 10px;
    touch-action: manipulation;
  }
}

@media (max-width: 480px) {
  .chat-window {
    left: 0;
    right: 0;
    width: 100%;
    bottom: 0;
    border-radius: 0;
    /* use 100dvh to account for dynamic address bar */
    height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .chat-header {
    padding: 14px;
    padding-top: calc(env(safe-area-inset-top, 12px) + 10px);
  }

  .chat-messages {
    padding: 12px;
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
    max-height: calc(100dvh - 140px);
  }

  .chat-input-container {
    padding: 12px 16px;
    bottom: calc(env(safe-area-inset-bottom, 12px) + 8px);
  }
}

@media (max-width: 360px) {
  .chat-header-text h3 { font-size: 14px; }
  .chat-header-text p { font-size: 11px; }
  .pro-button { font-size: 10px; padding: 4px 10px; }
  .contact-form-button { padding: 10px 16px; font-size: 13px; }
  .success-button { padding: 12px 24px; font-size: 14px; }
}
