/* ==========================================================================
   BARSÄZ — Detail
   صفحهٔ جزئیات دوره و صفحهٔ خواندن مقاله
   ========================================================================== */

/* --------------------------------------------------------------------------
   Course hero
   -------------------------------------------------------------------------- */
.course-detail-hero {
    display: grid;
    grid-template-columns: 1.05fr .95fr;
    gap: 46px;
    align-items: center;
    padding-block: 46px 10px;
}

.detail-media {
    position: relative;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
}

.detail-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail-media .ph {
    position: absolute;
    inset: 0;
}

.detail-info .detail-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.detail-info h1 {
    margin-bottom: 14px;
    font-size: clamp(1.7rem, 3.2vw, 2.5rem);
}

.detail-lead {
    margin: 0;
    color: var(--muted);
    font-size: 15.5px;
    line-height: 2.1;
}

.detail-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 26px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}

.detail-fact-wide {
    grid-column: 1 / -1;
}

.detail-fact {
    display: flex;
    align-items: center;
    gap: 11px;
}

.detail-fact .ic {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex: none;
    border-radius: 13px;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
}

.detail-fact .ic svg {
    width: 20px;
    height: 20px;
}

.detail-fact b {
    display: block;
    font-size: 14px;
    line-height: 1.6;
}

.detail-fact small {
    color: var(--muted);
    font-size: 11.5px;
}

/* --------------------------------------------------------------------------
   Layout + sections
   -------------------------------------------------------------------------- */
.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 44px;
    align-items: start;
    margin-top: 58px;
    margin-bottom: 90px;
}

.detail-content {
    display: grid;
    gap: 24px;
    min-width: 0;
}

.detail-section {
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.detail-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.detail-section-head h2 {
    font-size: 1.2rem;
}

.detail-section-head .muted {
    font-size: 12.5px;
}

.faq-list .faq-answer {
    font-weight: 500;
}

.detail-side {
    position: sticky;
    top: calc(var(--header-h) + 24px);
    display: grid;
    gap: 18px;
}

/* --------------------------------------------------------------------------
   Buy card
   -------------------------------------------------------------------------- */
.buy-card {
    padding: 26px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
}

/* سکشن خرید موبایل (بعد از سوالات متداول، قبل از نظرات) — فقط در موبایل نمایش داده می‌شود */
.detail-buy-mobile {
    display: none;
}

.buy-price {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: 900;
    line-height: 1.4;
    color: var(--accent);
}

.buy-price small {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 400;
    color: var(--muted);
}

.buy-price.free {
    font-size: 22px;
}

.buy-actions {
    display: grid;
    gap: 10px;
    margin-top: 20px;
}

/* ---------- شمارندهٔ تعداد دورهٔ آنلاین داخل سبد (صفحهٔ دوره) ---------- */
.buy-qty {
    display: grid;
    gap: 10px;
}

.cart-qty-inline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 10px 14px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
}

.cart-qty-inline .cart-qty-value {
    font-size: 20px;
    min-width: 28px;
    text-align: center;
}

/* --------------------------------------------------------------------------
   استپر تعداد (دورهٔ آنلاین / محصول) — ویترین خرید بدون رفرش
   ساختار مورد انتظار:
   .qty-stepper-wrap[data-cart-stepper] >
     .qty-stepper-head (.qty-stepper-title + .badge)
     .qty-stepper > (form[data-cart-remove] > .qty-btn.minus)
                    (.qty-input-wrap > input.qty-input[data-qty-input][data-qty-value] + .qty-unit)
                    (form[data-cart-add] > .qty-btn.plus)
     .qty-hint
   -------------------------------------------------------------------------- */
.qty-stepper-wrap {
    display: grid;
    gap: 10px;
}

.qty-stepper-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.qty-stepper-title {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 700;
}

.qty-stepper-title svg {
    width: 17px;
    height: 17px;
    color: var(--accent);
}

.qty-stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 8px;
    border-radius: var(--radius-pill);
    background:
        linear-gradient(180deg,
            color-mix(in srgb, var(--accent) 10%, var(--surface)),
            var(--surface));
    border: 1.5px solid color-mix(in srgb, var(--accent) 42%, var(--line-strong));
    box-shadow:
        var(--shadow-sm),
        0 10px 26px -18px color-mix(in srgb, var(--accent) 70%, transparent),
        inset 0 1px 0 rgba(255, 255, 255, .55);
}

.qty-stepper form {
    display: contents;
}

