/**
 * Companion Position Fix - Nuclear Approach
 *
 * CRITICAL: This fixes position:fixed not working when parent has transform.
 * When ANY ancestor has transform/filter/perspective, fixed positioning
 * becomes relative to that ancestor instead of viewport.
 */

/* CRITICAL: Remove transforms from body/html that break fixed positioning */
html, body {
  transform: none !important;
  transform-style: flat !important;
  perspective: none !important;
  filter: none !important;
  will-change: auto !important;
  contain: none !important;
  backdrop-filter: none !important;
}

/* Ensure floating ball has proper positioning */
.companion-floating-ball {
  position: fixed !important;
  z-index: 2147483647 !important; /* Maximum z-index */
  pointer-events: auto !important;
  /* Force GPU layer to prevent stacking issues */
  transform: translateZ(0) !important;
  backface-visibility: hidden !important;
}

/* Ensure visibility without breaking normal behavior */
.companion-floating-ball {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Default position (will be overridden by JavaScript) */
.companion-floating-ball:not([style*="bottom"]):not([style*="top"]) {
  bottom: 20px !important;
}

.companion-floating-ball:not([style*="right"]):not([style*="left"]) {
  right: 20px !important;
}

/* Ensure proper sizing */
.companion-floating-ball {
  width: 56px !important;
  height: 56px !important;
  border-radius: 50% !important;
}

/* Mobile responsive positioning */
@media (max-width: 768px) {
  .companion-floating-ball:not([style*="bottom"]):not([style*="top"]) {
    bottom: 15px !important;
  }
  
  .companion-floating-ball:not([style*="right"]):not([style*="left"]) {
    right: 15px !important;
  }
}

@media (max-width: 480px) {
  .companion-floating-ball:not([style*="bottom"]):not([style*="top"]) {
    bottom: 10px !important;
  }

  .companion-floating-ball:not([style*="right"]):not([style*="left"]) {
    right: 10px !important;
  }
}

/* CRITICAL: Chat panel must also be fixed to viewport */
.companion-chat-panel {
  position: fixed !important;
  z-index: 2147483646 !important;
  pointer-events: auto !important;
  transform: translateZ(0) !important;
  backface-visibility: hidden !important;
  bottom: 90px !important;
  right: 20px !important;
}

/* Ensure all companion elements are interactive */
.companion-floating-ball,
.companion-floating-ball *,
.companion-chat-panel,
.companion-chat-panel *,
.chat-panel-header,
.chat-panel-close,
.chat-panel-input,
.message-input,
.companion-send-button {
  pointer-events: auto !important;
  cursor: pointer;
}

/* Override any parent that might have transform/filter/perspective */
.companion-floating-ball,
.companion-chat-panel {
  /* These ensure the element stays fixed to viewport even if parent has transform */
  contain: layout style !important;
}