/* ========================================================
   ARTHABOT - PREMIUM SMART CUSTOMER SERVICE WIDGET
   PT Artha Jaya Bangun Perkasa
   Rock-solid Responsiveness for Laptop, Desktop & Mobile
   ======================================================== */

/* CSS Variables scoped to #arthabot-container */
#arthabot-container {
  --ab-primary: #008341;
  --ab-primary-dark: #006a34;
  --ab-primary-light: #E6F4EC;
  --ab-accent: #25D366;
  --ab-bg: #FFFFFF;
  --ab-dark: #111827;
  --ab-gray-50: #F9FAFB;
  --ab-gray-100: #F3F4F6;
  --ab-gray-200: #E5E7EB;
  --ab-gray-300: #D1D5DB;
  --ab-text: #1F2937;
  --ab-text-muted: #6B7280;
  --ab-shadow: 0 20px 48px -8px rgba(0, 0, 0, 0.22), 0 8px 16px -4px rgba(0, 0, 0, 0.1);
  --ab-radius: 18px;
  
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Hard reset for all elements inside arthabot to guarantee zero style leakage */
#arthabot-container,
#arthabot-container * {
  box-sizing: border-box !important;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
  line-height: normal;
  text-shadow: none !important;
  letter-spacing: normal;
}

/* ========================================================
   1. FLOATING LAUNCHER BUTTON & TEASER (BOTTOM RIGHT)
   ======================================================== */
.arthabot-launcher {
  position: fixed !important;
  bottom: 24px !important;
  right: 24px !important;
  z-index: 9999990 !important;
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  user-select: none !important;
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: transparent !important;
  transition: opacity 0.25s ease, transform 0.25s ease !important;
}

/* Hide launcher neatly when the chat window is open on desktop & laptop */
.arthabot-launcher.open {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: scale(0.8) translateY(10px) !important;
  display: none !important;
}

/* Teaser / Welcome Badge */
.arthabot-teaser {
  background: #FFFFFF;
  color: var(--ab-dark);
  padding: 10px 16px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 10px 25px -4px rgba(0, 0, 0, 0.15), 0 4px 10px -2px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--ab-gray-200);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  max-width: 270px;
  animation: arthabot-float 4s infinite ease-in-out;
  transition: transform 0.2s, box-shadow 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.arthabot-teaser:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px -4px rgba(0, 0, 0, 0.2);
}

.arthabot-teaser-icon {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.arthabot-teaser-text {
  color: var(--ab-dark);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arthabot-teaser-close {
  background: transparent !important;
  border: none !important;
  color: #9CA3AF !important;
  font-size: 14px !important;
  cursor: pointer !important;
  padding: 3px 6px !important;
  line-height: 1 !important;
  margin-left: 2px !important;
  border-radius: 50% !important;
  transition: color 0.15s, background 0.15s !important;
}

.arthabot-teaser-close:hover {
  color: #EF4444 !important;
  background: #FEE2E2 !important;
}

@keyframes arthabot-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* Circular Floating Button */
.arthabot-launcher-bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ab-primary) 0%, var(--ab-primary-dark) 100%);
  box-shadow: 0 10px 24px rgba(0, 131, 65, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s;
  position: relative;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.arthabot-launcher-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 14px 28px rgba(0, 131, 65, 0.55);
}

.arthabot-launcher-bubble::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 50%;
  border: 2px solid var(--ab-primary);
  opacity: 0.6;
  animation: arthabot-pulse 2.4s infinite;
  pointer-events: none;
}

@keyframes arthabot-pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 0; }
  100% { transform: scale(0.95); opacity: 0; }
}

.arthabot-launcher-icon {
  width: 28px;
  height: 28px;
  stroke: #FFFFFF;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* CRITICAL: Explicitly hide close icon unless launcher is open */
.arthabot-launcher-icon.close {
  display: none !important;
}

.arthabot-launcher.open .arthabot-launcher-icon.chat {
  display: none !important;
}

.arthabot-launcher.open .arthabot-launcher-icon.close {
  display: block !important;
}

.arthabot-launcher-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 14px;
  height: 14px;
  background: #10B981;
  border: 2.5px solid #FFFFFF;
  border-radius: 50%;
  pointer-events: none;
}

/* ========================================================
   2. CHAT WINDOW (DESKTOP & LAPTOP)
   Anchored directly at bottom: 24px; right: 24px;
   ======================================================== */
.arthabot-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(560px, calc(100vh - 48px));
  max-height: calc(100vh - 48px);
  background: var(--ab-bg);
  border-radius: var(--ab-radius);
  box-shadow: var(--ab-shadow);
  border: 1px solid var(--ab-gray-200);
  z-index: 9999995;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, 
              transform 0.22s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.22s;
}

