/* === Encabezados de la tabla de cotización === */
.cotizar-parts-header {
    display: flex;
    justify-content: space-between;
    padding-inline: 20px;
    font-weight: bold;
    font-size: 0.93rem;
    margin-bottom: 0.2em;
    color: #222;
}
.cotizar-parts-header .cotizar-header-codigo {
    flex: 2;
    text-align: left;
}
.cotizar-parts-header .cotizar-header-cantidad {
    flex: 1;
    text-align: right;
}

/* === Reset y base === */
/**
 * Cotizador MatixGo - Estilos
 * 
 * Estructura:
 * 1. Reset y Variables
 * 2. Layout Base
 * 3. Header y Navegación
 * 4. Área de Preview
 * 5. Controles y Paneles
 * 6. Modal de Cotización
 * 7. Utilidades y Helpers
 * 8. Media Queries
 */

/* === 1. Reset y Variables === */
:root {
    --color-primary: #EC6707;
    --color-dark: #1E1E1E;
    --color-light: #fff;
    --color-gray: #333;
    --color-gray-light: #f5f5f5;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    /* sombras neutras por defecto (gris suave) */
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.12);
    /* sombra acento (naranja) para botones específicos */
    --shadow-accent: 0 2px 7px rgba(255, 102, 0, 0.685);
    --transition: 160ms ease;
}

