/* ═══════════════════════════════════════════════════════════════════════
   CART — mini-cart drawer (every page) + the full /cart page.
   Loaded globally in _Layout.cshtml, right after layout.css — the drawer
   markup lives in the layout itself. Composes tokens.css/theme.css/
   components.css (.drawer, .btn, .badge, .empty-state, .state-banner,
   .icon) — nothing here redeclares a colour, radius, spacing or shadow.
   ═══════════════════════════════════════════════════════════════════════ */

/* Body-level scroll lock while the mini-cart drawer is open. */
html.cart-drawer-open { overflow: hidden; }

/* ── Cart line — the ONE row template shared by the drawer and the full
   page (cart.js:lineHtml). Compact by default; the full page widens the
   media/gap via .cart-lines (not .cart-lines--compact). ─────────────── */

.cart-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-4); }
.cart-lines--compact { gap: var(--space-4); }

.cart-line {
    display: grid;
    grid-template-columns: 64px 1fr auto;
    grid-template-areas:
        "media info total"
        "media controls total";
    column-gap: var(--space-3);
    row-gap: .4rem;
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--line);
}
.cart-lines--compact .cart-line { grid-template-columns: 56px 1fr auto; }
.cart-line:last-child { border-bottom: 0; padding-bottom: 0; }

.cart-line__media {
    grid-area: media;
    width: 64px;
    height: 64px;
    border-radius: var(--radius-sm);
    background: var(--tray);
    border: 1px solid var(--line);
    overflow: hidden;
    align-self: start;
}
.cart-lines--compact .cart-line__media { width: 56px; height: 56px; }
.cart-line__media img { width: 100%; height: 100%; object-fit: contain; padding: .5rem; }

.cart-line__info { grid-area: info; min-width: 0; display: flex; flex-direction: column; gap: .2rem; }
.cart-line__name {
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    color: var(--ink);
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cart-line__name:hover { color: var(--brand); }
.cart-line__variant {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    font-size: var(--text-xs);
    color: var(--ink-soft);
    background: var(--paper-muted);
    border-radius: var(--radius-sm);
    padding: .1rem .45rem;
}
.cart-line__unit-price { font-size: var(--text-sm); color: var(--ink-soft); }

.cart-line__controls { grid-area: controls; display: flex; align-items: center; gap: var(--space-3); }

.cart-line__total {
    grid-area: total;
    font-family: var(--font-display);
    font-weight: var(--weight-bold);
    font-size: var(--text-base);
    color: var(--ink);
    white-space: nowrap;
    align-self: start;
}

/* ── Quantity stepper — same shape as .pdp-qty, cart-scoped so this global
   stylesheet never collides with pdp.css's page-scoped rules. ─────────── */

.cart-qty {
    display: inline-flex;
    align-items: stretch;
    min-height: 44px; /* stretches __btn and __input to a real tap/click target (WCAG 2.5.5) */
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.cart-qty__btn {
    width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--paper-muted);
    border: 0;
    font-size: 1rem;
    color: var(--ink);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-standard);
}
.cart-qty__btn:hover { background: var(--brand-tint); color: var(--brand-deep); }
.cart-qty__input {
    width: 40px;
    text-align: center;
    border: 0;
    border-inline: 1px solid var(--line-strong);
    font: inherit;
    font-size: var(--text-sm);
    color: var(--ink);
    background: var(--paper);
}
.cart-qty__input:focus { outline: none; background: var(--brand-tint); }

.cart-line__remove {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: none;
    border: 0;
    color: var(--ink-soft);
    font-size: var(--text-sm);
    cursor: pointer;
    padding: .2rem .3rem;
    border-radius: var(--radius-sm);
    transition: color var(--duration-fast) var(--ease-standard), background var(--duration-fast) var(--ease-standard);
}
.cart-line__remove:hover { color: var(--danger-base); background: var(--danger-tint); }

/* ── Mini-cart drawer footer (structure only — .drawer/.drawer__footer are
   components.css primitives) ─────────────────────────────────────────── */

.mini-cart__subtotal-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    font-size: var(--text-md);
    font-weight: var(--weight-bold);
    color: var(--ink);
    margin-bottom: .3rem;
}
.mini-cart__note {
    display: flex;
    align-items: flex-start;
    gap: .4rem;
    font-size: var(--text-xs);
    color: var(--ink-soft);
    line-height: var(--leading-normal);
    margin: 0 0 var(--space-4);
}
.mini-cart__actions { display: flex; flex-direction: column; gap: .5rem; }
.mini-cart__actions .btn { width: 100%; }
.mini-cart__checkout-reason {
    margin: .5rem 0 0;
    font-size: var(--text-xs);
    color: var(--ink-faint);
    text-align: center;
}

