/* ==========================================================================
   BP Survey Landing — Foundation
   Loaded on every section. Contains: reset, typography, section base,
   shared chrome (header, glass button, nav arrows), share modal.
   Section-specific styles live in assets/css/sections/<name>.css
   ========================================================================== */

/* --- Box-sizing reset --- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* --- Body ---
   Selector is `body.bp-survey-landing` (not `.bp-survey-landing body`) — the
   landing template sets `<body class="bp-survey-landing">`, so `body` and the
   class live on the SAME element. A descendant selector `.X body` would only
   match a body nested inside .X, which can never happen. */
body.bp-survey-landing {
    margin: 0;
    font-family: 'Kanit', 'Noto Sans Thai', Helvetica, Arial, sans-serif;
    overflow-x: hidden;
}

/* --- Section base --- */
.bp-section {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
}
.bp-section--dark {
    background-color: #1a1a1a;
    color: #fff;
}
.bp-section--light {
    background-color: #f5f5f5;
    color: #1a1a1a;
}
.bp-section__inner {
    position: relative;
    z-index: 2;
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 40px;
}
.bp-section__bg {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* --- Page header (logo + CTA — sits OUTSIDE #smooth-wrapper so position:fixed
       actually works; ScrollSmoother's transform on #smooth-content would
       otherwise make fixed children behave as absolute).
       JS toggles .is-light when the current section is a light-theme section
       so the white logo + dark glass CTA stay legible on light backgrounds. */
.bp-fixed-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 40px;
    pointer-events: none; /* children re-enable; the header bar itself shouldn't block scroll */
}
.bp-fixed-header > * {
    pointer-events: auto;
}
.bp-logo a {
    display: inline-block;
    position: relative;
    line-height: 0;
}
.bp-logo__img {
    display: block;
    height: 36px;
    width: auto;
    transition: opacity 0.3s ease;
}
/* Stack the two variants; the inactive one fades out. Dark is hidden by default. */
.bp-logo__img--dark {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    pointer-events: none;
}
/* Light-theme sections: show the dark logo, hide the white one. */
.bp-fixed-header.is-light .bp-logo__img--white { opacity: 0; }
.bp-fixed-header.is-light .bp-logo__img--dark  { opacity: 1; }

/* Hide the header CTA while on the lead-survey section (added by updateNavArrows).
   opacity + pointer-events so the logo row keeps the same width — no layout shift. */
.bp-fixed-header.is-cta-hidden .bp-btn-glass {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

/* --- Glass button (header CTA, hero CTA, GDP popup CTA, GDP bottom CTA) --- */
.bp-btn-glass {
    display: inline-block;
    padding: 12px 28px;
    color: #fff;
    text-decoration: none;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.2;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    background-color: #000000;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow:
        -1px -1px 1px 0.5px #FFFFFFBF inset,
        1px 1px 1px 0.5px #FFFFFFBF inset;
    transition: background-color 0.2s ease, color 0.2s ease;
}
.bp-btn-glass:hover,
.bp-btn-glass:focus {
    background-color: #E6E6E6;
    color: #1a1a1a;
    outline: none;
}

/* --- Glass pill v2 — translucent dark default / bright light on hover -----
   Used by section 8 Stage B "ย้อนกลับ" and "ลดต้นทุน" buttons. Works with or
   without an icon (back button uses .bp-btn-back__icon img slot). Layered
   box-shadows build the inner rim highlights + outer drop shadow of a real
   "frost" pill — all values come straight from the Figma spec. */
.bp-btn-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 22px;
    border: none;
    border-radius: 999px;
    color: #ffffff;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    background: #3333334D;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow:
        0 1px 8px 0 #0000001A,
        0 0 1px 1px #FFFFFF26 inset,
        -1px -1px 1px 0.5px #FFFFFFBF inset,
        1px 1px 1px 0.5px #FFFFFFBF inset;
    transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}
.bp-btn-back:hover,
.bp-btn-back:focus {
    background: #E6E6E6;
    color: #1a1a1a;
    outline: none;
    box-shadow:
        0 0 2px 0 #0000001A,
        0 0 16px 0 #F2F2F2 inset,
        0 0 1px 1px #999999 inset,
        3px 3px 0.5px -3.5px #FFFFFFCC inset,
        3px 3px 0.5px -3.5px #FFFFFFBF inset;
}
.bp-btn-back__icon {
    width: 16px;
    height: 16px;
    display: block;
    flex-shrink: 0;
}
/* Icon SVG has stroke="white" — invert on hover so it reads on the light bg. */
.bp-btn-back:hover .bp-btn-back__icon,
.bp-btn-back:focus .bp-btn-back__icon {
    filter: invert(1);
}

