/* Premium Chatbot Styles for Sumayu Global */
:root {
  --chatbot-brand: #34A86A;
  --chatbot-brand-dark: #1E6A42;
  --chatbot-brand-light: #E0F6E8;
  --chatbot-bg: #FFFFFF;
  --chatbot-text: #0A0A0A;
  --chatbot-text-light: #666666;
  --chatbot-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.15);
  --chatbot-shadow-hover: 0 15px 50px -10px rgba(0, 0, 0, 0.2);
  --chatbot-radius: 24px;
}

/* ── Floating Toggle Button ── */
#sg-chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 30px;
    background: linear-gradient(135deg, var(--chatbot-brand), var(--chatbot-brand-dark));
    color: white;
    border: none;
    box-shadow: var(--chatbot-shadow);
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0;
    transition: width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                box-shadow 0.3s ease,
                opacity 0.3s ease;
    overflow: hidden;
}

#sg-chatbot-toggle.extended {
    width: 175px;
    padding-right: 20px;
}

#sg-chatbot-toggle.open {
    width: 60px !important;
    padding: 0 !important;
}

.sg-toggle-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    transform: scale(0.85);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.sg-toggle-avatar img,
.sg-toggle-avatar video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.02);
}

.sg-toggle-text {
    white-space: nowrap;
    opacity: 0;
    max-width: 0;
    font-size: 15px;
    font-weight: 700;
    transition: opacity 0.35s ease 0.1s, max-width 0.4s ease;
    overflow: hidden;
}

#sg-chatbot-toggle.extended .sg-toggle-text {
    opacity: 1;
    max-width: 120px;
    margin-left: 4px;
}

#sg-chatbot-toggle:hover {
  transform: scale(1.08) translateY(-4px);
  box-shadow: var(--chatbot-shadow-hover);
}

#sg-chatbot-toggle i {
  font-size: 28px;
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.35s ease;
}

/* X close icon inside toggle */
#sg-chatbot-toggle .ph-x {
    position: absolute;
    left: 16px;
    top: 16px;
    font-size: 28px;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

#sg-chatbot-toggle.open .sg-toggle-avatar {
    opacity: 0;
    transform: scale(0.5);
}

#sg-chatbot-toggle.open .sg-toggle-text {
    opacity: 0;
    max-width: 0;
}

#sg-chatbot-toggle.open .ph-x {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Pulse ring animation */
#sg-chatbot-toggle::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: 50%;
  border: 2px solid var(--chatbot-brand);
  opacity: 0;
  animation: chatbotPulse 2s infinite cubic-bezier(0.66, 0, 0, 1);
}

@keyframes chatbotPulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ── Chat Modal Container ── */
#sg-chatbot-container {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--chatbot-radius);
  box-shadow: 0 20px 40px rgba(0,0,0,0.1), inset 0 0 0 1px rgba(255,255,255,0.4);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(30px) scale(0.9);
  pointer-events: none;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: 'Outfit', sans-serif;
}

#sg-chatbot-container.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ── */
.sg-chatbot-header {
  background: linear-gradient(135deg, var(--chatbot-brand), var(--chatbot-brand-dark));
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top-left-radius: var(--chatbot-radius);
  border-top-right-radius: var(--chatbot-radius);
  flex-shrink: 0;
  min-height: 64px;
}

.sg-chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sg-chatbot-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chatbot-brand);
  font-size: 24px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.sg-chatbot-title {
  font-weight: 600;
  font-size: 16px;
  line-height: 1.2;
}

.sg-chatbot-subtitle {
  font-size: 12px;
  opacity: 0.9;
  font-weight: 300;
}

.sg-chatbot-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.3s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.sg-chatbot-close:hover {
  background: rgba(255,255,255,0.3);
  transform: rotate(90deg);
}

/* ── Messages Area ── */
.sg-chatbot-messages {
  flex-grow: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(249, 251, 249, 0.6);
  -webkit-overflow-scrolling: touch;
}

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

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