* { 
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

img { 
    max-width: 100%;
    height: auto;
    display: block;
}

/* === 2. Layout Base === */
:root {
    height: -webkit-fill-available;
}

html {
    height: 100vh;
    height: -webkit-fill-available;
}

body {
    background-color: var(--color-dark);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    width: 100%;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

main {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* === 3. Header y Navegación === */
header {
    background-color: var(--color-light);
    width: 100%;
}

.caja-header {
    display: flex;
    padding: 0.5em 1em;
    justify-content: flex-end;
    align-items: center;
}

.salir {
    margin-right: auto;
    order: -1;
    display: flex;
    align-items: center;
}

.salir a {
    color: var(--color-primary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    border-radius: var(--radius-sm);
    cursor: pointer;
    overflow: visible;
    transition: background-color 160ms ease;
    line-height: 1;
    font-size: 1rem;
}
.salir a::before {
    content: '◀';
    color: var(--color-primary);
    opacity: 0;
    transform: translateX(5px);
    transition: var(--transition);
    display: inline-block;
}

.salir a .texto {
    color: var(--color-dark);
    font-family: Arial, Helvetica, sans-serif;
    display: inline-block;
    transition: var(--transition);
}

.salir a:hover::before,
.salir a:focus::before {
    opacity: 1;
    transform: translateX(0);
}

.salir a:hover .texto,
.salir a:focus .texto {
    transform: translateX(5px);
    color: var(--color-primary);
}

/* Logos y separador */
.logos {
    display: flex;
    align-items: center;
    gap: 0.8em;
}

.logo-bticino,
.logo-matixgo {
    display: flex;
    align-items: center;
}

.logo-bticino img { height: 2.4em; }
.logo-matixgo img { height: 2.5em; }

.linea {
    height: 2.6em;
    background-color: var(--color-gray);
    width: 0.15em;
    border-radius: 1em;
}

/* === 4. Área de Preview === */
.producto {
    width: 100%;
    padding: 0.2rem 0 0.3rem;
    background: transparent;
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
}

.caja-producto {
    flex: 1 0 auto;
    width: 100%;
    margin: 0 auto;
    padding: 0 0.5rem;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Preview principal */
.producto-preview {
    position: relative;
    width: 100%;
    flex: 1 0 auto;
    min-height: 60vh; /* Asegurar altura mínima en móvil */
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-gray-light);
    border-radius: var(--radius-lg);
}

/* Capas del preview */
.preview-fondo {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1;
}

.preview-centro {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.preview-placa {
    width: 400px;
    position: relative;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

.preview-placa img {
    width: 100%;
    height: auto;
    display: block;
}

/* Módulos en el preview */
.preview-modulos {
    width: 218px;
    position: absolute;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    pointer-events: none;
}

.preview-modulos img {
    width: 100%;
    height: auto;
    display: block;
}

/* Botón de cotización */
.boton-cotizar {
    position: absolute;
    right: 2rem;
    bottom: 1rem;
    z-index: 5;
}

.boton-cotizar button {
    background: var(--color-gray);
    color: var(--color-light);
    border: 1px solid var(--color-light);
    padding: 0.55rem 0.9rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1.2rem;
    transition: var(--transition);
}

.boton-cotizar button:hover {
    box-shadow: var(--shadow-accent);
    border: 1px solid var(--color-gray);
}

.boton-cotizar button:active {
    transform: translateY(-4px);
}

.boton-cotizar button:focus {
    outline: 1px solid rgba(236, 103, 7, 0.14);
    outline-offset: 1px;
}



/* === 7. Mensajes y Alertas === */
.alert {
    position: fixed;
    left: 50%;
    bottom: 2rem;
    transform: translateX(-50%);
    background: rgba(30, 30, 30, 0.95);
    color: var(--color-light);
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius-md);
    font-size: 1rem;
    box-shadow: var(--shadow-sm);
    z-index: 10000;
    animation: fadeIn 0.2s ease;
    text-align: center;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, 1rem); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Indicador de descarga dentro del modal */
.download-progress {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.95);
    z-index: 20000;
    padding: 1rem;
    box-sizing: border-box;
}
.download-progress .dp-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    color: var(--color-gray);
}
.dp-spinner {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 4px solid rgba(0,0,0,0.08);
    border-top-color: var(--color-primary);
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.dp-text {
    font-size: 0.95rem;
    color: var(--color-gray);
}

/* === 5. Controles y Paneles === */
.opciones {
    background: var(--color-light);
    padding: 0.4rem 0 2rem;
    border-top: 6px solid var(--color-gray);
}

.opciones-caja {
    max-width: 100%;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
}

/* Tabs de navegación */
.tabs {
    display: flex; 
    align-items: center;
    gap: 0.1rem;
}

.op-btn {
    background: #7B7B7B;
    border: 1px solid #8C8C8C;
    padding: 0.45rem 0.8rem;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: transform var(--transition), background 760ms ease-out;
}

.op-btn .label {
    display: none; 
}

.op-btn.active {
    background: #DCDCDC; 
    border-color: #8C8C8C; 
    color: var(--color-primary); 
}

.op-btn.active .label {
    display: inline-block; 
}

/* Controles de fondo */
.fondo-controls {
    display: flex; 
    gap: 0.6rem; 
    align-items: center; 
}

#btn-upload {
    background: var(--color-dark);
    border-radius: var(--radius-sm);
    color: var(--color-light);
    border: none;
    font-size: 1rem;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
}

#btn-upload img {
    width: 25px;
    justify-self: center;
}

/* Carrusel de opciones */
.carrusel {
    background-color: #DCDCDC;
    border-color: #8C8C8C;
    width: 100%;
    min-height: 120px; /* Altura mínima fija */
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem;
    margin-top: auto; /* Empujar al fondo */
}

.carrusel-track {
    display: flex;
    gap: 1rem;
    flex: 1;
    overflow: hidden;
    padding: 0.6rem 0;
    touch-action: none;
    -ms-touch-action: none;
    contain: content;         
    will-change: transform;   
    -webkit-overflow-scrolling: touch;
}
/* Visual feedback while dragging */
.carrusel-track.dragging {
    cursor: grabbing;
    cursor: -webkit-grabbing;
}

/* Items del carrusel */
.carrusel-track .item {
    min-width: 120px;
    height: 92px;
    border-radius: var(--radius-md);
    background: transparent;
    box-shadow: none;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.carrusel-track .item img {
    width: auto;
    height: 80%;
    max-width: 100%;
    object-fit: contain;
    display: block;
}

/* Visible label for the back button inside the carrusel item */
.back-button-container .back-label {
    font-size: 0.85rem;
    color: var(--color-dark);
    display: inline-block;
    padding: 6px 10px;
}

/* Tooltip del carrusel */
.carrusel-track .item::after {
    content: attr(data-label);
    position: absolute;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    color: var(--color-light);
    padding: 0.28rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}
/* Hover efecto del tooltip */
.carrusel-track .item:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Panel de colores flotante: usar layout en grid para que coincida con position/module-options */
.color-panel.floating {
    width: min-content;
    height: min-content;
    padding: 6px;
    /* Usar grid para que las 'swatches' se acomoden igual que los botones de posición */
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(3, min-content);
    gap: 6px;
    align-items: center;
    justify-items: center;
    border-radius: var(--radius-lg);
    background: rgba(0, 0, 0, 0.11);
    box-shadow: var(--shadow-sm);
    z-index: 9999;
}

.color-panel .swatch {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-md);
    margin-inline: 2px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    cursor: pointer;
    padding: 0;
}

.color-panel { 
    /* transición más corta y menor desplazamiento para apariencia sutil */
    transition: opacity 180ms ease, transform 180ms ease;
    opacity: 0;
    transform: translateX(-4px);
}

.color-panel.open {
    opacity: 1;
    transform: translateX(0);
}

/* Personalización */
.carrusel-track .item.personalize {
    min-width: 220px;
    height: 92px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-light);
    border-radius: var(--radius-md);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    font-weight: 600;
    color: var(--color-gray);
}

.controls-item {
    min-width: 320px;
    padding: 0.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    box-shadow: none;
}

.personalize-inner {
    padding: 0.4rem 0.6rem;
}

/* Iconos de pestañas */
.icon-wrapper { 
    position: relative; 
    width: 28px;
    height: 28px; 
    display: inline-block; 
}

.icon-wrapper .tab-icon { 
    position: absolute; 
    inset: 0;
    width: 100%; 
    height: 100%; 
    object-fit: contain; 
    transition: var(--transition); 
    pointer-events: none;
}

/* Estados de iconos */
.icon-wrapper .icon-on { 
    opacity: 0; 
}

.op-btn.active .icon-on { 
    opacity: 1; 
}

.op-btn.active .icon-off { 
    opacity: 0; 
}

.op-btn .icon-wrapper { 
    transition: transform 700ms ease; 
}

.op-btn.active .icon-wrapper { 
    transform: translateY(-2px) scale(1.2); 
}

/* Botones de navegación */
button#prev,
button#next {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 2rem;
    color: var(--color-gray);
    transition: var(--transition);
}