.arthabot-window.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.arthabot-header {
  background: linear-gradient(135deg, var(--ab-primary) 0%, var(--ab-primary-dark) 100%);
  color: #FFFFFF;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}

.arthabot-header-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.arthabot-avatar {
  width: 42px;
  height: 42px;
  background: #FFFFFF;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.9);
  flex-shrink: 0;
}

.arthabot-header-info h4 {
  font-size: 15px !important;
  font-weight: 700 !important;
  color: #FFFFFF !important;
  line-height: 1.2 !important;
  margin: 0 !important;
}

.arthabot-header-info p {
  margin: 3px 0 0 !important;
  font-size: 11.5px !important;
  color: rgba(255, 255, 255, 0.92) !important;
  display: flex !important;
  align-items: center !important;
  gap: 5px !important;
}

.arthabot-status-dot {
  width: 7px;
  height: 7px;
  background: #10B981;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px #10B981;
}

.arthabot-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.arthabot-header-actions button {
  background: rgba(255, 255, 255, 0.15) !important;
  border: none !important;
  color: #FFFFFF !important;
  width: 32px !important;
  height: 32px !important;
  border-radius: 8px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: transparent !important;
  transition: background 0.15s, transform 0.1s !important;
}

.arthabot-header-actions button:hover {
  background: rgba(255, 255, 255, 0.3) !important;
  transform: scale(1.05) !important;
}

/* Chat Body (Messages) */
.arthabot-body {
  flex: 1 1 auto;
  min-height: 0; /* CRITICAL FOR FLEXBOX SCROLLING */
  padding: 16px 14px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--ab-gray-50);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.arthabot-body::-webkit-scrollbar {
  width: 5px;
}
.arthabot-body::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 10px;
}

/* Message Bubbles */
.arthabot-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  font-size: 13.5px;
  line-height: 1.5;
  animation: arthabot-fade 0.2s ease;
}

@keyframes arthabot-fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.arthabot-msg.bot {
  align-self: flex-start;
  margin-right: auto;
  margin-left: 0;
}

.arthabot-msg.user {
  align-self: flex-end;
  margin-left: auto;
  margin-right: 12px !important;
}

.arthabot-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 1.5px solid var(--ab-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}

.arthabot-msg-bubble {
  padding: 12px 15px;
  border-radius: 16px;
  word-break: break-word;
}

.arthabot-msg.bot .arthabot-msg-bubble {
  background: #FFFFFF;
  color: var(--ab-text);
  border: 1px solid var(--ab-gray-200);
  border-top-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.arthabot-msg.user .arthabot-msg-bubble {
  background: linear-gradient(135deg, var(--ab-primary) 0%, var(--ab-primary-dark) 100%);
  color: #FFFFFF;
  border-top-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 131, 65, 0.25);
}

.arthabot-msg-bubble strong {
  color: var(--ab-primary-dark);
  font-weight: 700;
}

.arthabot-msg.user .arthabot-msg-bubble strong {
  color: #FFFFFF;
}

.arthabot-msg-bubble em {
  font-style: italic;
  opacity: 0.9;
}

.arthabot-msg-time {
  font-size: 10px;
  margin-top: 5px;
  opacity: 0.65;
  text-align: right;
}

.arthabot-msg.user .arthabot-msg-time {
  color: rgba(255, 255, 255, 0.8) !important;
  opacity: 0.85;
}

/* In-Chat WhatsApp CTA Button */
.arthabot-wa-btn {
  display: inline-flex !important;
  align-items: center !important;
  gap: 7px !important;
  background: var(--ab-accent) !important;
  color: #FFFFFF !important;
  font-size: 12.5px !important;
  font-weight: 700 !important;
  padding: 9px 15px !important;
  border-radius: 8px !important;
  text-decoration: none !important;
  margin-top: 10px !important;
  box-shadow: 0 3px 10px rgba(37, 211, 102, 0.3) !important;
  transition: transform 0.15s, background 0.15s !important;
}

.arthabot-wa-btn:hover {
  background: #20BD5A !important;
  transform: translateY(-1px) !important;
}

/* Typing Indicator */
.arthabot-typing {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  background: #FFFFFF;
  border: 1px solid var(--ab-gray-200);
  border-radius: 12px;
  width: fit-content;
  align-self: flex-start;
  margin-left: 40px;
  margin-bottom: 6px;
}

.arthabot-typing.active {
  display: flex;
}

.arthabot-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--ab-text-muted);
  border-radius: 50%;
  animation: arthabot-typing-dot 1.3s infinite ease-in-out;
}

.arthabot-typing-dot:nth-child(1) { animation-delay: 0s; }
.arthabot-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.arthabot-typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Quick Replies Chips */
.arthabot-quick-replies {
  padding: 8px 12px 10px;
  background: var(--ab-gray-50);
  border-top: 1px dashed var(--ab-gray-200);
  display: flex;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
  flex-shrink: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}

