/* ============================================================
   ASSETS/CSS/PRODUCT.CSS — Product detail page (Phase 4)
   ============================================================
   Loaded only on /product/{slug} (after style.css + store.css).
    1. Page top + layout
    2. Gallery
    3. Summary: title, rating, price box, buttons
    4. Links, assurance, share
    5. Details (description, features, included, specs, license)
    6. Support box
    7. Sticky mobile purchase bar
    8. Lightbox
   Colours come from the design tokens in style.css.
   ============================================================ */

@layer components {

    /* ---------- 1. Page top + layout ---------- */
    .product-top { padding: clamp(18px, 3vw, 28px) 0 clamp(28px, 5vw, 56px); background: var(--gradient-soft); border-bottom: 1px solid var(--border); }
    .product-main { display: grid; gap: 28px; margin-top: 18px; align-items: start; }
    .product-main > * { min-width: 0; }
    @media (min-width: 960px) { .product-main { grid-template-columns: minmax(0, 1.12fr) minmax(0, .88fr); gap: 48px; } }

    /* ---------- 2. Gallery ---------- */
    .gallery { display: flex; flex-direction: column; gap: 12px; }
    @media (min-width: 960px) { .gallery { position: sticky; top: calc(var(--header-height) + 20px); } }
    .gallery__stage {
        position: relative; aspect-ratio: 16 / 10; border-radius: var(--radius-lg); overflow: hidden;
        background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
    }
    .gallery__main { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; position: relative; z-index: 1; }
    .gallery__main img { width: 100%; height: 100%; object-fit: cover; display: block; }
    .gallery__fallback { position: absolute; inset: 0; }
    .gallery__fallback .thumb__icon { width: 96px; height: 96px; border-radius: 26px; }
    .gallery__stage:has(.gallery__main) .gallery__fallback { display: none; }
    .gallery__stage.is-broken .gallery__fallback { display: flex; z-index: 2; }
    .gallery__stage.is-broken .gallery__nav, .gallery__stage.is-broken .gallery__counter { z-index: 3; }

    .gallery__nav {
        position: absolute; top: 50%; z-index: 2; transform: translateY(-50%);
        width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .6);
        display: flex; align-items: center; justify-content: center;
        background: rgba(255, 255, 255, .88); color: var(--text); box-shadow: var(--shadow);
        cursor: pointer; transition: background .2s var(--ease), transform .2s var(--ease);
    }
    .gallery__nav:hover { background: #fff; color: var(--primary); }
    .gallery__nav--prev { left: 12px; }
    .gallery__nav--next { right: 12px; }
    .gallery__counter {
        position: absolute; right: 12px; bottom: 12px; z-index: 2;
        padding: 4px 10px; border-radius: 999px; background: rgba(15, 23, 42, .72); color: #fff;
        font-size: .75rem; font-weight: 600; pointer-events: none;
    }
    @media (max-width: 479px) { .gallery__nav { width: 36px; height: 36px; } .gallery__nav--prev { left: 8px; } .gallery__nav--next { right: 8px; } }

    .gallery__thumbs { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: thin; scroll-snap-type: x proximity; }
    .gallery__thumb {
        flex: 0 0 auto; width: 92px; aspect-ratio: 16 / 10; border-radius: 10px; overflow: hidden; padding: 0;
        border: 2px solid transparent; background: var(--surface); cursor: pointer; opacity: .7;
        scroll-snap-align: start; transition: opacity .2s var(--ease), border-color .2s var(--ease);
        box-shadow: 0 0 0 1px var(--border);
    }
    .gallery__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
    .gallery__thumb:hover { opacity: 1; }
    .gallery__thumb.is-active { opacity: 1; border-color: var(--primary); box-shadow: none; }
    @media (max-width: 479px) { .gallery__thumb { width: 72px; } }

    /* ---------- 3. Summary ---------- */
    .product-summary { display: flex; flex-direction: column; gap: 14px; }
    .product-summary__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
    .product-title { font-size: clamp(1.625rem, 1.2rem + 1.8vw, 2.375rem); line-height: 1.15; font-weight: 700; letter-spacing: -.025em; overflow-wrap: anywhere; }
    .product-rating { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .9375rem; color: var(--text-soft); }
    .product-lead { font-size: 1.0625rem; line-height: 1.65; color: var(--text-soft); }

    .price-box {
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
        padding: clamp(18px, 3vw, 24px); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
    }
    .price--xl { align-items: center; gap: 6px 12px; }
    .price--xl .price__current { font-size: clamp(1.75rem, 1.4rem + 1.4vw, 2.25rem); letter-spacing: -.02em; }
    .price--xl .price__old { font-size: 1.125rem; }
    .price-box__save { font-size: .9375rem; font-weight: 600; color: var(--success); }
    .price-box .deal-countdown { margin-top: 0; }
    .availability { display: flex; align-items: center; gap: 8px; font-size: .875rem; font-weight: 500; }
    .availability.is-available { color: var(--success); }
    .availability.is-unavailable { color: var(--muted); }
    .product-cta { display: grid; gap: 10px; margin-top: 4px; }
    @media (min-width: 480px) { .product-cta { grid-template-columns: 1fr 1fr; } }
    .product-cta form { display: flex; }
    .product-cta .btn-lg { padding-left: 16px; padding-right: 16px; }
    .product-note { font-size: .8125rem; color: var(--muted); line-height: 1.5; }

    /* ---------- 4. Links, assurance, share ---------- */
    .product-links { display: flex; flex-wrap: wrap; gap: 8px; }
    .product-assurance { list-style: none; display: grid; gap: 8px; font-size: .875rem; color: var(--text-soft); }
    .product-assurance li { display: flex; align-items: flex-start; gap: 10px; }
    .product-assurance svg { flex-shrink: 0; margin-top: 2px; color: var(--primary); }

    .share { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
    .share__label { font-size: .875rem; font-weight: 600; color: var(--text-soft); margin-right: 2px; }
    .share__btn {
        display: inline-flex; align-items: center; justify-content: center; gap: 6px;
        min-width: 38px; height: 38px; padding: 0 10px; border-radius: 10px;
        background: var(--surface); border: 1px solid var(--border); color: var(--text-soft);
        font-size: .8125rem; font-weight: 500; cursor: pointer; transition: all .2s var(--ease);
    }
    .share__btn:hover { color: var(--primary); border-color: var(--primary); }

    /* ---------- 5. Details ---------- */
    .product-details { padding: clamp(28px, 5vw, 56px) 0; }
    .product-tabs {
        display: flex; gap: 6px; overflow-x: auto; padding: 6px; margin-bottom: 24px;
        background: var(--surface); border: 1px solid var(--border); border-radius: 14px; scrollbar-width: none;
        position: sticky; top: calc(var(--header-height) + 8px); z-index: 5; box-shadow: var(--shadow-sm);
    }
    .product-tabs::-webkit-scrollbar { display: none; }
    .product-tabs a { flex: 0 0 auto; padding: 8px 14px; border-radius: 10px; font-size: .875rem; font-weight: 500; color: var(--text-soft); white-space: nowrap; }
    .product-tabs a:hover { background: var(--primary-50); color: var(--primary); }
    .product-details__grid { display: grid; gap: 20px; align-items: start; }
    .product-details__grid > * { min-width: 0; }
    @media (min-width: 1024px) { .product-details__grid { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 28px; } }
    .product-details__main, .product-details__side { display: flex; flex-direction: column; gap: 20px; }

    .detail-card {
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
        padding: clamp(18px, 3vw, 28px); box-shadow: var(--shadow-sm);
        scroll-margin-top: calc(var(--header-height) + 80px);
    }
    .detail-card__title { display: flex; align-items: center; gap: 8px; font-size: 1.1875rem; font-weight: 700; letter-spacing: -.01em; margin-bottom: 14px; }
    .detail-card__title svg { color: var(--primary); }
    .detail-card--license { background: linear-gradient(180deg, var(--primary-50), var(--surface)); }

    .rich-text { color: var(--text-soft); line-height: 1.75; overflow-wrap: anywhere; }
    .rich-text > * + * { margin-top: 12px; }
    .rich-text h2, .rich-text h3, .rich-text h4 { color: var(--text); font-weight: 600; line-height: 1.3; margin-top: 20px; }
    .rich-text h2 { font-size: 1.25rem; } .rich-text h3 { font-size: 1.125rem; } .rich-text h4 { font-size: 1rem; }
    .rich-text ul, .rich-text ol { padding-left: 22px; }
    .rich-text ul { list-style: disc; } .rich-text ol { list-style: decimal; }
    .rich-text li + li { margin-top: 4px; }
    .rich-text a { text-decoration: underline; text-underline-offset: 3px; }
    .rich-text blockquote { border-left: 3px solid var(--primary-100); padding-left: 14px; font-style: italic; }
    .rich-text code { background: var(--surface-alt); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
    .rich-text img { max-width: 100%; height: auto; border-radius: 10px; }

    .feature-list { list-style: none; display: grid; gap: 10px; }
    @media (min-width: 640px) { .feature-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; } }
    .feature-list li { display: flex; align-items: flex-start; gap: 10px; color: var(--text-soft); line-height: 1.5; overflow-wrap: anywhere; min-width: 0; }
    .feature-list__icon { flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--success-bg); color: var(--success); margin-top: 1px; }

    .included-grid { list-style: none; display: grid; gap: 10px; }
    @media (min-width: 560px) { .included-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
    .included-grid li {
        display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
        background: var(--surface-alt); border: 1px solid var(--border); font-size: .9375rem; min-width: 0;
    }
    .included-grid li span { overflow-wrap: anywhere; min-width: 0; }
    .included-grid svg { flex-shrink: 0; color: var(--primary); }

    .spec-list { display: grid; gap: 0; }
    .spec-list > div { display: grid; grid-template-columns: minmax(0, 38%) minmax(0, 1fr); gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: .9375rem; }
    .spec-list > div:last-child { border-bottom: 0; }
    .spec-list dt { color: var(--muted); font-weight: 500; overflow-wrap: anywhere; }
    .spec-list dd { color: var(--text); overflow-wrap: anywhere; }
    .spec-list .spec-list__full { grid-column: 1 / -1; color: var(--text-soft); }
    .spec-list--table > div { grid-template-columns: minmax(0, 42%) minmax(0, 1fr); }

    .pre-line { white-space: pre-line; overflow-wrap: anywhere; color: var(--text-soft); line-height: 1.7; }

    /* ---------- 6. Support box ---------- */
    .support-box { margin: 18px 0; padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
    .support-box h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; font-weight: 600; margin-bottom: 8px; }
    .support-box h3 svg { color: var(--primary); }
    #product-support { scroll-margin-top: calc(var(--header-height) + 16px); }

    /* ---------- 7. Sticky mobile purchase bar ---------- */
    .sticky-cta { display: none; }
    @media (max-width: 959px) {
        .sticky-cta {
            display: flex; align-items: center; gap: 8px;
            position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
            padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
            background: rgba(255, 255, 255, .97); border-top: 1px solid var(--border);
            box-shadow: 0 -10px 30px -18px rgba(15, 23, 42, .35);
            transform: translateY(110%); visibility: hidden;
            transition: transform .25s var(--ease), visibility 0s linear .25s;
        }
        .sticky-cta.is-visible { transform: none; visibility: visible; transition: transform .25s var(--ease); }
        body.has-sticky-cta-visible { padding-bottom: 72px; }
        body.has-sticky-cta-visible .toast { bottom: 88px; }
    }
    .sticky-cta__price { display: flex; flex-direction: column; margin-right: auto; min-width: 0; line-height: 1.2; }
    .sticky-cta__price strong { font-size: 1.0625rem; white-space: nowrap; }
    .sticky-cta__price del { font-size: .8125rem; color: #94a3b8; }
    .sticky-cta form { display: flex; }
    .sticky-cta .btn { white-space: nowrap; }
    @media (max-width: 359px) { .sticky-cta { gap: 6px; padding-left: 10px; padding-right: 10px; } .sticky-cta .btn-sm { padding: 8px 10px; } }

    /* ---------- 8. Lightbox ---------- */
    .lightbox {
        position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
        padding: 56px 16px; background: rgba(2, 6, 23, .92);
    }
    .lightbox[hidden] { display: none; }
    .lightbox__img { max-width: min(100%, 1600px); max-height: 100%; object-fit: contain; border-radius: 12px; box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .6); }
    .lightbox__close, .lightbox__nav {
        position: absolute; display: flex; align-items: center; justify-content: center;
        width: 48px; height: 48px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .25);
        background: rgba(255, 255, 255, .12); color: #fff; cursor: pointer;
    }
    .lightbox__close:hover, .lightbox__nav:hover { background: rgba(255, 255, 255, .24); }
    .lightbox__close { top: 12px; right: 12px; }
    .lightbox__nav { top: 50%; transform: translateY(-50%); }
    .lightbox__nav--prev { left: 12px; }
    .lightbox__nav--next { right: 12px; }
    @media (max-width: 639px) { .lightbox__nav { top: auto; bottom: 12px; transform: none; } .lightbox__nav--prev { left: calc(50% - 60px); } .lightbox__nav--next { right: calc(50% - 60px); } }
}