button#prev:hover,
button#next:hover {
    color: var(--color-primary);
}

/* Prevención de arrastre en imágenes */
.carrusel-track .item img {
    -webkit-user-drag: none;
}

/* Controles de fondo */
.fondo-controls {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    padding: 6px;
    background: linear-gradient(180deg, var(--color-light), #fbfbfb);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 20px rgba(17, 17, 17, 0.06);
}

/* Botón de subida de imagen */
#btn-upload {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0.45rem 0.9rem;
    background: var(--color-gray);
    color: var(--color-light);
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}

#btn-upload:hover { 
    box-shadow: var(--shadow-accent);
}

#btn-upload:active { 
    transform: translateY(-2px); 
}

#btn-upload:focus { 
    outline: 1px solid rgba(236, 103, 7, 0.14); 
    outline-offset: 1px;
}

/* Selector de color personalizado */
#color-picker {
    -webkit-appearance: none;
    appearance: none;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-gray);
    padding: 0;
    cursor: pointer;
    transition: var(--transition);
}

#color-picker::-webkit-color-swatch-wrapper { 
    padding: 0; 
}

#color-picker::-webkit-color-swatch { 
    border-radius: var(--radius-md); 
    border: none; 
}

#color-picker::-moz-color-swatch { 
    border-radius: var(--radius-md); 
    border: none; 
}

#color-picker:hover { 
    box-shadow: var(--shadow-accent);
}

#color-picker:active { 
    transform: translateY(-2px); 
}

/* === 6. Paneles Flotantes === */

/* Controles de navegación */
#prev, #next {
    position: relative;
    z-index: 10001;
    pointer-events: auto;
}

/* Ocultar título del panel */
#panel-title { 
    display: none !important; 
}

/* Panel de colores flotante */
.color-panel.floating {
    z-index: 10000;
}

/* Ocultar scrollbar del carrusel */
.carrusel-track::-webkit-scrollbar { 
    display: none; 
}

/* Panel de posición */
.position-panel {
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.11);
    border-radius: var(--radius-lg);
    width: min-content;
    height: min-content;
    box-shadow: var(--shadow-sm);
    z-index: 10001;
    padding: 5px;
    transition: opacity 180ms ease, transform 180ms ease;
    transform: translateX(-2px);
}

