/*
 * Device Comparison widget (ADO #124646, SRS Part14 §3.1.4)
 * Scoped under .um-device-compare. Set inline by DeviceComparison.cshtml:
 *   --dc-cols      configured column count (2|3|4) — decides how wide ONE column is
 *   --dc-rendered  columns actually rendered (fewer when fewer devices are selected)
 * Tablet (768–1023) steps "4 columns" down to 3 (hides [data-col="3"]).
 * Mobile is FIXED at 2 columns: the media query forces --dc-cols and hides every
 * [data-col="2"] / [data-col="3"] cell (SRS #1).
 */

.um-device-compare {
    padding: 56px 0;
    /* No section background (AB#140903, AB#140983): Figma puts the widget straight on the
       page grey (BG Default #f5f5f7), the same grey as the 40px gap around it. */
    /* #134040: the gutter between columns. One variable because the track width below
       subtracts it, and .dc-columns / .dc-cat-values must stay on the same grid (#133969). */
    --dc-gap: 20px;
}

/* AB#140828: a column keeps the width it has in a full row of --dc-cols, however many devices
   are rendered (1 device + "3 columns" used to stretch to the full width).
   Reopen 29/09: the category rule under each row must also stop at the rendered columns instead
   of running across the page. So the WIDTH of the rendered block is computed once, on every
   direct child of .dc-inner that carries columns (heads, category rows, CTA row):
   N rendered tracks of one full-row column each + (N - 1) gaps, centred. Inside that box the
   grids use plain 1fr tracks, which come out exactly one column wide.
   The width cannot live in a shared custom property: `%` resolves against the element that
   USES the variable, so each grid would compute a different value. */
.um-device-compare .dc-columns,
.um-device-compare .dc-category-block {
    width: calc(var(--dc-rendered, var(--dc-cols, 2)) * (100% - (var(--dc-cols, 2) - 1) * var(--dc-gap)) / var(--dc-cols, 2)
        + (var(--dc-rendered, var(--dc-cols, 2)) - 1) * var(--dc-gap));
    margin-left: auto;
    margin-right: auto;
}

.um-device-compare .dc-columns,
.um-device-compare .dc-cat-values {
    grid-template-columns: repeat(var(--dc-rendered, var(--dc-cols, 2)), minmax(0, 1fr));
}

.um-device-compare .dc-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 32px;
}

.um-device-compare .dc-header {
    text-align: center;
    margin-bottom: 34px;
}

.um-device-compare .dc-header h2 {
    margin: 0 0 12px;
    font-size: 44px;
    line-height: 1.1;
    font-weight: 700;
    color: #222;
}

.um-device-compare .dc-subtitle {
    margin: 0;
    font-size: 17px;
    line-height: 1.5;
    color: #555;
}

/* ── column grid (device headers + bottom CTA row) ─────────────────────────── */

.um-device-compare .dc-columns {
    display: grid;
    /* grid-template-columns: shared rule at the top of the file (AB#140828). Equal fixed
       tracks, so one column with wide content (many swatches, #133966) cannot steal width
       from the others (#133969) — what minmax(0,1fr) used to guarantee.
       row-gap 0: with the subgrid below, each head block sits in its own shared row —
       vertical rhythm stays owned by the blocks' margins, not the grid gap.
       column-gap 20px (#134040) — it is the ONLY thing separating the [Model] dropdowns now
       that they fill their column, and .dc-cat-values below must carry the same value or the
       comparison rows stop lining up under the heads (the #133969 alignment). */
    gap: 0 var(--dc-gap);
    align-items: start;
}

.um-device-compare .dc-device-head {
    text-align: center;
    min-width: 0;
}

/* #133969 — align the columns' blocks (select / image / colours / brand / model / price / CTA)
   on shared rows, so a column with taller content (18 colour swatches, 2-line names…)
   doesn't push its siblings out of line. Browsers without subgrid fall back to the
   per-column block flow — equal track widths still come from the shared fixed-track rule.
   AB#140835 added the price row (7th): a column missing its RRP still gets the full row
   height, which is the BA's "price blocks the same height in every column" rule. */
@supports (grid-template-rows: subgrid) {
    .um-device-compare .dc-columns:not(.dc-cta-row) {
        grid-template-rows: repeat(7, auto);
    }

    .um-device-compare .dc-device-head {
        display: grid;
        grid-template-rows: subgrid;
        grid-row: span 7;
    }
}

.um-device-compare .dc-select-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* #134040 — the [Model] boxes must sit 20px apart. Two things did it before: the grid's 28px
   column gap, and a 320px cap on a ~395px column that centred the box and added ~37px of empty
   card on each side, so the boxes read ~100px apart. Figma (17506-36462) draws the dropdown
   filling its column edge-to-edge, aligned with the device column below it, with a 20px gutter —
   so the cap goes and the gutter becomes the single source of the spacing. */
