/**
 * COUNTRY SELECTOR GLOBAL - DESIGN MODERNE
 * Sélecteur de pays SEO-friendly avec redirection HTTP
 */

/* ============================================
   STRUCTURE DE BASE
   ============================================ */

.country-selector {
    position: relative;
    z-index: 1000;
}

/* Bouton principal */
.country-selector-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #1f2937;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.country-selector-trigger:hover {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.country-selector-trigger:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Drapeau */
.country-selector .flag {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    font-size: 20px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
}

/* Chevron animé */
.country-selector .chevron {
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.country-selector-trigger[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

/* ============================================
   DROPDOWN
   ============================================ */

.country-selector-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 280px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.country-selector-dropdown:not([hidden]) {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Header du dropdown */
.country-selector-header {
    padding: 16px;
    border-bottom: 1px solid #f3f4f6;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================
   LISTE DES PAYS
   ============================================ */

.country-list {
    list-style: none;
    margin: 0;
    padding: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.country-list li {
    margin: 0;
}

/* Option pays */
.country-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    text-decoration: none;
    color: #1f2937;
    transition: background 0.15s ease;
    cursor: pointer;
}

.country-option:hover {
    background: #f9fafb;
}

.country-option:focus {
    outline: none;
    background: #eff6ff;
    box-shadow: inset 0 0 0 2px #3b82f6;
}

.country-option.active {
    background: #eff6ff;
    color: #3b82f6;
}

/* Info pays */
.country-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.country-option .country-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.country-domain {
    font-size: 12px;
    color: #9ca3af;
    white-space: nowrap;
}

/* Checkmark */
.checkmark {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Footer */
.country-selector-footer {
    padding: 12px 16px;
    border-top: 1px solid #f3f4f6;
    background: #f9fafb;
    border-radius: 0 0 12px 12px;
}

.country-selector-footer small {
    font-size: 12px;
    color: #6b7280;
}

/* ============================================
   SCROLLBAR PERSONNALISÉ
   ============================================ */

.country-list::-webkit-scrollbar {
    width: 8px;
}

.country-list::-webkit-scrollbar-track {
    background: #f3f4f6;
    border-radius: 4px;
}

.country-list::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.country-list::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ============================================
   ÉTAT DE CHARGEMENT
   ============================================ */

.country-option.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.country-option .spinner {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: translateY(-50%) rotate(0deg); }
    to { transform: translateY(-50%) rotate(360deg); }
}

/* ============================================
   RESPONSIVE - MOBILE
   ============================================ */

@media (max-width: 768px) {
    /* Dropdown fullscreen sur mobile */
    .country-selector-dropdown {
        position: fixed;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        min-width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 70vh;
    }
    
    /* Cacher le nom du pays sur mobile (garder juste le drapeau) */
    .country-selector-trigger .country-name {
        display: none;
    }
    
    /* Ajouter un overlay backdrop */
    .country-selector-dropdown:not([hidden])::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }
}

/* ============================================
   DARK MODE
   ============================================ */

@media (prefers-color-scheme: dark) {
    .country-selector-trigger {
        background: #1f2937;
        border-color: #374151;
        color: #f3f4f6;
    }
    
    .country-selector-dropdown {
        background: #1f2937;
        border-color: #374151;
    }
    
    .country-selector-header {
        border-bottom-color: #374151;
        color: #9ca3af;
    }
    
    .country-option {
        color: #f3f4f6;
    }
    
    .country-option:hover {
        background: #374151;
    }
    
    .country-option:focus {
        background: #1e3a8a;
        box-shadow: inset 0 0 0 2px #3b82f6;
    }
    
    .country-option.active {
        background: #1e40af;
        color: #93c5fd;
    }
    
    .country-selector-footer {
        background: #111827;
        border-top-color: #374151;
        color: #9ca3af;
    }
    
    .country-domain {
        color: #6b7280;
    }
}

/* ============================================
   ACCESSIBILITÉ
   ============================================ */

.country-selector-trigger:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.country-option:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

/* Support mode contraste élevé */
@media (prefers-contrast: high) {
    .country-selector-trigger {
        border-width: 2px;
    }
    
    .country-option.active {
        font-weight: 700;
    }
}

/* Support animations réduites */
@media (prefers-reduced-motion: reduce) {
    .country-selector-trigger,
    .country-selector-dropdown,
    .country-option,
    .chevron {
        transition: none;
    }
    
    @keyframes spin {
        from, to { transform: translateY(-50%) rotate(0deg); }
    }
}

/* ============================================
   PRINT (masquer le sélecteur)
   ============================================ */

@media print {
    .country-selector {
        display: none;
    }
}
