/* Product detail view (dialog#detail). Colours from tokens.css only. */

html.detail-open,
html.detail-open body {
    overflow: hidden;
}

dialog.detail {
    padding: 0;
    margin: 0;
    border: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    background: var(--card);
    color: var(--ink);
    font-family: var(--font-body);
    overflow: hidden;
    overscroll-behavior: contain;
}

dialog.detail[open] {
    display: flex;
    flex-direction: column;
}

dialog.detail::backdrop {
    background: color-mix(in srgb, var(--ink) 55%, transparent);
}

.d-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.d-body {
    display: flex;
    flex-direction: column;
}

/* ---------- close ---------- */

.d-close {
    position: absolute;
    top: max(var(--space-3), env(safe-area-inset-top));
    right: var(--space-3);
    z-index: 3;
    display: grid;
    place-items: center;
    width: var(--tap);
    height: var(--tap);
    padding: 0;
    border: var(--border);
    border-radius: var(--radius-pill);
    background: var(--card);
    color: var(--ink);
    box-shadow: var(--shadow-hard-sm);
    cursor: pointer;
}

.d-close svg,
.d-nav svg,
.d-share svg,
.d-ref svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---------- gallery ---------- */

.d-gallery {
    background: var(--paper);
}

.d-stage {
    position: relative;
}

.d-track {
    display: flex;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
}

.d-track::-webkit-scrollbar {
    display: none;
}

.d-track:focus {
    outline: none;
}

.d-slide {
    flex: 0 0 100%;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    aspect-ratio: 3 / 4;
    max-height: 70vh;
    display: grid;
    place-items: center;
    background: var(--paper);
}

.d-slide img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.d-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    display: grid;
    place-items: center;
    width: var(--tap);
    height: var(--tap);
    padding: 0;
    border: var(--border);
    border-radius: var(--radius-pill);
    background: var(--card);
    color: var(--ink);
    box-shadow: var(--shadow-hard-sm);
    cursor: pointer;
}

.d-nav--prev { left: var(--space-3); }
.d-nav--next { right: var(--space-3); }

.d-counter {
    position: absolute;
    left: 50%;
    bottom: var(--space-3);
    transform: translateX(-50%);
    padding: var(--space-1) var(--space-3);
    border: var(--border);
    border-radius: var(--radius-pill);
    background: var(--card);
    color: var(--ink);
    font-size: 0.875rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.d-thumbs {
    display: none;
}

/* ---------- info ---------- */

.d-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-4) 0;
}

.d-kind {
    margin: 0;
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Brand logo + kind, separated by a hairline */
.d-eyebrow {
    --logo-h: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    min-height: 28px;
    margin: 0;
}

.d-brand-logo {
    display: block;
    height: calc(var(--logo-h) * var(--logo-scale, 1));
    width: auto;
    max-width: 100%;
}

.d-eyebrow .d-kind {
    padding-left: var(--space-3);
    border-left: 1px solid var(--line-strong);
    line-height: 1.2;
}

.d-title {
    margin: 0;
    text-wrap: balance;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1.5rem, 5vw, 2rem);
    line-height: 1.1;
    color: var(--ink);
}

.d-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.d-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 2px var(--space-3);
    border: 1.5px solid var(--ink);
    border-radius: var(--radius-pill);
    background: var(--card);
    color: var(--ink);
    font-size: 0.8125rem;
    font-weight: 600;
}

.d-badge--flag { background: var(--cardboard-tint); color: var(--cardboard-text); border-color: var(--cardboard-text); }
.d-badge--offer { background: var(--cta-tint); color: var(--cta); border-color: var(--cta); }
.d-badge--sold { background: var(--sold); color: var(--on-dark); border-color: var(--sold); text-transform: uppercase; letter-spacing: 0.04em; }
.d-badge--reserved { background: var(--reserved-tint); color: var(--reserved-text); border-color: var(--reserved-text); }

.d-price {
    padding: var(--space-3) var(--space-4);
    border: var(--border);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow-hard);
}

.d-price p {
    margin: 0;
}

.d-price-value {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 2.25rem;
    line-height: 1.1;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.is-sold .d-price-value {
    color: var(--muted);
}

.d-price-ask {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.375rem;
    color: var(--ink-soft);
}

.d-retail {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-1) !important;
    color: var(--muted);
}

.d-retail-value {
    color: var(--muted);
}

.d-off {
    padding: 2px var(--space-2);
    border: 1.5px solid var(--ink);
    border-radius: var(--radius-sm);
    background: var(--tag);
    color: var(--ink);
    font-weight: 700;
    font-size: 0.875rem;
}

.d-save {
    margin-top: var(--space-1) !important;
    color: var(--ink-soft);
    font-weight: 600;
}

.d-note {
    margin: 0;
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
}

.d-note--sold { background: var(--sold-tint); color: var(--sold-text); }
.d-note--reserved { background: var(--reserved-tint); color: var(--reserved-text); }