/* ── Full /cart page ──────────────────────────────────────────────────────
   Two surfaces: the items panel (a real 4-column "table" built on top of
   the SAME <ul class="cart-lines"><li class="cart-line"> markup cart.js
   already renders for the mini-cart drawer — see cart.js:lineHtml) and the
   sticky order summary. Everything below is scoped under `.cart-lines-panel`
   so the mini-cart drawer's compact card look (the unscoped `.cart-line`
   rules above) is untouched — same pattern the file already used for the
   88px media override this replaces.
   ═══════════════════════════════════════════════════════════════════════ */

.cart-page { padding-block: var(--space-4) var(--space-16); }
.cart-page__title { font-size: var(--text-3xl); font-weight: var(--weight-bold); color: var(--ink); margin: 0 0 var(--space-6); }

.cart-page__loading { display: flex; flex-direction: column; gap: var(--space-4); }
.cart-page__loading .skeleton { height: 84px; }

/* ── Layout tiers (founder brief §67) ─────────────────────────────────────
   ≥1280 (--bp-xl, the container ceiling): items column flexible, summary a
   fixed 428px, 32px (--space-8) gap — §79's "820 + 32 + 428 = 1280" is the
   sum at the container's own max-width; the container itself reserves
   1.5rem/side padding (base.css border-box + layout.css .container), so the
   flexible items track settles a bit under the literal 820px on today's
   1280px container rather than overflowing it. RTL source order already
   puts the items panel (first in the DOM) on the visual right and the
   summary (second) on the visual left — no explicit column/order needed.
   1024–1279: still two columns, gap reduced to 24px (--space-6).
   768–1023 and below: single column, summary drops below (already second
   in the DOM), no longer sticky. ─────────────────────────────────────── */
.cart-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 428px;
    gap: var(--space-8);
    align-items: start;
}
@media (max-width: 1279px) { /* 1024–1279 tier */
    .cart-layout { gap: var(--space-6); }
}
@media (max-width: 1023px) { /* --bp-md tier and below — summary below, full width */
    .cart-layout { grid-template-columns: 1fr; }
}

/* ── Items panel + its static column-head row ───────────────────────────
   The head row is a sibling of #cartLines (never inside it — cart.js does
   pageLines.innerHTML = '...' on every render, which would wipe anything
   placed inside). Its 4 labels are decorative only (aria-hidden) — the
   real accessible labels stay on each control (aria-label="الكمية" etc.,
   already in cart.js's markup). ─────────────────────────────────────── */

.cart-lines-panel {
    background: var(--paper);
    border: var(--card-border, 1px solid var(--line));
    border-radius: var(--card-radius, var(--radius-md));
    padding: var(--space-6);
}

.cart-table-head {
    display: grid;
    grid-template-columns: 100px minmax(0, 1fr) minmax(3rem, auto) minmax(7.25rem, auto) minmax(3rem, auto) 2.5rem;
    column-gap: var(--space-3);
    padding: 0 var(--space-2) var(--space-3);
    margin-bottom: var(--space-3);
    border-bottom: 1px solid var(--line);
}
.cart-table-head__col { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--ink-soft); text-align: center; }
.cart-table-head__col--product { grid-column: 2; text-align: start; }
.cart-table-head__col--price   { grid-column: 3; }
.cart-table-head__col--qty     { grid-column: 4; }
.cart-table-head__col--total   { grid-column: 5; }

/* Row shape — desktop/tablet "table" mode (the default, active from 768px
   up — see the §67 breakpoint block below). `.cart-line__info` and
   `.cart-line__controls` are flattened (display:contents) so their
   children — name, variant, unit price, qty stepper, remove button — each
   take their own grid-area on THIS row, lining up under the head row's 4
   labels, without touching cart.js's markup. min-height keeps the row in
   §79's 140–160px band; the name column (minmax(0,1fr)) still absorbs any
   squeeze near the 768px hand-off so the row never forces horizontal
   overflow. */