/* Grid para paneles de control */
.position-panel .positions,
#module-options-panel .positions,
.color-panel .swatches {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(3, min-content);
    gap: 4px;
    align-items: center;
    justify-items: center;
    grid-auto-columns: min-content;
    padding: 0;
}

/* CSS basado en clases count-N que añade JS: asegura altura exacta según cantidad visible */
/* (removed) temporary count-N CSS - reverted to original styles */

.position-panel.open,
.floating-panel.open,
.floating-panel.open {
    opacity: 1;
    transform: translateX(0);
}

/* Panel flotante genérico */
.floating-panel {
    position: fixed;
    background: var(--color-light);
    border: 1px solid #ccc;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    padding: 8px;
    min-width: 180px;
    /* animación coherente con color-panel */
    transition: opacity 180ms ease, transform 180ms ease;
    opacity: 0;
    transform: translateX(-4px);
}

/* Sección de elección de módulos */
.module-choice {
    margin-bottom: 12px;
}

.choice-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--color-gray);
}

.choice-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.choice-btn {
    padding: 6px 12px;
    background: var(--color-gray-light);
    border: 1px solid #ddd;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    transition: var(--transition);
}

/* Estados de botones de elección */
.choice-btn:hover {
    background: #e8e8e8;
    border-color: #ccc;
}

.choice-btn:active {
    background: #ddd;
    transform: translateY(1px);
}

/* Imágenes en botones de opciones */
#module-options-panel .pos-btn img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.choice-btn .choice-icon {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    object-fit: contain;
    vertical-align: middle;
}

.choice-btn span {
    vertical-align: middle;
}

/* Botones de posición */
.pos-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
}

.pos-btn img {
    width: min-content;
    height: auto;
    display: block;
    pointer-events: none;
}

.pos-btn:hover,
.pos-btn:focus {
    transform: translateY(-3px);
}

/* === 7. Utilidades y Helpers === */

/* Accesibilidad: texto oculto */
.sr-only,
.visually-hidden {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
}

/* Prevención de selección */
html, 
body, 
#track, 
.track, 
.container, 
.preview, 
.modulo-item {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
}

