/* --- Card Toggles Details (Análisis, Nutrición y Tiendas) --- */

.product-details-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.product-details-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    width: 100%;
    background-color: transparent;
    border: none;
    padding: 8px 4px;
    margin-top: 12px;
    border-top: 1px solid var(--border-color);
    cursor: pointer;
    font-size: clamp(0.5625rem, 2vw, 0.6875rem);
    font-weight: 500;
    text-transform: uppercase;
    color: var(--main-purple);
    font-family: var(--font-secondary);
    transition: background-color 0.2s ease;
}

.product-details-toggle:hover {
    background-color: color-mix(in srgb, var(--main-purple), transparent 95%);
}

.product-details-toggle .toggle-icon {
    width: 16px;
    height: 16px;
    color: currentColor;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.collapsible-container {
    display: grid;
    gap: 12px;
    overflow: hidden;
    max-height: 500px;
    opacity: 1;
    padding-top: 8px;
    padding-bottom: 4px;
    margin-top: -8px;
}

/* --- Card Toggles Details Collapsed States --- */

body.analysis-collapsed .collapsible-analysis,
body.nutrition-collapsed .collapsible-nutrition,
body.stores-collapsed .collapsible-stores {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
}

body.analysis-collapsed .analysis-toggle,
body.nutrition-collapsed .nutrition-toggle,
body.stores-collapsed .stores-toggle {
    margin-bottom: -4px;
}

body.analysis-collapsed .analysis-toggle .toggle-icon,
body.nutrition-collapsed .nutrition-toggle .toggle-icon,
body.stores-collapsed .stores-toggle .toggle-icon {
    transform: rotate(-90deg);
}

/* 1. Estado inicial: Oculto totalmente */
#products {
    display: none;
}

/* 2. Estado Activo: Se muestran con su layout */
body.results-active #products {
    display: grid;
}

/* 3. Caso especial: Sin resultados */
body.results-active #products:has(.no-results) {
    display: block;
    text-align: center;
}

#products {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    min-height: 40vh;
    gap: 16px;
    padding: 10px 16px 20px 16px;
}

.product {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: fit-content;
    gap: 4px;
    position: relative;
}

.product-card-actions {
    align-self: flex-end;
    margin-bottom: 1px;
    width: auto;
}

.product-main-info {
    display: flex;
    align-items: flex-start;
    gap: 4x;
    width: 100%;
}

.product h2 {
    font-size: clamp(0.6875rem, 3vw, 0.75rem);
    text-align: left;
    font-weight: 500;
    color: var(--text-body);
    line-height: 1.4;
    margin: 0;
    flex-grow: 1;
    text-transform: uppercase;
}

.product-content-wrapper {
    margin-top: auto;
    width: 100%;
}

/* --- Card Product Image --- */

.product-image-wrapper {
    flex: 0 0 85px;
    width: 85px;
}

.product img {
    width: 100%;
    height: 75px;
    max-height: 100px;
    object-fit: contain;
    border-radius: 4px;
    aspect-ratio: 1 / 1;
    will-change: transform, opacity, filter;
}

.product img.loaded {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.product img.loaded[data-reloaded="true"] {
    transition: none;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* --- Card Copy Button --- */

.copy-product-button {
    background-color: transparent;
    border: none;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    transition: color 0.2s ease, transform 0.1s ease;
    opacity: 0.6;
}

.copy-product-button:hover {
    color: var(--main-purple);
    transform: scale(1.1);
}

.copy-product-button:active {
    transform: scale(0.95);
}

.copy-product-button .clipboard-icon,
.copy-product-button .clipboard-icon-success {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

/* --- Card Store and Prices Info --- */

ul.stores {
    width: 100%;
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 10px 6px;
}

/* 2. La etiqueta de cada tienda */

.stores li {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px;
    border-radius: 4px;
    background-color: transparent;
    border: 1.25px solid var(--border-color);
    text-align: left;
    min-height: 70px;
    box-sizing: border-box;
    width: 100%;
    position: relative;
}

/* 3. Contenedor del nombre */

.store-info {
    width: 100%;
    margin: 0;
}

.store-info .location-icon-svg {
    display: none;
}

/* 4. Estilo para el nombre de la tienda */

ul.stores li .store-info>a.store-link,
ul.stores li .store-info>span.store-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: clamp(0.52rem, 2vw, 0.55rem);
    font-family: var(--font-secondary);
    text-transform: uppercase;
    font-weight: 500;
    color: var(--text-body);
    line-height: 1.25;
    margin: 0;
    opacity: 0.9;
}

/* 5. Contenedor del precio */

.price-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-top: 6px;
    padding: 0;
}

/* 6. Estilo del precio principal */

ul.stores li .price {
    font-size: clamp(0.85rem, 2.5vw, 0.95rem);
    font-weight: 700;
    color: var(--text-main);
    line-height: 0.85;
    letter-spacing: var(--smart-spacing);
    display: block;
}

.price .currency-symbol {
    font-size: 0.60em;
    vertical-align: top;
    margin-top: 0.1em;
    font-weight: 700;
    display: inline-block;
    margin-right: 1px;
}

/* --- Price Range Penalty --- */

.price .price-range {
    font-size: 0.8em;
    font-weight: 500;
}

.stores li.is-price-range {
    color: var(--text-muted);
    opacity: 0.7;
}

/* --- Card Details Icon --- */

.details-indicator-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    color: var(--text-muted);
    opacity: 0.8;
    margin-left: 4px;
    flex-shrink: 0;
    transition: color 0.1s ease, opacity 0.1s ease;
}

