/* ============================================================
   Stage Zero Livechat - SCOPED OVERRIDES ONLY
   Purpose: style 1Stream/Odoo live chat WITHOUT impacting site UI
   Scope: targets the 1Stream livechat iframe + nearby launcher only
   ============================================================ */

/* Brand tokens */
:root {
  --sz-blue: #00144B;
  --sz-blue-700: #001A70;
  --sz-white: #FFFFFF;
  --sz-grey-50: #F7F8FB;
  --sz-grey-100: #EEF1F6;
  --sz-shadow: 0 24px 70px rgba(0, 20, 75, 0.16);
  --sz-radius-lg: 22px;

  --sz-launcher-size: 56px;
  --sz-offset: 14px;
  --sz-chat-gap: 16px;
  --sz-mobile-launcher-bottom: 72px;
  --sz-chat-open-duration: 260ms;
  --sz-chat-open-ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* Hosted icon */
  --sz-launcher-icon: url("/wp-content/themes/ai/resources/assets/images/stagezero-livechat-launcher.png");
}

/* ------------------------------------------------------------
   1) Chat iframe (SAFE: only matches 1Stream livechat iframe)
   ------------------------------------------------------------ */
iframe[src^="https://stagezero.1stream.co.za/im_livechat"] {
  position: fixed !important;
  right: var(--sz-chat-gap) !important;
  bottom: calc(var(--sz-offset) + var(--sz-launcher-size) + var(--sz-chat-gap)) !important;

  width: min(380px, calc(100vw - (var(--sz-chat-gap) * 2))) !important;
  height: min(640px, calc(100vh - 140px)) !important;
  max-height: calc(100vh - (var(--sz-chat-gap) * 2) - var(--sz-launcher-size) - 20px) !important;

  border: 1px solid rgba(0, 20, 75, 0.06) !important;
  background: #FFFFFF !important;
  border-radius: var(--sz-radius-lg) !important;
  backdrop-filter: blur(8px);
  box-shadow: var(--sz-shadow) !important;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transform-origin: calc(100% - 28px) calc(100% + 72px);
  pointer-events: none;
  transition:
    opacity var(--sz-chat-open-duration) var(--sz-chat-open-ease),
    transform var(--sz-chat-open-duration) var(--sz-chat-open-ease),
    box-shadow var(--sz-chat-open-duration) ease;
  will-change: opacity, transform;
  overflow: hidden !important;
  z-index: 2147483647 !important;
}

iframe[src^="https://stagezero.1stream.co.za/im_livechat"][style*="display: block"],
iframe[src^="https://stagezero.1stream.co.za/im_livechat"][style*="visibility: visible"],
iframe[src^="https://stagezero.1stream.co.za/im_livechat"][style*="opacity: 1"] {
  opacity: 1 !important;
  transform: translateY(0) scale(1) !important;
  pointer-events: auto !important;
}

iframe[src^="https://stagezero.1stream.co.za/im_livechat"][style*="display: none"],
iframe[src^="https://stagezero.1stream.co.za/im_livechat"][style*="visibility: hidden"] {
  opacity: 0 !important;
  transform: translateY(10px) scale(0.98) !important;
  pointer-events: none !important;
}

/* ------------------------------------------------------------
   2) Launcher button (SCOPED)
   We avoid global selectors and only style known Odoo livechat
   elements if present. If 1Stream uses different IDs/classes,
   update these 2-3 selectors (not the whole website).
   ------------------------------------------------------------ */
div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib,
.o_livechat_button.o_website_livechat_button.o-isExternalLib,
.o_livechat_button_container .o_livechat_button.o_website_livechat_button.o-isExternalLib {
  position: fixed !important;
  right: var(--sz-offset) !important;
  bottom: var(--sz-offset) !important;

  width: var(--sz-launcher-size) !important;
  height: var(--sz-launcher-size) !important;
  border-radius: 16px !important;

  background-color: var(--sz-blue) !important;
  background-image: var(--sz-launcher-icon) !important;
  background-repeat: no-repeat !important;
  background-position: center !important;
  background-size: 78% !important;

  border: 0 !important;
  box-shadow: 0 14px 34px rgba(0, 20, 75, 0.18) !important;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background-color 180ms ease;
  z-index: 2147483646 !important;

  cursor: pointer !important;
  transform: translateZ(0);
  opacity: 1 !important;
  visibility: visible !important;
}

/* Force the exact 1Stream/Odoo launcher to render the Stage Zero icon */
div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib,
.o_livechat_button.o_website_livechat_button.o-isExternalLib,
.o_livechat_button_container .o_livechat_button.o_website_livechat_button.o-isExternalLib {
  background-color: var(--sz-blue) !important;
  background-image: var(--sz-launcher-icon) !important;
  background-repeat: no-repeat !important;
  background-position: center !important;
  background-size: 78% !important;
}

