/* Product comparison screen.
 *
 * v3 styled this with four LESS files (product-comparison.less and friends) that
 * were never migrated, so v4 rendered the whole comparison unstyled: the header
 * stacked vertically and the value columns inherited `.attribute-value { flex: 0 0 60% }`
 * from component.css, which overflows as soon as there is more than one product.
 *
 * The layout is one grid shared by the header and every attribute row, so the
 * product columns line up with their values. The column count is not known at
 * build time, so it comes from a modifier class on the container — an inline
 * custom property would be cleaner but style-src is not guaranteed to allow it.
 *
 * Colours come from the theme tokens (see component.css for the rationale).
 */

.product-comparison {
    --comparison-columns: 2;
    --comparison-label-width: minmax(0, 1.4fr);
    --comparison-column-width: minmax(0, 1fr);
}

.product-comparison--cols-2 { --comparison-columns: 2; }
.product-comparison--cols-3 { --comparison-columns: 3; }
.product-comparison--cols-4 { --comparison-columns: 4; }
.product-comparison--cols-5 { --comparison-columns: 5; }
.product-comparison--cols-6 { --comparison-columns: 6; }

/* Beyond six the columns stop being readable side by side; the container scrolls
   horizontally instead of squeezing them further. */
.product-comparison--cols-many {
    --comparison-columns: 6;
    --comparison-column-width: minmax(14rem, 1fr);
}

.product-comparison__scroller {
    overflow-x: auto;
}

.product-comparison__grid {
    display: grid;
    grid-template-columns: var(--comparison-label-width) repeat(var(--comparison-columns), var(--comparison-column-width));
    min-width: 100%;
}

/* ---- Toolbar ---------------------------------------------------------- */

.product-comparison__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.product-comparison__search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.product-comparison__search-field {
    min-width: 16rem;
}

/* "Limpiar búsqueda" wraps onto two lines at the button's default width. */
.product-comparison__search button {
    white-space: nowrap;
}

.product-comparison__toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-soft);
    white-space: nowrap;
    cursor: pointer;
}

/* Rows whose products actually differ carry a quiet marker, so they stand out
   even when the "only differences" filter is off. */
.attribute--different > .attribute-label {
    box-shadow: inset 3px 0 0 color-mix(in srgb, var(--color-primary) 55%, transparent);
}

.product-comparison__empty {
    padding: 1.5rem 1rem;
    color: var(--muted);
    text-align: center;
}

/* ---- Product header --------------------------------------------------- */

.product-comparison__header {
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 1.5rem;
    background-color: color-mix(in srgb, var(--surface) 55%, transparent);
}

.product-comparison__product {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    text-align: center;
    border-left: 1px solid var(--line);
}

/* The first cell sits under the label column and holds nothing. */
.product-comparison__product--spacer {
    border-left: none;
}

.product-comparison__carrier-logo {
    max-height: 2.5rem;
    max-width: 100%;
    width: auto;
    object-fit: contain;
}

.product-comparison__carrier-name {
    font-weight: 600;
    color: var(--text-soft);
}

.product-comparison__product-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text);
}

.product-comparison__product-meta {
    font-size: 0.8125rem;
    color: var(--muted);
}

.product-comparison__product-meta strong {
    color: var(--text-soft);
}

/* ---- Attribute rows --------------------------------------------------- */

.benefits-compare-table {
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

/* component.css sizes the two-column (single product) view with flex
   percentages. In the comparison every row — the price block, each coverage
   table and the additional details — is a grid instead, so the percentages have
   to be dropped or the columns overflow the container. Scoped to the whole
   comparison rather than .benefits-compare-table, because the price and details
   rows sit outside that wrapper. */
.product-comparison .attribute {
    display: grid;
    grid-template-columns: var(--comparison-label-width) repeat(var(--comparison-columns), var(--comparison-column-width));
}

.product-comparison .attribute-label,
.product-comparison .attribute-value {
    flex: none;
}

.product-comparison .attribute-value + .attribute-value {
    border-left: 1px solid var(--line);
}

/* Top-level groups (price, each coverage, additional details) each read as their
   own panel, the way .benefits-table frames the single-product view. */
.product-comparison .product-comparison__body > .attribute-group {
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

/* A product that does not carry a benefit renders an em dash rather than an
   empty cell, which next to a neighbouring amount reads as "$0.00".
   See macros/component.html.twig and macros/additional_details.html.twig. */
.attribute-value--absent {
    color: var(--muted);
}

/* ---- Price block ------------------------------------------------------ */

.product-comparison__price-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-soft);
}

.product-comparison__price-line-amount {
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.product-comparison__price-total {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
    text-align: center;
}

.product-comparison__price-total-label {
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.product-comparison__price-amount {
    display: block;
    font-size: 1.875rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
}

.product-comparison__price-interval {
    display: block;
    font-size: 0.8125rem;
    color: var(--muted);
}

.product-comparison__addons {
    margin-top: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.375rem;
    background-color: var(--surface);
    text-align: center;
}

.product-comparison__addons-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-soft);
    margin-bottom: 0.25rem;
}

.product-comparison__addon {
    font-size: 0.875rem;
    color: color-mix(in srgb, var(--color-primary) 45%, var(--text));
}

/* Geometry for the "Opciones Disponibles" link. Written here rather than as
   Tailwind utilities in the template because the build is not regenerated as
   part of this change and py-1.5 is not in the current app.built.css; the
   colours still come from the shared .btn-alternative component class. */
.product-comparison__addon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

/* ---- Narrow screens --------------------------------------------------- */

/* component.css stacks .attribute below 768px, which would put every product's
   value in an unlabelled pile. Keep the grid and let the container scroll. */
@media (max-width: 768px) {
    .product-comparison {
        --comparison-label-width: minmax(9rem, 1fr);
        --comparison-column-width: minmax(11rem, 1fr);
    }

    .product-comparison .attribute {
        flex-direction: row;
    }

    .product-comparison .attribute-label,
    .product-comparison .attribute-value {
        flex: none;
    }

    .product-comparison .attribute-value {
        border-top: none;
        background-color: transparent;
    }
}