/* Permitir selección en controles de formulario */
input, 
textarea, 
select, 
button, 
[contenteditable="true"] {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* Clase utilitaria para permitir selección */
.allow-select {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* === Estilos de Interacción === */

/* Prevención de resaltado azul por defecto */
a, 
button, 
.op-btn, 
.pos-btn {
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

/* Estilos de foco accesibles */
a:focus, 
a:active, 
button:focus, 
button:active,
.op-btn:focus, 
.op-btn:active, 
.pos-btn:focus, 
.pos-btn:active {
    color: inherit;
    outline: 2px solid rgba(0, 0, 0, 0.06);
    outline-offset: 2px;
}

/* Preservar color de iconos */
.icon-wrapper img, 
.pos-btn img, 
.op-btn img, 
.icon-wrapper svg, 
.pos-btn svg, 
.op-btn svg {
    color: inherit !important;
    fill: currentColor !important;
    filter: none !important;
}

*:focus {
    -webkit-tap-highlight-color: transparent;
}

/* === 6. Modal de Cotización === */

/* Lista de partes */
.cotizar-section { 
    margin-top: 0.5rem; 
}

.cotizar-parts {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding-inline: 20px;
}

.cotizar-part {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--color-gray-light);
}

.cotizar-part-info {
    color: var(--color-gray);
    font-size: 0.8125rem;
    display: flex;
    gap: 0.25rem;
}

.cotizar-part-name {
    font-weight: 500;
}

.cotizar-part-code {
    color: #666;
}

.cotizar-part-qty {
    color: #666;
    font-size: 0.8125rem;
}

/* === Layout Principal === */
.producto {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.caja-producto {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* === 8. Media Queries === */
.carrusel {
    max-height: 25vh;
    overflow-y: hidden;
}

/* Barra de controles */
.controls {
    padding: 0.5rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(5px);
}

/* === 8. Media Queries === */
@media (max-width: 768px) {
    /* Header */
    .caja-header {
        padding: 0.3em 0.5em;
        flex-direction: row;
        justify-content: flex-end;
        gap: 0.5em;
    }
    
    .logo-bticino img { height: 2em; }
    .logo-matixgo img { height: 2.1em; }

    /* Preview del producto */
    .producto-preview { 
        /* Dar más espacio vertical en pantallas pequeñas */
        min-height: 48vh;
        max-height: none; /* Quitar limitación que encogía el preview */
    }
    .preview-placa { 
        width: 280px;
        max-width: 90vw; /* Ajustar al ancho de la pantalla */
    }
    .preview-modulos { 
        width: 153px;
        max-width: 49vw;
    }

    /* Paneles flotantes en móvil: no forzar centrado ni fondo blanco
        para que mantengan la misma apariencia que en escritorio. El JS seguirá
        posicionando el panel cerca del ancla cuando sea posible. */
    .color-panel.floating,
    .position-panel.floating,
    #module-options-panel.floating {
        /* No forzar left/top/transform aquí: permitir que el JS aplique
           left/top/transform inline y el panel quede junto al ancla. */
        position: fixed;
        z-index: 10002;
        max-width: 90vw;
        max-height: 90vh;
        overflow: auto;
        /* Mantener el mismo fondo translúcido que el panel de posición en desktop */
        background: rgba(0, 0, 0, 0.11);
        box-shadow: var(--shadow-sm);
    }

    /* Botones de posición más compactos en móvil */
    .position-panel .pos-btn,
    #module-options-panel .pos-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        flex-shrink: 0;
    }
    
    .position-panel .pos-btn img,
    #module-options-panel .pos-btn img {
        width: 24px;
        height: 24px;
    }

    /* Ajustar layout vertical */
    body {
        height: 100%;
        overflow-y: auto; /* Permitir scroll vertical */
    }

    .producto {
        /* Permitir que el contenedor crezca para dar más espacio al preview */
        flex: 1 0 auto;
        margin-bottom: 0;
    }

    .carrusel {
        max-height: none; /* Quitar límite de altura */
        padding-bottom: 4rem; /* Espacio para scroll */
    }

    /* Botón de cotizar: mantenerlo absoluto respecto al contenedor (no fijarlo al viewport)
       para que no cambie su posición cuando el preview cambie de tamaño. */
    .boton-cotizar {
        position: absolute;
        bottom: 1rem;
        right: 1rem;
        z-index: 1000;
    }

    /* Controles */
    .fondo-controls {
        flex-wrap: wrap;
        justify-content: center;
        padding: 0.3rem;
    }

    #btn-upload {
        font-size: 0.85rem;
        padding: 0.35rem 0.7rem;
    }

    #color-picker {
        width: 38px;
        height: 38px;
    }

    /* Carrusel */
    .carrusel { padding: 0.4rem; }

    .carrusel-track .item {
        min-width: 100px;
        height: 82px;
    }

    .controls-item { min-width: 280px; }

    button#prev, 
    button#next {
        font-size: 1.5rem;
        padding: 0.2rem;
    }
}

@media (max-width: 480px) {
    .caja-header {
        padding: 0.2em 0.4em;
    }

    .logo-bticino img {
        height: 1.8em;
    }
    
    .logo-matixgo img {
        height: 1.9em;
    }

    .boton-salida {
        margin-right: auto;
    }

    /* Product Preview */
    .producto-preview {
        /* Aumentar altura mínima en móviles muy pequeños */
        min-height: 50vh;
        max-height: none;
    }

    .preview-placa {
        width: 240px;
        max-width: 85vw;
    }

    .preview-modulos {
        width: 131px;
        max-width: 46vw;
    }

    /* Mejorar visibilidad de paneles */
    .swatches,
    .positions {
        padding: 6px;
        gap: 6px;
    }

    .swatch,
    .pos-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }
    
    /* Asegurar que .position-panel .positions tenga el mismo tamaño que .color-panel .swatches */
    .position-panel .positions,
    #module-options-panel .positions {
        width: fit-content;
        height: fit-content;
    }

    /* Paneles más compactos pero usables */
    .color-panel.floating,
    .position-panel.floating,
    #module-options-panel.floating {
        bottom: 15vh !important;
    }

    /* Dejar que la regla base controle el tamaño (min-content) */
    .position-panel .positions {
        /* usar el comportamiento por defecto definido en la sección principal */
        grid-template-rows: repeat(3, min-content);
        gap: 4px;
        height: fit-content;
    }

    /* Buttons and Controls */
    .boton-cotizar {
        right: 1rem;
        bottom: 0.5rem;
    }

    .boton-cotizar button {
        padding: 0.45rem 0.8rem;
        font-size: 1rem;
    }

    /* Carousel */
    .carrusel-track .item {
        min-width: 90px;
        height: 72px;
    }

    .controls-item {
        min-width: 240px;
    }

    /* Tabs */
    .op-btn {
        padding: 0.35rem 0.6rem;
    }

    .icon-wrapper {
        width: 24px;
        height: 24px;
    }
}