.d-subtitle {
    margin: var(--space-3) 0 0;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.125rem;
}

.d-facts {
    margin: 0;
    border-top: 1px solid var(--line);
}

.d-fact {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--line);
}

.d-fact dt {
    color: var(--ink-soft);
}

.d-fact dd {
    margin: 0;
    font-weight: 600;
    text-align: right;
}

.d-desc {
    margin: 0;
    line-height: 1.55;
    color: var(--ink);
    white-space: pre-line;
}

.d-ref {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    align-self: flex-start;
    min-height: var(--tap);
    color: var(--ink);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.d-ref svg {
    width: 18px;
    height: 18px;
}

/* ---------- actions (sticky bar) ---------- */

.d-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-3) calc(-1 * var(--space-4)) 0;
    padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
    border-top: var(--border);
    background: var(--card);
}

.d-actions-price {
    flex: 0 0 auto;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--ink);
    white-space: nowrap;
}

.d-actions-price:empty {
    display: none;
}

.is-sold .d-actions-price {
    color: var(--muted);
}

.detail .btn-cta {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: var(--space-2) var(--space-4);
    border: var(--border);
    border-radius: var(--radius);
    background: var(--cta);
    color: var(--on-dark);
    box-shadow: var(--shadow-hard-sm);
    font: inherit;
    font-weight: 700;
    font-size: 1rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.detail .btn-cta:hover {
    background: var(--cta-hover);
}

.detail .btn-cta:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.detail .btn-cta[disabled],
.detail .btn-cta--sold {
    background: var(--line);
    color: var(--ink-soft);
    border-color: var(--line-strong);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.d-share {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-width: var(--tap);
    min-height: var(--tap);
    padding: var(--space-2);
    border: var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.d-share-label {
    display: none;
}

.d-share:hover,
.d-nav:hover,
.d-close:hover,
.d-thumb:hover {
    background: var(--tag-tint);
}

/* ---------- toast ---------- */

.d-toast {
    position: absolute;
    left: 50%;
    bottom: calc(96px + env(safe-area-inset-bottom));
    z-index: 4;
    margin: 0;
    padding: var(--space-2) var(--space-4);
    border: var(--border);
    border-radius: var(--radius-pill);
    background: var(--ink);
    color: var(--on-dark);
    font-weight: 600;
    white-space: nowrap;
    transform: translate(-50%, 8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.d-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.d-copy-buffer {
    position: fixed;
    top: 0;
    left: 0;
    opacity: 0;
    pointer-events: none;
}

/* ---------- focus ---------- */

dialog.detail :focus-visible {
    outline: 3px solid var(--ink);
    outline-offset: 2px;
}

.detail .btn-cta:focus-visible {
    outline-color: var(--ink);
    outline-offset: 3px;
}

/* ---------- desktop: centered two-column modal ---------- */

@media (min-width: 768px) {
    dialog.detail {
        margin: auto;
        width: min(960px, calc(100% - 48px));
        height: fit-content;
        max-height: min(90vh, 900px);
        border: var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-hard), var(--shadow-soft);
    }

    dialog.detail[open] {
        display: block;
    }

    .d-scroll {
        max-height: min(90vh, 900px);
    }

    .d-close {
        top: var(--space-3);
    }

    .d-body {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: start;
    }

    .d-gallery {
        position: sticky;
        top: 0;
        border-right: var(--border);
        padding-bottom: var(--space-3);
    }

    .d-slide {
        max-height: calc(min(90vh, 900px) - 110px);
    }

    .d-thumbs {
        display: flex;
        gap: var(--space-2);
        padding: var(--space-3) var(--space-3) 0;
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .d-thumb {
        flex: 0 0 auto;
        width: 56px;
        height: 75px;
        padding: 0;
        border: 2px solid var(--line-strong);
        border-radius: var(--radius-sm);
        background: var(--card);
        overflow: hidden;
        cursor: pointer;
    }

    .d-thumb img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        display: block;
    }

    .d-thumb[aria-current="true"] {
        border-color: var(--ink);
        box-shadow: var(--shadow-hard-sm);
    }

    .d-info {
        padding: var(--space-6) var(--space-5) 0;
    }

    .d-info > .d-kind,
    .d-eyebrow,
    .d-title {
        padding-right: var(--tap);
    }

    .d-actions {
        margin-left: calc(-1 * var(--space-5));
        margin-right: calc(-1 * var(--space-5));
        padding-left: var(--space-5);
        padding-right: var(--space-5);
        padding-bottom: var(--space-4);
    }

    .d-actions-price {
        display: none;
    }

    .d-share-label {
        display: inline;
    }

    .d-share {
        padding: var(--space-2) var(--space-4);
    }
}

@media (prefers-reduced-motion: reduce) {
    .d-toast { transition: none; }
    .detail .btn-cta:active { transform: none; }
}