/* --- Page transition overlay (outside #smooth-wrapper, position:fixed) --- */
/* A dark panel that sweeps across the viewport to mask a scroll jump. JS uses
   it via slideOverlayTransition() — panel enters from the right, fires a
   midway callback (safe moment to scroll), then exits to the left. */
.bp-page-transition {
    position: fixed;
    inset: 0;
    background: #0a0a0a;
    transform: translateX(100%);
    z-index: 10000;
    pointer-events: none;
    will-change: transform;
}

/* --- Horizontal carousel (native scroll + arrow-driven scrollBy) ---------
   Set `--bp-per-view` on the .bp-carousel root to pick how many items fit
   across the viewport; the track uses scroll-snap so swipes on touch feel
   natural and arrow buttons use `track.scrollBy()` to advance by 1 card. */
.bp-carousel {
    position: relative;
    width: 100%;
    --bp-per-view: 3;
    --bp-carousel-gap: 16px;
}
.bp-carousel__track {
    display: flex;
    gap: var(--bp-carousel-gap);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    /* hide scrollbar — arrows are the nav affordance */
    scrollbar-width: none;
    padding-bottom: 4px;
}
.bp-carousel__track::-webkit-scrollbar { display: none; }
.bp-carousel__track > * {
    flex: 0 0 calc((100% - (var(--bp-carousel-gap) * (var(--bp-per-view) - 1))) / var(--bp-per-view));
    scroll-snap-align: start;
    min-width: 0;
}

/* Arrow buttons for .bp-carousel — user-provided PNG icons, we just frame them. */
.bp-carousel-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 999px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.bp-carousel-btn img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.bp-carousel-btn:hover { transform: translateY(-1px); }
.bp-carousel-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

/* --- TikTok modal (outside #smooth-wrapper, position:fixed) -------------
   Populated by JS: clicking a .bp-tiktok-card injects an <iframe> into
   [data-tiktok-player] and updates [data-tiktok-index] counter. Compact
   single-column: card wraps the 9:16 player with a thin bar above (index
   + close). Uses TikTok's /player/v1/ URL (minimal player, no profile
   header / description / CTA / comments) — for the rich embed with that
   chrome, swap to /embed/v2/ in landing.js. */