ul.stores li.clickable:hover .details-indicator-icon {
    color: var(--main-purple);
    opacity: 1;
}

ul.stores li.highlighted-store .details-indicator-icon {
    color: var(--main-focus);
    opacity: 1;
}

/* --- Card Expire Label --- */

.price-expiry-info {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 6px;
    font-size: clamp(0.5rem, 2vw, 0.5625rem);
    font-weight: 600;
    color: var(--text-inverse);
    background-color: var(--status-alert);
    border-radius: 4px;
}

ul.stores li:has(.price-expiry-info) {
    grid-column: 1 / -1;
}

/* --- Card Highlight Store --- */

.stores li.highlighted-store {
    background-color: color-mix(in srgb, var(--main-purple), transparent 90%);
    border: 1px solid var(--main-focus);
    transition: all 0.2s ease-in-out;
}

.stores li.highlighted-store .store-name {
    font-weight: 900 !important;
    color: var(--main-purple) !important;
}

/* --- Card Add to Budget Button (Base) --- */

.add-to-budget {
    width: 100%;
    min-height: 36px;
    padding: 4px 2px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 1;
    flex-grow: 0;

    /* Colores y Bordes */
    background-color: var(--bg-main);
    color: var(--main-purple);
    border: 1px solid var(--main-purple);
    border-radius: 4px;

    /* Tipografía */
    font-size: clamp(0.65rem, 3.0vw, 0.90rem);
    font-weight: 500;
    line-height: 1;
    text-align: center;
    text-transform: initial;

    /* Gestión de Texto */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    /* Interacción */
    cursor: pointer;
    margin-top: 12px;
    transition: all 0.2s ease;
    letter-spacing: var(--smart-spacing);
}


.add-to-budget:hover {
    background-color: var(--bg-hover);
}

.add-to-budget:active {
    background-color: var(--main-purple);
    color: var(--text-inverse);
    border-color: var(--main-purple);
}

/* --- Card Look --- */

.status-nuevo-look {
    background-color: var(--status-success);
    color: var(--text-inverse);
}

.status-viejo-look {
    background-color: var(--text-muted);
    color: var(--text-inverse);
}

/* --- Look Image Slider Styles --- */

.image-slider-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: 4px;
}

.slider-wrapper {
    display: flex;
    width: 200%;
    height: 100%;
    transition: none;
}

.slider-item {
    width: 50%;
    height: 100%;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slider-item img {
    width: 100%;
    height: 100%;
    margin-top: 15px;
    object-fit: contain;
    display: block;
}

/* --- Botones de Navegación del Slider --- */

.slider-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(0, 0, 0, 0.3);
    color: var(--main-white);
    border: none;
    padding: 8px 6px;
    border-radius: 4px;
    cursor: pointer;
    z-index: 10;
    opacity: 0.25;
    transition: opacity 0.3s ease, background-color 0.3s ease;
    line-height: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-slider-container:hover .slider-nav-btn {
    opacity: 1;
}

.slider-nav-btn:hover {
    background-color: rgba(0, 0, 0, 0.6);
}

.slider-nav-btn.prev {
    left: 8px;
}

.slider-nav-btn.next {
    right: 8px;
}

/* --- Card Labels & Status --- */

.product-labels-container {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    pointer-events: none;
}

.product-status-label {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    font-size: clamp(0.45rem, 2vw, 0.55rem);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-radius: 2px;
    line-height: 1;
    white-space: nowrap;
}

/* --- Card Status Modifiers --- */

.product-status-label.status-nuevo {
    background-color: color-mix(in srgb, var(--status-success), transparent 85%);
    color: var(--status-success);
    border: 1px solid color-mix(in srgb, var(--status-success), transparent 80%);
}

.product-status-label.status-lanzamiento {
    background-color: var(--status-warning);
    color: #212529;
    font-weight: 800;
}

.product-status-label.status-preguntar-por {
    background-color: var(--main-purple);
    color: var(--text-inverse);
}

/* --- Card AI Label (Imagine Result) --- */

.product-status-label.status-recomendado {
    background: linear-gradient(135deg, var(--main-purple-action), var(--main-focus));
    color: white;
    border: none;
    opacity: 0.95;
}

body.dark-mode .product-status-label.status-recomendado {
    background: linear-gradient(135deg, var(--main-purple), var(--main-purple-action));
    color: var(--text-inverse);
}

/* --- Card Labels + Assets (External Link) --- */

.store-info .store-link {
    color: var(--text-main);
    text-decoration: none;
    display: inline;
    cursor: pointer;
    transition: color 0.2s ease;
}

.store-info .store-link svg {
    width: 1em;
    height: 1em;
    opacity: 0.8;
    display: inline-block;
    vertical-align: baseline;
    margin-left: 3px;
    margin-bottom: -1px;
}

.store-info .store-link:hover {
    text-decoration: underline;
    color: var(--main-purple);
}

/* --- Card Labels + Assets (Nutrition Styles) --- */

.extra-info-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.8rem;
    margin-top: 0.3rem;
    width: 100%;
}

