/* ============================================================
   Float Popup Locale Switcher — Frontend Styles v2
   Responsive · RTL/LTR · Accessible · CSS Custom Properties
   ============================================================ */

/* ---- Custom properties (overridden by inline PHP) ---- */
:root {
  --fpl-bar-bg:     #3d3530;
  --fpl-bar-fg:     #ffffff;
  --fpl-accent:     #da9fa3;
  --fpl-popup-bg:   #ffffff;
  --fpl-popup-fg:   #1a1a1a;
  --fpl-radius:     12px;
  --fpl-bar-h:      52px;
  --fpl-shadow:     0 8px 32px rgba(0,0,0,.22);
  --fpl-overlay:    rgba(0,0,0,.35);
  --fpl-border:     rgba(0,0,0,.1);
  --fpl-input-border: rgba(0,0,0,.18);
  --fpl-transition: .22s cubic-bezier(.4,0,.2,1);
  --fpl-font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

/* ============================================================
   ROOT / WRAPPER
   ============================================================ */
.fpl-root {
  font-family: var(--fpl-font);
  line-height: 1;
  box-sizing: border-box;
}
.fpl-root *, .fpl-root *::before, .fpl-root *::after {
  box-sizing: inherit;
}

/* Fixed wrapper positions */
.fpl-fixed {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
}

/* Bottom positions */
.fpl-pos--bottom-center { bottom: 0; left: 0; right: 0; display: flex; justify-content: center; padding-bottom: 16px; }
.fpl-pos--bottom-left   { bottom: 16px; left: 16px; right: auto; }
.fpl-pos--bottom-right  { bottom: 16px; right: 16px; left: auto; }
/* Top positions */
.fpl-pos--top-center    { top: 0; left: 0; right: 0; display: flex; justify-content: center; padding-top: 16px; }
.fpl-pos--top-left      { top: 16px; left: 16px; right: auto; }
.fpl-pos--top-right     { top: 16px; right: 16px; left: auto; }

.fpl-inline {
  position: relative;
  z-index: 1;
  display: inline-block;
}

/* ============================================================
   FLOATING BAR
   ============================================================ */
.fpl-bar {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--fpl-bar-h);
  padding: 0 18px;
  background: var(--fpl-bar-bg);
  color: var(--fpl-bar-fg);
  box-shadow: var(--fpl-shadow);
  user-select: none;
  max-width: calc(100vw - 24px);
  overflow: hidden;
}

/* Style variants */
.fpl-style--pill   .fpl-bar { border-radius: calc(var(--fpl-bar-h) / 2); }
.fpl-style--square .fpl-bar { border-radius: 6px; }
.fpl-style--minimal .fpl-bar {
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  border-top: 1px solid var(--fpl-border);
  padding: 0 12px;
  color: var(--fpl-popup-fg);
}

/* Bar item (button) */
.fpl-bar__item {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: calc(var(--fpl-radius) / 2);
  transition: background var(--fpl-transition), opacity var(--fpl-transition);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  color: inherit;
}
.fpl-bar__item:hover,
.fpl-bar__item:focus-visible {
  background: rgba(255,255,255,.12);
  outline: none;
}
.fpl-style--minimal .fpl-bar__item:hover {
  background: rgba(0,0,0,.06);
}

.fpl-bar__text { white-space: nowrap; }

.fpl-sep {
  opacity: .35;
  font-weight: 300;
  flex-shrink: 0;
}

/* Caret */
.fpl-caret {
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  opacity: .65;
  flex-shrink: 0;
  margin-inline-start: 2px;
}

/* ============================================================
   FLAGS
   ============================================================ */
.fpl-flag {
  display: inline-block;
  width: 24px;
  height: 17px;
  border-radius: 3px;
  background: rgba(255,255,255,.15) center / cover no-repeat;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
  flex-shrink: 0;
  vertical-align: middle;
}

/* ============================================================
   MODAL OVERLAY
   ============================================================ */
.fpl-modal {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;
  pointer-events: none;
}
.fpl-modal.is-open {
  display: block;
  pointer-events: auto;
}
.fpl-overlay {
  position: absolute;
  inset: 0;
  background: var(--fpl-overlay);
}

/* ============================================================
   POPUP PANEL
   ============================================================ */
.fpl-panel {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  width: min(440px, calc(100vw - 24px));
  background: var(--fpl-popup-bg);
  color: var(--fpl-popup-fg);
  border-radius: var(--fpl-radius);
  padding: 22px 20px 18px;
  box-shadow: 0 24px 64px rgba(0,0,0,.22);
  border: 1px solid var(--fpl-border);
  will-change: transform, opacity;
}

