/* ============================================
   AI CHAT WIDGET — Startup Advisory GmbH
   v3: Session-based • Persistent History
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Floating Button ──────────────────────── */
#sa-chat-btn {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #A37002, #d4a017);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(163, 112, 2, 0.4), 0 0 0 0 rgba(163, 112, 2, 0.3);
  z-index: 99999;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: sa-pulse 2.5s infinite;
  color: white;
}

#sa-chat-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 40px rgba(163, 112, 2, 0.5);
}

#sa-chat-btn svg {
  color: white;
  transition: transform 0.3s ease;
}

@keyframes sa-pulse {
  0%, 100% { box-shadow: 0 8px 32px rgba(163, 112, 2, 0.4), 0 0 0 0 rgba(163, 112, 2, 0.3); }
  50% { box-shadow: 0 8px 32px rgba(163, 112, 2, 0.4), 0 0 0 14px rgba(163, 112, 2, 0); }
}

/* ── Badge ────────────────────────────────── */
.sa-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  background: #e53e3e;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
  font-family: 'Inter', sans-serif;
}

/* ── Chat Window ──────────────────────────── */
#sa-chat-window {
  position: fixed;
  bottom: 110px;
  right: 30px;
  width: 420px;
  height: 620px;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.15), 0 10px 30px rgba(0, 0, 0, 0.08);
  z-index: 99998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-family: 'Inter', sans-serif;
}

#sa-chat-window.sa-hidden {
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
}

/* ── Header ───────────────────────────────── */
.sa-header {
  background: linear-gradient(135deg, #1e1810 0%, #3a2a10 100%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sa-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sa-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #A37002, #d4a017);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: white;
  font-weight: 700;
  flex-shrink: 0;
  position: relative;
}

.sa-avatar::after {
  content: '';
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  background: #48bb78;
  border-radius: 50%;
  border: 2px solid #1e1810;
}

.sa-header-title {
  color: white;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.sa-header-sub {
  color: #48bb78;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.sa-status-dot {
  width: 6px;
  height: 6px;
  background: #48bb78;
  border-radius: 50%;
  display: inline-block;
  animation: sa-status-pulse 2s infinite;
}

@keyframes sa-status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sa-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sa-header-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.sa-header-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── Messages ─────────────────────────────── */
.sa-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #faf8f5;
}

.sa-messages::-webkit-scrollbar { width: 4px; }
.sa-messages::-webkit-scrollbar-track { background: transparent; }
.sa-messages::-webkit-scrollbar-thumb { background: #d4c5a8; border-radius: 4px; }

/* ── Message Bubbles ─────────────────────── */
.sa-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

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

.sa-msg-bot {
  align-self: flex-start;
}

.sa-msg-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
}

.sa-msg-user .sa-msg-bubble {
  background: linear-gradient(135deg, #A37002, #d4a017);
  color: white;
  border-bottom-right-radius: 4px;
}

.sa-msg-bot .sa-msg-bubble {
  background: white;
  color: #1e1810;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.sa-msg-meta {
  font-size: 10px;
  color: #aaa;
  margin-top: 4px;
  padding: 0 4px;
}

.sa-msg-user .sa-msg-meta {
  text-align: right;
}

@keyframes sa-msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Restored Indicator ──────────────────── */
.sa-restored-indicator {
  text-align: center;
  font-size: 11px;
  color: #aaa;
  padding: 8px 16px;
  background: rgba(163, 112, 2, 0.06);
  border-radius: 20px;
  margin: 4px auto;
  max-width: fit-content;
}

/* ── Typing Indicator ────────────────────── */
.sa-typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 4px 0;
}

.sa-typing-dots span {
  width: 8px;
  height: 8px;
  background: #c4b494;
  border-radius: 50%;
  animation: sa-typing-bounce 1.4s infinite ease-in-out;
}

.sa-typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.sa-typing-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes sa-typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Quick Actions ───────────────────────── */
.sa-quick-actions {
  padding: 8px 16px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: white;
  border-top: 1px solid #f0ebe3;
}

.sa-quick-btn {
  padding: 6px 14px;
  background: #faf5eb;
  border: 1px solid #e8dcc8;
  border-radius: 20px;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  color: #6b5b3e;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.sa-quick-btn:hover {
  background: linear-gradient(135deg, #A37002, #d4a017);
  color: white;
  border-color: #A37002;
  transform: translateY(-1px);
}

/* ── Input Area ──────────────────────────── */
.sa-input-area {
  padding: 12px 16px;
  background: white;
  border-top: 1px solid #f0ebe3;
}

.sa-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: #f8f5f0;
  border: 2px solid #e8dcc8;
  border-radius: 14px;
  padding: 8px 12px;
  transition: border-color 0.3s;
}

.sa-input-row:focus-within {
  border-color: #A37002;
  box-shadow: 0 0 0 3px rgba(163, 112, 2, 0.1);
}

#sa-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  color: #1e1810;
  outline: none;
  resize: none;
  line-height: 1.4;
  max-height: 100px;
}

