/**
 * InDevX Currency Switcher — Styles v2.0
 * ════════════════════════════════════════════════════════════════════════════
 * Dark Mode | RTL Primary | LTR Compatible | Responsive | Accessible
 *
 * Changes from v1.0:
 * ─────────────────────────────────────────────────────────────────────────
 * • Scoped entirely under #indevx-currency-switcher to avoid bleeding into
 *   Elementor or theme styles.
 * • Added prefers-reduced-motion support (removes animation for those users).
 * • Dropdown animation re-triggers correctly via animation: none reset trick.
 * • Improved focus-visible for keyboard users.
 * • Added cs-open animation guard to re-play on every open.
 * ════════════════════════════════════════════════════════════════════════════
 */

/* ── Reset scope ─────────────────────────────────────────────────────────── */
#indevx-currency-switcher,
#indevx-currency-switcher *,
#indevx-currency-switcher *::before,
#indevx-currency-switcher *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Host container ──────────────────────────────────────────────────────── */
#indevx-currency-switcher {
    display: inline-block;
    position: relative;
    font-family: 'Segoe UI', 'Cairo', Tahoma, Arial, sans-serif;
    direction: rtl;
    z-index: 9999;
    /* Isolate stacking context to avoid z-index wars with Elementor */
    isolation: isolate;
}

/* ── Trigger button ──────────────────────────────────────────────────────── */
.indevx-cs-trigger {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    background: #1a1a2e;
    border: 1px solid #2e2e4a;
    border-radius: 8px;
    padding: 8px 14px;
    color: #e0e0f0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.3px;
    white-space: nowrap;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    min-width: 110px;
    /* Prevent Elementor button resets from leaking in */
    line-height: normal;
    text-align: right;
}

.indevx-cs-trigger:hover,
.indevx-cs-trigger[aria-expanded="true"] {
    background: #23234a;
    border-color: #4a4a8a;
    box-shadow: 0 0 0 3px rgba(100, 100, 220, 0.15);
}

.indevx-cs-trigger .cs-flag {
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}

.indevx-cs-trigger .cs-code {
    flex: 1;
    text-align: center;
}

.indevx-cs-trigger .cs-arrow {
    font-size: 10px;
    opacity: 0.6;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.indevx-cs-trigger[aria-expanded="true"] .cs-arrow {
    transform: rotate(180deg);
}

/* ── Dropdown panel ──────────────────────────────────────────────────────── */
.indevx-cs-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    background: #1a1a2e;
    border: 1px solid #2e2e4a;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    z-index: 10000;
}

/*
 * Animation technique:
 * Setting animation: none when closed, then restoring on .cs-open
 * ensures the drop-in plays every time the dropdown opens —
 * not just the first time.
 */
.indevx-cs-dropdown.cs-open {
    display: block;
    animation: csDropIn 0.18s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes csDropIn {
    from { opacity: 0; transform: translateY(-6px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* Respect system preference for reduced motion */
@media (prefers-reduced-motion: reduce) {
    .indevx-cs-dropdown.cs-open {
        animation: none;
    }
    .indevx-cs-trigger .cs-arrow,
    .indevx-cs-trigger {
        transition: none;
    }
}

/* ── Each currency option ────────────────────────────────────────────────── */
.indevx-cs-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    cursor: pointer;
    color: #c8c8e8;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.12s ease, color 0.12s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: right;
    direction: rtl;
    /* Prevent theme styles from overriding button appearance */
    -webkit-appearance: none;
    appearance: none;
    line-height: normal;
}

.indevx-cs-option:hover {
    background: #25254a;
    color: #ffffff;
}

.indevx-cs-option.cs-active {
    background: #2e2e6a;
    color: #a0a0ff;
    font-weight: 700;
}

.indevx-cs-option .cs-opt-flag {
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}

.indevx-cs-option .cs-opt-label {
    flex: 1;
    white-space: nowrap;
}

.indevx-cs-option .cs-opt-symbol {
    opacity: 0.5;
    font-size: 12px;
    flex-shrink: 0;
    margin-right: auto;  /* push to far end in RTL */
}

/* ── Divider between options ─────────────────────────────────────────────── */
.indevx-cs-option + .indevx-cs-option {
    border-top: 1px solid #232340;
}

/* ── LTR override (non-RTL page contexts) ───────────────────────────────── */
[dir="ltr"] #indevx-currency-switcher,
#indevx-currency-switcher.cs-ltr {
    direction: ltr;
}

[dir="ltr"] .indevx-cs-dropdown,
.cs-ltr .indevx-cs-dropdown {
    right: auto;
    left: 0;
}

[dir="ltr"] .indevx-cs-option,
.cs-ltr .indevx-cs-option {
    text-align: left;
    direction: ltr;
}

[dir="ltr"] .indevx-cs-option .cs-opt-symbol,
.cs-ltr .indevx-cs-option .cs-opt-symbol {
    margin-right: 0;
    margin-left: auto;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .indevx-cs-trigger {
        padding: 7px 10px;
        font-size: 13px;
        min-width: 90px;
    }

    .indevx-cs-dropdown {
        min-width: 155px;
    }

    .indevx-cs-option {
        font-size: 13px;
        padding: 10px 12px;
    }
}

/* ── Focus accessibility ─────────────────────────────────────────────────── */
/*
 * :focus-visible shows the ring only for keyboard navigation,
 * not on mouse clicks — cleaner UX without sacrificing accessibility.
 */
.indevx-cs-trigger:focus-visible {
    outline: 2px solid #7070cc;
    outline-offset: 2px;
}

.indevx-cs-option:focus-visible {
    outline: 2px solid #7070cc;
    outline-offset: -2px;
    background: #25254a;
    color: #ffffff;
}

/* ── High-contrast mode support ──────────────────────────────────────────── */
@media (forced-colors: active) {
    .indevx-cs-trigger,
    .indevx-cs-dropdown {
        border: 2px solid ButtonText;
    }
    .indevx-cs-option.cs-active {
        forced-color-adjust: none;
        background: Highlight;
        color: HighlightText;
    }
}
