/* =========================================
   MOBILE RESPONSIVENESS (Screens < 768px)
   ========================================= */

@media (max-width: 768px) {

  /* === SPRITE + PILL (corner widget) === */
  #chat-widget-container {
    position: fixed !important;
    bottom: 20px !important;
    right: 16px !important;
    left: auto !important;
    top: auto !important;
    z-index: 1000 !important;
    pointer-events: auto !important;
  }

  /* On mobile, use an ANIMATED WebP (self-playing) instead of the 80000px
     filmstrip. The filmstrip exceeds iOS image-dimension limits and renders
     blank; a normal-sized animated WebP plays natively on iOS 14+/Android.
     sprite.js skips its JS animation on mobile so it doesn't interfere. */
  #bot-sprite {
    width: 80px !important;
    height: 80px !important;
    background-image: url("/static/images/bubbl-mark-96.png") !important;
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-position: center center !important;
    margin-bottom: 4px !important;
    pointer-events: auto !important;
    cursor: pointer;
  }

  /* The container MUST be fixed to viewport and accept taps */
  #sprite-ask-container {
    position: fixed !important;
    bottom: 20px !important;
    right: 16px !important;
    left: auto !important;
    top: auto !important;
    align-items: center !important;
    pointer-events: auto !important;
    z-index: 1001 !important;
  }

  /* Shrink hit-area to cover the sprite — circle tap target */
  #sprite-hit-area {
    width: 80px !important;
    height: 80px !important;
    bottom: 4px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    pointer-events: auto !important;
    display: block !important;
    border-radius: 50% !important;
  }

  /* Hide sprite when chat is open */
  #sprite-ask-container.chat-open {
    display: none !important;
  }

  /* === CHAT WINDOW: Full-screen overlay on mobile === */
  #chat-window-popup {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    z-index: 9999 !important;
    display: flex !important;
    flex-direction: column !important;
    pointer-events: auto !important;
  }

  /* When open: override ALL desktop transforms/opacity so it shows cleanly */
  #chat-window-popup:not(.hidden) {
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  /* === HEADER: Compact and touch-friendly === */
  .chat-header {
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    min-height: auto;
    flex-shrink: 0;
  }

  .chat-header-title {
    font-size: 12px;
  }

  .chat-close-x {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  /* === MESSAGES: Scrollable, takes remaining space === */
  #chat-display {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
  }

  .msg {
    max-width: 88%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.45;
    border-radius: 16px;
  }

  /* === INPUT: Pinned to bottom, safe-area aware === */
  .chat-input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
  }

  .chat-input-wrapper {
    padding: 4px 6px 4px 14px;
    border-radius: 24px;
  }

  #user-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 8px 0;
  }

  #send-btn-icon {
    width: 36px;
    height: 36px;
  }

  /* === HIDDEN STATE: Slide down off-screen === */
  #chat-window-popup.hidden {
    transform: translateY(100%) !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  /* === FEEDBACK OVERLAY === */
  .feedback-overlay {
    border-radius: 0 !important;
  }

  .feedback-text {
    font-size: 16px; /* Prevent iOS zoom */
  }

  /* === LEAD CAPTURE FORM === */
  .lead-form input,
  .lead-input {
    font-size: 16px; /* Prevent iOS zoom */
    padding: 12px 14px;
    border-radius: 10px;
    width: 100%;
    box-sizing: border-box;
  }

  .lead-submit-btn {
    padding: 14px;
    font-size: 15px;
    border-radius: 10px;
  }

  /* Gatekeeper overlay: fills the chat area properly */
  .lead-overlay-container {
    padding: 24px 20px;
    border-radius: 0 !important;
  }

  .lead-form-card {
    padding: 24px 20px;
    border-radius: 16px;
  }

  /* In-chat form: wider on mobile */
  .in-chat-form-container {
    max-width: 95%;
    padding: 14px;
  }
}