.cart-lines-panel .cart-line {
    grid-template-columns: 100px minmax(0, 1fr) minmax(3rem, auto) minmax(7.25rem, auto) minmax(3rem, auto) 2.5rem;
    grid-template-areas:
        "media name    price qty total remove"
        "media variant price qty total remove";
    align-items: center;
    column-gap: var(--space-3);
    min-height: 150px; /* §79 — 140–160px line row height */
    padding-block: var(--space-5);
}
.cart-lines-panel .cart-line__media {
    grid-area: media;
    width: 100px;
    height: 100px;
    border-radius: var(--radius-md);
    align-self: center;
}
.cart-lines-panel .cart-line__info { display: contents; }
.cart-lines-panel .cart-line__name { grid-area: name; }
.cart-lines-panel .cart-line__variant { grid-area: variant; }
.cart-lines-panel .cart-line__unit-price {
    grid-area: price;
    align-self: center;
    font-size: var(--text-base);
    color: var(--ink);
    text-align: center;
}
.cart-lines-panel .cart-line__controls { display: contents; }
.cart-lines-panel .cart-line__controls .cart-qty { grid-area: qty; align-self: center; justify-self: center; }
.cart-lines-panel .cart-line__total {
    grid-area: total;
    align-self: center;
    text-align: center;
}
.cart-lines-panel .cart-line__remove {
    grid-area: remove;
    align-self: center;
    justify-self: center;
    position: relative;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-full);
}
/* Icon-only per the comp — the "إزالة" text stays in the DOM for screen
   readers (cart.js:lineHtml already writes it) and is visually hidden here,
   the standard accessible technique (never `display:none`, which would
   remove it from the accessibility tree too). */
