/* ==========================================================================
   Compra rápida de producto (el carrito de las tarjetas de la home y los listados).
   Archivo NUEVO con dos partes:

     1) #modal-preview-producto  -> la ventana, en la página que la abre (_Layout y _LayoutIndex).
     2) body.qv-page             -> el contenido del iframe (Views/Url/_UrlPreview.cshtml): la hoja de compra.

   La misma hoja en todos los tamaños: opciones como tarjetas, cantidad con escalas de precio, oferta por unidades, diseños
   iguales / diferentes y, fijos abajo, cantidad, importe y botón.
     - Móvil (hasta 767px): pantalla completa sobre fondo oscuro, foto arriba y panel inferior con esquinas redondeadas.
     - Tablet y escritorio (desde 768px): ventana centrada, foto a la izquierda y panel a la derecha.
   Estilo de la tienda: DM Sans, rojo de marca, tinta #222326, líneas #e9e7e5.
   ========================================================================== */

/* ---------- 1) Ventana (en la página que la abre) ---------- */
/* El ancho nunca baja de 768px (en la ventana más estrecha ocupa toda la pantalla): los media queries del iframe miden el
   ancho del iframe, y así la disposición foto + panel (>= 768px) coincide con la ventana centrada y la móvil (< 768px)
   solo se da cuando la pantalla entera es menor de 768px. */
#modal-preview-producto .modal-dialog.modal-full {
    width: min(940px, max(768px, calc(100% - 48px)));
    max-width: none;
    height: min(640px, calc(100% - 60px));
    top: 50%;
    right: auto;
    bottom: auto;
    left: 50%;
    margin: 0;
    transform: translate(-50%, -50%);
}
#modal-preview-producto .modal-content {
    overflow: hidden;
    background: #fff;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(34, 35, 38, .30);
    font-family: var(--ro-font, 'DM Sans', Arial, sans-serif);
}
/* Sin cabecera: la hoja trae su propio botón de cerrar */
#modal-preview-producto .modal-header {
    display: none;
}
#modal-preview-producto .modal-content .modal-body {
    top: 0;
    background: #fff;
    overflow: hidden;
}

@media (max-width: 767px) {
    #modal-preview-producto .modal-dialog.modal-full {
        width: 100%;
        height: auto;
        top: 0;
        bottom: 0;
        left: 0;
        margin: 0;
        transform: none;
    }
    #modal-preview-producto .modal-content {
        background: transparent;
        border-radius: 0;
        box-shadow: none;
    }
    #modal-preview-producto .modal-content .modal-body {
        background: transparent;
    }
    body:has(#modal-preview-producto.show) .modal-backdrop.show {
        background: #100c13;
        opacity: .87;
    }
    /* Chat y flecha de subir quedan fuera mientras la hoja está abierta: tapaban el pie con el importe y el botón. */
    body:has(#modal-preview-producto.show) .chatOct8ne,
    body:has(#modal-preview-producto.show) #bottom-arrow {
        display: none !important;
    }
}

/* ---------- 2) Contenido del iframe: la hoja de compra ---------- */
html:has(body.qv-page),
body.qv-page {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: var(--ro-font, 'DM Sans', Arial, sans-serif);
    font-size: 15px;
    line-height: 1.6;
    color: var(--ro-ink, #222326);
    background: #fff;
}
body.qv-page form#form1 {
    height: 100%;
}

