/* =============================================================================
   WC Currency Switch — switcher.css  v1.0.5
   Full RTL support: CSS logical properties + [dir="rtl"] overrides.
   WCAG 2.1 AA: focus rings, sr-only, reduced-motion, forced-colors.
   ============================================================================= */

/* ── Screen reader only ───────────────────────────────────────────────────── */

.wccs-sr-only {
    position:    absolute;
    width:       1px;
    height:      1px;
    padding:     0;
    margin:      -1px;
    overflow:    hidden;
    clip:        rect(0, 0, 0, 0);
    white-space: nowrap;
    border:      0;
}

/* ── CSS custom property defaults ─────────────────────────────────────────── */

.wccs-switcher {
    --wccs-bg:           transparent;
    --wccs-color:        inherit;
    --wccs-border:       currentColor;
    --wccs-border-width: 1px;
    --wccs-radius:       6px;
    --wccs-padding:      7px 12px;
    --wccs-font-size:    0.9em;
    --wccs-font-weight:  inherit;
    --wccs-gap:          6px;
    --wccs-hover-bg:     var(--wccs-bg);
    --wccs-hover-color:  var(--wccs-color);
    --wccs-hover-border: var(--wccs-border);

    display:        inline-flex;
    align-items:    center;
    position:       relative;
    vertical-align: middle;
}

/* ── Trigger ─────────────────────────────────────────────────────────────── */

.wccs-trigger {
    display:       inline-flex;
    align-items:   center;
    gap:           var(--wccs-gap);
    padding:       var(--wccs-padding);
    background:    var(--wccs-bg);
    color:         var(--wccs-color);
    border:        var(--wccs-border-width) solid var(--wccs-border);
    border-radius: var(--wccs-radius);
    font-size:     var(--wccs-font-size);
    font-weight:   var(--wccs-font-weight);
    font-family:   inherit;
    line-height:   1.4;
    white-space:   nowrap;
    cursor:        pointer;
    transition:    background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    user-select:   none;
    -webkit-tap-highlight-color: transparent;
}

.wccs-trigger:hover {
    background:   var(--wccs-hover-bg);
    color:        var(--wccs-hover-color);
    border-color: var(--wccs-hover-border);
}

.wccs-trigger:focus-visible {
    outline:        3px solid var(--wccs-primary, currentColor);
    outline-offset: 3px;
}

.wccs-trigger:disabled,
.wccs-trigger[aria-disabled="true"] {
    opacity: 0.45;
    cursor:  not-allowed;
}

.wccs-flag    { font-size: 1.15em; line-height: 1; flex-shrink: 0; }
.wccs-code    { font-weight: 600; letter-spacing: 0.03em; }
.wccs-symbol  { font-weight: 500; opacity: 0.75; }
.wccs-name    { font-weight: 400; }

.wccs-chevron {
    flex-shrink: 0;
    opacity:     0.55;
    transition:  transform 0.2s ease;
}

.wccs-trigger[aria-expanded="true"] .wccs-chevron {
    transform: rotate(180deg);
}

/* RTL: chevron rotates the same way visually but from the mirrored position */
[dir="rtl"] .wccs-trigger[aria-expanded="true"] .wccs-chevron {
    transform: rotate(-180deg);
}

/* ── Backdrop ────────────────────────────────────────────────────────────── */

.wccs-backdrop {
    display:         none;
    position:        fixed;
    inset:           0;
    background:      rgba(0, 0, 0, 0.4);
    z-index:         999980;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation:       wccs-fade-in 0.18s ease forwards;
}

.wccs-backdrop.wccs-backdrop--visible { display: block; }

/* ── Modal ───────────────────────────────────────────────────────────────── */

.wccs-modal {
    position:       fixed;
    z-index:        999990;
    top:            50%;
    left:           50%;
    transform:      translate(-50%, -50%) scale(0.96);
    width:          min(var(--wccs-modal-width, 700px), 92vw);
    max-height:     min(560px, 85vh);
    display:        flex;
    flex-direction: column;
    background:     #ffffff;
    border-radius:  22px;
    border:         1px solid rgba(0,0,0,.06);
    box-shadow:     0 40px 100px rgba(0,0,0,.18), 0 8px 30px rgba(0,0,0,.1), 0 2px 8px rgba(0,0,0,.06);
    overflow:       hidden;
    opacity:        0;
    transition:     opacity 0.2s ease, transform 0.2s cubic-bezier(0.34,1.2,0.64,1);
}

.wccs-modal.wccs-modal--open {
    opacity:   1;
    transform: translate(-50%, -50%) scale(1);
}

/* ── Modal header separator ──────────────────────────────────────────────── */

