/* ==========================================================================
   popover-select.css — dropdown moderno para selects nativos (.js-popover-select)
   Componente: trigger tipo input + listbox flotante. El <select> real queda
   oculto dentro de .psel y sigue enviando su valor con el formulario.

   Variantes por data-popover-style en el <select>:
     - (sin dato) "solid": sobre fondos claros (inputs del checkout/dashboard)
     - "glass":            sobre fondos oscuros (moneda en el header)
   Solo se monta en >=768px; en movil el select nativo queda intacto.
   ========================================================================== */

.psel {
    position: relative;
    display: inline-flex;
}

.psel > select {
    display: none;
}

/* --------------------------------------------------------------------------
   Trigger
   -------------------------------------------------------------------------- */
.psel__trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    max-width: 220px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    text-align: left;
    background-color: #fff;
    color: #1e293b;
    border: 1px solid #d7dde3;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transition: border-color 0.15s ease, box-shadow 0.15s ease,
        background-color 0.15s ease, transform 0.1s ease;
}

.psel__trigger:not(:disabled):active {
    transform: scale(0.97);
}

.psel__trigger:hover {
    border-color: #b6c2cd;
}

.psel__trigger:focus-visible {
    outline: none;
    border-color: #06b6d4;
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.22);
}

.psel__label {
    flex: 1 1 auto;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.psel__chevron {
    flex: 0 0 auto;
    color: #64748b;
    transition: transform 0.18s ease;
}

.psel--open .psel__chevron {
    transform: rotate(180deg);
}

.psel--glass .psel__trigger {
    min-height: 38px;
    padding-top: 6px;
    padding-bottom: 6px;
    background-color: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 999px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.psel--glass .psel__trigger:hover {
    background-color: rgba(255, 255, 255, 0.22);
    border-color: #fff;
}

.psel--glass .psel__trigger:focus-visible {
    border-color: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18),
        0 0 0 2px rgba(255, 255, 255, 0.25);
}

.psel--glass .psel__trigger:not(:disabled):active {
    transform: scale(0.97);
}

.psel--glass .psel__chevron {
    color: #fff;
}

/* --------------------------------------------------------------------------
   Listbox (popover)
   -------------------------------------------------------------------------- */
.psel__listbox {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    z-index: 1060;
    min-width: 100%;
    width: max-content;
    max-width: min(280px, calc(100vw - 32px));
    margin: 0;
    padding: 7px;
    list-style: none;
    background: rgba(255, 255, 255, 0.86);
    -webkit-backdrop-filter: blur(12px) saturate(160%);
    backdrop-filter: blur(12px) saturate(160%);
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 14px;
    box-shadow:
        0 1px 2px rgba(2, 20, 40, 0.05),
        0 12px 32px -12px rgba(2, 20, 40, 0.22),
        0 28px 56px -24px rgba(2, 20, 40, 0.18);

    /* cerrado por defecto; solo visible con el wrapper abierto */
    display: none;
    transform: translateX(-50%);
    transform-origin: top center;

    /* scroll de opciones; la altura exacta la ajusta el JS al abrir
       segun el espacio real disponible (fallback por si no corrio) */
    max-height: min(320px, 60vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.psel__listbox::-webkit-scrollbar {
    width: 8px;
}

.psel__listbox::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 8px;
}

.psel__listbox::-webkit-scrollbar-track {
    background-color: transparent;
}

.psel--open .psel__listbox {
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: psel-in 0.19s cubic-bezier(0.16, 1, 0.3, 1);
}

/* posicion: flip arriba cuando no hay espacio debajo */
.psel--flip .psel__listbox {
    top: auto;
    bottom: calc(100% + 8px);
    transform-origin: bottom center;
    animation-name: psel-in-flip;
}

@keyframes psel-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-6px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

@keyframes psel-in-flip {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(6px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

/* --------------------------------------------------------------------------
   Opciones
   -------------------------------------------------------------------------- */
.psel__option {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    /* 30px por lado: zona simetrica que reserva lugar al check (sin overlap) */
    padding: 8px 30px;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    border-radius: 10px;
    cursor: pointer;
    outline: none;
    transition: background-color 0.12s ease, transform 0.1s ease;
}

.psel__option:hover,
.psel__option:focus {
    /* celeste de marca del tema (mismo que tabs/filtros: #0ea5e9) */
    background-color: rgba(14, 165, 233, 0.1);
    color: #0369a1;
}

.psel__option:focus-visible {
    box-shadow: inset 0 0 0 2px rgba(14, 165, 233, 0.35);
}

.psel__option:not(.psel__option--selected):active {
    transform: scale(0.985);
}

/* El reset global del tema pinta span/li con #353535 (bajo contraste sobre el
   vidrio): reforzamos con especificidad .psel para ganar la cascada. */
.psel .psel__option-label {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #1f2937;
}

.psel .psel__option:hover .psel__option-label,
.psel .psel__option:focus .psel__option-label {
    color: #075985;
}

.psel .psel__option--selected .psel__option-label {
    color: #0369a1;
}

/* placeholder: opcion vacia seleccionada (p.ej. "Seleccionar departamento") */
.psel .psel__trigger .psel__label--placeholder {
    color: #94a3b8;
    font-weight: 400;
}

.psel__check {
    /* fuera del flujo: no descentra el texto centrado */
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    visibility: hidden;
    color: #0ea5e9;
}

.psel__option--selected {
    color: #0284c7;
    font-weight: 600;
    background-color: rgba(14, 165, 233, 0.12);
}

.psel__option--selected:hover,
.psel__option--selected:focus {
    background-color: rgba(14, 165, 233, 0.17);
}

.psel__option--selected .psel__check {
    visibility: visible;
}

.psel__option--disabled {
    color: #94a3b8;
    cursor: not-allowed;
}

.psel__option--disabled:hover,
.psel__option--disabled:focus {
    background-color: transparent;
}

/* --------------------------------------------------------------------------
   Buscador (solo en listas largas, lo activa el JS).
   Sticky: queda fijo arriba mientras las opciones hacen scroll.
   -------------------------------------------------------------------------- */
.psel__search {
    position: sticky;
    top: -7px; /* compensa el padding del listbox para pegarse al borde */
    z-index: 1;
    margin: -7px -4px 4px;
    padding: 10px 8px 8px;
    background-color: rgba(252, 253, 255, 0.96);
    border-bottom: 1px solid rgba(226, 232, 240, 0.9);
}

.psel__search[hidden] {
    display: none;
}

.psel__search-input {
    width: 100%;
    min-height: 32px;
    padding: 6px 10px;
    font-family: inherit;
    font-size: 13px;
    color: #1f2937;
    background-color: #f8fafc;
    border: 1px solid #d7dde3;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease,
        background-color 0.15s ease;
}

.psel__search-input::placeholder {
    color: #94a3b8;
}

.psel__search-input:focus {
    background-color: #fff;
    border-color: #0ea5e9;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.14);
}

/* opciones filtradas fuera */
.psel__option[hidden] {
    display: none;
}

/* --------------------------------------------------------------------------
   Accesibilidad / RTL
   -------------------------------------------------------------------------- */
[dir='rtl'] .psel__listbox {
    left: auto;
    right: 0;
}

@media (prefers-reduced-motion: reduce) {
    .psel__listbox {
        animation: none;
    }

    .psel__chevron,
    .psel__trigger {
        transition: none;
    }
}
