/* ============================================================
   Correcciones móviles globales
   Capa visual únicamente: no altera estructura ni lógica.
   ============================================================ */

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
}

@supports not (overflow-x: clip) {
    html,
    body {
        overflow-x: hidden;
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

img,
video,
iframe,
svg {
    max-width: 100%;
}

img {
    height: auto;
}

p,
span,
div,
td,
th,
a,
button,
label,
li {
    overflow-wrap: break-word;
}

h1,
h2,
h3,
h4 {
    overflow-wrap: break-word;
}

/* Contenedores principales: nunca deben crecer por el min-content
   de una tabla, un código largo o una imagen. */
.site-main,
.main,
.panel,
.summary-card,
.panel-header,
.page-head,
.cards-row,
.report-grid,
.cash-main-grid,
.cash-currency-panel,
.cash-currency-sections,
.product-detail,
.product-detail-media,
.product-detail-info,
.header-inner,
.footer-inner,
.order-layout,
.payment-layout,
.checkout-layout {
    min-width: 0;
    max-width: 100%;
}

.panel-header {
    flex-wrap: wrap;
}

/* Todas las tablas se desplazan horizontalmente dentro de su caja. */
.table-responsive,
.table-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
}

.table-responsive > table,
.table-container > table {
    max-width: 100%;
}

@media (max-width: 900px) {
    .table-responsive > table,
    .table-container > table {
        width: max-content;
        min-width: 100%;
        max-width: none;
    }

    /* Estas tablas ya tienen su propio layout responsive de tarjetas
       o columnas fijas; no deben convertirse en max-content. */
    .table-responsive.orders-table-wrap > .orders-table,
    .table-responsive > .checkout-table {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .table-responsive th,
    .table-responsive td,
    .table-container th,
    .table-container td {
        white-space: normal;
    }
}

/* Carrito lateral: el panel no puede superar el ancho del viewport
   y los botones deben apilarse como bloques de ancho completo. */
.cart-overlay {
    max-width: 100vw;
    overflow: hidden;
}

.cart-panel {
    width: 100%;
    max-width: min(420px, 100vw);
    overflow-x: hidden;
}

.cart-header,
.cart-items,
.cart-footer {
    min-width: 0;
    max-width: 100%;
}

.cart-footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

/* Alias explícitos del pie del drawer y de las acciones del carrito. */
.cart-drawer-footer,
.cart-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-bottom: 16px;
}

.cart-drawer-footer a,
.cart-drawer-footer button,
.cart-actions a,
.cart-actions button {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    white-space: normal;
    text-align: center;
}

.cart-footer .cart-total {
    width: 100%;
    min-width: 0;
}

.cart-footer .cart-checkout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 12px 16px;
    white-space: normal;
    text-align: center;
    overflow-wrap: anywhere;
}

.cart-item {
    min-width: 0;
    max-width: 100%;
}

.cart-item-info,
.cart-item-name {
    min-width: 0;
    max-width: 100%;
}

.cart-item-name {
    overflow-wrap: anywhere;
}

/* Miniaturas del drawer y de la página del carrito: tamaño estable
   incluso si la imagen no carga y muestra el texto alternativo. */
.cart-item-img {
    width: 56px;
    height: 56px;
    flex: 0 0 56px;
    object-fit: cover;
}

