/* ── Reset: scoped only to widget ── */
#bsw-widget,
#bsw-widget *,
#bsw-widget *::before,
#bsw-widget *::after {
  box-sizing: border-box;
}

/* ── Root container ── */
#bsw-widget.bsw-widget {
  position: fixed;
  right: var(--bsw-side);
  bottom: var(--bsw-bottom);
  z-index: 99999;
  font-family: inherit;
  direction: rtl;
  /* NO isolation — avoids Elementor/page stacking-context conflicts */
  width: 0;
  height: 0;
  overflow: visible;
}

/* ── Popup ── */
#bsw-widget .bsw-popup {
  /*
   * Use position:fixed but attach it to document root, NOT to the widget container.
   * This avoids the iOS Safari bug where a fixed child of a fixed parent
   * mis-positions on scroll or keyboard open.
   * The popup is already a sibling-level fixed element via PHP output; this
   * rule just ensures the CSS is correct regardless of DOM depth.
   */
  position: fixed;
  right: var(--bsw-side);
  top: var(--bsw-popup-top);
  width: min(340px, calc(100vw - 24px));
  max-height: calc(100vh - var(--bsw-popup-top) - 16px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--bsw-popup-bg);
  color: var(--bsw-popup-text);
  border-radius: 20px;
  box-shadow: 0 18px 50px rgba(22, 18, 32, 0.65);
  padding: 18px 16px 16px;
  border: 1px solid rgba(0, 0, 0, .05);
  /* Hidden by default — NO transition, NO animation, NO transform */
  display: none;
  pointer-events: none;
}

#bsw-widget .bsw-popup.is-open {
  display: block;
  pointer-events: auto;
}

/* center variant */
#bsw-widget.bsw-popup-center .bsw-popup {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

/* ── Close button ── */
#bsw-widget .bsw-close {
  all: unset;
  position: absolute;
  top: 10px;
  left: 10px;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  max-width: 36px;
  max-height: 36px;
  border-radius: 50%;
  border: 1px solid var(--bsw-close-border);
  background: var(--bsw-close-bg);
  color: var(--bsw-close-color);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .10);
  line-height: 1;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

#bsw-widget .bsw-close span {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  pointer-events: none;
}

#bsw-widget .bsw-close span::before,
#bsw-widget .bsw-close span::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 17px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transform-origin: center;
}

#bsw-widget .bsw-close span::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

#bsw-widget .bsw-close span::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* ── Popup head ── */
#bsw-widget .bsw-popup-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding-left: 44px;
}

#bsw-widget .bsw-popup-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 12px;
  overflow: visible;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

#bsw-widget .bsw-popup-icon img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

#bsw-widget .bsw-popup-title {
  color: var(--bsw-popup-title);
  font-weight: 800;
  font-size: 17px;
  line-height: 1.5;
}

#bsw-widget .bsw-popup-text {
  font-size: 14px;
  line-height: 1.9;
  margin-bottom: 12px;
}

/* ── Timer ── */
#bsw-widget .bsw-timer {
  margin: 0 0 14px;
  color: var(--bsw-timer-text);
}

#bsw-widget .bsw-timer-line {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  line-height: 1.7;
  margin-bottom: 7px;
}

#bsw-widget .bsw-timer-count {
  font-size: 13px;
  font-weight: 900;
  color: var(--bsw-popup-title);
  min-width: 18px;
  text-align: center;
}

#bsw-widget .bsw-timer-bar {
  width: 100%;
  height: 6px;
  background: var(--bsw-timer-bar-bg);
  border-radius: 999px;
  overflow: hidden;
}

#bsw-widget .bsw-timer-bar span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bsw-timer-bar-fill);
  border-radius: 999px;
  transform-origin: right center;
  transform: scaleX(1);
  /* transition is applied dynamically by JS only when timer is active */
}

/* ── CTA button ── */
#bsw-widget .bsw-popup-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  width: 100%;
  text-decoration: none;
  border-radius: 14px;
  background: var(--bsw-button-bg);
  color: var(--bsw-button-text);
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 10px 24px rgba(158, 86, 164, 0.25);
  -webkit-tap-highlight-color: transparent;
}

#bsw-widget .bsw-popup-btn:hover,
#bsw-widget .bsw-popup-btn:focus {
  color: var(--bsw-button-text);
  opacity: .92;
}

/* ── Don't-show checkbox ── */
#bsw-widget .bsw-dontshow {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  user-select: none;
  cursor: pointer;
  color: var(--bsw-popup-text);
}

