/* =============================================================================
 * rf5-ads.css — โฆษณาซ้าย/ขวา/footer ของหน้าลงทะเบียน RF5
 *
 * เลือกใช้ position: fixed สำหรับ rail แทนการยัดเข้า flex row ของ .rf5-shell
 * เพราะ shell เดิมเป็น max-width container ที่มี CSS เยอะมาก การไปแก้โครง
 * เสี่ยงพังฟอร์ม — fixed rail ให้ผลทางสายตาเหมือนกัน และเมื่อไม่มีโฆษณา
 * ฟอร์มก็กว้างเต็มเองอยู่แล้วโดยไม่ต้องทำอะไร
 *
 * เอกสาร: expopass-api-v2-nest/docs/11-ad-banner-system.md
 * ========================================================================== */

:root {
    --rf5-ad-width: 160px;
    --rf5-ad-height: 480px;
    --rf5-ad-gap: 24px;
    /* ระยะห่างจากขอบจอของ rail — 0 = ชิดขอบ ปรับที่นี่ที่เดียวถ้าอยากเว้นบ้าง */
    --rf5-ad-edge: 0px;
    /* ความกว้างของ .rf5-shell:not(.rf5-banner-wrap) */
    --rf5-ad-shell: 1036px;
}

/* ── rail ซ้าย/ขวา (desktop เท่านั้น) ─────────────────────────────────── */
.rf5-ad-rail {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: var(--rf5-ad-width);
    z-index: 20;
    display: none;
}

.rf5-ad-rail[data-ready="1"] {
    display: block;
}

/* ชิดขอบจอ ไม่ผูกกับตำแหน่งของ .rf5-shell
 *
 * เดิม left: calc(50% - shell/2 - gap - width) ทำให้ระยะห่างจากขอบโตตามความกว้างจอ
 * (จอ 1455 เหลือ 26px แต่จอ 1920 เหลือถึง 258px) กลายเป็นพื้นที่ว่างเปล่าก้อนใหญ่
 *
 * ปลอดภัยทุกความกว้าง: rail โชว์เฉพาะจอ >= 1404px (media query ด้านล่าง) ซึ่ง
 * 1404 = 1036 + 2 x (160 + 24) พอดี ดังนั้นที่ 0px ก็ยังไม่ทับ shell แม้จอแคบสุด */
.rf5-ad-rail--left {
    left: var(--rf5-ad-edge);
}

.rf5-ad-rail--right {
    right: var(--rf5-ad-edge);
}

/* ต้องมีที่ว่างพอทั้งสองข้าง ไม่งั้นซ่อน rail แล้วใช้ strip ล่างแทน
   1036 + 2 × (160 + 24) = 1404 */
@media (max-width: 1403.98px) {
    .rf5-ad-rail {
        display: none !important;
    }
}

/* ── การ์ดโฆษณา ──────────────────────────────────────────────────────── */
.rf5-ad-card {
    position: relative;
    width: var(--rf5-ad-width);
    border-radius: 12px;
    overflow: hidden;
    background: #111827;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
    cursor: pointer;
}

.rf5-ad-card__img {
    display: block;
    width: var(--rf5-ad-width);
    height: var(--rf5-ad-height);
    object-fit: cover;
    opacity: 1;
    transition: opacity .5s ease;
}

/* หมุนสลับ: fade out → เปลี่ยน src → fade in */
.rf5-ad-card.is-fading .rf5-ad-card__img {
    opacity: 0;
}

/* รูปโหลดไม่ได้ → พื้นเทา ไม่ให้ layout กระโดด */
.rf5-ad-card__img.is-broken {
    background: #e5e7eb;
    object-fit: contain;
}

.rf5-ad-card__close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(17, 24, 39, .75);
    color: #fff;
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: .5;
    transition: opacity .18s ease;
}

.rf5-ad-card:hover .rf5-ad-card__close,
.rf5-ad-card__close:focus-visible {
    opacity: 1;
}

/* CTA ต้องเห็นตลอด ไม่ใช่โผล่ตอน hover
   เดิม opacity: 0 + เผยตอน :hover เท่านั้น ทำให้บนอุปกรณ์ touch (แท็บเล็ต /
   จอกว้างที่ใช้นิ้ว) ไม่มี hover จึงไม่เห็นปุ่มเลยตลอดกาล ทั้งที่มันเป็น
   call-to-action หลักของโฆษณา — footer CTA (.rf5-ad-footer__cta) ก็เห็นตลอดอยู่แล้ว
   จึงทำให้สองที่สอดคล้องกัน แล้วเก็บ hover ไว้เป็นแค่การยกตัวขึ้นเล็กน้อย */