/* Panel position relative to bar position */
.fpl-pos--bottom-center .fpl-panel,
.fpl-pos--bottom-left   .fpl-panel,
.fpl-pos--bottom-right  .fpl-panel { bottom: calc(var(--fpl-bar-h) + 24px); }

.fpl-pos--top-center    .fpl-panel,
.fpl-pos--top-left      .fpl-panel,
.fpl-pos--top-right     .fpl-panel { top: calc(var(--fpl-bar-h) + 24px); }

/* Inline / shortcode */
.fpl-inline .fpl-panel {
  position: absolute;
  bottom: calc(100% + 10px);
}

/* Animations */
.fpl-anim--slide .fpl-panel {
  transition: transform var(--fpl-transition), opacity var(--fpl-transition);
}
.fpl-anim--slide:not(.is-open) .fpl-panel {
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
}
.fpl-anim--slide.is-open .fpl-panel {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
/* Top positions — slide down */
.fpl-pos--top-center.fpl-anim--slide:not(.is-open) .fpl-panel,
.fpl-pos--top-left.fpl-anim--slide:not(.is-open)   .fpl-panel,
.fpl-pos--top-right.fpl-anim--slide:not(.is-open)  .fpl-panel {
  transform: translateX(-50%) translateY(-16px);
}

.fpl-anim--fade .fpl-panel {
  transition: opacity var(--fpl-transition);
}
.fpl-anim--fade:not(.is-open) .fpl-panel {
  opacity: 0;
  pointer-events: none;
}
.fpl-anim--fade.is-open .fpl-panel {
  opacity: 1;
}

/* Close button */
.fpl-modal__close {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.06);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fpl-popup-fg);
  transition: background var(--fpl-transition);
  padding: 0;
}
.fpl-modal__close:hover { background: rgba(0,0,0,.12); }
.fpl-modal__close:focus-visible { outline: 2px solid var(--fpl-accent); outline-offset: 2px; }

/* Panel title */
.fpl-panel__title {
  font-size: 17px;
  font-weight: 700;
  color: var(--fpl-popup-fg);
  margin-bottom: 18px;
  padding-inline-end: 36px;
}

/* ============================================================
   SECTIONS
   ============================================================ */
.fpl-section { margin-bottom: 14px; }

.fpl-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(0,0,0,.45);
  margin-bottom: 8px;
}
[dir="rtl"] .fpl-label { letter-spacing: 0; }

/* Select wrap */
.fpl-select-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--fpl-input-border);
  border-radius: 8px;
  padding: 10px 14px;
  transition: border-color var(--fpl-transition);
  background: var(--fpl-popup-bg);
}
.fpl-select-wrap:focus-within {
  border-color: var(--fpl-accent);
  box-shadow: 0 0 0 3px rgba(218,159,163,.2);
}

.fpl-select {
  border: none !important;
  background: transparent !important;
  padding: 0 !important;
  margin: 0 !important;
  width: 100%;
  font-size: 16px;
  font-family: inherit;
  color: var(--fpl-popup-fg);
  outline: none !important;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  font-weight: 500;
}
.fpl-select:focus { outline: none !important; box-shadow: none !important; }

.fpl-arrow {
  position: absolute;
  inset-inline-end: 14px;
  top: 50%;
  margin-top: -5px;
  width: 9px;
  height: 9px;
  border-right: 2px solid rgba(0,0,0,.4);
  border-bottom: 2px solid rgba(0,0,0,.4);
  transform: rotate(45deg);
  pointer-events: none;
  flex-shrink: 0;
}

/* ============================================================
   APPLY BUTTON
   ============================================================ */
.fpl-actions {
  display: flex;
  justify-content: stretch;
  padding-top: 6px;
}

.fpl-btn-apply {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  background: var(--fpl-popup-fg);
  color: var(--fpl-popup-bg);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  padding: 13px 22px;
  cursor: pointer;
  transition: filter var(--fpl-transition), transform var(--fpl-transition);
  position: relative;
  overflow: hidden;
}
.fpl-btn-apply:hover:not(:disabled) { filter: brightness(1.08); }
.fpl-btn-apply:active { transform: scale(.98); }
.fpl-btn-apply:disabled { opacity: .55; cursor: not-allowed; }
.fpl-btn-apply:focus-visible { outline: 2px solid var(--fpl-accent); outline-offset: 2px; }

/* Spinner */
.fpl-btn-apply__spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: fpl-spin .7s linear infinite;
}
.fpl-btn-apply.is-loading .fpl-btn-apply__spinner { display: block; }
.fpl-btn-apply.is-loading .fpl-btn-apply__text { opacity: .6; }

@keyframes fpl-spin {
  to { transform: rotate(360deg); }
}

@keyframes fpl-pulse {
  0%   { opacity: .7; transform: scale(1); }
  100% { opacity: 0;  transform: scale(1.45); }
}