.arthabot-quick-replies::-webkit-scrollbar {
  display: none;
}

.arthabot-chip {
  background: #FFFFFF !important;
  border: 1px solid var(--ab-gray-200) !important;
  color: var(--ab-dark) !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  padding: 7px 13px !important;
  border-radius: 20px !important;
  cursor: pointer !important;
  transition: all 0.15s !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 5px !important;
  flex-shrink: 0 !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: transparent !important;
}

.arthabot-chip:hover,
.arthabot-chip:active {
  background: var(--ab-primary-light) !important;
  border-color: var(--ab-primary) !important;
  color: var(--ab-primary-dark) !important;
  transform: translateY(-1px);
}

/* Footer / Input Box */
.arthabot-footer {
  padding: 10px 14px;
  background: #FFFFFF;
  border-top: 1px solid var(--ab-gray-200);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.arthabot-input {
  flex: 1;
  border: 1.5px solid var(--ab-gray-200) !important;
  border-radius: 24px !important;
  padding: 10px 16px !important;
  font-size: 13.5px !important;
  outline: none !important;
  background: var(--ab-gray-50) !important;
  color: var(--ab-text) !important;
  transition: border-color 0.15s, background 0.15s !important;
}

.arthabot-input:focus {
  border-color: var(--ab-primary) !important;
  background: #FFFFFF !important;
  box-shadow: 0 0 0 3px rgba(0, 131, 65, 0.12) !important;
}

.arthabot-send-btn {
  width: 40px !important;
  height: 40px !important;
  border-radius: 50% !important;
  background: var(--ab-primary) !important;
  border: none !important;
  color: #FFFFFF !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important;
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: transparent !important;
  transition: background 0.15s, transform 0.1s !important;
}

.arthabot-send-btn:hover {
  background: var(--ab-primary-dark) !important;
  transform: scale(1.05) !important;
}

.arthabot-send-btn svg {
  width: 18px;
  height: 18px;
  fill: #FFFFFF;
  margin-left: 2px;
}

/* ========================================================
   3. RESPONSIVE DESIGN FOR SMARTPHONES & TABLETS (WIDTH <= 768PX)
   Flawless Touch-Optimized Layout
   ======================================================== */
@media (max-width: 768px) {
  /* Closed State: Robust bottom-right placement that works on ALL mobile browsers */
  .arthabot-launcher {
    position: fixed !important;
    bottom: 24px !important;
    bottom: calc(24px + env(safe-area-inset-bottom)) !important;
    right: 20px !important;
    z-index: 9999999 !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    pointer-events: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  /* On smartphones: Hide wide horizontal teaser pill to prevent overflow/pushing button off screen */
  .arthabot-teaser {
    display: none !important;
  }

  /* Large, easily tappable 58x58px circular floating bubble */
  .arthabot-launcher-bubble {
    width: 58px !important;
    height: 58px !important;
    min-width: 58px !important;
    min-height: 58px !important;
    background: #008341 !important;
    background: linear-gradient(135deg, #008341 0%, #006a34 100%) !important;
    box-shadow: 0 10px 28px rgba(0, 131, 65, 0.55) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  .arthabot-launcher-icon {
    width: 30px !important;
    height: 30px !important;
    fill: #FFFFFF !important;
    color: #FFFFFF !important;
  }

  /* When CLOSED on Mobile: Hide completely so zero touches are blocked */
  .arthabot-window:not(.active) {
    display: none !important;
  }

  /* When OPEN on Mobile: Pure Native App Experience */
  .arthabot-window.active {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100% !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    z-index: 99999999 !important;
    transform: none !important;
    animation: arthabot-slide-up 0.25s ease-out;
  }

  @keyframes arthabot-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* Hide launcher button completely when open on mobile */
  .arthabot-launcher.open {
    display: none !important;
  }

  /* Mobile Header with Safe Area */
  .arthabot-header {
    padding: 14px 16px;
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .arthabot-header-info h4 {
    font-size: 16px !important;
  }

  /* Prominent 42x42px close button on mobile for effortless thumb tapping */
  .arthabot-header-actions button {
    width: 42px !important;
    height: 42px !important;
    font-size: 20px !important;
    border-radius: 12px !important;
  }

  .arthabot-body {
    padding: 14px 12px;
  }

  .arthabot-msg {
    max-width: 90%;
    font-size: 13.5px;
  }

  .arthabot-msg-avatar {
    width: 30px;
    height: 30px;
    font-size: 15px;
  }

  /* CRITICAL FOR IOS SAFARI: 16px prevents automatic browser zooming */
  .arthabot-input {
    font-size: 16px !important;
    padding: 12px 18px !important;
  }

  .arthabot-footer {
    padding: 12px 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    background: #FFFFFF;
  }
}