/* Tablet y escritorio: foto a la izquierda, panel a la derecha */
.qv-sheet {
    display: grid;
    grid-template-columns: minmax(0, 43%) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    height: 100%;
    font-family: var(--ro-font, 'DM Sans', Arial, sans-serif);
    color: var(--ro-ink, #222326);
}
.qs-media {
    display: flex;
    flex-direction: column;
    padding: 28px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--ro-soft, #f7f4f1);
}
.qs-media img {
    display: block;
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    object-fit: contain;
    border-radius: 14px;
}
/* Descripción bajo la foto (tablet y escritorio); si es larga, la columna de la foto se desplaza */
.qs-desc {
    flex: 0 0 auto;
    margin-top: 22px;
}
.qs-desc-title {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ro-muted, #686a70);
}
.qs-desc-text {
    font-size: 14px;
    line-height: 1.6;
    color: #3a3b3f;
}
.qs-desc-text img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}
.qs-desc-text p {
    margin: 0 0 10px;
}
.qs-desc-text ul,
.qs-desc-text ol {
    padding-left: 20px;
    margin: 0 0 10px;
}
.qs-desc-text h1,
.qs-desc-text h2,
.qs-desc-text h3,
.qs-desc-text h4,
.qs-desc-text h5,
.qs-desc-text h6 {
    margin: 14px 0 6px;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--ro-ink, #222326);
}
.qs-desc-text a {
    color: var(--ro-brand-dark, #b71c2e);
    text-decoration: underline;
}
.qs-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #fff;
}
.qs-handle {
    display: none;
}
.qs-heading {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 0 0 auto;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #eee6ea;
}
.qs-heading h2 {
    flex: 1;
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -.01em;
}
.qs-close {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 27px;
    line-height: 1;
    color: #736470;
    background: #f5f1f3;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color .15s, color .15s;
}
.qs-close:hover {
    color: #fff;
    background: var(--ro-ink, #222326);
}
.qs-scroll {
    flex: 1 1 auto;
    min-height: 0;
    padding: 18px 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.qs-prompt {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
}
.qs-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.qs-option {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    margin: 0;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.3;
    text-align: center;
    background: #fff;
    border: 1px solid #e2d9df;
    border-radius: 9px;
    cursor: pointer;
    transition: border-color .15s, background-color .15s;
}
.qs-option:hover {
    background: #faf8f9;
    border-color: #cfc8cc;
}
.qs-option input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}
.qs-option:has(input:checked) {
    background: #fcf0f4;
    border-color: var(--ro-brand, #d9263b);
    box-shadow: inset 0 0 0 1px var(--ro-brand, #d9263b);
}
.qs-option:has(input:focus-visible) {
    outline: 3px solid #c291a8;
    outline-offset: 2px;
}
.qs-option:has(input:disabled) {
    color: #aaa;
    background: #f6f6f6;
    cursor: default;
}
.qs-discount {
    margin: 0 0 12px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--ro-brand, #d9263b);
}
.qs-design {
    margin: 0 0 12px;
    padding: 0;
    border: 0;
}
.qs-design legend {
    margin: 0 0 9px;
    font-size: 14px;
    line-height: 1.4;
}
.qs-design label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0 20px 0 0;
    font-size: 14px;
}
.qs-design input {
    accent-color: var(--ro-brand, #d9263b);
}
.qs-status {
    margin: 0;
    font-size: 14px;
    color: var(--ro-brand, #d9263b);
}
/* Parte fija inferior: cantidad, importe y botón */
.qs-footer {
    flex: 0 0 auto;
    padding: 14px 24px calc(18px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid #eee6ea;
}
.qs-qty-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}
.qs-qty-row[hidden],
.qs-discount[hidden],
.qs-design[hidden] {
    display: none;
}
.qs-qty {
    display: flex;
    flex: 0 0 150px;
    overflow: hidden;
    border: 1px solid #dfd7dc;
    border-radius: 9px;
}
.qs-qty button {
    flex: 0 0 44px;
    height: 40px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
    color: var(--ro-brand, #d9263b);
    cursor: pointer;
    background: #f7f3f5;
    border: 0;
}
.qs-qty button:disabled {
    color: #c4b9c1;
    cursor: default;
}
.qs-qty input {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0;
    font: inherit;
    font-size: 16px;
    text-align: center;
    color: var(--ro-ink, #222326);
    background: #fff;
    border: 0;
    border-right: 1px solid #dfd7dc;
    border-left: 1px solid #dfd7dc;
    border-radius: 0;
    -moz-appearance: textfield;
    appearance: textfield;
}
.qs-qty input::-webkit-inner-spin-button,
.qs-qty input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.qs-unit {
    font-size: 13px;
    text-align: right;
    color: #766572;
}
.qs-unit strong {
    color: var(--ro-brand, #d9263b);
}
.qs-buy-row {
    display: flex;
    align-items: center;
    gap: 16px;
}
.qs-total {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    line-height: 1.2;
    color: #766572;
}
.qs-total strong {
    font-size: 22px;
    font-weight: 700;
    white-space: nowrap;
    color: var(--ro-brand, #d9263b);
}
.qs-buy-row > button {
    flex: 1;
    min-height: 46px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
    text-transform: uppercase;
    color: #fff;
    cursor: pointer;
    background: var(--ro-brand, #d9263b);
    border: 0;
    border-radius: 9px;
    transition: background-color .15s;
}
.qs-buy-row > button:hover:not(:disabled) {
    background: var(--ro-brand-dark, #b71c2e);
}
.qs-buy-row > button:disabled {
    cursor: default;
    background: #c9bdc4;
}

/* Móvil (hasta 767px): la hoja ocupa la pantalla. Foto arriba (32%) y panel blanco inferior con esquinas redondeadas;
   las opciones y la oferta se desplazan por su cuenta y quedan fijos abajo la cantidad, el importe y el botón. */
@media (max-width: 767px) {
    html:has(body.qv-page),
    body.qv-page {
        background: transparent;
    }
    .qv-sheet {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: 32% minmax(0, 1fr);
        transition: grid-template-rows .3s ease;
    }
    /* Panel desplegado (arrastrar hacia arriba): la foto desaparece y el panel ocupa toda la hoja para ver más opciones.
       Arrastrar hacia abajo (o tocar el tirador) lo devuelve a su posición inicial, con la foto. */
    .qv-sheet.qv-expanded {
        grid-template-rows: 0px minmax(0, 1fr);
    }
    .qv-sheet.qv-expanded .qs-media {
        padding: 0;
        opacity: 0;
        pointer-events: none;
    }
    .qs-media {
        transition: opacity .2s ease, padding .3s ease;
    }
    .qv-sheet.qv-expanded .qs-panel {
        border-radius: 0;
    }
    .qs-media {
        align-items: center;
        justify-content: center;
        padding: 12px 18px 16px;
        overflow: hidden;
        background: transparent;
    }
    /* La caja de la imagen se ajusta a la foto (antes height:100% + contain dejaba la foto más estrecha que su caja y el
       redondeo caía en un hueco invisible): así las esquinas redondeadas son las de la propia foto. */
    .qs-media img {
        width: auto;
        max-width: 100%;
        height: auto;
        max-height: 100%;
        border-radius: 14px;
    }
    .qs-desc {
        display: none;
    }
    .qs-panel {
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -8px 30px #0002;
        animation: qs-in .25s ease-out;
    }
    .qs-handle {
        display: block;
        flex: 0 0 auto;
        width: 38px;
        height: 4px;
        margin: 9px auto 0;
        background: #dbd5d9;
        border-radius: 4px;
        position: relative;
    }
    /* Zona de toque del tirador más grande que la barra visible */
    .qs-handle::before {
        content: "";
        position: absolute;
        inset: -12px -30px;
    }
    .qs-heading {
        padding: 12px 20px;
    }
    .qs-heading h2 {
        font-size: 18px;
        line-height: 1.3;
    }
    /* Al arrastrar el panel (ratón o dedo) no se selecciona el título ni el tirador */
    .qs-heading,
    .qs-handle {
        -webkit-user-select: none;
        user-select: none;
    }
    .qs-scroll {
        padding: 16px 20px;
    }
    .qs-prompt {
        font-size: 16px;
        font-weight: 400;
    }
    .qs-options {
        display: block;
    }
    .qs-option {
        margin: 0 0 8px;
    }
    .qs-footer {
        padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
    }
}
@keyframes qs-in {
    from { transform: translateY(10%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .qs-panel {
        animation: none;
    }
}
