/* صفحهٔ محصول (templates/product_detail.html) */
    /* ===== صفحهٔ محصول (فاز ۵-ج): هرچه کاربر برایش آمده بدون اسکرول دیده شود ===== */
    body { padding-top: 0 !important; }
    main { position: relative; z-index: 10; }
    /* overflow-x: hidden روی html و body، body را ظرف اسکرول می‌کند و position: sticky را از کار می‌اندازد.
       clip همان برش افقی را بدون این اثر جانبی انجام می‌دهد. هدر سایت مثل بقیهٔ صفحه‌ها با اسکرول بالا می‌رود. */
    html, body { overflow-x: clip !important; }
    .master-header-v2 { position: relative !important; }
    /* روی body (نه :root) تا رنگ‌های تم روشن (body.light-mode) هم برسند */
    :root { --pd-header-h: 0px; }
    body { --pd-accent: var(--primary, #06b6d4); --pd-rose: var(--cosmic-rose, #f43f5e); }

    .pd-card {
        background: var(--card-glass);
        border: 1px solid var(--border-glow);
        box-shadow: var(--card-shadow);
        border-radius: 1.25rem;
    }
    .pd-h { font-size: .9rem; font-weight: 900; color: var(--text-main); display: flex; align-items: center; gap: .5rem; }
    .pd-h::before { content: ''; width: 4px; height: 1.1rem; border-radius: 4px; background: var(--pd-accent); }
    .pd-muted { color: var(--text-muted); }
    .pd-mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

    /* --- چیدمان بالای صفحه --- */
    .pd-main-grid { display: grid; gap: 1rem; grid-template-areas: "head" "buy" "keyspecs"; }
    .pd-head { grid-area: head; }
    .pd-buy { grid-area: buy; }
    .pd-keyspecs { grid-area: keyspecs; }
    @media (min-width: 1280px) {
        .pd-main-grid { grid-template-columns: minmax(0, 1fr) 340px; grid-template-areas: "head buy" "keyspecs buy"; align-items: start; }
        .pd-buy { position: sticky; top: calc(var(--pd-header-h) + 1rem); }
    }

    /* --- گالری: یک اسلایدر برای موبایل و دسکتاپ (فقط یک بار دانلود) --- */
    .pd-gallery-card { padding: .75rem; position: relative; }
    .pd-slider {
        direction: ltr; display: flex; overflow-x: auto; overscroll-behavior-x: contain;
        scroll-snap-type: x mandatory; scroll-behavior: smooth; scrollbar-width: none;
        background: var(--input-bg); border-radius: 1rem; aspect-ratio: 1 / 1; width: 100%;
    }
    .pd-slider::-webkit-scrollbar { display: none; }
    .pd-slide { flex: 0 0 100%; scroll-snap-align: center; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
    /* وقتی نسبت عکس با کادر یکی نیست، فضای خالی کنار عکس با نسخهٔ تار همان عکس (بندانگشتی ۲۰۰ پیکسلی) پر می‌شود، نه نوار سفید */
    .pd-slide[style*="--pd-bg"]::before {
        content: ''; position: absolute; inset: -24px; background: var(--pd-bg) center / cover no-repeat;
        filter: blur(22px) saturate(1.1) brightness(.92); transform: scale(1.1);
    }
    .pd-slide-img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; }
    .pd-slider.is-empty { aspect-ratio: auto; height: auto; min-height: 0; }
    .pd-empty { flex: 0 0 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem; padding: 1.75rem 1rem; text-align: center; }
    .pd-empty-icon { width: 3rem; height: 3rem; border-radius: .9rem; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; background: rgba(6, 182, 212, .1); border: 1px dashed rgba(6, 182, 212, .35); }
    @media (min-width: 1024px) { .pd-slider.is-empty { aspect-ratio: 1 / 1; } }
    .pd-slide-video { width: 100%; height: 100%; object-fit: contain; background: #000; }
    @media (max-width: 1023px) {
        /* موبایل: عکس اول دیده می‌شود ولی قیمت و دکمهٔ خرید هم بدون اسکرول بالای داک ناوبری می‌مانند */
        .pd-slider:not(.is-empty) { aspect-ratio: auto; height: min(32vh, calc(100vw - 2.5rem)); min-height: 200px; }
        .pd-gallery-card { padding: .5rem; }
        .pd-dots { margin-top: .35rem; }
        .pd-price { font-size: 1.6rem; }
    }
    @media (max-width: 1023px) and (max-height: 760px) {
        .pd-slider:not(.is-empty) { height: min(28vh, calc(100vw - 2.5rem)); min-height: 180px; }
    }
    .pd-arrow {
        position: absolute; top: 50%; transform: translateY(-50%); z-index: 5; width: 2.25rem; height: 2.25rem;
        border-radius: 999px; background: rgba(15, 23, 42, .55); color: #fff; display: none; align-items: center;
        justify-content: center; font-size: 1.25rem; line-height: 1; border: 1px solid rgba(255, 255, 255, .25);
    }
    .pd-arrow:hover { background: rgba(15, 23, 42, .8); }
    .pd-gallery-card:hover .pd-arrow { display: flex; }
    .pd-arrow.prev { left: 1.25rem; } .pd-arrow.next { right: 1.25rem; }
    .pd-dots { display: flex; justify-content: center; gap: .35rem; margin-top: .5rem; }
    .pd-dot { width: .45rem; height: .45rem; border-radius: 999px; background: var(--border-glow); transition: all .2s; }
    .pd-dot.active { width: 1.2rem; background: var(--pd-accent); }
    .pd-thumbs { display: flex; gap: .5rem; overflow-x: auto; scrollbar-width: none; margin-top: .65rem; padding: 2px; }
    .pd-thumb {
        flex: 0 0 64px; height: 64px; border-radius: .7rem; border: 2px solid transparent; background: #fff;
        overflow: hidden; opacity: .6; transition: all .2s; display: flex; align-items: center; justify-content: center;
    }
    .pd-thumb img { width: 100%; height: 100%; object-fit: contain; }
    .pd-thumb.active, .pd-thumb:hover { opacity: 1; border-color: var(--pd-accent); }
    .pd-thumb-video { background: #0b1324; color: var(--pd-accent); font-size: .7rem; font-weight: 900; flex-direction: column; }
    .pd-sale {
        position: absolute; top: 1.25rem; right: 1.25rem; z-index: 6; background: linear-gradient(135deg, var(--pd-rose), #be123c);
        color: #fff; padding: .2rem .6rem; border-radius: .6rem; font-weight: 900; font-size: .75rem;
    }

    /* --- کادر خرید --- */
    .pd-price { font-weight: 900; font-size: 1.9rem; line-height: 1.1; color: var(--pd-accent); letter-spacing: -.5px; }
    .pd-price.is-discounted { color: var(--pd-rose); }
    .pd-old-price { text-decoration: line-through; opacity: .45; font-size: .85rem; font-weight: 700; }
    .pd-stock { font-size: .75rem; font-weight: 900; padding: .3rem .65rem; border-radius: .6rem; white-space: nowrap; }
    .pd-stock.in { color: var(--success, #10b981); background: rgba(16, 185, 129, .1); border: 1px solid rgba(16, 185, 129, .25); }
    .pd-stock.out { color: var(--pd-rose); background: rgba(244, 63, 94, .08); border: 1px solid rgba(244, 63, 94, .25); }
    .pd-btn {
        display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border-radius: .85rem;
        font-weight: 900; font-size: .85rem; transition: transform .15s, box-shadow .15s, background .15s; cursor: pointer; text-decoration: none;
    }
    .pd-btn-primary { background: var(--pd-accent); color: #04121a; box-shadow: 0 6px 18px rgba(6, 182, 212, .3); }
    body.light-mode .pd-btn-primary { color: #fff; }
    .pd-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(6, 182, 212, .4); }
    .pd-btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }
    .pd-btn-outline { border: 1px solid var(--border-glow); color: var(--text-main); background: transparent; }
    .pd-btn-outline:hover { border-color: var(--pd-accent); color: var(--pd-accent); }
    .pd-qty { display: flex; align-items: center; background: var(--input-bg); border: 1px solid var(--border-glow); border-radius: .85rem; padding: 3px; }
    .pd-qty button { width: 2.25rem; height: 2.5rem; font-size: 1.25rem; font-weight: 900; color: var(--text-main); border-radius: .6rem; }
    .pd-qty button:hover { color: var(--pd-accent); background: rgba(6, 182, 212, .08); }
    .pd-qty input { width: 3.25rem; text-align: center; background: transparent; border: 0; outline: none; color: var(--text-main); font-weight: 900; font-size: 1.05rem; }

    .variant-pill-item { transition: transform .2s; user-select: none; }
    .variant-pill-item .pd-variant-box { border: 1px solid var(--border-glow); background: var(--input-bg); }
    .variant-pill-item:hover:not(.is-out-of-stock) .pd-variant-box { border-color: var(--pd-accent); }
    .variant-pill-item.is-selected .pd-variant-box { border-color: var(--pd-accent); background: rgba(6, 182, 212, .14); box-shadow: 0 0 12px rgba(6, 182, 212, .2); }
    .variant-pill-item.is-selected .variant-check-icon { display: inline-block !important; }
    .variant-pill-item.is-out-of-stock { opacity: .45; cursor: not-allowed; }
    .variant-pill-item.is-out-of-stock .pd-variant-box { border-style: dashed; }

    /* --- مشخصات --- */
    .pd-spec-list { display: grid; grid-template-columns: 1fr; }
    @media (min-width: 640px) { .pd-spec-list.two-col { grid-template-columns: 1fr 1fr; column-gap: 2rem; } }
    .pd-spec { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px dashed var(--border-glow); font-size: .8rem; }
    .pd-spec dt { color: var(--text-muted); font-weight: 700; }
    .pd-spec dd { color: var(--text-main); font-weight: 900; text-align: left; direction: ltr; unicode-bidi: plaintext; }

    /* --- نوار بخش‌ها --- */
    .pd-tabs {
        position: sticky; top: var(--pd-header-h); z-index: 30; display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none;
        background: var(--nav-bg, var(--card-glass)); border: 1px solid var(--border-glow); border-radius: 1rem; padding: .35rem;
        backdrop-filter: blur(16px);
    }
    .pd-tabs::-webkit-scrollbar { display: none; }
    .pd-tab { white-space: nowrap; padding: .5rem .85rem; border-radius: .7rem; font-size: .78rem; font-weight: 900; color: var(--text-muted); text-decoration: none; }
    .pd-tab:hover { color: var(--text-main); }
    .pd-tab.active { background: rgba(6, 182, 212, .14); color: var(--pd-accent); }
    .pd-section { scroll-margin-top: calc(var(--pd-header-h) + 4.5rem); padding: 1.25rem; }
    @media (min-width: 768px) { .pd-section { padding: 1.75rem; } }

    .pd-prose { color: var(--text-main); font-size: .9rem; line-height: 2; text-align: justify; }
    .pd-prose h2, .pd-prose h3 { font-weight: 900; margin: 1.2rem 0 .5rem; }
    .pd-prose ul { list-style: disc; padding-right: 1.25rem; }
    .pd-prose ol { list-style: decimal; padding-right: 1.25rem; }
    .pd-prose table { width: 100%; font-size: .8rem; }
    .pd-prose td, .pd-prose th { border: 1px solid var(--border-glow); padding: .35rem .5rem; }
    .pd-prose img { max-width: 100%; height: auto; border-radius: .75rem; }
    .pd-collapsible.is-collapsed { max-height: 520px; overflow: hidden; position: relative; }
    .pd-collapsible.is-collapsed::after {
        content: ''; position: absolute; inset: auto 0 0 0; height: 6rem;
        background: linear-gradient(to bottom, transparent, var(--card-glass));
    }

    .pd-tiers th { font-weight: 700; color: var(--text-muted); padding: .3rem 0; font-size: .7rem; }
    .pd-tiers td { padding: .35rem 0; border-top: 1px dashed var(--border-glow); }
    .pd-tiers tr.is-current td { color: rgb(6 182 212); }
    .pd-equivalents { display: grid; gap: .5rem; }
    @media (min-width: 768px) { .pd-equivalents { grid-template-columns: 1fr 1fr; } }
    .pd-equivalent { display: flex; align-items: center; justify-content: space-between; gap: .75rem; border: 1px solid var(--border-glow); border-radius: .9rem; padding: .6rem .75rem; text-decoration: none; transition: border-color .2s; }
    .pd-equivalent:hover { border-color: rgb(6 182 212 / .6); }
    .pd-similar { display: flex; flex-direction: column; border: 1px solid var(--border-glow); border-radius: 1rem; padding: .6rem; text-decoration: none; transition: border-color .2s, transform .2s; height: 100%; }
    .pd-similar:hover { border-color: var(--pd-accent); transform: translateY(-2px); }
    .pd-similar-img { background: #fff; border-radius: .75rem; aspect-ratio: 1/1; overflow: hidden; display: flex; align-items: center; justify-content: center; }
    .pd-similar-img img { width: 100%; height: 100%; object-fit: contain; }

    .review-card, .q-box { background: var(--input-bg); border: 1px solid var(--border-glow); }
    .a-box { background: rgba(16, 185, 129, .05); border-right: 3px solid rgba(16, 185, 129, .45); }
    .pd-badge { font-size: .65rem; font-weight: 900; padding: .25rem .55rem; border-radius: .5rem; border: 1px solid; }
    .console-input input, .console-input textarea, .pd-input {
        background: var(--input-bg); border: 1px solid var(--border-glow); color: var(--text-main); outline: none; transition: border-color .2s;
    }
    .console-input input:focus, .console-input textarea:focus, .pd-input:focus { border-color: var(--pd-accent); }

    /* --- نوار خرید چسبان --- */
    .pd-sticky {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 9980; padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom));
        background: var(--nav-bg, rgba(10, 15, 30, .95)); border-top: 1px solid var(--border-glow); backdrop-filter: blur(18px);
        box-shadow: 0 -10px 30px rgba(0, 0, 0, .35); transform: translateY(110%); transition: transform .25s ease; visibility: hidden;
    }
    .pd-sticky.is-visible { transform: translateY(0); visibility: visible; }
    @media (max-width: 767px) {
        /* بالای داک ناوبری موبایل (base.html: ارتفاع ۶۴ و فاصلهٔ ۱۴ پیکسل) */
        .pd-sticky { bottom: 86px; left: 14px; right: 14px; border: 1px solid var(--border-glow); border-radius: 1.1rem; padding: .5rem .6rem; }
        .pd-sticky .pd-qty button { width: 1.9rem; height: 2.1rem; }
        .pd-sticky .pd-qty input { width: 2.4rem; font-size: .95rem; }
    }

    /* --- بزرگ‌نمایی --- */
    #image-lightbox {
        position: fixed; inset: 0; z-index: 10000; background: rgba(0, 0, 0, .96); display: none;
        flex-direction: column; align-items: center; justify-content: center; padding: 3.5rem 1rem 1rem; touch-action: pan-y pinch-zoom;
    }
    #image-lightbox.is-open { display: flex; }
    .lightbox-main-img { max-width: 100%; max-height: calc(100vh - 11rem); object-fit: contain; border-radius: 1rem; background: #fff; touch-action: pinch-zoom; }
    .lightbox-btn { position: absolute; width: 3rem; height: 3rem; border-radius: 999px; background: rgba(255, 255, 255, .12); color: #fff; font-size: 1.6rem; display: flex; align-items: center; justify-content: center; border: 1px solid rgba(255, 255, 255, .2); }
    .lightbox-btn:hover { background: rgba(255, 255, 255, .22); }
    .lightbox-close { top: 1rem; right: 1rem; }
    .lightbox-prev { left: 1rem; top: 50%; transform: translateY(-50%); }
    .lightbox-next { right: 1rem; top: 50%; transform: translateY(-50%); }
    .lightbox-count { position: absolute; top: 1.6rem; left: 50%; transform: translateX(-50%); color: rgba(255, 255, 255, .7); font-size: .8rem; font-weight: 700; }
    .lightbox-thumbs { display: flex; gap: .5rem; margin-top: 1rem; overflow-x: auto; max-width: 100%; padding: .25rem; scrollbar-width: none; direction: ltr; }
    .lightbox-thumb-item { width: 56px; height: 56px; flex: 0 0 56px; border-radius: .6rem; border: 2px solid transparent; opacity: .5; object-fit: contain; background: #fff; cursor: pointer; }
    .lightbox-thumb-item.active { opacity: 1; border-color: var(--pd-accent); }

    #compare-modal { position: fixed; inset: 0; z-index: 9999; background: rgba(0, 0, 0, .75); display: none; align-items: center; justify-content: center; padding: 1rem; }

/* دستیار فنی (مرحلهٔ ۸): پرسش از دیتاشیت */
.pd-ai-badge { display: inline-block; margin-inline-start: .35rem; padding: 0 .4rem; border-radius: .35rem; font-size: .65rem; font-weight: 800;
    border: 1px solid var(--border-glow); color: var(--text-muted); }
.pd-ai-input { min-width: 12rem; border-radius: .75rem; border: 1px solid var(--border-glow); background: var(--input-bg, transparent);
    color: var(--text-main); padding: .55rem .8rem; font-size: .8rem; }
.pd-ai-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.pd-ai-out { margin-top: .8rem; padding: .8rem .9rem; border-radius: .75rem; background: var(--card-inner); border: 1px solid var(--border-glow); }
.pd-ai-label { margin: 0 0 .4rem; font-size: .7rem; font-weight: 800; color: var(--text-muted); }
.pd-ai-msg { margin: 0; font-size: .8rem; color: var(--text-main); }
.pd-ai-msg.is-warn { color: var(--cosmic-rose); }
.pd-ai-answer { font-size: .85rem; line-height: 2; color: var(--text-main); overflow-wrap: anywhere; }
.pd-ai-answer p { margin: .3rem 0; }
.pd-ai-answer ul, .pd-ai-answer ol { margin: .3rem 0; padding-inline-start: 1.2rem; }
.pd-ai-answer code { font-size: .85em; }
.pd-ai-cites { margin: .5rem 0 0; padding-inline-start: 1.1rem; font-size: .75rem; line-height: 1.9; color: var(--text-muted); }
.pd-ai-cites a { color: var(--primary); font-weight: 700; }
.pd-ai-cites q { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .7rem; }