.qty-btn {
    width: 46px;
    height: 46px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1.5px solid transparent;
    font-size: 24px;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    transition:
        transform .16s var(--ease),
        box-shadow .22s var(--ease),
        background-color .22s var(--ease),
        border-color .22s var(--ease),
        color .22s var(--ease),
        opacity .2s var(--ease);
}

.qty-btn svg {
    width: 18px;
    height: 18px;
}

.qty-btn.minus {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--ink-2);
}

.qty-btn.minus:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 8%, var(--surface));
    box-shadow: 0 8px 18px -12px color-mix(in srgb, var(--danger) 60%, transparent);
}

.qty-btn.plus {
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--accent) 88%, #fff),
        var(--accent));
    color: var(--accent-ink);
    box-shadow: 0 10px 22px -10px color-mix(in srgb, var(--accent) 75%, transparent);
}

.qty-btn.plus:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 26px -10px color-mix(in srgb, var(--accent) 80%, transparent);
}

.qty-btn:active {
    transform: scale(.9);
}

.qty-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.qty-btn:focus-visible,
.qty-input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.qty-input-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    flex: 1;
    gap: 1px;
}

.qty-input {
    width: 72px;
    border: 0;
    background: transparent;
    text-align: center;
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 900;
    line-height: 1.3;
    color: var(--ink);
    direction: ltr;
}

.qty-input {
    -moz-appearance: textfield;
    appearance: textfield;
}

.qty-unit {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
}

.qty-hint {
    margin: 0;
    text-align: center;
    color: var(--muted);
    font-size: 11.5px;
}

.qty-stock {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}

/* جهش عدد هنگام تغییر تعداد */
[data-qty-value].qty-bump {
    animation: qty-bump .38s var(--ease);
}

@keyframes qty-bump {
    0% { transform: scale(.65); }
    55% { transform: scale(1.14); }
    100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    [data-qty-value].qty-bump {
        animation: none;
    }
    .qty-btn {
        transition: none;
    }
}

.buy-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 14px;
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.9;
}

.buy-note svg {
    width: 16px;
    height: 16px;
    flex: none;
    margin-top: 4px;
    color: var(--accent);
}

/* --------------------------------------------------------------------------
   Sessions
   -------------------------------------------------------------------------- */
.detail-sessions {
    display: grid;
    gap: 10px;
}

.detail-session {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--bg);
    transition: border-color var(--dur) var(--ease);
}

.detail-session:hover {
    border-color: var(--line-strong);
}

.detail-session .no {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: none;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 900;
}

.detail-session b {
    font-size: 14px;
}

.detail-session .end {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-inline-start: auto;
    color: var(--muted);
    font-size: 12px;
}

.detail-session .end svg {
    width: 15px;
    height: 15px;
}

/* --------------------------------------------------------------------------
   Instructor
   -------------------------------------------------------------------------- */
.instructor-card {
    display: flex;
    align-items: flex-start;
    gap: 24px;
}

.instructor-info {
    flex: 1;
    min-width: 0;
}

.instructor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.instructor-avatar {
    display: grid;
    place-items: center;
    width: 104px;
    height: 104px;
    flex: none;
    overflow: hidden;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--accent);
    font-family: var(--font-display);
    font-size: 38px;
    font-weight: 900;
}

.instructor-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.instructor-card h3 {
    margin-bottom: 4px;
    font-size: 1.15rem;
}

.instructor-card .specialty {
    display: inline-block;
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
}

.instructor-card .bio {
    margin: 10px 0 16px;
    color: var(--muted);
    font-size: 13.5px;
    line-height: 2;
}

.instructor-card .social-row {
    margin-top: 2px;
}

/* --------------------------------------------------------------------------
   Reviews
   -------------------------------------------------------------------------- */
.rating-summary {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 22px;
    padding: 18px 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
}

.rating-score {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 900;
    line-height: 1.2;
    color: var(--accent);
}

.rating-summary .meta {
    color: var(--muted);
    font-size: 12.5px;
}

.review-list {
    display: grid;
    gap: 16px;
}

.review-item {
    display: flex;
    gap: 14px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
}

.review-avatar {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: none;
    overflow: hidden;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--accent);
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 900;
}

.review-body {
    flex: 1;
    min-width: 0;
}

