/**
 * Divi WPML Language Switcher - Frontend Styles
 *
 * @package Divi_WPML_Language_Switcher
 */

/* ==========================================================================
   Reset y base
   ========================================================================== */

.dwls-language-switcher {
    position: relative;
    display: inline-block;
    font-family: inherit;
    line-height: 1.5;
}

.dwls-language-switcher *,
.dwls-language-switcher *::before,
.dwls-language-switcher *::after {
    box-sizing: border-box;
}

/* ==========================================================================
   Elementos de idioma
   ========================================================================== */

.dwls-lang-item {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
    transition: color 0.2s ease, opacity 0.2s ease, background-color 0.2s ease;
}

.dwls-lang-item:hover {
    text-decoration: none;
    opacity: 0.85;
}

.dwls-lang-item:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.dwls-lang-current {
    font-weight: 600;
}

.dwls-lang-missing {
    opacity: 0.5;
}

/* ==========================================================================
   Banderas
   ========================================================================== */

.dwls-flag {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
    object-fit: cover;
}

.dwls-flag--default {
    border-radius: 0;
}

.dwls-flag--rounded {
    border-radius: 3px;
}

.dwls-flag--circle {
    border-radius: 50%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
}

/* ==========================================================================
   Nombre del idioma
   ========================================================================== */

.dwls-lang-name {
    white-space: nowrap;
}

/* ==========================================================================
   Separador
   ========================================================================== */

.dwls-separator {
    display: inline-block;
    margin: 0 0.5em;
    opacity: 0.5;
}

/* ==========================================================================
   Lista horizontal
   ========================================================================== */

.dwls-list--horizontal {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
}

.dwls-list--horizontal .dwls-lang-item:last-child {
    margin-right: 0;
}

.dwls-list--horizontal .dwls-separator:last-child {
    display: none;
}

/* ==========================================================================
   Lista vertical
   ========================================================================== */

.dwls-list--vertical {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.dwls-list--vertical .dwls-lang-item {
    display: flex;
    width: 100%;
    padding: 0.5em 0;
}

.dwls-list--vertical .dwls-lang-item:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   Dropdown
   ========================================================================== */

.dwls-dropdown {
    position: relative;
    display: inline-block;
}

/* Toggle button */
.dwls-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    padding: 0.5em 1em;
    background: transparent;
    border: 1px solid currentColor;
    border-radius: 4px;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.dwls-dropdown-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.dwls-dropdown-toggle:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Estilos del toggle */
.dwls-dropdown--style-minimal .dwls-dropdown-toggle {
    border: none;
    background: transparent;
    padding: 0.5em;
}

.dwls-dropdown--style-minimal .dwls-dropdown-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.dwls-dropdown--style-filled .dwls-dropdown-toggle {
    border: none;
}

.dwls-dropdown--style-filled .dwls-dropdown-toggle:hover {
    opacity: 0.9;
    background-color: inherit;
}

/* Flecha del dropdown */
.dwls-dropdown-arrow {
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 0.25em;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid currentColor;
    transition: transform 0.2s ease;
}

.dwls-dropdown.is-open .dwls-dropdown-arrow {
    transform: rotate(180deg);
}

/* --------------------------------------------------------------------------
   Menú desplegable

   CERRADO por defecto: opacity 0, visibility hidden, pointer-events none.
   Se abre SOLO con .is-open (JS) o :hover (modo hover CSS).
   NO usa display:none para permitir transiciones suaves.
   -------------------------------------------------------------------------- */

.dwls-dropdown-menu {
    position: absolute;
    z-index: 1000;
    min-width: 150px;
    margin: 0;
    padding: 0;
    list-style: none !important;
    list-style-type: none !important;
    background-color: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    overflow: hidden;

    /* CERRADO */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

/* ABIERTO via JavaScript (.is-open en el contenedor) */
.dwls-dropdown.is-open > .dwls-dropdown-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

/* --------------------------------------------------------------------------
   Modo hover (CSS puro, sin JS)
   -------------------------------------------------------------------------- */

.dwls-dropdown--hover:hover > .dwls-dropdown-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.dwls-dropdown--hover:hover > .dwls-dropdown-toggle > .dwls-dropdown-arrow {
    transform: rotate(180deg);
}

/* Posiciones del menú */
.dwls-dropdown--bottom-left .dwls-dropdown-menu {
    top: 100%;
    left: 0;
    margin-top: 0;
}

.dwls-dropdown--bottom-right .dwls-dropdown-menu {
    top: 100%;
    right: 0;
    margin-top: 0;
}

.dwls-dropdown--top-left .dwls-dropdown-menu {
    bottom: 100%;
    left: 0;
    margin-bottom: 0;
}

.dwls-dropdown--top-right .dwls-dropdown-menu {
    bottom: 100%;
    right: 0;
    margin-bottom: 0;
}

/* Ancho del menú */
.dwls-dropdown--width-auto .dwls-dropdown-menu {
    min-width: max-content;
}

.dwls-dropdown--width-full .dwls-dropdown-menu {
    width: 100%;
    min-width: 100%;
}

/* Items del dropdown */
.dwls-dropdown-item {
    margin: 0;
    padding: 0;
    list-style: none !important;
    list-style-type: none !important;
}

.dwls-dropdown-item::before,
.dwls-dropdown-item::marker {
    display: none !important;
    content: none !important;
}

.dwls-dropdown-item .dwls-lang-item {
    display: flex;
    width: 100%;
    padding: 0.5em 1em;
    margin: 0;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.dwls-dropdown-item .dwls-lang-item:hover {
    opacity: 1;
}

.dwls-dropdown-item .dwls-lang-item.dwls-lang-current {
    background-color: rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   Aviso para administradores
   ========================================================================== */

.dwls-notice {
    padding: 1em;
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    color: #856404;
    font-size: 0.875em;
}

/* ==========================================================================
   Estados de accesibilidad
   ========================================================================== */

.dwls-language-switcher [aria-current="true"] {
    position: relative;
}

.dwls-language-switcher a:focus-visible,
.dwls-language-switcher button:focus-visible {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Reducir movimiento para usuarios que lo prefieran */
@media (prefers-reduced-motion: reduce) {
    .dwls-dropdown-menu,
    .dwls-dropdown-arrow,
    .dwls-lang-item {
        transition: none;
    }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media screen and (max-width: 768px) {
    .dwls-list--horizontal {
        flex-wrap: wrap;
        gap: 0.5em;
    }

    .dwls-dropdown-toggle {
        padding: 0.75em 1em;
    }

    .dwls-dropdown-menu {
        max-height: 60vh;
        overflow-y: auto;
    }
}

/* ==========================================================================
   Modo oscuro (si el tema lo soporta)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .et-db #et-main-area .dwls-dropdown-menu,
    body.et-dark-mode .dwls-dropdown-menu {
        background-color: #2d2d2d;
        border-color: rgba(255, 255, 255, 0.1);
    }

    .et-db #et-main-area .dwls-dropdown-item .dwls-lang-item:hover,
    body.et-dark-mode .dwls-dropdown-item .dwls-lang-item:hover {
        background-color: rgba(255, 255, 255, 0.1);
    }
}