.bp-tiktok-modal {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.bp-tiktok-modal.is-open {
    display: flex;
}
.bp-tiktok-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    cursor: pointer;
}
.bp-tiktok-modal__card {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 24px 64px -16px rgba(0, 0, 0, 0.55);
    /* Width auto-fits the player (no wide empty sides). Max-width caps
       desktop size; 100vw fallback handles narrow viewports. */
    max-width: min(420px, calc(100vw - 32px));
}
.bp-tiktok-modal__bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 8px;
}
.bp-tiktok-modal__index {
    font-weight: 600;
    color: #171717;
    font-size: 0.9rem;
    letter-spacing: 0.02em;
}
.bp-tiktok-modal__close {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #171717;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}
.bp-tiktok-modal__close:hover { background: rgba(0, 0, 0, 0.08); }

/* Player width is the min of:
   - 400px  (desktop cap — avoids oversized embeds)
   - 100vw - 52px  (leaves room for card padding + modal padding)
   - available height × 9/16  (keeps the 9:16 shape from pushing below the fold)
   Height then derives from the aspect ratio. On short landscape phones the
   third term kicks in so the player shrinks instead of clipping. */
.bp-tiktok-modal__player {
    width: min(400px, calc(100vw - 52px), calc((100vh - 100px) * 9 / 16));
    aspect-ratio: 9 / 16;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    position: relative;
}
.bp-tiktok-modal__player iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* --- Nav arrows (lives outside #smooth-wrapper so position:fixed works) --- */
.bp-nav-arrows {
    position: fixed;
    bottom: 40px;
    right: 40px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.bp-nav-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    transition: opacity 0.2s ease;
}
.bp-nav-arrow__icon {
    display: block;
    width: 100%;
    height: 100%;
}
/* Show dark icons by default; light variants appear when .bp-nav-arrows.is-light */
.bp-nav-arrow__icon--light { display: none; }
.bp-nav-arrows.is-light .bp-nav-arrow__icon--dark { display: none; }
.bp-nav-arrows.is-light .bp-nav-arrow__icon--light { display: block; }

.bp-nav-arrow:hover,
.bp-nav-arrow:focus {
    opacity: 0.7;
    outline: none;
}

/* --- Social icons (universal) — Facebook / TikTok / YouTube / Share button.
       Each icon is rendered as TWO stacked imgs (--dark and --light); CSS
       hides the inactive one. Add `.is-light` on .bp-social-icons (or set
       $variant = 'light' on the partial) to flip to the light icon set —
       used on dark backgrounds (default) and light backgrounds (lead form).
       Per-context positioning lives in the section's own CSS. */
.bp-social-icons {
    display: flex;
    flex-direction: row;
    gap: 12px;
    align-items: center;
}
.bp-social-icons a,
.bp-social-icons button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: opacity 0.2s ease;
}
.bp-social-icons a:hover,
.bp-social-icons a:focus,
.bp-social-icons button:hover,
.bp-social-icons button:focus {
    opacity: 0.75;
    outline: none;
}
.bp-social-icons__img {
    display: block;
    width: 52px;
    height: 52px;
}
/* Default = dark icons; light variants hidden until .is-light flips them. */
.bp-social-icons__img--light { display: none; }
.bp-social-icons.is-light .bp-social-icons__img--dark  { display: none; }
.bp-social-icons.is-light .bp-social-icons__img--light { display: block; }

/* --- Share modal (lives outside #smooth-wrapper for position:fixed) --- */
.bp-share-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bp-share-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}
.bp-share-modal__content {
    position: relative;
    background: #e0e0e0;
    border-radius: 16px;
    padding: 28px 32px;
    max-width: 400px;
    width: 90%;
    z-index: 1;
}
.bp-share-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.bp-share-modal__title {
    font-size: 1.125rem;
    font-weight: 700;
    color: #1a1a1a;
}
.bp-share-modal__close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    line-height: 1;
    padding: 0;
}
.bp-share-modal__divider {
    border: none;
    border-top: 1px solid #ccc;
    margin: 12px 0 16px;
}
.bp-share-modal__label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #555;
    margin: 0 0 12px;
}
.bp-share-modal__icons {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}
.bp-share-modal__icon {
    display: block;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    transition: transform 0.2s;
}
.bp-share-modal__icon:hover {
    transform: scale(1.1);
}
.bp-share-modal__icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.bp-share-modal__copy {
    display: flex;
    align-items: center;
    background: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    gap: 8px;
}
.bp-share-modal__copy-icon {
    font-size: 1.125rem;
    color: #888;
    flex-shrink: 0;
}
.bp-share-modal__copy-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.875rem;
    color: #333;
    outline: none;
    min-width: 0;
}
.bp-share-modal__copy-btn {
    flex-shrink: 0;
    padding: 6px 16px;
    background: #1a1a1a;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.bp-share-modal__copy-btn:hover {
    background: #333;
}

/* --- Post-survey thank-you popup — lives outside #smooth-wrapper so its
       overlay can cover the full viewport (position:fixed). Opens via JS
       on a successful survey submit; close link/overlay navigates to the
       post-survey destination URL. Login-aware CTA is server-rendered. --- */
.bp-thanks-popup {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.bp-thanks-popup.is-open {
    display: flex;
    opacity: 1;
}
.bp-thanks-popup__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}
.bp-thanks-popup__card {
    position: relative;
    background: #ffffff;
    color: #171717;
    border-radius: 20px;
    padding: 40px 36px 32px;
    width: calc(100% - 40px);
    max-width: 360px;
    text-align: center;
    z-index: 1;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}
.bp-thanks-popup__close {
    position: absolute;
    top: 14px;
    right: 18px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    color: #737373;
    text-decoration: none;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}
.bp-thanks-popup__close:hover,
.bp-thanks-popup__close:focus-visible {
    background: #F5F5F5;
    color: #171717;
    outline: none;
}
.bp-thanks-popup__title {
    margin: 0 0 18px;
    font-size: 1.25rem;
    font-weight: 800;
    line-height: 1.4;
    color: #171717;
}
.bp-thanks-popup__text {
    margin: 0 0 24px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #404040;
}
.bp-thanks-popup__cta {
    display: inline-block;
    padding: 12px 36px;
    background: #171717;
    color: #ffffff;
    border-radius: 999px;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s, transform 0.2s;
}
.bp-thanks-popup__cta:hover,
.bp-thanks-popup__cta:focus-visible {
    background: #000000;
    outline: none;
    transform: translateY(-1px);
}