#sa-input::placeholder {
  color: #aaa;
}

#sa-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #A37002, #d4a017);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

#sa-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(163, 112, 2, 0.3);
}

/* ── Powered By ──────────────────────────── */
.sa-powered {
  text-align: center;
  font-size: 11px;
  color: #aaa;
  padding: 8px 16px;
  background: white;
  flex-shrink: 0;
}

.sa-powered a {
  color: #A37002;
  text-decoration: none;
  font-weight: 500;
}

/* ── Lead Form ───────────────────────────── */
.sa-lead-form {
  padding: 16px;
  background: #faf8f5;
  border-radius: 12px;
}

.sa-lead-form input:focus,
.sa-lead-form select:focus,
.sa-lead-form textarea:focus {
  border-color: #A37002 !important;
  box-shadow: 0 0 0 2px rgba(163, 112, 2, 0.1);
}

/* ── Success Message ─────────────────────── */
.sa-success-msg {
  text-align: center;
  padding: 20px;
  animation: sa-msg-in 0.5s ease;
}

.sa-success-msg .sa-check-icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #48bb78, #38a169);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  animation: sa-check-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes sa-check-pop {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

.sa-success-msg .sa-check-icon svg {
  width: 28px;
  height: 28px;
}

.sa-success-msg h5 {
  color: #1e1810;
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
}

.sa-success-msg p {
  color: #888;
  font-size: 13px;
  margin: 0;
}

/* ── Shake animation ─────────────────────── */
@keyframes sa-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ── Booking Form date fix ───────────────── */
.sa-booking-form input[type="date"] {
  font-family: 'Inter', sans-serif;
  color: #1e1810;
}

/* ── Responsive: Tablets ─────────────────── */
@media (max-width: 768px) {
  #sa-chat-window {
    width: calc(100vw - 20px);
    height: 70vh;
    bottom: 90px;
    right: 10px;
    border-radius: 16px;
  }
}

/* ── Responsive: Mobile — FULL SCREEN ────── */
@media (max-width: 480px) {
  #sa-chat-window {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    bottom: 0;
    right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  /* Hide the FAB when the chat window is open */
  #sa-chat-widget:has(#sa-chat-window:not(.sa-hidden)) #sa-chat-btn {
    display: none !important;
  }

  #sa-chat-window.sa-hidden {
    transform: translateY(100%) scale(1);
  }

  #sa-chat-btn {
    bottom: 80px;
    right: 16px;
    width: 56px;
    height: 56px;
  }

  .sa-header {
    padding: 14px 16px;
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .sa-avatar {
    width: 36px;
    height: 36px;
    font-size: 13px;
  }

  .sa-header-title {
    font-size: 15px;
  }

  .sa-messages {
    padding: 14px 12px;
    gap: 10px;
  }

  .sa-msg {
    max-width: 90%;
  }

  .sa-msg-bubble {
    padding: 10px 14px;
    font-size: 14px;
    border-radius: 14px;
  }

  .sa-quick-actions {
    padding: 8px 12px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    scrollbar-width: none;
  }

  .sa-quick-actions::-webkit-scrollbar {
    display: none;
  }

  .sa-quick-btn {
    padding: 8px 14px;
    font-size: 13px;
    flex-shrink: 0;
  }

  .sa-input-area {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .sa-input-row {
    padding: 6px 10px;
    border-radius: 12px;
  }

  #sa-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  #sa-send-btn {
    width: 42px;
    height: 42px;
  }

  .sa-powered {
    padding: 6px 12px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    font-size: 10px;
  }

  /* Lead / Booking forms on mobile */
  .sa-lead-form {
    padding: 14px 12px;
  }

  .sa-lead-form input,
  .sa-lead-form select,
  .sa-lead-form textarea {
    font-size: 16px !important; /* Prevent iOS zoom */
    padding: 12px 14px !important;
  }

  .sa-success-msg .sa-check-icon {
    width: 48px;
    height: 48px;
  }

  .sa-success-msg h5 {
    font-size: 15px;
  }
}
