/**
 * Estilos para componentes dinámicos
 * Estos estilos pueden ser sobrescritos desde la BD mediante config.styles en el JSON
 */

/* Prevenir scroll horizontal en toda la página */
html, body {
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
    overflow-x: hidden !important;
}

/* Asegurar que el contenedor principal no cause overflow */
#main-view {
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
    overflow-x: hidden !important;
}

/* Asegurar que las secciones no causen overflow */
#main-view > div[id^="section-"],
#main-view section {
    overflow-x: hidden;
    max-width: 100%;
    overflow-x: hidden !important;
}

/* Contenedor de productos sin overflow */
.products-layout {
    overflow-x: hidden;
    max-width: 100%;
}

/* Sección de productos en móvil */
#main-view > div[id*="section-products"],
#main-view > div[id*="section-shop"],
section[id*="products"],
section[id*="shop"] {
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: hidden !important;
}

/* ============================================
   ESTILOS PARA PREVENIR FOUC (Flash of Unstyled Content)
   ============================================ */

/* main-view debe estar oculto hasta que TODO esté cargado */
#main-view {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Cuando main-view tiene display:block en style, mostrarlo */
#main-view[style*="display: block"],
#main-view[style*="display:block"] {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Secciones con contenido pendiente (guardado pero no mostrado) */
#main-view > div.section-pending {
    display: none !important;
}

/* Cuando se marca como cargado, mostrar el contenido */
#main-view > div.section-loaded {
    display: block !important;
}

/* Cuando las secciones tienen contenido, mostrarlas con transición suave */
#main-view > div[id^="section-"]:not(:empty),
#main-view > div[id="inicio"]:not(:empty),
#main-view > div[id="confianza"]:not(:empty),
#main-view > div[id="productos"]:not(:empty),
#main-view > div[id="servicios-profesionales"]:not(:empty),
#main-view > div[id="nosotros"]:not(:empty),
#main-view > div[id="social-banner"]:not(:empty),
#main-view > div[id="ubicacion"]:not(:empty) {
    opacity: 1;
    visibility: visible;
}

/* Mostrar secciones que tienen contenido */
#main-view section:not(:empty) {
    opacity: 1;
    visibility: visible;
    display: block !important;
}

/* Indicador de carga global mientras se renderizan las secciones */
#page-loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease-in-out, visibility 0.4s ease-in-out;
}

#page-loading-indicator.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#page-loading-indicator .loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Skeleton loader para secciones individuales */
.section-skeleton {
    padding: 4rem 0;
    background-color: #f9fafb;
}

.section-skeleton .skeleton-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.skeleton-item {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
    border-radius: 0.5rem;
    height: 200px;
    margin-bottom: 1rem;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Clase para marcar cuando la página está completamente cargada */
body.page-loaded #page-loading-indicator {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

body.page-loaded #main-view > div[id^="section-"]:not(:empty) {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   ESTILOS ESPECÍFICOS PARA TIENDA
   ============================================ */

/* Secciones de tienda */
#main-view > div[id^="section-shop-"],
#main-view > div[id^="section-products-"] {
    opacity: 1;
    visibility: visible;
}

#main-view section[id^="shop-"],
#main-view section[id^="products-"] {
    opacity: 1;
    visibility: visible;
    display: block !important;
}

/* Layout personalizado para la tienda */
.products-layout {
    grid-template-columns: 1fr;
    max-width: 100%;
    width: 100%;
    overflow-x: hidden;
}

/* Eliminado: productos-layout ya no usa grid en desktop */