.nutrition-block-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.18rem;
    margin-top: 0.35rem;
}

.nutrition-block {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.22rem;
    width: 100%;
}

.nutrition-item-shape {
    border-radius: 4px;
    background-color: transparent;
    padding: 0.25em;
    width: 3rem;
    height: 3rem;
    aspect-ratio: 1 / 1;
    min-width: 0;
    max-width: none;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-sizing: border-box;
    border: 1px solid var(--border-color);
    font-size: clamp(0.375rem, 2vw, 0.5rem);
}

.nutrition-name {
    font-size: clamp(0.375rem, 2vw, 0.5625rem);
    color: var(--text-main);
    font-weight: 500;
    margin-bottom: 0.12em;
    line-height: 1;
    font-family: var(--font-secondary);
    text-transform: uppercase;
}

.nutrition-value {
    font-size: clamp(0.50rem, 3vw, 0.60rem);
    font-weight: 700;
    letter-spacing: var(--smart-spacing);
    color: var(--text-muted);
    margin: 0;
    line-height: 1;
}

.nutrition-unit-info {
    font-size: clamp(0.3125rem, 1.5vw, 0.5rem);
    font-weight: 500;
    color: var(--text-main);
    margin-top: 0.12rem;
    line-height: 1.1;
    text-align: center;
    opacity: 0.8;
    width: 100%;
}

.ingredients-container {
    text-align: left;
    padding: 0 8px;
}

.ingredients-link {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 4px 8px;
    border-radius: 4px;
    background-color: var(--bg-main);
    border: 1.25px solid var(--main-purple);
    color: var(--main-purple);
    font-size: clamp(0.5rem, 2vw, 0.625rem);
    font-weight: 500;
    font-family: var(--font-secondary);
    text-transform: uppercase;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.ingredients-icon {
    width: 1.3em;
    height: 1.3em;
    flex-shrink: 0;
}

.ingredients-link:hover {
    background-color: color-mix(in srgb, var(--main-purple), transparent 95%);
    border-color: color-mix(in srgb, var(--main-purple), transparent 60%);
}

/* --- Card Labels + Assets (Fluoride Styles) --- */

.fluoride-info-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    margin-bottom: 8px;
}

.fluor-badge-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    text-align: center;
    font-size: clamp(0.55rem, 1.8vw, 0.65rem);
    line-height: 0.9;
    margin: 0;
    justify-content: center;
    letter-spacing: -0.02em;
    padding: 0 4px;
}

.fluor-badge-line .fluor-badge-icon {
    width: 1.2em;
    height: 1.2em;
    flex-shrink: 0;
    margin-top: -2px;
}

.fluor-badge-recommended {
    color: var(--main-purple);
    font-weight: 800;
}

.fluor-badge-no-info {
    color: var(--status-alert);
    font-weight: 800;
}

.product .product-name-ppm {
    font-weight: 700;
    font-size: clamp(0.5625rem, 2vw, 0.625rem);
    border: 1px solid var(--text-muted);
    border-radius: 4px;
    padding: 2px 4px;
    margin: 0;
    color: var(--text-muted);
    line-height: 1.2;
    cursor: help;
    display: inline-block;
}

.product-title-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    margin-bottom: 5px;
    padding: 0 5px;
    box-sizing: border-box;
}

.product-title-container h2 {
    margin-bottom: 0;
}

/* --- Card Labels + Assets (Price Per Unit) --- */

.store-price-per-unit {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    margin-top: 4px;
    font-size: clamp(0.55rem, 2vw, 0.60rem);
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: var(--smart-spacing);
    opacity: 0.9;
    line-height: 1;
    white-space: nowrap;
}

