/* Estilos generales para la tabla de productos */
#product-list-container {
    max-height: 70vh; /* Altura máxima del 70% de la ventana */
    overflow-y: auto; /* Scroll vertical si el contenido excede la altura */
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
}

.table {
    table-layout: fixed; /* Algoritmo fijo para evitar el "baile" de columnas */
    width: 100%;
    margin-bottom: 0; /* Eliminar margen inferior de la tabla */
}

/* Estilos para las cabeceras de la tabla */
.table thead th {
    background-color: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 10; /* Asegura que la cabecera esté por encima del contenido */
    padding: 0.5rem 0.75rem;
    text-align: center; /* Centrar el texto de la cabecera */
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table thead th:hover {
    background-color: #e9ecef;
}

.table thead th.asc::after {
    content: ' \25B2'; /* Triángulo hacia arriba */
    margin-left: 5px;
}

.table thead th.desc::after {
    content: ' \25BC'; /* Triángulo hacia abajo */
    margin-left: 5px;
}

/* Anchos de columna */
.table thead th:nth-child(1) { width: 40%; } /* Nombre */
.table thead th:nth-child(2) { width: 20%; } /* Precio */
.table thead th:nth-child(3) { width: 20%; } /* €/ud */
.table thead th:nth-child(4) { width: 20%; } /* €⊘/ud */

/* Estilos para las celdas de la tabla */
.table tbody td {
    padding: 0.5rem 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background-color: #fff; /* Fondo blanco por defecto para todas las celdas */
    border-bottom: 1px solid #eee; /* Borde inferior para las celdas */
}

.table tbody tr:last-child td {
    border-bottom: none; /* Eliminar borde inferior de la última fila */
}

/* Indicador de color del supermercado */
.product-row-color-indicator {
    display: inline-block;
    width: 8px;
    height: 2.5rem;
    min-height: 2.5rem;
    margin-right: 0.75rem;
    vertical-align: top;
    flex-shrink: 0;
    border-radius: 1px;
    /* Fuerza la renderización en iOS */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    /* Asegura que siempre tenga un color visible */
    border: 1px solid rgba(0, 0, 0, 0.1);
    /* Optimizaciones específicas para Chrome en iOS */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    position: relative;
    /* Fuerza el layout en Chrome iOS */
    contain: layout style paint;
}

/* Resaltar columna de precio por unidad */
.table thead th.header-price-per-unit,
.table tbody td.price-per-unit {
    background-color: #fff5e6; /* Un naranja muy suave */
    border-bottom-color: #fff5e6; /* Borde del mismo color que el fondo para hacerlo invisible */
}

/* Colores de supermercado para el indicador */
.color-mercadona { 
    background-color: #008000 !important; 
    border-color: #006600 !important;
}
.color-hiperdino { 
    background-color: #FFD700 !important; 
    border-color: #ccac00 !important;
}
.color-alcampo { 
    background-color: #FF0000 !important; 
    border-color: #cc0000 !important;
}
.color-lidl { 
    background-color: #0000FF !important; 
    border-color: #0000cc !important;
}
.color-spar { 
    background-color: #808080 !important; 
    border-color: #666666 !important;
}
.color-primor { 
    background-color: #8A2BE2 !important; 
    border-color: #6a1fb5 !important;
}
.color-druni { 
    background-color: #00CED1 !important; 
    border-color: #00a5a8 !important;
}

/* Estilos para el botón flotante (FAB) */
.fab-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: auto;
    min-width: 100px;
    height: 56px;
    border-radius: 28px;
    background-color: #007bff;
    color: white;
    font-size: 1.2rem;
    padding: 0 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 1000;
}

/* Estilos para los botones de supermercado */
.supermarket-buttons-container {
    display: flex;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 8px;
    margin-bottom: 15px;
    overflow-x: auto;
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
}

.supermarket-btn {
    flex-shrink: 0 !important;
    width: 30px !important;
    height: 30px !important;
    border-radius: 50% !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    font-weight: bold !important;
    color: white !important;
    border: 2px solid transparent !important;
    transition: all 0.2s ease-in-out !important;
    font-size: 0.7rem !important;
}

.supermarket-btn.selected {
    border-color: #007bff !important;
    box-shadow: 0 0 0 0.25rem rgba(0, 123, 255, 0.25) !important;
}