/* --- Foundation responsive (≤768px) --- */
@media (max-width: 768px) {
    .bp-section__inner { padding: 40px 20px; }
    .bp-fixed-header { padding: 16px 20px; }
    .bp-fixed-header .bp-btn-glass { font-size: 0.78rem; padding: 8px 14px; }
    .bp-logo img { height: 28px; }
    .bp-nav-arrows { bottom: 20px; right: 16px; }
    .bp-nav-arrow { width: 38px; height: 38px; font-size: 17px; }
    .bp-social-icons__img { width: 34px; height: 34px; }
}

/* --- Mobile section snap ---
   Mirrors the desktop arrow-nav UX (one swipe → one section). Native CSS snap
   on <html>: ScrollSmoother is created with `smoothTouch: false` (default), so
   on touch devices its transform tracks scrollTop 1:1 — snap operates on the
   real scroll position and visible content stays in sync.

   Sections taller than the viewport (lead-survey Stage A form, section-8
   Stage B carousels, survey Stage B 9 questions) keep their `min-height:
   100vh` from `.bp-section` and overflow naturally; `scroll-snap-stop: always`
   forces snap to land at the top of each section so a fast flick can't skip one.

   `100dvh` accounts for iOS Safari's address bar — `100vh` would leave snap
   targets ~80px off when the bar collapses. `dvh` is the dynamic-viewport unit
   that updates as the bar shows/hides. */
@media (max-width: 768px) {
    /* Snap mode is `proximity`, not `mandatory`. With mandatory snap, sections
       taller than the viewport (section-7 with 4 long items, section-8 chapter
       Stage B carousels) become unscrollable: any small swipe within the
       section snaps back to its top because mandatory always rests at a snap
       point. Proximity only snaps when the user is near a snap point — small
       swipes within a tall section flow naturally, and approaching the next
       section still snaps the user in cleanly. */
    html {
        scroll-snap-type: y proximity;
    }
    .bp-section {
        min-height: 100dvh;
        scroll-snap-align: start;
        scroll-snap-stop: always;
    }

    /* Disable snap while a modal/popup is open so the background can't drift
       to a different section under the overlay. JS adds .is-modal-open on
       <html> when share-modal / gdp-popup / tiktok-modal / thanks-popup open,
       and removes it on close. */
    html.is-modal-open {
        scroll-snap-type: none;
    }

    /* Section 5 opts out of forced snap stop. The video + mask-image + dvh
       address-bar reflow combination caused noticeable bouncing — letting the
       browser flick past it freely (still aligning to its top, just not
       forcing a stop) avoids the jitter while keeping the section snap-able. */
    .bp-section-5 {
        scroll-snap-stop: normal;
    }

    /* Section 8 chapters: on mobile we drop the desktop horizontal-slide
       Stage A/B pattern in favor of vertical stacking. Outer section is no
       longer a snap target — instead each inner __stage element snaps. User
       scrolls naturally Stage A → Stage B → next section. The per-section CSS
       below changes the stages-wrapper from row → column and zeros out the
       slide transform.

       Outer needs overflow:visible + auto height so the stacked stages can
       grow past 100vh into normal document flow without being clipped. */
    .bp-section-8-01,
    .bp-section-8-02,
    .bp-section-8-03,
    .bp-section-8-04 {
        scroll-snap-align: none;
        scroll-snap-stop: normal;
        overflow: visible;
        min-height: 0;
    }
    .bp-section-8-01__stage,
    .bp-section-8-02__stage,
    .bp-section-8-03__stage,
    .bp-section-8-04__stage {
        scroll-snap-align: start;
        scroll-snap-stop: always;
        min-height: 100dvh;
    }

    /* Lead-survey opts out of snap entirely on mobile. The Stage A form fields
       trigger keyboard show/hide and dropdown panels that fight a snap port —
       focus jumps, scroll snaps mid-input, the combobox dropdown gets clipped.
       Letting the user scroll freely through the form + survey questions is
       far better UX. The CTA "ถัดไป" still slides A→B (it's a form submit, not
       a scroll-driven advance), and the wrapped toggler scrolls back to the
       section top after the slide so Stage B starts at the top. */
    .bp-lead-survey {
        scroll-snap-align: none;
        scroll-snap-stop: normal;
    }
}