.sg-chatbot-messages::-webkit-scrollbar-thumb {
  background: #C1ECCF;
  border-radius: 10px;
}

.sg-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  animation: messageSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  position: relative;
  word-wrap: break-word;
}

@keyframes messageSlideIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sg-message.bot {
  align-self: flex-start;
  background: white;
  color: var(--chatbot-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.03);
  border: 1px solid rgba(0,0,0,0.02);
}

.sg-message.user {
  align-self: flex-end;
  background: var(--chatbot-brand-light);
  color: var(--chatbot-brand-dark);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(52, 168, 106, 0.1);
}

/* Formatting inside messages */
.sg-message p { margin-bottom: 8px; }
.sg-message p:last-child { margin-bottom: 0; }
.sg-message ul { margin-top: 8px; margin-bottom: 8px; padding-left: 20px; }
.sg-message li { margin-bottom: 4px; }
.sg-message strong { font-weight: 600; color: var(--chatbot-brand-dark); }
.sg-message a { color: var(--chatbot-brand); text-decoration: underline; }

/* ── Quick Replies ── */
.sg-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.sg-quick-reply-btn {
  background: white;
  border: 1px solid var(--chatbot-brand);
  color: var(--chatbot-brand-dark);
  padding: 8px 12px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-family: inherit;
}

.sg-quick-reply-btn:hover {
  background: var(--chatbot-brand);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(52, 168, 106, 0.3);
}

/* ── Typing Indicator ── */
.sg-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: white;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 4px 15px rgba(0,0,0,0.03);
  margin-bottom: 10px;
}

.sg-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--chatbot-brand-light);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.sg-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.sg-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); background: var(--chatbot-brand); }
}

/* ── Input Area ── */
.sg-chatbot-input-container {
  padding: 12px 16px;
  background: white;
  border-top: 1px solid rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sg-chatbot-input {
  flex-grow: 1;
  background: #F2FBF5;
  border: 1px solid rgba(52, 168, 106, 0.2);
  border-radius: 20px;
  padding: 12px 16px;
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  outline: none;
  transition: all 0.3s ease;
  font-family: 'Outfit', sans-serif;
  -webkit-text-size-adjust: 100%;
}

.sg-chatbot-input:focus {
  background: white;
  border-color: var(--chatbot-brand);
  box-shadow: 0 0 0 3px rgba(52, 168, 106, 0.1);
}

.sg-chatbot-send {
  background: var(--chatbot-brand);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.sg-chatbot-send:hover {
  background: var(--chatbot-brand-dark);
  transform: scale(1.05);
}

.sg-chatbot-send:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: scale(1);
}

/* ── Mobile Responsiveness ── */
@media (max-width: 480px) {
  #sg-chatbot-container {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100vw;
    height: 100%;
    max-height: 100%;
    max-width: 100vw;
    border-radius: 0;
    /* Use dvh for modern browsers to account for mobile address bar */
    height: 100dvh;
    max-height: 100dvh;
  }
  
  .sg-chatbot-header {
    border-radius: 0;
    padding: 16px 16px;
    padding-top: max(16px, env(safe-area-inset-top, 16px));
    min-height: 60px;
  }
  
  .sg-chatbot-messages {
    padding: 12px;
  }
  
  .sg-chatbot-input-container {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
  }
  
  .sg-chatbot-input {
    font-size: 16px; /* Critical: prevents iOS auto-zoom */
  }
  
  #sg-chatbot-toggle.open {
    display: none !important;
  }
}

/* Safari Mobile Optimization */
@media (max-width: 768px) {

  #sg-chatbot-container {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(255,255,255,0.98) !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08) !important;
  }

  #sg-chatbot-toggle {
    box-shadow: 0 4px 10px rgba(0,0,0,0.08) !important;
  }

  #sg-chatbot-toggle::before {
    display: none !important;
  }

  .sg-toggle-avatar img {
    animation: none !important;
  }
}