.btn-mercadona { background-color: #008000 !important; }
.btn-hiperdino { background-color: #FFD700 !important; color: #333 !important; }
.btn-alcampo { background-color: #FF0000 !important; }
.btn-lidl { background-color: #0000FF !important; }
.btn-spar { background-color: #808080 !important; }
.btn-primor { background-color: #8A2BE2 !important; }
.btn-druni { background-color: #00CED1 !important; }

/* Estilos para el swipe */
.product-row {
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    
}

.product-row.swiping {
    transition: none;
}

/* Ocultar botones de edición/borrado por defecto */
.edit-button, .delete-button {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 0;
    visibility: hidden;
}

.product-row-wrapper.show-edit .edit-button,
.product-row-wrapper.show-delete .delete-button {
    visibility: visible;
}

.edit-button {
    left: 0;
    background-color: #007bff;
}

.delete-button {
    right: 0;
    background-color: #dc3545;
}

.btn-success:disabled {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
}

/* Estilos para el popup de información del producto */
.product-info-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.product-info-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 90%;
    width: 500px;
    position: relative;
    animation: popup-appear 0.3s ease-out;
}

@keyframes popup-appear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.product-info-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    z-index: 1;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.product-info-close:hover {
    background-color: #f0f0f0;
    color: #333;
}

.product-info-body {
    display: flex;
    padding: 20px;
    gap: 80px;
}

.product-info-image-section {
    width: 120px;
    height: 120px;
    background-color: #f8f9fa;
    border-radius: 12px;
    border: 2px dashed #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.product-info-image-section.has-image {
    border: none;
    background-color: transparent;
}

.product-info-image-placeholder {
    font-size: 2.5rem;
    color: #6c757d;
    cursor: pointer;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.product-info-image-placeholder:hover {
    color: #007bff;
}

.product-info-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
    cursor: pointer;
}

/* Estilos para el carrusel de búsqueda de imágenes */
.image-search-carousel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    max-height: 600px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 10001;
    overflow: hidden;
    opacity: 0;
    animation: carousel-appear 0.2s ease-out forwards;
}

@keyframes carousel-appear {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.image-search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #dee2e6;
    background-color: #f8f9fa;
}

.image-search-title {
    font-weight: 600;
    color: #333;
    font-size: 1rem;
}

.image-search-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.image-search-close:hover {
    background-color: #e9ecef;
}

.image-search-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #666;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.image-search-results {
    display: flex;
    flex-direction: row;
    max-height: 450px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 15px;
    gap: 15px;
    white-space: nowrap;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

.image-search-results::-webkit-scrollbar {
    height: 8px;
}

.image-search-results::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.image-search-results::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.image-search-results::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.image-search-item {
    width: 140px;
    height: 100px;
    flex-shrink: 0;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    object-fit: cover;
    border: 2px solid transparent;
}

.image-search-item:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: #007bff;
}

.product-info-content-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.product-info-color-bar {
    display: none; /* Ya no usamos la barra vertical */
}

.product-info-details {
    flex: 1;
    position: relative;
}

.product-info-main-content {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.product-info-main-content .product-info-quantity {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin-right: 8px;
}

.product-info-main-content .product-info-price {
    font-size: 1.4rem;
    font-weight: 700;
    color: #007bff;
    margin-left: auto;
}

.product-info-prices-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
}

.product-info-price-item {
    text-align: center;
}

.product-info-price-label {
    font-size: 0.85rem;
    color: #6c757d;
    font-weight: 500;
    margin-bottom: 4px;
}

.product-info-price-value {
    font-size: 1.1rem;
    color: #333;
    font-weight: 500;
}

.product-info-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
}

.product-info-title {
    margin: 10px 0 20px 20px;
    font-size: 1.5rem;
    font-weight: 700;
    color: #333;
    line-height: 1.3;
    padding-left: 0;
    text-align: left;
}



.product-info-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
}

.product-info-date {
    font-size: 0.9rem;
    color: #666;
    font-weight: 500;
}

.product-info-supermarket {
    font-size: 0.85rem;
    color: white;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 20px;
    display: inline-block;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Colores específicos para las etiquetas de supermercado en el popup */
.product-info-supermarket.color-mercadona { background-color: #008000; }
.product-info-supermarket.color-hiperdino { background-color: #FFD700; color: #333; }
.product-info-supermarket.color-alcampo { background-color: #FF0000; }
.product-info-supermarket.color-lidl { background-color: #0000FF; }
.product-info-supermarket.color-spar { background-color: #808080; }
.product-info-supermarket.color-primor { background-color: #8A2BE2; }
.product-info-supermarket.color-druni { background-color: #00CED1; }

.product-info-unit {
    font-size: 1.1rem;
    color: #666;
    margin-left: 4px;
    margin-right: 8px;
}

/* Estilos responsivos para el popup */
@media (max-width: 480px) {
    .product-info-content {
        width: 95%;
        margin: 0 10px;
    }
    
    .product-info-body {
        flex-direction: column;
        gap: 15px;
    }
    
    .product-info-image-section {
        width: 100px;
        height: 100px;
        align-self: center;
    }
    
    .product-info-title {
        font-size: 1.1rem;
    }
    
    .product-info-main-content .product-info-price {
        font-size: 1.2rem;
    }
    
    /* Estilos responsive para el carrusel de imágenes */
    .image-search-carousel {
        width: 95%;
        max-height: 80vh;
    }
    
    .image-search-results {
        max-height: 350px;
        gap: 12px;
    }
    
    .image-search-item {
        width: 120px;
        height: 85px;
    }
    
    /* Corrección específica para iOS - indicadores de color */
    .product-row-color-indicator {
        width: 6px;
        height: 2.2rem;
        min-height: 2.2rem;
        margin-right: 0.5rem;
        /* Fuerza la renderización en dispositivos móviles */
        will-change: transform;
        backface-visibility: hidden;
    }
}

/* Reglas específicas para Chrome en iOS */
@supports (-webkit-touch-callout: none) {
    .product-row-color-indicator {
        /* Chrome en iOS necesita estas propiedades adicionales */
        -webkit-appearance: none;
        appearance: none;
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
        /* Asegura que el elemento sea visible */
        opacity: 1 !important;
        visibility: visible !important;
        /* Fuerza el repaint */
        will-change: auto;
    }
    
    /* Asegura que los colores se apliquen correctamente en Chrome iOS */
    .color-mercadona { 
        background: #008000 !important; 
        background-color: #008000 !important;
    }
    .color-hiperdino { 
        background: #FFD700 !important; 
        background-color: #FFD700 !important;
    }
    .color-alcampo { 
        background: #FF0000 !important; 
        background-color: #FF0000 !important;
    }
    .color-lidl { 
        background: #0000FF !important; 
        background-color: #0000FF !important;
    }
    .color-spar { 
        background: #808080 !important; 
        background-color: #808080 !important;
    }
    .color-primor { 
        background: #8A2BE2 !important; 
        background-color: #8A2BE2 !important;
    }
    .color-druni { 
        background: #00CED1 !important; 
        background-color: #00CED1 !important;
    }
}