.wccs-modal[hidden] { display: none; }

.wccs-drag-handle { display: none; }

/* ── Modal header ────────────────────────────────────────────────────────── */

.wccs-modal-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    padding:         16px 18px 14px;
    flex-shrink:     0;
    border-bottom:   1px solid #f0f0f0;
}

.wccs-modal-header-left {
    display:     flex;
    align-items: center;
    gap:         8px;
}

.wccs-modal-title {
    font-weight: 700;
    font-size:   var(--wccs-title-size, 1rem);
    color:       #111827;
    line-height: 1.2;
    margin:      0;
    padding:     0;
}

.wccs-modal-count {
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    background:      #f3f4f6;
    color:           #6b7280;
    font-size:       0.7rem;
    font-weight:     600;
    padding:         2px 7px;
    border-radius:   99px;
    letter-spacing:  0.02em;
    line-height:     1.6;
}

.wccs-close {
    display:         flex;
    align-items:     center;
    justify-content: center;
    width:           36px;
    height:          36px;
    min-width:       36px;
    padding:         0;
    background:      transparent;
    border:          none;
    border-radius:   8px;
    cursor:          pointer;
    color:           #9ca3af;
    transition:      background 0.12s, color 0.12s;
}

.wccs-close:hover      { background: #f3f4f6; color: #374151; }
.wccs-close:focus-visible {
    outline:        2px solid #374151;
    outline-offset: 2px;
}

/* RTL modal header */
[dir="rtl"] .wccs-modal-header { flex-direction: row-reverse; }
[dir="rtl"] .wccs-modal-header-left { flex-direction: row-reverse; }

/* ── Search ──────────────────────────────────────────────────────────────── */

.wccs-search-wrap {
    display:       flex;
    align-items:   center;
    gap:           10px;
    margin:        12px 14px 10px;
    padding:       0 14px;
    background:    #f4f4f5;
    border:        1.5px solid transparent;
    border-radius: 14px;
    flex-shrink:   0;
    transition:    border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.wccs-search-wrap:focus-within {
    border-color: var(--wccs-primary, #22c55e);
    box-shadow:   0 0 0 4px color-mix(in srgb, var(--wccs-primary, #22c55e) 12%, transparent);
    background:   #fff;
}

.wccs-search-icon { color: #9ca3af; flex-shrink: 0; }

.wccs-search {
    flex:         1;
    border:       none;
    background:   transparent;
    padding:      13px 0;
    font-size:    0.9rem;
    color:        #111827;
    font-family:  inherit;
    font-weight:  400;
    outline:      none;
    min-width:    0;
    unicode-bidi: plaintext;
}

.wccs-search::placeholder { color: #9ca3af; }
.wccs-search::-webkit-search-decoration,
.wccs-search::-webkit-search-cancel-button,
.wccs-search::-webkit-search-results-button,
.wccs-search::-webkit-search-results-decoration { display: none; }

.wccs-search-clear {
    display:         flex;
    align-items:     center;
    justify-content: center;
    width:           22px;
    height:          22px;
    padding:         0;
    background:      #e5e7eb;
    border:          none;
    border-radius:   50%;
    cursor:          pointer;
    color:           #6b7280;
    flex-shrink:     0;
    transition:      background 0.12s;
}

.wccs-search-clear:hover { background: #d1d5db; color: #374151; }
.wccs-search-clear:focus-visible { outline: 2px solid #374151; outline-offset: 2px; }
.wccs-search-clear[hidden] { display: none; }

/* RTL: icon moves to end, clear button to start */
[dir="rtl"] .wccs-search-wrap { flex-direction: row-reverse; }
[dir="rtl"] .wccs-search      { text-align: right; }

/* ── Currency list ───────────────────────────────────────────────────────── */

.wccs-list {
    flex:                  1;
    overflow-y:            auto;
    overscroll-behavior:   contain;
    padding:               4px 12px 14px;
    margin:                0;
    list-style:            none;
    scrollbar-width:       thin;
    scrollbar-color:       #e5e7eb transparent;
    /* 2-column grid */
    display:               grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap:                   6px;
    align-content:         start;
}

.wccs-list::-webkit-scrollbar       { width: 4px; }
.wccs-list::-webkit-scrollbar-track { background: transparent; }
.wccs-list::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }

/* RTL: scrollbar moves to left */
[dir="rtl"] .wccs-list { scrollbar-gutter: stable; direction: rtl; }

.wccs-list li { padding: 0; margin: 0; }

/* ── Currency option row ─────────────────────────────────────────────────── */

.wccs-option {
    display:        flex;
    align-items:    center;
    gap:            9px;
    width:          100%;
    padding:        11px 10px;
    background:     #fafafa;
    border:         1.5px solid #f0f0f0;
    border-radius:  14px;
    cursor:         pointer;
    font-family:    inherit;
    text-align:     start;
    transition:     all 0.18s ease;
    -webkit-tap-highlight-color: transparent;
    box-sizing:     border-box;
    box-shadow:     0 1px 3px rgba(0,0,0,.04);
}

.wccs-option:hover {
    background:   color-mix(in srgb, var(--wccs-primary, #22c55e) 6%, white);
    border-color: color-mix(in srgb, var(--wccs-primary, #22c55e) 40%, white);
    box-shadow:   0 3px 10px color-mix(in srgb, var(--wccs-primary, #22c55e) 10%, transparent);
    transform:    translateY(-1px);
}

.wccs-option--active {
    background:   color-mix(in srgb, var(--wccs-primary, #22c55e) 8%, white);
    border-color: var(--wccs-primary, #22c55e);
    box-shadow:   0 3px 12px color-mix(in srgb, var(--wccs-primary, #22c55e) 15%, transparent);
}

.wccs-option--active:hover {
    background:   color-mix(in srgb, var(--wccs-primary, #22c55e) 16%, white);
    border-color: var(--wccs-primary, #22c55e);
    transform:    translateY(-1px);
}

.wccs-option[hidden] { display: none; }

.wccs-option:focus-visible {
    outline:      2px solid var(--wccs-primary, #22c55e);
    outline-offset: 2px;
    background:   color-mix(in srgb, var(--wccs-primary, #22c55e) 8%, white);
}

.wccs-option-flag {
    font-size:        1.35rem;
    line-height:      1;
    flex-shrink:      0;
    width:            36px;
    height:           36px;
    display:          flex;
    align-items:      center;
    justify-content:  center;
    border-radius:    10px;
    text-align:       center;
    overflow:         hidden;
}

.wccs-option-body {
    display:        flex;
    flex-direction: column;
    flex:           1;
    min-width:      0;
    gap:            2px;
}

.wccs-option-code {
    font-size:      var(--wccs-code-size, 0.8rem);
    font-weight:    800;
    color:          #111827;
    letter-spacing: 0.04em;
    line-height:    1.2;
    text-align:     left;
    direction:      ltr;
    unicode-bidi:   embed;
}

.wccs-option-name {
    font-size:     var(--wccs-name-size, 0.69rem);
    color:         #9ca3af;
    white-space:   nowrap;
    overflow:      hidden;
    text-overflow: ellipsis;
    line-height:   1.3;
    text-align:    start;
}

.wccs-option-symbol {
    font-size:           0.75rem;
    color:               #d1d5db;
    flex-shrink:         0;
    min-width:           18px;
    text-align:          end;
    font-weight:         600;
    direction:           ltr;
    unicode-bidi:        embed;
    margin-inline-start: auto;
    letter-spacing:      0.02em;
}

.wccs-option--active .wccs-option-symbol {
    color: color-mix(in srgb, var(--wccs-primary, #22c55e) 60%, white);
}

.wccs-option-check {
    flex-shrink:  0;
    width:        18px;
    height:       18px;
    border-radius: 50%;
    display:      none;   /* hidden on all non-active options */
}

.wccs-option--active .wccs-option-check {
    display:         flex;
    background:      var(--wccs-primary, #22c55e);
    color:           #fff;
    align-items:     center;
    justify-content: center;
}

/* RTL: row items flow right-to-left automatically with flex + dir=rtl.
   The flag appears on the right, text in middle, checkmark on left. */
[dir="rtl"] .wccs-option {
    flex-direction: row-reverse;
    text-align:     right;
}

[dir="rtl"] .wccs-option-body { text-align: right; }

/* ── No results ──────────────────────────────────────────────────────────── */

.wccs-no-results {
    padding:    24px 16px;
    text-align: center;
    color:      #9ca3af;
    font-size:  0.875rem;
    margin:     0;
}

.wccs-no-results[hidden] { display: none; }

/* ── Animations ──────────────────────────────────────────────────────────── */

@keyframes wccs-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .wccs-trigger, .wccs-modal, .wccs-chevron,
    .wccs-option, .wccs-search-wrap, .wccs-close, .wccs-search-clear {
        transition: none;
        animation:  none;
    }
    .wccs-backdrop { animation: none; }
    .wccs-modal.wccs-modal--open {
        opacity:   1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ── Windows High Contrast ───────────────────────────────────────────────── */

@media (forced-colors: active) {
    .wccs-trigger {
        border:     2px solid ButtonText;
        color:      ButtonText;
        background: ButtonFace;
    }
    .wccs-trigger:hover,
    .wccs-trigger:focus-visible {
        forced-color-adjust: none;
        background:  Highlight;
        color:       HighlightText;
        border-color: Highlight;
    }
    .wccs-modal {
        border:     2px solid ButtonText;
        background: Canvas;
        color:      CanvasText;
    }
    .wccs-option--active {
        forced-color-adjust: none;
        background:          Highlight;
        color:               HighlightText;
    }
    .wccs-option--active .wccs-option-code,
    .wccs-option--active .wccs-option-name,
    .wccs-option--active .wccs-option-symbol,
    .wccs-option--active .wccs-option-check { color: HighlightText; }
    .wccs-option-check svg {
        forced-color-adjust: none;
        color: Highlight;
    }
    .wccs-search-wrap { border: 2px solid ButtonText; background: Canvas; }
}

/* ── Mobile bottom sheet (≤ 520px) ──────────────────────────────────────── */

@media (max-width: 520px) {
    .wccs-modal {
        top:           auto;
        bottom:        0;
        left:          0;
        right:         0;
        transform:     translateY(100%);
        width:         100%;
        max-width:     100vw;
        overflow-x:    hidden;
        max-height:    82svh;
        border-radius: 20px 20px 0 0;
        box-shadow:    0 -8px 40px rgba(0,0,0,.15);
        transition:    transform 0.28s cubic-bezier(0.32,0.72,0,1), opacity 0.15s;
        opacity:       1;
    }

    .wccs-modal.wccs-modal--open { transform: translateY(0); }

    .wccs-drag-handle {
        display:       block;
        width:         36px;
        height:        4px;
        background:    #d1d5db;
        border-radius: 2px;
        margin:        10px auto 4px;
        flex-shrink:   0;
    }

    .wccs-modal-header { padding-top: 10px; }

    /* Auto-fit grid: 2 cols when each card is ≥ 150px, else 1 col automatically */
    .wccs-list         { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; padding: 4px 10px 14px; }
    .wccs-option       { padding: 10px 8px; border-radius: 12px; min-width: 0; }
    .wccs-option-flag  { width: 28px; height: 28px; border-radius: 6px; flex-shrink: 0; }
    .wccs-option-code  { font-size: 0.78rem; }
    /* Hide long currency names on mobile — code + flag identifies the currency.
       Prevents "United Arab Emirates dirham" etc. from causing overflow. */
    .wccs-option-name  { display: none; }

    @media (prefers-reduced-motion: reduce) {
        .wccs-modal, .wccs-modal.wccs-modal--open { transform: translateY(0); }
    }
}

/* ── Very small mobile (≤ 360px) — 1 column ──────────────────────────────── */

@media (max-width: 360px) {
    .wccs-list         { grid-template-columns: 1fr; }
    .wccs-option       { padding: 12px 12px; border-radius: 12px; }
    .wccs-option-flag  { width: 34px; height: 34px; font-size: 1.25rem; }
    .wccs-option-name  { font-size: 0.72rem; }
}

/* ── Flag images (flagcdn.com) ───────────────────────────────────────────── */

.wccs-flag-img {
    display:        inline-block;
    vertical-align: middle;
    border-radius:  2px;
    object-fit:     cover;
    flex-shrink:    0;
}

/* Trigger button flag */
.wccs-flag .wccs-flag-img {
    height: 1em;
    width:  auto;
}

/* Modal option flag — inside the rounded 36×36 container */
.wccs-option-flag .wccs-flag-img {
    width:         100%;
    height:        auto;
    border-radius: 4px;
    display:       block;
}

/* Globe fallback SVG */
.wccs-flag-globe svg {
    display:        block;
    color:          #9ca3af;
    vertical-align: middle;
}

/* ── BU OffCanvas "push content" body-transform fix ──────────────────────── */
/*
 * Bricks Ultimate OffCanvas in "push content" mode applies
 * transform:translate(Xpx,0) to <body> to push page content aside.
 * CSS position:fixed children of a transformed body are fixed relative to that
 * body frame, not the viewport. We add .wccs-modal-open to <html> when our
 * modal opens and use it to neutralise the body transform only while the
 * modal is visible. This freezes the push-content position momentarily
 * (which is invisible since the backdrop covers everything) then restores
 * it when the modal closes.
 */
html.wccs-modal-open body.bu-ocp-toggled {
    transform: none !important;
    transition: none !important; /* skip the un-transform animation */
}

/* Portaled backdrop must cover the full viewport */
body > .wccs-backdrop {
    position: fixed;
    inset:    0;
}
/* Modal keeps its own centered positioning — do NOT apply inset:0 here */
body > .wccs-modal {
    position: fixed; /* redundant but explicit for portaled element */
}