@media (max-width: 640px) {
    .cart-page-item {
        grid-template-columns: 56px minmax(0, 1fr);
        gap: 12px;
        padding: 12px;
    }

    .cart-page-image img {
        width: 56px;
        height: 56px;
        flex: 0 0 56px;
        object-fit: cover;
    }

    .cart-page-actions {
        grid-column: 1 / -1;
        width: 100%;
        max-width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .cart-page-actions .qty-form {
        width: 100%;
        max-width: 100%;
        flex-wrap: wrap;
        justify-content: space-between;
    }

    .cart-page-actions .qty-form input {
        flex: 1 1 68px;
        max-width: 96px;
    }

    .cart-page-actions .link-button {
        width: 100%;
        min-height: 44px;
        justify-content: center;
        text-align: center;
    }

    .cart-line-equation {
        width: 100%;
        max-width: 100%;
        justify-content: flex-start;
    }

    .cart-summary-card {
        width: 100%;
        max-width: 100%;
    }
}

@media (max-width: 520px) {
    .cart-panel {
        max-width: 100vw;
        padding: 1rem;
    }

    .cart-items {
        padding: 12px 0;
    }

    .cart-footer {
        padding: 14px 0 max(16px, env(safe-area-inset-bottom));
    }

    .cart-header h2 {
        font-size: 1.8rem;
    }
}

/* Producto: galería, imagen principal y contador dentro del marco. */
.product-slider {
    position: relative;
    display: block;
    width: 100%;
    max-width: 100%;
    min-height: 220px;
    overflow: hidden;
    border-radius: 20px;
    background: #f6f1ea;
}

.product-slider .product-detail-image {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 560px;
    object-fit: cover;
}

.slider-counter {
    max-width: calc(100% - 16px);
    white-space: nowrap;
}

.product-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    width: 100%;
    max-width: 100%;
    gap: 8px;
    margin-top: 12px;
}

.product-gallery .product-thumb {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.product-gallery .product-thumb img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 10px;
}

.product-image-container {
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 4 / 5;
}

.product-image {
    width: 100%;
    max-width: 100%;
    height: 100%;
    object-fit: cover;
}

@media (max-width: 640px) {
    .product-detail {
        width: 100%;
        max-width: 100%;
        padding-left: 16px;
        padding-right: 16px;
        gap: 24px;
    }

    .product-slider {
        min-height: 240px;
    }

    .product-slider .product-detail-image {
        aspect-ratio: 1 / 1;
        max-height: none;
    }

    .slider-arrow {
        width: 36px;
        height: 36px;
    }

    .slider-arrow-prev {
        left: 8px;
    }

    .slider-arrow-next {
        right: 8px;
    }

    .slider-counter {
        right: 8px;
        bottom: 8px;
    }

    .product-detail-info h1 {
        font-size: clamp(28px, 9vw, 34px);
    }

    .product-detail-price {
        font-size: clamp(28px, 9vw, 34px);
    }

    .add-to-cart-form {
        width: 100%;
        max-width: 100%;
        padding: 14px;
    }

    .add-to-cart-form .btn {
        width: 100%;
        max-width: 100%;
    }
}

/* Tablas especiales del panel: conservan scroll, sin comprimir columnas. */
@media (max-width: 768px) {
    .manual-products-table > table,
    .combined-products-table {
        min-width: 680px;
    }

    .payments-multiple-table {
        min-width: 560px;
    }

    .orders-table-wrap {
        overflow-x: auto;
    }
}

/* Botones de acciones: en móvil ocupan una fila completa. */
@media (max-width: 600px) {
    .btn,
    button,
    input[type="submit"] {
        max-width: 100%;
        white-space: normal;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .page-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-actions > .btn,
    .page-actions > a.btn {
        flex: 1 1 100%;
        width: 100%;
        min-width: 0;
        white-space: normal;
        text-align: center;
    }

    .cart-actions,
    .drawer-footer,
    .modal-footer,
    .btn-group {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .cart-actions .btn,
    .drawer-footer .btn {
        flex: 1 1 100%;
        min-width: 0;
        white-space: normal;
        text-align: center;
    }
}

/* Números de cuenta, referencias y notas largas. */
.payment-method-details,
.bank-data,
.transfer-data,
.account-number,
.reference,
.mono,
.detail-list dd,
.order-notes,
.support-detail-message {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Los flotantes no deben tapar la última fila de una tabla o el total. */
@media (max-width: 600px) {
    .site-main,
    .main {
        padding-bottom: 86px;
    }

    .float-bubbles {
        right: 10px;
        bottom: calc(12px + env(safe-area-inset-bottom));
        gap: 8px;
    }

    .float-bubbles a {
        width: 44px;
        height: 44px;
        font-size: 18px;
        line-height: 44px;
    }
}

/* Evita que una tabla aislada fuera de .table-responsive desborde. */
.panel > table {
    width: 100%;
    max-width: 100%;
}