.um-device-compare .dc-select-box {
    position: relative;
    display: flex;
    align-items: center;
    /* a <div> is content-box by default (the <select> it replaced was border-box): without
       this, width:100% + padding + border spills into the next column on pages without a
       global box-sizing reset */
    box-sizing: border-box;
    width: 100%;
    margin: 0 auto 22px;
    padding: 10px 36px 10px 14px;
    font-size: 15px;
    font-weight: 600;
    color: #222;
    background-color: #fff;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23222' stroke-width='2' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    border: 1px solid #d9d9d9;
    border-radius: 8px;
}

/* AB#140834 (BA 20/10): a long model name wraps to at most 2 lines, a longer one ends in "…"
   on the 2nd. The full name stays in the picker, the select's title and under the image
   (.dc-model). In the shared-row grid the box stretches to the row, so a 1-line box next to a
   2-line one is just as tall, its text centred. */
.um-device-compare .dc-select-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
    width: 100%;
    /* a 1-line box is as tall as the old <select> (42px, mobile 38px); min-height keeps that
       line when a device has no model name */
    line-height: 20px;
    min-height: 20px;
    text-align: left;
}

/* The real control: transparent and covering the whole box, so a tap anywhere opens the
   native picker and keyboard / screen readers keep a plain <select>. 16px stops iOS zooming
   the page on focus (the old 14px mobile select did zoom); only the open option list on
   desktop shows that size. */