/* Productos grid - permitir que Tailwind controle las columnas */
.products-grid {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.products-grid.products-grid-list {
    grid-template-columns: 1fr;
    justify-items: stretch;
}

.products-grid.products-grid-list article {
    max-width: 100%;
}

.product-card-image {
    width: 100%;
    max-width: 220px;
    height: 240px;
    object-fit: contain;
}

.btn-primary {
    background-color: #0A2342;
    color: #F8F7F4;
    border-radius: 0.75rem;
    font-weight: 600;
    padding: 0.65rem 1.25rem;
    text-align: center;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: #08192e;
    color: #F8F7F4;
    box-shadow: 0 6px 18px -10px rgba(10, 35, 66, 0.45);
}

.btn-outline {
    background-color: #FFFFFF;
    color: rgba(10, 35, 66, 0.75);
    border: 1px solid rgba(216, 195, 165, 0.8);
    border-radius: 0.75rem;
    font-weight: 600;
    padding: 0.65rem 1.25rem;
    text-align: center;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.btn-outline:hover,
.btn-outline:focus {
    background-color: #F8F7F4;
    color: #0A2342;
    border-color: #0A2342;
}

.btn-primary[disabled],
.btn-primary[aria-disabled="true"] {
    background-color: rgba(10, 35, 66, 0.35);
    color: #F0F3F8;
    box-shadow: none;
    cursor: not-allowed;
}

.btn-outline[disabled],
.btn-outline[aria-disabled="true"] {
    color: rgba(10, 35, 66, 0.4);
    border-color: rgba(216, 195, 165, 0.6);
    cursor: not-allowed;
}

.pagination-btn {
    border: 1px solid rgba(10, 35, 66, 0.08);
    border-radius: 9999px;
    color: rgba(10, 35, 66, 0.7);
    background-color: transparent;
    padding: 0.5rem 0.8rem;
    transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.pagination-btn:hover,
.pagination-btn:focus {
    background-color: #FFFFFF;
    color: #0A2342;
    box-shadow: 0 6px 20px -12px rgba(10, 35, 66, 0.6);
}

.pagination-btn.is-active {
    background-color: #0A2342;
    color: #F8F7F4;
    border-color: transparent;
    box-shadow: 0 10px 25px -15px rgba(10, 35, 66, 0.75);
}

.pagination-btn[disabled],
.pagination-btn[aria-disabled="true"] {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}


/* CSS para el slider de rango de precios doble */
.range-slider {
    position: relative;
    width: 100%;
    height: 4px;
    background-color: #e2e8f0;
    border-radius: 4px;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}
.range-slider .progress {
    position: absolute;
    height: 100%;
    background-color: #0A2342;
    border-radius: 4px;
    left: 0%;
    right: 0%;
}
.range-slider input[type="range"] {
    position: absolute;
    width: 100%;
    height: 0;
    top: -6px;
    -webkit-appearance: none;
    pointer-events: none;
    background: none;
}
.range-slider input[type="range"]::-webkit-slider-thumb {
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: #0A2342;
    pointer-events: auto;
    -webkit-appearance: none;
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
    cursor: pointer;
    border: 2px solid white;
}

/* Ocultar la flechita por defecto de <details> */
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }

/* Banner tienda - margen para el menú fixed */
#shop-header {
    margin-top: 80px !important;
}

/* Menú sticky - CSS PURO sin Tailwind */
#main-menu {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 9999 !important;
    background-color: #ffffff !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Asegurar que main no tenga overflow que rompa sticky */
main {
    overflow: visible !important;
}

#main-view {
    overflow: visible !important;
}

/* Remover overflow-x problemático */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Pero permitir scroll vertical */
body {
    overflow-y: auto !important;
}

/* Forzar visibilidad de filtros en desktop */
@media (min-width: 1024px) {
    /* Ocultar botón toggle de filtros en desktop */
    #toggle-filters-btn {
        display: none !important;
    }

    /* Ocultar contenedor del botón toggle en desktop */
    .lg\:hidden.mb-6 {
        display: none !important;
    }

    /* Contenedor padre directo del botón toggle */
    div.lg\:hidden.mb-6 {
        display: none !important;
    }

    /* Mostrar sidebar de filtros en desktop */
    #products-filters-sidebar {
        display: block !important;
        visibility: visible !important;
    }

    /* Contenedor layout en flex row para desktop */
    .products-layout {
        display: flex !important;
        flex-direction: row !important;
    }
}
