/* ===================================
   LANGUAGE SELECTOR
   Complete Responsive Solution
   =================================== */

.language-selector {
    position: relative;
    z-index: 10001;
}

.language-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 6px 8px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    /* iOS fix - remover highlight azul */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    /* Botão compacto - apenas as 2 letras */
    width: fit-content;
    min-width: auto;
}

.language-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
}

.language-btn:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* iOS fix - prevenir zoom no double-tap */
.language-btn:active {
    transform: scale(0.98);
}

/* Bandeira SVG no botão */
.language-current-flag {
    display: flex;
    align-items: center;
    justify-content: center;
}

.language-current-flag .flag-icon {
    width: 20px;
    height: 15px;
    border-radius: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.language-current {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.language-arrow {
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.language-selector.active .language-arrow {
    transform: rotate(180deg);
}

.language-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    min-width: 180px;
    z-index: 10002;
    /* iOS fix */
    -webkit-tap-highlight-color: transparent;
}

.language-selector.active .language-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.language-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s ease;
    position: relative;
    user-select: none;
    /* iOS fix */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

.language-option:hover {
    background: #f5f5f5;
}

.language-option.active {
    background: #f0f0f0;
}

/* iOS fix - feedback visual no toque */
.language-option:active {
    background: #e8e8e8;
}

.lang-flag {
    font-size: 20px;
    line-height: 1;
}

.lang-name {
    flex: 1;
    color: #333;
    font-size: 14px;
    font-weight: 500;
}

.lang-check {
    color: var(--color-primary, #8B1538);
    font-size: 16px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.language-option.active .lang-check {
    opacity: 1;
}

/* ===================================
   MOBILE OPTIMIZATIONS - BOTÃO MENOR
   =================================== */

@media (max-width: 768px) {
    .language-selector {
        z-index: 10001 !important;
    }
    
    /* BOTÃO COMPACTO NO MOBILE - SÓ 2 LETRAS */
    .language-btn {
        padding: 4px 6px !important;
        min-height: 30px !important;
        gap: 3px !important;
        border-radius: 5px !important;
        width: fit-content !important;
        min-width: auto !important;
    }
    
    /* SVG menor */
    .language-btn svg {
        width: 13px !important;
        height: 13px !important;
    }
    
    /* Bandeira SVG no botão - mobile */
    .language-current-flag .flag-icon {
        width: 18px !important;
        height: 13px !important;
    }
    
    /* Texto menor */
    .language-current {
        font-size: 11px !important;
        font-weight: 700 !important;
        letter-spacing: 0.3px !important;
    }
    
    /* Arrow menor */
    .language-arrow {
        width: 9px !important;
        height: 9px !important;
    }
    
    .language-dropdown {
        right: 20px !important;
        left: auto !important;
        min-width: 160px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
        z-index: 10002 !important;
        position: fixed !important;
        top: 80px !important;
        /* iOS fix - forçar hardware acceleration */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
    
    .language-selector.active .language-dropdown {
        /* iOS fix - forçar reflow */
        transform: translateY(0) translateZ(0);
        -webkit-transform: translateY(0) translateZ(0);
        z-index: 10002 !important;
    }
    
    .language-option {
        padding: 14px 16px;
        /* Área de toque aumentada para mobile (Google guidelines) */
        min-height: 48px;
    }
    
    .lang-name {
        font-size: 15px;
    }
    
    .lang-flag {
        font-size: 22px;
    }
    
    /* Melhorar feedback visual no mobile */
    .language-option:active {
        background: #e8e8e8 !important;
        /* iOS fix - prevenir double-tap zoom */
        touch-action: manipulation;
    }
    
    /* Garantir que dropdown não saia da tela */
    .language-dropdown {
        max-width: calc(100vw - 32px);
    }
}

/* ===================================
   SMALL MOBILE (< 480px)
   =================================== */

@media (max-width: 480px) {
    .language-btn {
        padding: 3px 5px !important;
        min-height: 26px !important;
        gap: 2px !important;
    }
    
    .language-btn svg {
        width: 11px !important;
        height: 11px !important;
    }
    
    /* Bandeira SVG no botão - small mobile */
    .language-current-flag .flag-icon {
        width: 16px !important;
        height: 12px !important;
    }
    
    .language-current {
        font-size: 10px !important;
        letter-spacing: 0.2px !important;
    }
    
    .language-arrow {
        width: 7px !important;
        height: 7px !important;
    }
    
    .language-dropdown {
        min-width: 140px;
    }
}

/* ===================================
   IOS SPECIFIC FIXES
   =================================== */

/* Prevenir partes brancas no iOS */
@supports (-webkit-touch-callout: none) {
    /* Safari iOS */
    .language-dropdown {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-perspective: 1000;
        perspective: 1000;
    }
    
    .language-option {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    /* Forçar repaint no iOS */
    .language-selector.active .language-dropdown {
        will-change: transform, opacity;
    }
}

/* ===================================
   ACESSIBILIDADE
   =================================== */

/* Melhorar contraste para modo escuro (se aplicável) */
@media (prefers-color-scheme: dark) {
    .language-dropdown {
        background: #2a2a2a;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }
    
    .lang-name {
        color: #e0e0e0;
    }
    
    .language-option:hover {
        background: #3a3a3a;
    }
    
    .language-option.active {
        background: #404040;
    }
}

/* Animação suave para transição de idioma */
[data-i18n] {
    transition: opacity 0.2s ease;
}

.language-changing [data-i18n] {
    opacity: 0.6;
}

/* ===================================
   PREFERS REDUCED MOTION
   =================================== */

@media (prefers-reduced-motion: reduce) {
    .language-btn,
    .language-dropdown,
    .language-option,
    .language-arrow,
    .lang-check,
    [data-i18n] {
        transition: none !important;
        animation: none !important;
    }
}

/* ===================================
   HIGH CONTRAST MODE
   =================================== */

@media (prefers-contrast: high) {
    .language-btn {
        border-width: 2px;
    }
    
    .language-dropdown {
        border: 2px solid #000;
    }
    
    .language-option.active {
        outline: 2px solid #000;
        outline-offset: -2px;
    }
}