.um-device-compare .dc-select {
    position: absolute;
    /* -1px: the containing block is the box's padding box, so this also covers its border */
    top: -1px;
    left: -1px;
    width: calc(100% + 2px);
    height: calc(100% + 2px);
    margin: 0;
    /* tap highlight follows the rounded box, not a square */
    border-radius: inherit;
    font-size: 16px;
    opacity: 0;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

/* the select is invisible, so its focus ring is drawn on the box */
.um-device-compare .dc-select-box:has(.dc-select:focus-visible) {
    outline: 2px solid #FF7300;
    outline-offset: 2px;
}

/* browsers without :has (Firefox < 121, Safari < 15.4): the select is the box's only
   focusable child, so :focus-within marks the same focus (on taps too) */
@supports not selector(:has(*)) {
    .um-device-compare .dc-select-box:focus-within {
        outline: 2px solid #FF7300;
        outline-offset: 2px;
    }
}

.um-device-compare .dc-image-wrap {
    margin-bottom: 18px;
    /* in the shared-row grid the image row is as tall as the TALLEST image —
       bottom-align shorter images onto the swatch row (no-op without subgrid) */
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.um-device-compare .dc-image {
    width: 100%;
    max-width: 258px;   /* recommended asset 516×387 @2x */
    height: auto;
    display: block;
    margin: 0 auto;
}

/* display:block above out-ranks the UA [hidden] rule — a device without an image (or whose
   image failed to load) must really disappear, not show a broken-image icon. */
.um-device-compare .dc-image[hidden] {
    display: none;
}

/* ── colour swatches + names (SRS #4) ─────────────────────────────────────── */

.um-device-compare .dc-colors {
    margin-bottom: 16px;
    min-height: 46px;
}

.um-device-compare .dc-swatches {
    display: flex;
    /* #133966 — device-detail can hold many colours (QA: 18); without wrapping the
       centered row overflows BOTH edges of the column and paints over its neighbours. */
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
    max-width: 100%;
}

.um-device-compare .dc-swatch {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

/* The 2px gap between dot and ring is transparent (Figma swatch-ring), not a painted white
   ring: with no section background a white box-shadow spacer shows as a white halo. */
.um-device-compare .dc-swatch.is-active {
    outline: 2px solid #FF7300;
    outline-offset: 2px;
}

.um-device-compare .dc-color-names {
    font-size: 13px;
    line-height: 1.4;
    color: #7e7e7e;
    overflow-wrap: break-word;
}

/* ── brand / model / CTA (SRS #5 #6 #7) ───────────────────────────────────── */

.um-device-compare .dc-brand {
    color: #7e7e7e;
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 2px;
}

.um-device-compare .dc-model {
    margin: 0 0 14px;
    font-size: 22px;
    line-height: 1.2;
    font-weight: 700;
    color: #222;
}

/* ── price (AB#140835, BA rule 02/10, Figma 18493-61519) ─────────────────────
   Line 1: prefix + amount + suffix, small / large bold / small. Line 2: RRP struck through.
   Same sizes as Device With Capacity (.dwc-price*), which shows these same deviceitem fields. */
.um-device-compare .dc-price {
    margin-bottom: 14px;
}

.um-device-compare .dc-price.is-empty {
    margin-bottom: 0;
}

.um-device-compare .dc-price-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: 4px;
}

/* An empty part leaves no gap behind; with no amount the adapter sends no prefix/suffix either,
   so the whole line collapses. */
.um-device-compare .dc-price-line > :empty,
.um-device-compare .dc-price-rrp:empty {
    display: none;
}

.um-device-compare .dc-price-prefix,
.um-device-compare .dc-price-suffix {
    font-size: 13px;
    color: #666;
}

.um-device-compare .dc-price-amount {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
    color: #1a1a1a;
}

.um-device-compare .dc-price-rrp {
    margin-top: 2px;
    font-size: 13px;
    color: #999;
    text-decoration: line-through;
}

.um-device-compare .dc-ctas {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    min-width: 0;
}

/* #133944 — Figma (node 17506-36462): CTA fills the card width at 48px tall
   ("354.67 Fill × 48 Hug"), not a 160px content-hugging pill. */
.um-device-compare .dc-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 48px;
    padding: 10px 22px;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    border: 1px solid #FF7300;
    color: #FF7300;
    background: #fff;
    transition: background 0.2s, color 0.2s;
}

.um-device-compare .dc-cta:first-child {
    background: #FF7300;
    color: #fff;
}

.um-device-compare .dc-cta-row {
    margin-top: 26px;
}

/* ── comparison rows (SRS #8 #9) ───────────────────────────────────────────
   Figma node 17506-36424 "Compare_item": one row = a 1px #E6E6E6 rule + one cell per
   device column (vertical stack, 8px gap, 16px vertical padding). The category label is
   REPEATED inside every cell as a small grey caption above the value — desktop and mobile
   (SRS mocks image65 / image66). Cell value = bold headline + grey description block. */

.um-device-compare .dc-category-block {
    margin-top: 26px;
    border-top: 1px solid #e6e6e6;
}

.um-device-compare .dc-cat-values {
    display: grid;
    /* columns: shared rule at the top of the file; gap = .dc-columns' gap (#134040) */
    gap: var(--dc-gap);
}

.um-device-compare .dc-cell {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 0;
    min-width: 0;
}

.um-device-compare .dc-cat-label {
    font-size: 12px;
    line-height: 1.2;
    font-weight: 600;
    color: #999;
}

.um-device-compare .dc-spec-headline {
    font-size: 16px;
    line-height: 1.2;
    font-weight: 600;
    color: #1D1D1F;
    overflow-wrap: break-word;
}

.um-device-compare .dc-spec-detail {
    font-size: 14px;
    line-height: 18px;
    color: #86868B;
    /* multi-line devicecompare-spec.details must keep its line breaks */
    white-space: pre-line;
    overflow-wrap: break-word;
}

/* label alignment — device-comparison.categoryalignment (default left) */
.um-device-compare.dc-cat-left   .dc-cat-label { text-align: left; }
.um-device-compare.dc-cat-center .dc-cat-label { text-align: center; }
.um-device-compare.dc-cat-right  .dc-cat-label { text-align: right; }

/* spec value alignment — device-comparison.specsalignment (default center) */
.um-device-compare.dc-spec-left   .dc-spec { text-align: left; }
.um-device-compare.dc-spec-center .dc-spec { text-align: center; }
.um-device-compare.dc-spec-right  .dc-spec { text-align: right; }

.um-device-compare .dc-spec {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ── mobile: FIXED at 2 device columns (SRS #1) ───────────────────────────── */

@media (max-width: 767px) {
    .um-device-compare {
        padding: 40px 0;
        /* beats the inline style="--dc-cols:3" so both grids collapse to 2 tracks */
        --dc-cols: 2 !important;
        /* column 3 is display:none on mobile, so never render a 3rd (empty) track */
        --dc-rendered: var(--dc-rendered-mobile, 2) !important;
        --dc-gap: 14px;
    }

    .um-device-compare .dc-inner { padding: 0 18px; }
    .um-device-compare .dc-header h2 { font-size: 30px; }
    .um-device-compare .dc-subtitle { font-size: 15px; }
    .um-device-compare .dc-select-box { font-size: 14px; padding: 9px 32px 9px 12px; margin-bottom: 16px; }
    .um-device-compare .dc-select-text { line-height: 18px; min-height: 18px; }
    .um-device-compare .dc-model { font-size: 17px; }
    /* half-width columns: the amount steps down with the model name so "RM 126" stays on one line */
    .um-device-compare .dc-price-amount { font-size: 20px; }
    .um-device-compare .dc-price-prefix,
    .um-device-compare .dc-price-suffix,
    .um-device-compare .dc-price-rrp { font-size: 12px; }
    .um-device-compare .dc-cta { min-width: 0; width: 100%; font-size: 14px; padding: 9px 14px; }
    .um-device-compare .dc-spec-headline { font-size: 15px; }
    .um-device-compare .dc-spec-detail { font-size: 13px; line-height: 17px; }

    /* the third (and fourth) desktop column disappears entirely on mobile */
    .um-device-compare [data-col="2"],
    .um-device-compare [data-col="3"] { display: none; }
}

/* ── tablet: "4 columns" steps down to 3 — four device columns are too narrow below 1024 ── */

@media (min-width: 768px) and (max-width: 1023px) {
    .um-device-compare[data-cols-config="4"] {
        --dc-cols: 3 !important;
        --dc-rendered: var(--dc-rendered-tablet, 3) !important;
    }

    .um-device-compare[data-cols-config="4"] [data-col="3"] { display: none; }
}
