/**
 * Selector tipo «hoja inferior» (assets/js/hoja-selector.js).
 *
 * La hoja es un <dialog> que se cuelga del <body>, fuera de .pp-modal / .pp-locales, así que los colores van
 * como valores propios (los mismos de marca que el resto del sitio) y no como variables --ppm-*.
 * Siempre clara: no sigue el modo oscuro del teléfono, para verse igual de marca en todos los aparatos.
 */

/* ── El botón que reemplaza al select (sólo en pantallas táctiles o angostas) ───────────────────── */

.pp-hoja__boton { display: none; }

@media (pointer: coarse), (max-width: 768px) {
    .pp-hoja__boton {
        -webkit-appearance: none;
        appearance: none;
        align-items: center;
        background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%2306038d' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") right .55rem center / 18px no-repeat;
        border: 1.5px solid #e3e5e8;
        border-radius: .5rem;
        box-shadow: none;
        color: #777a80;
        cursor: pointer;
        display: flex;
        font: inherit;
        font-size: .85rem;
        font-weight: 400;
        min-height: 44px;
        padding: .55rem 2rem .55rem .7rem;
        text-align: left;
        text-transform: none;
        width: 100%;
    }
    .pp-hoja__boton.es-valor { color: #06038d; }
    .pp-hoja__boton:focus-visible { border-color: #3453d3; outline: 2px solid rgba(6, 3, 141, .35); outline-offset: 2px; }
    .pp-hoja__rotulo { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    /* El select de siempre queda en la página, escondido: el código que lo lee no se entera. */
    select.pp-hoja__nativo {
        border: 0;
        clip: rect(0 0 0 0);
        height: 1px;
        margin: -1px;
        opacity: 0;
        overflow: hidden;
        padding: 0;
        pointer-events: none;
        position: absolute;
        width: 1px;
    }
}

/* ── La hoja ────────────────────────────────────────────────────────────────────────────────────── */

html.pp-hoja-abierta { overflow: hidden; }

dialog.pp-hoja {
    background: #fff;
    border: 0;
    border-radius: 16px 16px 0 0;
    bottom: 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 40, .25);
    color: #06038d;
    display: flex;
    flex-direction: column;
    font-family: 'AvenirNextLTPro', -apple-system, BlinkMacSystemFont, sans-serif;
    height: auto;
    left: 0;
    margin: auto 0 0;
    max-height: 82vh;
    max-height: 82dvh;
    max-width: 100%;
    padding: 0;
    position: fixed;
    right: 0;
    top: auto;
    width: 100%;
}

dialog.pp-hoja:not([open]) { display: none; }

dialog.pp-hoja::backdrop { background: rgba(5, 5, 40, .5); }

@media (prefers-reduced-motion: no-preference) {
    dialog.pp-hoja[open] { animation: pp-hoja-sube .22s ease-out; }
    dialog.pp-hoja[open]::backdrop { animation: pp-hoja-fondo .22s ease-out; }
    @keyframes pp-hoja-sube { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
    @keyframes pp-hoja-fondo { from { opacity: 0; } to { opacity: 1; } }
}

/* En una pantalla ancha (tableta apaisada) la hoja no se estira de borde a borde. */
@media (min-width: 600px) {
    dialog.pp-hoja { border-radius: 16px; bottom: 1.5rem; left: 50%; max-width: 440px; right: auto; transform: translateX(-50%); }
    @media (prefers-reduced-motion: no-preference) {
        dialog.pp-hoja[open] { animation: none; }
    }
}

.pp-hoja__cabecera {
    align-items: center;
    border-bottom: 1px solid #e3e5e8;
    display: flex;
    flex: none;
    gap: .5rem;
    justify-content: space-between;
    padding: .9rem 1rem .8rem 1.25rem;
}

dialog.pp-hoja .pp-hoja__titulo {
    color: #06038d;
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: .04em;
    line-height: 1.2;
    margin: 0;
    text-transform: uppercase;
}

dialog.pp-hoja .pp-hoja__cerrar {
    align-items: center;
    background: #eef1ff;
    border: 0;
    border-radius: 50%;
    box-shadow: none;
    color: #06038d;
    cursor: pointer;
    display: grid;
    flex: none;
    height: 36px;
    padding: 0;
    place-items: center;
    width: 36px;
}
dialog.pp-hoja .pp-hoja__cerrar:focus-visible { outline: 2px solid #06038d; outline-offset: 2px; }

.pp-hoja__buscar { border-bottom: 1px solid #e3e5e8; flex: none; padding: .6rem 1rem; }

dialog.pp-hoja .pp-hoja__buscar input {
    -webkit-appearance: none;
    appearance: none;
    background: #fff;
    border: 1.5px solid #e3e5e8;
    border-radius: .5rem;
    box-shadow: none;
    box-sizing: border-box;
    color: #06038d;
    font: inherit;
    font-size: 16px; /* 16 px: por debajo, iPhone hace zoom al enfocar el campo */
    min-height: 44px;
    padding: .5rem .75rem;
    width: 100%;
}
dialog.pp-hoja .pp-hoja__buscar input:focus { border-color: #3453d3; outline: none; }

.pp-hoja__lista {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    -webkit-overflow-scrolling: touch;
}

dialog.pp-hoja .pp-hoja__op {
    -webkit-appearance: none;
    appearance: none;
    align-items: center;
    background: #fff;
    border: 0;
    border-bottom: 1px solid #f0f1f3;
    border-radius: 0;
    box-shadow: none;
    color: #06038d;
    cursor: pointer;
    display: flex;
    font: inherit;
    font-size: .95rem;
    font-weight: 400;
    gap: .75rem;
    justify-content: space-between;
    min-height: 52px;
    padding: .6rem 1.25rem;
    text-align: left;
    text-transform: none;
    width: 100%;
}
dialog.pp-hoja .pp-hoja__op[hidden] { display: none; }
dialog.pp-hoja .pp-hoja__op:active { background: #eef1ff; color: #06038d; }
dialog.pp-hoja .pp-hoja__op:focus-visible { background: #eef1ff; outline: 2px solid #06038d; outline-offset: -2px; }

dialog.pp-hoja .pp-hoja__op.es-elegida { background: #eef1ff; font-weight: 700; }

.pp-hoja__check { color: #007f35; display: none; flex: none; }
.pp-hoja__op.es-elegida .pp-hoja__check { display: block; }

.pp-hoja__vacio { color: #777a80; font-size: .9rem; margin: 0; padding: 1.25rem; text-align: center; }
.pp-hoja__vacio[hidden] { display: none; }

@media (hover: hover) and (pointer: fine) {
    dialog.pp-hoja .pp-hoja__op:hover { background: #eef1ff; }
}
