/* =====================================================================
   JR Visitor Preferences — language / currency / region / units panel
   v2.0 · 2026-06-28 — flag-icons integration + design polish
   ===================================================================== */

.jr-prefs-root {
    position: relative;
    z-index: 60;
    font-family: 'Poppins', system-ui, -apple-system, sans-serif;
}

/* ── Trigger button (header) ────────────────────────────────────────── */
.jr-prefs-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: #1f2937;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.jr-prefs-trigger:hover,
.jr-prefs-trigger:focus-visible {
    background: #f8fafc;
    border-color: #e2e8f0;
    outline: none;
}

.jr-prefs-trigger > .fa-globe {
    color: #f8991b;
    font-size: 14px;
}

.jr-prefs-trigger-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13.5px;
    color: #0f172a;
}

.jr-prefs-trigger-code {
    font-weight: 700;
    letter-spacing: 0.03em;
}

.jr-prefs-sep {
    opacity: 0.4;
    font-weight: 400;
}

.jr-prefs-chevron {
    font-size: 10px;
    color: #94a3b8;
    transition: transform 0.18s ease;
}

.jr-prefs-chevron.is-open {
    transform: rotate(180deg);
    color: #f8991b;
}

/* ── Flag rendering (works for emoji, image, and flag-icons sprites) ── */
.jr-prefs-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* flag-icons library sprites (https://flagicons.lipis.dev) */
.jr-prefs-flag .fi {
    display: inline-block;
    width: 22px;
    height: 16px;
    border-radius: 3px;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
    background-size: cover;
    background-position: 50%;
    background-repeat: no-repeat;
}

.jr-prefs-flag img {
    display: block;
    width: 22px;
    height: 16px;
    border-radius: 3px;
    object-fit: cover;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.jr-prefs-flag-fallback {
    font-size: 18px;
    line-height: 1;
}

/* Trigger flag should be slightly smaller */
.jr-prefs-trigger .jr-prefs-flag .fi,
.jr-prefs-trigger .jr-prefs-flag img {
    width: 20px;
    height: 15px;
}

/* ── Panel ─────────────────────────────────────────────────────────── */
.jr-prefs-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 70;
    animation: jrPrefsFadeIn 0.18s ease;
}

.jr-prefs-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    width: min(380px, calc(100vw - 24px));
    max-height: min(74vh, 560px);
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: 16px;
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.05),
        0 12px 32px rgba(15, 23, 42, 0.12),
        0 28px 60px -16px rgba(248, 153, 27, 0.12);
    border: 1px solid rgba(15, 23, 42, 0.06);
    z-index: 80;
    overflow: hidden;
    animation: jrPrefsSlideIn 0.18s ease;
}

@keyframes jrPrefsFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes jrPrefsSlideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.jr-prefs-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid #f1f5f9;
    background: linear-gradient(180deg, #ffffff 0%, #fffaf3 100%);
}

.jr-prefs-head strong {
    font-size: 15px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.01em;
}

.jr-prefs-close {
    border: 0;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.jr-prefs-close:hover {
    background: #f1f5f9;
    color: #0f172a;
}

/* ── Tabs ─────────────────────────────────────────────────────────── */
.jr-prefs-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    border-bottom: 1px solid #f1f5f9;
    background: #f8fafc;
}

.jr-prefs-tab {
    border: 0;
    background: transparent;
    padding: 12px 8px 11px;
    font-size: 11.5px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: color 0.15s, background 0.15s;
    position: relative;
}

.jr-prefs-tab-icon {
    font-size: 14px;
    color: #94a3b8;
    transition: color 0.15s;
}

.jr-prefs-tab:hover {
    color: #0f172a;
    background: #ffffff;
}

.jr-prefs-tab:hover .jr-prefs-tab-icon {
    color: #f8991b;
}

.jr-prefs-tab.is-active {
    background: #ffffff;
    color: #f8991b;
}

.jr-prefs-tab.is-active::after {
    content: '';
    position: absolute;
    left: 16%;
    right: 16%;
    bottom: 0;
    height: 2.5px;
    background: #f8991b;
    border-radius: 2px 2px 0 0;
}

.jr-prefs-tab.is-active .jr-prefs-tab-icon {
    color: #f8991b;
}

/* ── Body ─────────────────────────────────────────────────────────── */
.jr-prefs-body {
    padding: 12px;
    overflow: auto;
    flex: 1;
    background: #ffffff;
}

.jr-prefs-hint {
    margin: 0 4px 12px;
    font-size: 12.5px;
    color: #64748b;
    line-height: 1.45;
}

.jr-prefs-search {
    width: 100%;
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    color: #0f172a;
    background: #f8fafc;
    transition: border-color 0.15s, background 0.15s;
}

.jr-prefs-search::placeholder {
    color: #94a3b8;
}

.jr-prefs-search:focus {
    outline: none;
    border-color: #f8991b;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(248, 153, 27, 0.12);
}

.jr-prefs-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.jr-prefs-list--scroll {
    max-height: 360px;
    overflow-y: auto;
    padding-right: 4px;
}

.jr-prefs-list--scroll::-webkit-scrollbar {
    width: 6px;
}

.jr-prefs-list--scroll::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 3px;
}

.jr-prefs-list--scroll::-webkit-scrollbar-thumb:hover {
    background: #cbd5e1;
}

.jr-prefs-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.12s, color 0.12s;
}

.jr-prefs-item:hover {
    background: #f8fafc;
}

.jr-prefs-item:focus-visible {
    outline: none;
    background: #f1f5f9;
    box-shadow: inset 0 0 0 2px rgba(248, 153, 27, 0.25);
}

.jr-prefs-item.is-active {
    background: linear-gradient(90deg, #fff7ed 0%, #ffffff 100%);
    box-shadow: inset 0 0 0 1px rgba(248, 153, 27, 0.25);
}

.jr-prefs-item-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.jr-prefs-item-text strong {
    font-size: 13.5px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.jr-prefs-item-text small {
    font-size: 11.5px;
    color: #64748b;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.jr-prefs-item.is-active .jr-prefs-item-text strong {
    color: #c2410c;
}

.jr-prefs-check {
    color: #f8991b;
    font-size: 13px;
    flex-shrink: 0;
}

/* Currency symbol + unit icon avatars */
.jr-prefs-currency-symbol,
.jr-prefs-unit-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    font-weight: 700;
    font-size: 13px;
    color: #334155;
    flex-shrink: 0;
}

.jr-prefs-item.is-active .jr-prefs-currency-symbol,
.jr-prefs-item.is-active .jr-prefs-unit-icon {
    background: #ffedd5;
    border-color: rgba(248, 153, 27, 0.35);
    color: #c2410c;
}

.jr-prefs-empty {
    padding: 24px 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
}

/* ── RTL support ──────────────────────────────────────────────────── */
[dir="rtl"] .jr-prefs-panel {
    right: auto;
    left: 0;
}

[dir="rtl"] .jr-prefs-item.is-active {
    background: linear-gradient(270deg, #fff7ed 0%, #ffffff 100%);
}

/* ── Mobile ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .jr-prefs-panel {
        position: fixed;
        right: 12px;
        left: 12px;
        top: 72px;
        width: auto;
        max-height: 80vh;
    }

    .jr-prefs-tab span {
        font-size: 10.5px;
    }
}