/* === 8. Media Queries === */

/* Tablet */
@media (max-width: 768px) {
    /* Modal */
    .cotizar-modal {
        width: 92%;
    }

    .cotizar-preview {
        min-height: 120px;
    }

    /* Preview tamaños */
    .cotizar-preview .preview-placa {
        width: 300px;
    }

    .cotizar-preview .preview-modulos {
        width: 164px;
    }

    /* Lista de partes */
    .cotizar-part {
        padding: 0.3rem 0.4rem;
    }

    .cotizar-part-info,
    .cotizar-part-qty {
        font-size: 0.75rem;
    }

    /* Botones */
    .btn-primary {
        padding: 0.5rem 1.5rem;
        font-size: 0.875rem;
    }
}

/* Móvil */
@media (max-width: 480px) {
    /* Modal */
    .cotizar-modal {
        width: 96%;
    }

    .cotizar-preview {
        min-height: 100px;
    }

    /* Preview tamaños */
    .cotizar-preview .preview-placa {
        width: 250px;
    }

    .cotizar-preview .preview-modulos {
        width: 136px;
    }

    /* Lista de partes */
    .cotizar-parts {
        padding-inline: 12px;
    }

    .cotizar-part {
        padding: 0.25rem 0.3rem;
    }

    .cotizar-part-info,
    .cotizar-part-qty {
        font-size: 0.7rem;
    }

    /* Botones */
    .btn-primary {
        padding: 0.45rem 1.2rem;
        font-size: 0.8125rem;
    }
}

/* Media query específica para iOS Safari (iPhone/iPad)
   Detecta -webkit-appearance y webkit para aplicar fix solo en iOS */
/* Removed iOS-specific fixed-height block to allow base grid rules to work.
   If an iOS-only fix is required later, we'll add a narrowly-scoped rule
   that does not affect Android. */

/* Ajustes de orientación landscape */
@media (max-height: 480px) and (orientation: landscape) {
    .producto-preview {
        min-height: 180px;
        max-height: 45vh;
    }

    .preview-placa {
        width: 260px;
        max-width: 40vw;
    }

    .preview-modulos {
        width: 142px;
        max-width: 22vw;
    }

    /* Paneles al lado derecho en landscape */
    .color-panel.floating,
    .position-panel.floating,
    #module-options-panel.floating {
        left: auto !important;
        right: 1rem !important;
        bottom: 50% !important;
        transform: translateY(50%) !important;
    }

    /* Carrusel más compacto */
    .carrusel {
        padding-bottom: 1rem;
    }

    .carrusel-track .item {
        min-width: 80px;
        height: 64px;
    }
}

/* Optimizaciones táctiles */
@media (hover: none) {
    .op-btn:hover,
    .btn-primary:hover,
    .btn-secondary:hover {
        transform: none;
    }

    .carrusel-track .item::after {
        display: none;
    }

    #btn-upload:hover,
    #color-picker:hover {
        box-shadow: none;
    }
}

/* === 6. Modal de Cotización === */

/* Overlay */
.cotizar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 12000;
    opacity: 0;
    transition: background-color 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
}

.cotizar-overlay.open { 
    background: rgba(0, 0, 0, 0.55);
    opacity: 1;
    pointer-events: auto;
}

/* Modal */
.cotizar-modal {
    width: min(520px, 96%);
    background: var(--color-light);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), 
                opacity 0.3s ease;
    padding: 0;
    overflow: hidden;
}

.cotizar-overlay.open .cotizar-modal { 
    transform: translateY(0) scale(1); 
    opacity: 1; 
}