.review-body .who {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.review-body .who b {
    font-size: 13.5px;
}

.review-stars {
    color: var(--accent);
    font-size: 12px;
    letter-spacing: 2px;
}

.review-body p {
    margin: 0;
    color: var(--ink-2);
    font-size: 13.5px;
    line-height: 2.05;
}

.review-replies {
    display: grid;
    gap: 9px;
    margin-top: 12px;
    padding-inline-start: 16px;
    border-inline-start: 2px solid var(--line);
}

.review-reply {
    color: var(--muted);
    font-size: 13px;
}

.review-reply b {
    color: var(--ink-2);
}

/* --------------------------------------------------------------------------
   Video
   -------------------------------------------------------------------------- */
.video-embed {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--dark);
    aspect-ratio: 16 / 9;
}

.video-embed iframe,
.video-embed video {
    width: 100%;
    height: 100%;
    border: 0;
}

/* --------------------------------------------------------------------------
   Review form
   -------------------------------------------------------------------------- */
.review-form-wrap {
    position: relative;
    margin-bottom: 26px;
}

.review-form {
    display: grid;
    gap: 14px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
}

.review-form-title {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.review-form-title b {
    font-family: var(--font-display);
    font-size: 15.5px;
}

.review-form-title .muted {
    font-size: 12.5px;
}

.star-input {
    display: flex;
    flex-direction: row-reverse;
    justify-content: flex-end;
    gap: 4px;
    direction: ltr;
}

.star-input input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.star-input label {
    font-size: 28px;
    line-height: 1;
    color: var(--line-strong);
    cursor: pointer;
    transition: color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.star-input label:hover {
    transform: scale(1.12);
}

.star-input label:hover,
.star-input label:hover ~ label,
.star-input input:checked ~ label {
    color: var(--accent);
}

.review-form textarea.input {
    min-height: 96px;
    resize: vertical;
}

.review-form .btn {
    justify-self: start;
}

.review-gate {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-items: center;
    padding: 24px;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
    text-align: center;
}

.review-gate-inner {
    display: grid;
    justify-items: center;
    gap: 10px;
    max-width: 340px;
}

.review-gate .lock {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--accent);
}

.review-gate .lock svg {
    width: 24px;
    height: 24px;
}

.review-gate b {
    font-family: var(--font-display);
    font-size: 15.5px;
}

.review-gate p {
    margin: 0;
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.95;
}

/* --------------------------------------------------------------------------
   Article
   -------------------------------------------------------------------------- */
.article-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 48px;
    align-items: start;
    margin-top: 34px;
    margin-bottom: 90px;
}

.article-main {
    min-width: 0;
}

.article-cover {
    aspect-ratio: 16 / 8;
    overflow: hidden;
    margin-bottom: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
}

.article-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.article-header h1 {
    margin-bottom: 16px;
}

.article-meta-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 22px;
    padding-bottom: 22px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-size: 13px;
}

.article-meta-bar .m {
    display: flex;
    align-items: center;
    gap: 8px;
}

.article-meta-bar svg {
    width: 16px;
    height: 16px;
    color: var(--accent);
}