/* --- Product Analysis Block --- */

.product-analysis-block {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: center;
    gap: 8px 10px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: transparent;
}

.analysis-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex-shrink: 0;
    padding: 0 5px;
    font-size: clamp(0.625rem, 2vw, 0.75rem);
    font-weight: 400;
    color: var(--text-body);
    letter-spacing: -0.01em;
}

.analysis-item>span {
    display: block;
    margin-bottom: 3px;
    font-size: clamp(0.5rem, 2vw, 0.5625rem);
    font-weight: 500;
    text-transform: uppercase;
    color: var(--text-muted);
    font-family: var(--font-secondary);
}

.analysis-item strong {
    display: inline-flex !important;
    align-items: baseline;
}

.currency-symbol {
    font-size: inherit;
    vertical-align: baseline;
    font-weight: inherit;
    display: inline;
}

/* --- Card Labels + Assets (Best Value) --- */

.value-badge-container {
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.value-badge {
    display: inline-flex;
    align-items: center;
    font-size: clamp(0.45rem, 1.5vw, 0.5rem);
    text-transform: uppercase;
    font-weight: 600;
    line-height: 1;
}

.value-badge.value-badge-good-value {
    background-color: #17a2b8;
    color: var(--text-inverse);
    padding: 4px 8px;
    border-radius: 4px;
}

.value-badge-container:not(:empty) {
    height: auto;
    margin: 5px 0 8px 0;
}

.value-price-highlight {
    display: flex;
    align-items: center;
    color: #17a2b8;
    font-weight: 900;
}

/* --- Media Queries --- */

@media (max-width: 700px) {


    /* --- Universal rule: grid stores --- */
    body.results-active #products ul.stores {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
        gap: 10px 6px;
        align-items: stretch;
        margin-top: 8px;
    }

    body.results-active #products ul.stores li {
        padding: 8px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .value-badge.value-badge-good-value {
        padding: 4px 6px;
    }

    /* --- Grid: Se aplica cuando el toggle NO está chequeado --- */

    body.results-active #products.grid-view {
        grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
        gap: 12px;
        padding: 4px 12px 15px 12px;

        & .product {
            padding: 10px;
            align-items: flex-start;
        }

        & .product-main-info {
            flex-direction: column;
            align-items: flex-start;
            gap: 10px;
        }

        & .product-image-wrapper {
            width: 100%;
            margin-bottom: 4px;
        }

        & .product img {
            width: 100%;
            height: 95px;
            object-fit: contain;
        }

        & .product h2 {
            margin: 0;
            line-height: 1.3;
            text-align: left;
        }

        & .extra-info-container {
            gap: 0.5rem;
            margin-top: 0.2rem;
            align-items: flex-start;
        }

        & .nutrition-block-container {
            gap: 0.1rem;
            margin-top: 0.25rem;
            align-items: flex-start;
        }

        & .nutrition-block {
            gap: 0.18rem;
            justify-content: center;
        }

        & .nutrition-item-shape {
            padding: 0.35em 0.20em;
            min-width: 36px;
            min-height: 4.2em;
        }

        & .nutrition-unit-info {
            margin-top: 0.1rem;
        }

        & .ingredients-link {
            padding: 3px 6px;
            gap: 2px;
        }

        & .ingredients-icon {
            width: 1.1em;
            height: 1.1em;
        }

        & .store-price-per-unit {
            margin-top: 1.5px;
        }

        & .price-expiry-info {
            margin-top: 1px;
            padding: 1.5px 3px;
        }
    }

    body.results-active #products.grid-view ul.stores {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
        gap: 8px 6px;
        max-height: 360px;
        overflow-y: auto;
        padding-right: 5px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    /* --- Chips Store Fade --- */

    body.results-active #products.grid-view .collapsible-stores {
        position: relative;
    }

    body.results-active #products.grid-view .collapsible-stores::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 15px;
        background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #fff 80%);
        pointer-events: none;
    }

    body.dark-mode.results-active #products.grid-view .collapsible-stores::after {
        background: linear-gradient(to bottom, rgba(40, 42, 45, 0), #282a2d 80%);
    }

    /* --- Lista: se aplica cuando SÍ está chequeado el toggle --- */
    body.results-active #products.list-view {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 4px 20px 20px 20px;
    }
}

@media (max-width: 400px) {
    body.results-active #products.grid-view {
        & .product img {
            width: 100%;
            height: 80px;
            object-fit: contain;
        }
    }
}

@media (max-width: 381px) {
    body.results-active #products.grid-view {
        & ul.stores li:only-child {
            grid-column: 1 / -1;
        }
    }
}