/* ============================================================
   GEO LOADER — spinner while detecting location
   ============================================================ */
.fpl-geo-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px 28px;
  gap: 14px;
  text-align: center;
  font-size: 14px;
  color: rgba(0,0,0,.5);
}
.fpl-geo-loader__spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(0,0,0,.1);
  border-top-color: var(--fpl-accent);
  border-radius: 50%;
  animation: fpl-spin .8s linear infinite;
}

/* ============================================================
   WELCOME BANNER — shown when country is detected & supported
   ============================================================ */
.fpl-welcome-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, rgba(var(--fpl-accent-rgb,218,159,163),.12) 0%, rgba(var(--fpl-accent-rgb,218,159,163),.05) 100%);
  border: 1px solid rgba(var(--fpl-accent-rgb,218,159,163),.3);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.fpl-welcome-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.fpl-welcome-text strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--fpl-popup-fg);
}
.fpl-welcome-sub {
  font-size: 12px;
  color: rgba(0,0,0,.5);
  line-height: 1.4;
}

/* ============================================================
   UNSUPPORTED COUNTRY SCREEN
   ============================================================ */
.fpl-unsupported {
  text-align: center;
  padding: 8px 4px 4px;
}
.fpl-unsupported__icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 10px;
  color: var(--fpl-popup-fg);
  opacity: .7;
}
.fpl-unsupported__icon svg {
  width: 100%;
  height: 100%;
}
.fpl-unsupported__title {
  font-size: 17px;
  font-weight: 700;
  color: var(--fpl-popup-fg);
  margin: 0 0 6px;
  line-height: 1.3;
}
.fpl-unsupported__country-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fpl-accent);
  margin: 0 0 10px;
  letter-spacing: .03em;
}
.fpl-unsupported__msg {
  font-size: 13px;
  color: rgba(0,0,0,.5);
  line-height: 1.55;
  margin: 0 0 18px;
}
.fpl-unsupported__countries {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 20px;
}

/* Country chips on unsupported screen */
.fpl-country-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--fpl-border);
  border-radius: 999px;
  background: var(--fpl-popup-bg);
  color: var(--fpl-popup-fg);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--fpl-transition), background var(--fpl-transition), transform .1s;
}
.fpl-country-chip:hover {
  border-color: var(--fpl-accent);
  background: rgba(var(--fpl-accent-rgb,218,159,163),.08);
  transform: translateY(-1px);
}
.fpl-country-chip:active { transform: translateY(0); }

/* "Choose a supported country" button */
.fpl-btn-choose-country {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 28px;
  border: 2px solid var(--fpl-popup-fg);
  border-radius: 8px;
  background: transparent;
  color: var(--fpl-popup-fg);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--fpl-transition), color var(--fpl-transition);
  width: 100%;
}
.fpl-btn-choose-country:hover {
  background: var(--fpl-popup-fg);
  color: var(--fpl-popup-bg);
}


[dir="rtl"] .fpl-caret {
  transform: rotate(45deg) scaleX(-1);
}
[dir="rtl"] .fpl-bar {
  direction: rtl;
}
[dir="rtl"] .fpl-panel {
  direction: rtl;
}
[dir="rtl"] .fpl-select {
  direction: rtl;
  text-align: right;
}
[dir="rtl"] .fpl-label {
  text-align: right;
}
[dir="rtl"] .fpl-panel__title {
  text-align: right;
}

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
  :root { --fpl-bar-h: 48px; }

  .fpl-bar {
    gap: 4px;
    padding: 0 12px;
  }

  .fpl-bar__item {
    padding: 5px 8px;
    font-size: 13px;
    gap: 6px;
  }

  .fpl-bar__text {
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .fpl-panel {
    left: 12px;
    right: 12px;
    width: auto;
    transform: translateX(0) !important;
    padding: 18px 16px 14px;
  }

  /* Bottom-positioned: slide up animation on mobile */
  .fpl-pos--bottom-center .fpl-panel,
  .fpl-pos--bottom-left   .fpl-panel,
  .fpl-pos--bottom-right  .fpl-panel {
    bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    left: 0;
    right: 0;
    width: 100%;
  }

  /* Mobile slide from bottom */
  .fpl-anim--slide .fpl-panel {
    transition: transform var(--fpl-transition), opacity var(--fpl-transition);
  }
  .fpl-pos--bottom-center.fpl-anim--slide:not(.is-open) .fpl-panel,
  .fpl-pos--bottom-left.fpl-anim--slide:not(.is-open)   .fpl-panel,
  .fpl-pos--bottom-right.fpl-anim--slide:not(.is-open)  .fpl-panel {
    transform: translateY(100%);
    opacity: 0;
  }
  .fpl-pos--bottom-center.fpl-anim--slide.is-open .fpl-panel,
  .fpl-pos--bottom-left.fpl-anim--slide.is-open   .fpl-panel,
  .fpl-pos--bottom-right.fpl-anim--slide.is-open  .fpl-panel {
    transform: translateY(0);
    opacity: 1;
  }

  .fpl-select { font-size: 15px; }
  .fpl-btn-apply { padding: 12px; font-size: 15px; }

  /* Full-width bar on mobile center positions */
  .fpl-pos--bottom-center .fpl-bar,
  .fpl-pos--top-center    .fpl-bar {
    border-radius: 0;
    max-width: 100vw;
    width: 100vw;
    justify-content: center;
  }
}

