/**
 * Local Panels — location switcher dropdown + country popup.
 *
 * Dropdown mirrors the user-menu dropdown behaviour; the popup mirrors the
 * logout popup but is right-aligned and sticky.
 *
 * @package PS5_Theme
 * @since 1.3.0
 */

/* ------------------------------------------------------------ dropdown */

.ps-location-menu-dropdown {
  position: relative;
  display: inline-block;
  height: 100%;
  /* Space between the world icon and the user menu / login button. */
  margin-right: 16px;
}

/* When open, lift the whole switcher above the sticky country popup
   (popup z-index 9998). Raising the container — not just the content —
   ensures it wins regardless of stacking-context nesting. */
#locationMenuDropdown.open {
  z-index: 10000;
}

.ps-location-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 100%;
  padding: 0 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #ffffff;
  font-family: 'Inter', sans-serif;
}

.ps-location-menu-globe {
  display: inline-flex;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.ps-location-menu-globe svg {
  width: 100%;
  height: 100%;
}

.ps-location-menu-text {
  font-weight: 600;
  font-size: 16px;
  line-height: 19px;
  white-space: nowrap;
}

.ps-location-menu-arrow {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: currentColor;
  transition: transform 0.2s ease;
}

.ps-location-menu-dropdown.open .ps-location-menu-arrow {
  transform: rotate(180deg);
}

/* Dropdown content */
.ps-location-menu-dropdown-content {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.15);
  border: 1px solid #e5e7eb;
  z-index: 1000;
  padding: 6px 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition:
    opacity 0.2s ease,
    visibility 0.2s ease,
    transform 0.2s ease;
}

.ps-location-menu-dropdown-content.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Header switcher dropdown: open to the right of the icon and stay above the
   sticky country popup (which sits at z-index 9998). */
#locationMenuDropdownContent {
  left: 0;
  right: auto;
  z-index: 10000;
}

/* Dropdown items */
.ps-location-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 16px;
  line-height: 20px;
  color: #374151;
  text-decoration: none;
  box-sizing: border-box;
  transition: background-color 0.2s ease;
}

.ps-location-menu-item:hover,
.ps-location-menu-item:focus {
  background-color: #f3f4f6;
  outline: none;
}

.ps-location-menu-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  /* Monochrome icons inherit the text colour; colour icons keep their own. */
  color: #111113;
}

.ps-location-menu-item-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.ps-location-menu-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------- popup */

.ps-country-popup {
  position: fixed;
  top: 166px;
  right: 0;
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  width: 330px;
  padding: 16px 20px;
  background: #ffffff;
  box-shadow: 0px 0px 12px 2px rgba(0, 0, 0, 0.2);
  border-radius: 32px 0 0 32px;
  transition:
    transform 0.25s ease,
    opacity 0.25s ease;
}

/* Hidden state — slides off the right edge and stays hidden for the view. */
.ps-country-popup.is-hidden {
  opacity: 0;
  transform: translateX(100%);
  pointer-events: none;
}

.ps-country-popup-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.ps-country-popup-close:hover {
  opacity: 0.7;
}

.ps-country-popup-title {
  align-self: stretch;
  margin: 0;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 16px;
  line-height: 19px;
  color: #111113;
}

.ps-country-popup-select-wrap {
  align-self: stretch;
  position: relative;
}

.ps-country-popup-select {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: 44px;
  padding: 12px 16px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 18px;
  line-height: 22px;
  color: #4f4f55;
  background: #ffffff;
  border: 2px solid #ececec;
  border-radius: 32px;
  cursor: pointer;
  box-sizing: border-box;
  text-align: left;
}

.ps-country-popup-select:focus {
  outline: none;
  border-color: #d5d5d5;
}

.ps-country-popup-select-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ps-country-popup-select .ps-location-menu-arrow {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: #4f4f55;
}

/* Popup dropdown list: stretch to the pill width, open below it. */
.ps-country-popup-dropdown-content {
  left: 0;
  right: 0;
  min-width: 0;
  max-height: 240px;
  overflow-y: auto;
}

/* Small screens: center the popup horizontally and round all corners. */
@media (max-width: 480px) {
  .ps-country-popup {
    width: calc(100vw - 24px);
    right: 50%;
    transform: translateX(50%);
    border-radius: 32px;
  }

  /* Keep the hidden state consistent with the centered transform. */
  .ps-country-popup.is-hidden {
    transform: translateX(150%);
  }
}