.rf5-ad-card__cta {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translate(-50%, 0);
    padding: 7px 16px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
    opacity: 1;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
    transition: opacity .22s ease, transform .22s ease;
    pointer-events: none;
}

/* เฉพาะเครื่องที่ hover ได้จริง — กัน :hover ค้างบน touch หลังแตะ */
@media (hover: hover) and (pointer: fine) {
    .rf5-ad-card__cta {
        transform: translate(-50%, 4px);
    }

    .rf5-ad-card:hover .rf5-ad-card__cta {
        transform: translate(-50%, -2px);
    }
}

/* ── dot indicators ──────────────────────────────────────────────────── */
.rf5-ad-dots {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
}

.rf5-ad-dots[hidden] {
    display: none;
}

.rf5-ad-dot {
    width: 6px;
    height: 6px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: rgba(148, 163, 184, .55);
    cursor: pointer;
    transition: width .2s ease, background .2s ease;
}

.rf5-ad-dot.is-active {
    width: 18px;
    background: #94a3b8;
}

/* ── footer banner ───────────────────────────────────────────────────── */
.rf5-ad-footer {
    max-width: var(--rf5-ad-shell);
    /* อยู่ระหว่างการ์ดฟอร์มกับ footer ของหน้า — เว้นระยะทั้งบนและล่าง
       ไม่งั้นมันไปติดขอบล่างสุดของเพจแล้วดูเหมือนแบนเนอร์เต็มความสูง */
    margin: 18px auto 22px;
    padding: 0 20px;
    display: none;
}

.rf5-ad-footer[data-ready="1"] {
    display: block;
}

.rf5-ad-footer__inner {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #111827;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
}

.rf5-ad-footer__img {
    display: block;
    width: 100%;
    /* ล็อกเป็นแถบเตี้ย ไม่ให้สูงตามภาพต้นฉบับ — ภาพ footer ที่อัปโหลดมามีสัดส่วน
       ไม่แน่นอน ถ้าใช้ height: auto การ์ดจะสูงเกินจนกินพื้นที่ฟอร์ม
       aspect-ratio + object-fit: cover ทำให้ได้แถบสูงคงที่และ crop กลางภาพให้ */
    aspect-ratio: 1200 / 280;
    height: auto;
    max-height: 185px;
    object-fit: cover;
    opacity: 1;
    transition: opacity .5s ease;
}

@media (max-width: 767px) {
    .rf5-ad-footer__img {
        max-height: 185px;
    }
}

.rf5-ad-footer__inner.is-fading .rf5-ad-footer__img {
    opacity: 0;
}

.rf5-ad-footer__cta {
    position: absolute;
    right: 16px;
    bottom: 16px;
    padding: 8px 18px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.rf5-ad-footer__close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(17, 24, 39, .75);
    color: #fff;
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: .6;
}

/* ── mobile strip ────────────────────────────────────────────────────── */
.rf5-ad-strip {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1040;
    background: #0f172a;
    color: #fff;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -6px 20px rgba(15, 23, 42, .28);
    display: none;
}

.rf5-ad-strip[data-ready="1"] {
    display: block;
}

/* strip เป็นของจอเล็กเท่านั้น — จอใหญ่ใช้ rail */
@media (min-width: 1404px) {
    .rf5-ad-strip {
        display: none !important;
    }
}

.rf5-ad-strip__row {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.rf5-ad-strip__thumb {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    background: #1f2937;
}

.rf5-ad-strip__body {
    flex: 1 1 auto;
    min-width: 0;
}

.rf5-ad-strip__title {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

.rf5-ad-strip__sub {
    font-size: 11px;
    color: #94a3b8;
    line-height: 1.3;
}

.rf5-ad-strip__cta {
    flex: 0 0 auto;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
}

.rf5-ad-strip__close {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* progress bar แทน dot บน mobile */
.rf5-ad-strip__progress {
    height: 2px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .14);
    margin-top: 7px;
    overflow: hidden;
}

.rf5-ad-strip__progress[hidden] {
    display: none;
}

.rf5-ad-strip__progress span {
    display: block;
    height: 100%;
    width: 0;
    background: #60a5fa;
    border-radius: 999px;
}

/* strip บังปุ่ม submit ที่อยู่ท้ายฟอร์ม — ดันพื้นที่ล่างเพิ่ม */
body.rf5-has-ad-strip {
    padding-bottom: 84px;
}

@media (min-width: 1404px) {
    body.rf5-has-ad-strip {
        padding-bottom: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rf5-ad-card__img,
    .rf5-ad-footer__img,
    .rf5-ad-card__cta,
    .rf5-ad-dot {
        transition: none;
    }
}
