/* Currency side panel (mirrors cart panel) */
.currency-toggle {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  font: inherit;
  font-size: var(--font-sm, 14px);
  font-weight: var(--weight-bold, 600);
  letter-spacing: 0.02em;
}

/* Direct child of the .header-inner grid: without this it creates an empty
   implicit row, and the grid row-gap shows up as blank space under the header. */
.currency-wrap {
  display: contents;
}

.currency-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration);
  z-index: var(--z-overlay);
}

.currency-wrap.open .currency-overlay {
  opacity: 1;
  visibility: visible;
}

.currency-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 640px;
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  transform: translateX(100%);
  transition: transform var(--duration-slow) var(--ease-drawer);
  z-index: var(--z-popup);
  display: flex;
  flex-direction: column;
}

.currency-panel[hidden] {
  display: none !important;
}

.currency-wrap.open .currency-panel {
  transform: translateX(0);
}

body.currency-open .site-header {
  z-index: var(--z-popup);
}

.currency-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.currency-panel-title {
  font-weight: var(--weight-bold);
  font-size: var(--font-lg);
  line-height: var(--leading-heading);
  letter-spacing: var(--tracking-heading);
}

.currency-close {
  background: transparent;
  border: 0;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  color: var(--text);
  transition: var(--button-transition);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.currency-close svg {
  width: 24px;
  height: 24px;
  display: block;
}

@media (hover: hover) {
  .currency-close:hover {
    background: var(--surface-hover);
  }
}

.currency-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
}

.currency-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.currency-option {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 56px 1fr auto 24px;
  align-items: center;
  gap: 16px;
  padding: 18px 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.currency-option__flag {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-hover);
  font-size: 10px;
  font-weight: var(--weight-bold);
  box-shadow: 0 0 0 1px var(--border);
}

.currency-option__flag img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.currency-option__code {
  font-weight: var(--weight-bold);
}

.currency-option__name {
  opacity: 0.7;
}

.currency-option__symbol {
  opacity: 0.7;
}

.currency-option.is-active .currency-option__name,
.currency-option.is-active .currency-option__symbol {
  opacity: 1;
}

.currency-option.is-loading {
  opacity: 0.5;
  pointer-events: none;
}

@media (hover: hover) {
  .currency-option:hover .currency-option__name {
    opacity: 1;
  }
}

@media (max-width: 1024px) {
  .currency-panel {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: auto;
    max-height: 85vh;
    max-height: 85dvh;
    transform: translateY(100%);
  }

  .currency-wrap.open .currency-panel {
    transform: translateY(0);
  }

  body.currency-open {
    overflow: hidden;
  }
}

/* Active currency: tinted row, outline and a check badge */
.currency-option {
  padding-left: 12px;
  padding-right: 12px;
  border-radius: 8px;
  transition: background var(--duration-fast, 0.15s);
}

.currency-option__check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  transform: scale(0.6);
  transition:
    opacity var(--duration-fast, 0.15s),
    transform var(--duration-fast, 0.15s);
}

.currency-option.is-active {
  background: var(--surface-hover);
  box-shadow: inset 0 0 0 1.5px var(--text);
  border-bottom-color: transparent;
}

.currency-option.is-active .currency-option__check {
  opacity: 1;
  transform: scale(1);
}

@media (hover: hover) {
  .currency-option:not(.is-active):hover {
    background: var(--surface-hover);
  }
}

.currency-toggle .currency-toggle-icon {
  display: block;
}

.site-header .currency-toggle {
  color: var(--header-chrome-color, #fff);
}

/* Desktop: like the bag drawer, the panel runs full height and the header's
   controls sit on top of it. --pf-currency-top is set from JS on open. */
@media (min-width: 1025px) {
  html body .currency-wrap .currency-panel {
    box-sizing: border-box;
    padding-top: var(--pf-currency-top, 0px);
  }

  html body .currency-panel .currency-panel-header .currency-close {
    display: none;
  }

  html body .currency-panel .currency-panel-header {
    border-top: 0;
  }

  /* Keyed to the panel being visible (not .open) so controls stay above the
     drawer while it slides out on close. */
  html body .site-header:has(.currency-panel:not([hidden])) {
    --header-chrome-color: var(--text);
  }

  html body .site-header:has(.currency-panel:not([hidden])) .header-right > *,
  html body .site-header:has(.currency-panel:not([hidden])) .currency-toggle {
    position: relative;
    z-index: calc(var(--z-popup) + 1);
  }

  .currency-wrap.open ~ .header-right .currency-toggle,
  .site-header:has(.currency-wrap.open) .currency-toggle {
    background: var(--surface-hover);
    border-radius: 999px;
    padding: 6px 12px;
    margin: -6px -12px;
  }

  .currency-wrap.open.overlay-ready .currency-overlay {
    cursor:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Ccircle cx='24' cy='24' r='24' fill='%23000'/%3E%3Cpath d='M18 18L30 30M30 18L18 30' stroke='%23fff' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E")
        24 24,
      pointer;
  }

  [data-theme="dark"] .currency-wrap.open.overlay-ready .currency-overlay {
    cursor:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Ccircle cx='24' cy='24' r='24' fill='%23fff'/%3E%3Cpath d='M18 18L30 30M30 18L18 30' stroke='%23000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E")
        24 24,
      pointer;
  }
}