.article-side {
    position: sticky;
    top: calc(var(--header-h) + 24px);
    display: grid;
    gap: 18px;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
    .course-detail-hero {
        grid-template-columns: 1fr;
        gap: 32px;
        padding-top: 34px;
    }
    .detail-media {
        max-width: 560px;
        margin-inline: auto;
    }
    .detail-layout {
        grid-template-columns: 1fr;
        gap: 30px;
        margin: 0;
    }

    /* نوار خرید موبایل تا رسیدن به سکشن خریدِ بعد از سوالات همراه صفحه می‌ماند */
    body:has(.course-detail-hero):not(.course-buy-section-visible) {
        padding-bottom: calc(100px + env(safe-area-inset-bottom));
    }

    .detail-side {
        position: fixed;
        inset-inline: 0;
        top: auto;
        bottom: 0;
        z-index: 80;
        display: block;
        padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--line);
        background: var(--surface);
        box-shadow: 0 -12px 30px color-mix(in srgb, var(--ink) 9%, transparent);
    }

    body.course-buy-section-visible .detail-side {
        display: none;
    }

    .detail-buy-mobile {
        display: block;
    }

    /* نوار خرید شناور فشرده؛ سکشن اصلی بعد از سوالات با ظاهر عادی باقی می‌ماند */
    .detail-side .buy-card {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
        max-height: 60vh;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }

    .detail-buy-mobile .buy-note {
        display: none;
    }

    .detail-buy-mobile .buy-card {
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }

    .detail-buy-mobile .buy-actions {
        max-width: none;
        justify-items: stretch;
        margin-top: 16px;
    }

    .detail-buy-mobile .buy-actions .btn {
        width: 100%;
    }

    /* قیمت در موبایل دو خطی: قیمت خط‌خورده بالا، قیمت نهایی پایین */
    .buy-price {
        flex: none;
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        min-width: 0;
        font-size: 21px;
        line-height: 1.35;
    }

    .buy-price .price-original {
        margin-inline-end: 0;
        font-size: 11px;
        line-height: 1.6;
    }

    .buy-price .price-current {
        gap: 4px;
        max-width: 100%;
    }

    .buy-price small {
        font-size: 11px;
    }

    .buy-price.free {
        font-size: 19px;
    }

    /* دکمه‌ها جمع‌وجور (مثل نوار پرداخت سبد) و با استایل معمولی btn-primary */
    .buy-actions {
        display: grid;
        flex: none;
        max-width: 60%;
        justify-items: end;
        gap: 10px;
        margin-top: 0;
    }

    .buy-actions .btn {
        width: auto;
        min-width: 190px;
        min-height: 46px;
        padding: 13px 26px;
        font-size: 13px;
        white-space: normal;
    }

    .buy-actions .badge {
        display: none;
    }

    .detail-buy-mobile .buy-actions {
        width: 100%;
        grid-template-columns: minmax(0, 1fr);
        justify-items: stretch;
        gap: 10px;
    }

    .detail-buy-mobile .buy-actions > *,
    .detail-buy-mobile .buy-actions > form {
        width: 100%;
        min-width: 0;
    }

    .detail-buy-mobile .buy-actions .btn {
        width: 100%;
        min-width: 0;
        min-height: 48px;
        padding-inline: 16px;
        white-space: normal;
    }

    .detail-side .buy-note {
        display: none;
    }
    .article-layout {
        grid-template-columns: 1fr;
        gap: 34px;
    }
    .article-side {
        position: static;
    }
}

/* دکمهٔ شناور تغییر تم روی محتوا یا کارت خرید صفحه جزئیات نیفتد. */
body:has(.course-detail-hero) .theme-switcher {
    display: none;
}

@media (max-width: 640px) {
    .course-detail-hero {
        gap: 20px;
        padding-top: 22px;
    }
    .detail-media {
        width: 100%;
        margin-inline: auto;
    }
    .detail-info h1 {
        font-size: clamp(1.5rem, 7vw, 2rem);
        overflow-wrap: anywhere;
    }
    .detail-facts {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 10px;
        margin-top: 20px;
        padding-top: 18px;
    }
    .detail-fact {
        min-width: 0;
        align-items: flex-start;
        gap: 8px;
    }
    .detail-fact > span:last-child {
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .detail-fact b {
        font-size: 13px;
    }
    .detail-layout {
        margin: 0;
    }
    .detail-content {
        gap: 12px;
    }
    /* باکس‌های سفید به لبه‌ها می‌چسبند و پدینگ کانتینر داخلشان اعمال می‌شود */
    .detail-section {
        margin-inline: calc(var(--gutter) * -1);
        padding: 26px var(--gutter) 20px;
        border-inline: 0;
        border-radius: 0;
    }

    /* سوالات متداول: پس‌زمینهٔ صفحه برای هر سؤال در موبایل */
    .faq-item {
        background: var(--bg);
    }
    .instructor-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    .instructor-avatar {
        width: 82px;
        height: 82px;
        font-size: 30px;
    }
    .rating-summary {
        gap: 14px;
        padding: 14px 16px;
    }
    .rating-score {
        font-size: 28px;
    }
    .buy-card {
        gap: 10px;
    }
    .buy-price {
        max-width: 45%;
        font-size: clamp(16px, 5vw, 21px);
        overflow-wrap: anywhere;
    }
    .buy-actions .btn {
        min-width: 185px;
        min-height: 48px;
        padding-inline: 20px;
        line-height: 1.5;
    }
    .article-cover {
        aspect-ratio: 16 / 10;
        margin-bottom: 24px;
    }
}

@media (max-width: 380px) {
    .detail-fact .ic {
        width: 36px;
        height: 36px;
    }
    .detail-fact .ic svg {
        width: 18px;
        height: 18px;
    }
    .buy-card {
        gap: 8px;
    }
    .buy-price {
        max-width: 42%;
        font-size: 16px;
    }
    .buy-actions .btn {
        min-width: 150px;
        padding-inline: 16px;
        font-size: 11.5px;
    }
}