#bsw-widget .bsw-dontshow input {
  margin: 0;
}

/* ── FAB ── */
#bsw-widget .bsw-fab {
  all: unset;
  position: absolute;
  bottom: 0;
  right: 0;
  width: var(--bsw-icon-size);
  height: var(--bsw-icon-size);
  min-width: var(--bsw-icon-size);
  min-height: var(--bsw-icon-size);
  display: block;
  cursor: pointer;
  user-select: none;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Flip stage */
#bsw-widget .bsw-flip-stage {
  position: relative;
  display: block;
  width: var(--bsw-icon-size);
  height: var(--bsw-icon-size);
}

/* Both faces sit on top of each other; only one visible at a time */
#bsw-widget .bsw-fab-face {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--bsw-icon-size);
  height: var(--bsw-icon-size);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Icon face: visible by default */
#bsw-widget .bsw-face-icon {
  background: transparent;
  border-radius: 0;
  overflow: visible;
  visibility: visible;
  opacity: 1;
  /* NO transition */
}

#bsw-widget .bsw-fab.show-text .bsw-face-icon {
  visibility: hidden;
  opacity: 0;
}

#bsw-widget .bsw-face-icon img {
  display: block;
  max-width: var(--bsw-icon-size);
  max-height: var(--bsw-icon-size);
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Default icon (fallback circle) */
#bsw-widget .bsw-default-icon {
  width: var(--bsw-icon-size);
  height: var(--bsw-icon-size);
  border-radius: 50%;
  background: var(--bsw-bubble-bg);
  color: var(--bsw-bubble-text);
  box-shadow: 0 12px 30px rgba(158, 86, 164, .24);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--bsw-icon-size) * .46);
}

/* Text face: hidden by default, shown with show-text — NO transition */
#bsw-widget .bsw-face-text {
  width: var(--bsw-text-bubble-size);
  height: var(--bsw-text-bubble-size);
  min-width: var(--bsw-text-bubble-size);
  min-height: var(--bsw-text-bubble-size);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  overflow: hidden;
  background:
    radial-gradient(circle at 28% 22%, rgba(255,255,255,.34), rgba(255,255,255,0) 34%),
    linear-gradient(145deg, rgba(255,255,255,.16), rgba(255,255,255,0) 42%),
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(0,0,0,.10)),
    var(--bsw-bubble-bg);
  color: var(--bsw-bubble-text);
  box-shadow:
    0 14px 32px rgba(158, 86, 164, .24),
    inset 0 1px 0 rgba(255,255,255,.22),
    inset 0 -10px 18px rgba(0,0,0,.10);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  line-height: 1.22;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.18);
  visibility: hidden;
  opacity: 0;
  /* NO transition — instant swap, no flash */
}

#bsw-widget .bsw-fab.show-text .bsw-face-text {
  visibility: visible;
  opacity: 1;
}

#bsw-widget .bsw-face-text::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.10);
  pointer-events: none;
}

#bsw-widget .bsw-face-text::after {
  content: "";
  position: absolute;
  top: 12%;
  left: 18%;
  width: 40%;
  height: 20%;
  border-radius: 999px;
  background: rgba(255,255,255,.16);
  transform: rotate(-18deg);
  filter: blur(2px);
  pointer-events: none;
}

#bsw-widget .bsw-face-text > span {
  position: relative;
  z-index: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-align: center;
  max-width: 100%;
  word-break: break-word;
  text-shadow: 0 1px 2px rgba(0,0,0,.18);
  letter-spacing: .1px;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  #bsw-widget.bsw-widget {
    right: var(--bsw-side);
    bottom: var(--bsw-bottom);
  }

  #bsw-widget .bsw-popup {
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    top: var(--bsw-popup-top);
    /*
     * Use 100dvh where available (iOS Safari accounts for browser chrome),
     * fall back to 100vh for older browsers.
     */
    max-height: calc(100dvh - var(--bsw-popup-top) - 12px);
  }

  /* center variant on mobile — drop translate, use full-width pinning */
  #bsw-widget.bsw-popup-center .bsw-popup {
    left: 12px;
    right: 12px;
    transform: none;
  }

  #bsw-widget .bsw-popup-title {
    font-size: 16px;
  }

  #bsw-widget .bsw-popup-text {
    font-size: 13px;
  }

  #bsw-widget .bsw-close {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    max-width: 36px;
    max-height: 36px;
  }
}