.cart-lines-panel .cart-line__remove span {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* <768px (--bp-md — §67): the table head hides and each <li class="cart-line">
   becomes a stacked card, no horizontal scroll down to 360px wide. `.cart-line__info`
   stays flattened (its children are still direct grid items of `.cart-line`) but
   `.cart-line__controls` is switched back to a real flex row (qty stepper +
   remove together) — the base/desktop rule above only sets `display: contents`
   on it, so this override wins here on source order at equal specificity. */
@media (max-width: 767px) { /* --bp-md */
    .cart-table-head { display: none; }

    .cart-lines-panel { padding: var(--space-4); }

    .cart-lines-panel .cart-line {
        grid-template-columns: 100px 1fr;
        grid-template-areas:
            "media name"
            "media variant"
            "price price"
            "controls controls"
            "total total";
        column-gap: var(--space-3);
        row-gap: var(--space-2);
        align-items: start;
        min-height: 0; /* card mode ignores the 140–160px table-row band; content sets its own height */
        border: 1px solid var(--line);
        border-radius: var(--radius-md);
        padding: var(--space-4);
        margin-bottom: var(--space-3);
    }
    .cart-lines-panel .cart-line:last-child { margin-bottom: 0; }

    .cart-lines-panel .cart-line__name,
    .cart-lines-panel .cart-line__variant { text-align: start; }

    .cart-lines-panel .cart-line__unit-price {
        text-align: start;
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: var(--space-2);
        padding-top: var(--space-2);
        border-top: 1px dashed var(--line);
    }
    .cart-lines-panel .cart-line__unit-price::before {
        content: "السعر";
        font-weight: var(--weight-semibold);
        color: var(--ink-soft);
    }

    .cart-lines-panel .cart-line__controls {
        display: flex;
        align-items: center;
        gap: var(--space-3);
    }
    .cart-lines-panel .cart-line__controls::before {
        content: "الكمية";
        font-size: var(--text-sm);
        font-weight: var(--weight-semibold);
        color: var(--ink-soft);
    }
    .cart-lines-panel .cart-line__remove { margin-inline-start: auto; }

    .cart-lines-panel .cart-line__total {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        padding-top: var(--space-2);
        border-top: 1px dashed var(--line);
    }
    .cart-lines-panel .cart-line__total::before {
        content: "الإجمالي";
        font-family: var(--font-body);
        font-weight: var(--weight-semibold);
        font-size: var(--text-sm);
        color: var(--ink-soft);
    }
}

/* ── Order summary ────────────────────────────────────────────────────── */

.cart-summary {
    background: var(--paper);
    border: 1px solid var(--neutral-200);
    border-radius: var(--card-radius, var(--radius-md));
    padding: var(--space-6);
    position: sticky;
    top: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
@media (max-width: 1023px) { /* --bp-md tier and below (§67: 768–1023 + <768) — moves below the items panel, full width, not sticky */
    .cart-summary { position: static; }
}
.cart-summary h2 { font-size: var(--text-lg); font-weight: var(--weight-bold); color: var(--ink); margin: 0; }

.cart-summary__rows { display: flex; flex-direction: column; gap: .5rem; margin: 0; }
.cart-summary__row { display: flex; align-items: baseline; justify-content: space-between; font-size: var(--text-base); color: var(--ink-soft); }
.cart-summary__row dt, .cart-summary__row dd { margin: 0; font-weight: inherit; }
.cart-summary__row--total { padding-top: .5rem; border-top: 1px solid var(--line); font-size: var(--text-xl); font-weight: var(--weight-bold); color: var(--ink); }

.cart-summary__note {
    display: flex;
    align-items: flex-start;
    gap: .4rem;
    font-size: var(--text-xs);
    color: var(--ink-soft);
    line-height: var(--leading-normal);
    margin: 0;
}
.cart-summary__note .icon { flex: 0 0 auto; margin-top: 2px; }

.cart-summary__actions { display: flex; flex-direction: column; gap: .6rem; }
.cart-summary__actions .btn { width: 100%; }
.cart-summary__reason { margin: -.2rem 0 0; font-size: var(--text-xs); color: var(--ink-faint); text-align: center; }

/* §79 — short payment-security reassurance line, directly below the main
   CTA. Reserves its own row via normal flow (part of the always-rendered
   static markup, never toggled) so it cannot shift anything else in this
   card — there is nothing to reserve height FOR since it never appears or
   disappears. */
.cart-summary__security {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    margin: 0;
    font-size: var(--text-xs);
    color: var(--ink-soft);
}
.cart-summary__security .icon { flex: 0 0 auto; color: var(--success-base, var(--ink-soft)); }

/* Comp-specific button treatment for this card only — CTA on --gold with
   dark ink (the shared .btn--primary elsewhere in the store stays on
   --brand; --gold on white text fails AA per tokens.css's own measured
   note, hence --neutral-900 ink here, not --brand-on). Secondary stays
   outlined in --brand rather than the shared .btn--secondary's neutral
   border. */
.cart-summary__actions .btn--primary {
    background: var(--gold);
    color: var(--neutral-900);
    /* height, not min-height. MEASURED at 1440px the button rendered 55px, not the
       52px the brief specifies: .btn--lg (components.css) sets padding .8rem block,
       and padding + line-box exceeded the 52px floor, so min-height never bound.
       A fixed height pins it exactly; the flex centring in .btn keeps the label
       optically centred regardless. */
    height: 52px;
    min-height: 52px; /* §27 — main CTA height */
}
.cart-summary__actions .btn--primary:hover:not(:disabled) {
    background: color-mix(in srgb, var(--gold) 88%, black);
}
.cart-summary__actions .btn--secondary {
    background: transparent;
    color: var(--brand);
    border-color: var(--brand);
}
.cart-summary__actions .btn--secondary:hover:not(:disabled) {
    background: var(--brand-tint, var(--paper-muted));
}

/* بنود لم تُحتسب بعد — تُقرأ كحالة لا كرقم. الخط أصغر واللون ثانوي حتى لا يخلط
   المشتري بينها وبين مبلغ فعلي، مع بقائها ظاهرة (§76: لا تُخفَ تكلفة إلزامية). */
.cart-summary__row--pending dd {
    font-size: var(--text-xs);
    font-weight: var(--weight-regular);
    color: var(--neutral-500);
}

/* ── [hidden] must outrank every display rule in this file ────────────────────
   cart.js drives four MUTUALLY EXCLUSIVE page states (#cartLoading, #cartError,
   #cartEmpty, #cartLayout) purely by toggling the `hidden` attribute. The UA
   sheet's `[hidden] { display: none }` is an attribute selector (0,0,1); any
   rule here that sets `display: flex|grid` on those same elements via a class or
   id outranks it, so the attribute is set but has no effect.

   MEASURED on /cart after the redesign: all four elements reported
   `hidden=true` (or false for the layout) while computed display stayed
   flex/grid — the page painted skeleton loaders, the error banner, the empty
   state AND the populated items table simultaneously, with the header badge
   showing 1 item. Four contradictory answers to "what is in your cart" on one
   screen (Q42).

   Scoped to the cart page root so it can never leak into the mini-cart drawer
   or any other component that legitimately manages its own visibility. */
#cartPageRoot [hidden] { display: none !important; }