/* Encabezado del modal */
.cotizar-header { 
    display: flex; 
    align-items: center; 
    justify-content: space-between;
    margin-bottom: 1rem;
}
/* Encabezado */
.cotizar-header h3 {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--color-gray);
    margin: 0;
}

/* Contenido del modal */
.cotizar-body { 
    display: flex; 
    flex-direction: column;
}

/* Preview en modal */
.cotizar-preview { 
    position: relative;
    width: 100%;
    min-height: 140px;
    max-height: 50vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-gray-light);
    padding: 0;
    box-sizing: border-box;
    border-radius: 0;
}

/* Fondo del preview */
.cotizar-preview .preview-fondo {
    border-radius: 0;
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1;
}

/* Centro del preview */
.cotizar-preview .preview-centro {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    padding: 2px 0;
}

/* Wrapper del preview clonado */
.cotizar-preview .preview-clone-wrapper {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    pointer-events: none;
}

/* Placa en el preview */
.cotizar-preview .preview-placa {
    width: 400px;
    position: relative;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

.cotizar-preview .preview-placa img {
    width: 100%;
    height: auto;
    display: block;
}

/* Módulos en el preview */
.cotizar-preview .preview-modulos {
    width: 218px;
    position: absolute;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    pointer-events: none;
}

.cotizar-preview .preview-modulos img {
    width: 100%;
    height: auto;
    display: block;
}

/* Posicionamiento de módulos */
.cotizar-preview .preview-modulos .mod-pos {
    width: 33%;
    height: auto;
    object-fit: contain;
}

.cotizar-preview .preview-modulos .mod-pos[data-pos="left"] {
    left: 0;
}

.cotizar-preview .preview-modulos .mod-pos[data-pos="center"] {
    left: 50%;
    transform: translateX(-50%);
}

.cotizar-preview .preview-modulos .mod-pos[data-pos="right"] {
    right: 0;
}

.cotizar-preview .preview-modulos .mod-pos[data-pos="full"] {
    width: 100%;
}

/* Capas del modal */
.cotizar-preview .layer {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1;
}

.cotizar-preview img.placa-layer {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    height: auto;
    z-index: 10;
}

.cotizar-preview img.module-layer {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: auto;
    z-index: 20;
}

/* Lista de partes */
.cotizar-section { 
    margin-top: 0.5rem; 
}

.cotizar-part {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--color-gray-light);
}

.cotizar-part-info {
    color: var(--color-gray);
    font-size: 0.8125rem;
}

.cotizar-part-qty {
    color: #666;
    font-size: 0.8125rem;
}

/* Pie del modal */
.cotizar-footer { 
    display: flex; 
    justify-content: center; 
    padding: 1rem;
    background: var(--color-light);
}
/* Botones del modal */
.btn-primary { 
    background: var(--color-gray); 
    color: var(--color-light); 
    padding: 0.6rem 2rem; 
    border-radius: var(--radius-md); 
    border: none; 
    cursor: pointer;
    font-size: 0.9375rem;
    transition: var(--transition);
}

.btn-primary:hover {
    background: #444;
}

.btn-secondary { 
    background: transparent; 
    color: var(--color-gray); 
    padding: 0.6rem 1.2rem; 
    border-radius: var(--radius-md); 
    border: 1px solid #ddd; 
    cursor: pointer;
    font-size: 0.9375rem;
    transition: var(--transition);
}

.btn-secondary:hover {
    border-color: #bbb;
    background: var(--color-gray-light);
}

/* Botón de cerrar */
.cotizar-close { 
    background: transparent; 
    border: none; 
    color: #666;
    font-size: 1.5rem; 
    cursor: pointer;
    transition: var(--transition);
    padding: 0.25rem;
    margin: -0.25rem;
    line-height: 1;
}

.cotizar-close:hover {
    color: var(--color-gray);
}

/* === Botón "Volver" Fijo === */
#back-button-container {
    display: none;
    animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

#back-button-container .back-item {
    min-width: 60px;
    padding: 8px 16px;
    height: auto;
    background: linear-gradient(135deg, var(--color-primary) 0%, #d85a06 100%);
    color: var(--color-light);
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    box-shadow: var(--shadow-accent);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

#back-button-container .back-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(236, 103, 7, 0.5);
}

#back-button-container .back-item:active {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(236, 103, 7, 0.4);
}