/* Hide any generated icon/text only inside the exact launcher */
div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib::before,
div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib::after,
.o_livechat_button.o_website_livechat_button.o-isExternalLib::before,
.o_livechat_button.o_website_livechat_button.o-isExternalLib::after,
.o_livechat_button.o_website_livechat_button.o-isExternalLib svg,
.o_livechat_button.o_website_livechat_button.o-isExternalLib i,
.o_livechat_button.o_website_livechat_button.o-isExternalLib span {
  display: none !important;
  content: none !important;
}

/* Keep launcher visible even when 1Stream toggles inline styles after close */
div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib[style*="display: none"],
.o_livechat_button.o_website_livechat_button.o-isExternalLib[style*="display: none"] {
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* Hover/focus states for launcher only */
div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib:hover,
.o_livechat_button.o_website_livechat_button.o-isExternalLib:hover,
.o_livechat_button_container .o_livechat_button.o_website_livechat_button.o-isExternalLib:hover {
  transform: translateY(-1px) scale(1.015) !important;
  box-shadow: 0 18px 40px rgba(0, 20, 75, 0.24) !important;
}

div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib:focus-visible,
.o_livechat_button.o_website_livechat_button.o-isExternalLib:focus-visible,
.o_livechat_button_container .o_livechat_button.o_website_livechat_button.o-isExternalLib:focus-visible {
  outline: 3px solid rgba(0, 20, 75, 0.35) !important;
  outline-offset: 3px !important;
}

/* ------------------------------------------------------------
   3) Mobile sizing (iframe only)
   ------------------------------------------------------------ */
@media (max-width: 420px) {
  div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib,
  .o_livechat_button.o_website_livechat_button.o-isExternalLib,
  .o_livechat_button_container .o_livechat_button.o_website_livechat_button.o-isExternalLib {
    bottom: var(--sz-mobile-launcher-bottom) !important;
    right: 14px !important;
  }
  iframe[src^="https://stagezero.1stream.co.za/im_livechat"] {
    left: 10px !important;
    right: 10px !important;
    bottom: calc(var(--sz-mobile-launcher-bottom) + var(--sz-launcher-size) + 10px) !important;
    width: auto !important;
    height: calc(100vh - var(--sz-mobile-launcher-bottom) - var(--sz-launcher-size) - 24px) !important;
    max-height: calc(100vh - var(--sz-mobile-launcher-bottom) - var(--sz-launcher-size) - 24px) !important;
    transform-origin: calc(100% - 26px) calc(100% + 88px) !important;
    border-radius: 20px !important;
  }
  :root {
    --sz-launcher-size: 52px;
    --sz-offset: 12px;
    --sz-mobile-launcher-bottom: 88px;
  }
}

@media (prefers-reduced-motion: reduce) {
  iframe[src^="https://stagezero.1stream.co.za/im_livechat"] {
    transition: none !important;
    transform: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    will-change: auto !important;
    backdrop-filter: none !important;
  }

  div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib,
  .o_livechat_button.o_website_livechat_button.o-isExternalLib,
  .o_livechat_button_container .o_livechat_button.o_website_livechat_button.o-isExternalLib {
    transition: none !important;
  }

  div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib:hover,
  .o_livechat_button.o_website_livechat_button.o-isExternalLib:hover,
  .o_livechat_button_container .o_livechat_button.o_website_livechat_button.o-isExternalLib:hover {
    transform: none !important;
    box-shadow: 0 14px 34px rgba(0, 20, 75, 0.18) !important;
  }
}

.o_thread_window.o_in_home_menu {
  z-index: 111111111111;
}

@media(min-width: 768px) {
  body .o_thread_window .o_thread_window_header {
    border-radius: 12px 12px 0 0;
  }

  .o_thread_window.o_in_home_menu {
    border-radius: 12px;
  }

  .o_thread_window.o_in_home_menu .o_thread_composer.o_chat_mini_composer .o_composer_text_field, .o_thread_window.o_in_home_menu .o_thread_composer.o_chat_mini_composer {
    border-radius: 0 0 20px 20px;
  }
}

@media(min-width: 768px) {
  .o_thread_window.o_in_home_menu {
    margin-right: 20px !important;
    margin-bottom: 20px;
  }
}

@media(max-width: 991px) {
  div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib[style*="display: none"], .o_livechat_button.o_website_livechat_button.o-isExternalLib[style*="display: none"], div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib, .o_livechat_button.o_website_livechat_button.o-isExternalLib {
    left: 20px !important;
    right: auto !important;
    top: auto !important;
    bottom: 20px !important;
    margin-bottom: 0 !important;
  }
}

@media(max-width: 420px) {
  div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib[style*="display: none"], .o_livechat_button.o_website_livechat_button.o-isExternalLib[style*="display: none"], div.openerp.o_livechat_button.o_website_livechat_button.o-isExternalLib, .o_livechat_button.o_website_livechat_button.o-isExternalLib {
    left: 32px !important;
    right: auto !important;
  }
}
