/* =========================================================================
   Popup "Choisir une devise / un moyen de paiement" — remplace le menu
   déroulant inline sur /trade et / (page d'accueil). Un seul popup partagé,
   repeuplé dynamiquement selon le champ cliqué (Vous payez / Vous recevez).
   Utilise les variables CSS du thème actif (--bg-card, --accent, ...),
   déjà définies globalement (admin-design.css) ou sur .trade-widget-scope.
   ========================================================================= */

html.cp-lock, body.cp-lock { overflow: hidden !important; height: 100%; }

@keyframes cpFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes cpPopIn {
    from { opacity: 0; transform: translateY(24px) scale(.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes cpGlowMove {
    0%, 100% { transform: translate(-10%, -10%) scale(1); }
    50%      { transform: translate(10%, 8%) scale(1.15); }
}

.cp-overlay {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity .25s ease, visibility 0s linear .25s;
}
.cp-overlay.is-active {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    transition: opacity .25s ease;
}
.cp-backdrop {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 30% 20%, rgba(59,130,246,.16), transparent 55%),
                rgba(15, 23, 42, .58);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
html[data-theme="dark"] .cp-backdrop {
    background: radial-gradient(circle at 30% 20%, rgba(79,140,255,.12), transparent 55%),
                rgba(4, 8, 18, .72);
}

.cp-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    min-height: min(58vh, 460px);
    max-height: min(82vh, 640px);
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: 0 30px 70px -20px rgba(15,23,42,.45), 0 10px 30px -12px rgba(15,23,42,.25);
    overflow: hidden;
    opacity: 0;
    transform: translateY(24px) scale(.96);
}
.cp-overlay.is-active .cp-panel {
    animation: cpPopIn .4s cubic-bezier(.22,1,.36,1) forwards;
}
.cp-panel-glow {
    position: absolute;
    top: -50px; left: -50px;
    width: 180px; height: 180px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    filter: blur(46px);
    opacity: .32;
    pointer-events: none;
    animation: cpGlowMove 9s ease-in-out infinite;
}

.cp-header {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 20px 12px;
    flex-shrink: 0;
}
.cp-title { margin: 0; font-size: 1.05rem; font-weight: 700; color: var(--text-main); }
.cp-close {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    padding: 0;
    margin: 0;
    line-height: 0;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-body);
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: all .15s ease;
    /* Retire le style natif du bouton (iOS/Android ajoutent un padding
       interne par défaut, souvent asymétrique, qui décale visuellement
       l'icône par rapport au centre du cercle). */
    appearance: none;
    -webkit-appearance: none;
    /* Isole le bouton dans sa propre couche de rendu : sur certains
       mobiles (iOS/Android), le backdrop-filter du .cp-backdrop peut
       "baver" sur les éléments voisins et transformer le tracé fin du
       SVG en simple point flou. */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    isolation: isolate;
}
.cp-close:hover { color: #fff; background: #ef4444; border-color: #ef4444; }
.cp-close svg {
    display: block;
    width: 18px; height: 18px;
    margin: 0;
    flex-shrink: 0;
    shape-rendering: geometricPrecision;
}

.cp-search {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 20px 14px;
    padding: 10px 14px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    flex-shrink: 0;
    transition: border-color .15s ease;
}
.cp-search:focus-within { border-color: var(--accent); }
.cp-search svg { flex-shrink: 0; color: var(--text-muted); }
.cp-search input {
    flex: 1; min-width: 0;
    border: none; background: transparent; outline: none;
    /* 16px minimum : en dessous, iOS/Android zooment automatiquement la
       page au focus de l'input, ce qui décale et "casse" la mise en page
       du popup. 16px désactive ce zoom automatique. */
    font-size: 16px; color: var(--text-main); font-family: inherit;
}
.cp-search input::placeholder { color: var(--text-muted); }

/* Filtre pays : un seul déclencheur compact qui ouvre une petite liste
   déroulante (au lieu d'une rangée de puces qui grossit indéfiniment à
   chaque pays ajouté). Reste léger visuellement quelle que soit la
   quantité de pays disponibles, grâce au scroll interne du menu. */
.cp-country-filter {
    position: relative;
    z-index: 3;
    margin: 0 20px 14px;
    flex-shrink: 0;
}
.cp-country-filter-tag {
    display: block;
    margin: 0 0 6px 2px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.cp-country-trigger {
    display: flex; align-items: center; gap: 9px;
    width: 100%;
    padding: 9px 13px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-body);
    color: var(--text-main);
    font-size: .82rem; font-weight: 600; font-family: inherit;
    cursor: pointer;
    transition: border-color .15s ease;
}
.cp-country-trigger:hover { border-color: var(--accent); }
.cp-country-filter.is-open .cp-country-trigger { border-color: var(--accent); }
.cp-country-trigger-icon { display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--accent); }
.cp-country-trigger-icon img { width: 16px; height: 16px; border-radius: 3px; object-fit: cover; display: block; }
.cp-country-trigger-label { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-country-trigger-chevron { flex-shrink: 0; color: var(--text-muted); transition: transform .15s ease; }
.cp-country-filter.is-open .cp-country-trigger-chevron { transform: rotate(180deg); }

.cp-country-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    max-height: 220px;
    overflow-y: auto;
    display: none;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 16px 40px -14px rgba(15,23,42,.4);
}
.cp-country-filter.is-open .cp-country-dropdown { display: flex; }
.cp-country-option {
    display: flex; align-items: center; gap: 9px;
    width: 100%;
    padding: 8px 10px;
    border: none; border-radius: 9px;
    background: transparent;
    color: var(--text-main);
    font-size: .83rem; font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color .15s ease;
}
.cp-country-option img { width: 16px; height: 16px; border-radius: 3px; object-fit: cover; flex-shrink: 0; }
.cp-country-option:hover { background: var(--bg-body); }
.cp-country-option.active { background: rgba(59,130,246,.12); color: var(--accent); font-weight: 700; }

.cp-list {
    position: relative;
    z-index: 1;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 2px 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cp-item {
    display: flex; align-items: center; gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: none; border-radius: 12px;
    background: transparent;
    color: var(--text-main);
    font-size: .88rem; font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color .15s ease;
}
.cp-item:hover { background: var(--bg-body); }
.cp-item.active { background: rgba(59,130,246,.12); color: var(--accent); font-weight: 700; }
.cp-item img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--bg-body); flex-shrink: 0; }
.cp-item-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-item.active::after {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}

.cp-empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 36px 20px; text-align: center; color: var(--text-muted); font-size: .85rem; }

@media (max-width: 480px) {
    .cp-overlay { padding: 0; align-items: flex-end; }
    .cp-panel { max-width: none; min-height: min(58vh, 460px); max-height: 86vh; border-radius: 20px 20px 0 0; }
    .cp-overlay.is-active .cp-panel { animation-name: cpPopIn; }
}