/* ============================================================
   MOBILE FAB (Floating Action Button)
   Injected by JS when mobile_bar_style = "small", screen <= 600px
   ============================================================ */
.fpl-fab {
  display: none; /* hidden by default; JS shows it on mobile only */
  position: fixed;
  z-index: 99999;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--fpl-bar-bg);
  color: var(--fpl-bar-fg);
  box-shadow: 0 4px 18px rgba(0,0,0,.35);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform .15s ease, box-shadow .15s ease, opacity .2s ease;
}
.fpl-fab:active {
  transform: scale(.93);
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.fpl-fab svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  fill: none;
  pointer-events: none;
}

/* Pulse ring */
.fpl-fab::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid var(--fpl-accent);
  opacity: 0;
  animation: fpl-pulse 3s ease-out infinite 2.5s;
}

/* Horizontal position */
.fpl-fab--right  { right: 18px; left: auto; }
.fpl-fab--left   { left: 18px;  right: auto; }
.fpl-fab--center { left: 50%; margin-left: -27px; right: auto; }
.fpl-fab--center:active { transform: scale(.93); }

/* Vertical position — set via JS inline style (top/bottom + px offset) */

/* ============================================================
   BOTTOM SHEET — when FAB is active (body.fpl-fab-active)
   Applied regardless of screen size (JS only adds class on mobile)
   ============================================================ */
body.fpl-fab-active .fpl-root.fpl-fixed .fpl-modal {
  /* make modal full screen so overlay covers everything */
  position: fixed;
  inset: 0;
  z-index: 100000;
}

body.fpl-fab-active .fpl-root.fpl-fixed .fpl-modal .fpl-panel {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  top: auto !important;
  width: 100% !important;
  max-width: 100% !important;
  border-radius: var(--fpl-radius) var(--fpl-radius) 0 0 !important;
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)) !important;
  /* reset any translateX centering */
  transform: translateY(0) !important;
}

/* Slide-up animation for bottom sheet */
body.fpl-fab-active .fpl-root.fpl-fixed .fpl-modal.fpl-anim--slide .fpl-panel {
  transition: transform var(--fpl-transition), opacity var(--fpl-transition) !important;
}
body.fpl-fab-active .fpl-root.fpl-fixed .fpl-modal.fpl-anim--slide:not(.is-open) .fpl-panel {
  transform: translateY(100%) !important;
  opacity: 0 !important;
  pointer-events: none;
}
body.fpl-fab-active .fpl-root.fpl-fixed .fpl-modal.fpl-anim--slide.is-open .fpl-panel {
  transform: translateY(0) !important;
  opacity: 1 !important;
}

/* Fade animation for bottom sheet */
body.fpl-fab-active .fpl-root.fpl-fixed .fpl-modal.fpl-anim--fade .fpl-panel {
  transition: opacity var(--fpl-transition) !important;
}
body.fpl-fab-active .fpl-root.fpl-fixed .fpl-modal.fpl-anim--fade:not(.is-open) .fpl-panel {
  opacity: 0 !important;
  pointer-events: none;
}
body.fpl-fab-active .fpl-root.fpl-fixed .fpl-modal.fpl-anim--fade.is-open .fpl-panel {
  opacity: 1 !important;
}


@media (max-width: 360px) {
  .fpl-bar__text { display: none; }
  .fpl-flag { width: 22px; height: 16px; }
}

/* ============================================================
   SAFE AREA (iOS notch / home bar)
   ============================================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .fpl-pos--bottom-center,
  .fpl-pos--bottom-left,
  .fpl-pos--bottom-right {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .fpl-pos--bottom-center .fpl-panel,
  .fpl-pos--bottom-left   .fpl-panel,
  .fpl-pos--bottom-right  .fpl-panel {
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
}

/* ============================================================
   ACCESSIBILITY — reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .fpl-panel,
  .fpl-btn-apply,
  .fpl-bar__item,
  .fpl-modal__close { transition: none !important; }
  .fpl-btn-apply__spinner { animation-duration: 1.5s !important; }
}
