/* =====================================================
   TFAC Storefront — Design System & Base Components
   ===================================================== */

/* ---- CSS Custom Properties (Design Tokens) ---- */
:root {
    /* Spacing Scale */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    --space-3xl: 64px;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Transitions */
    --ease-out: cubic-bezier(0.25, 0.8, 0.25, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;

    /* Z-Index Scale */
    --z-sticky: 40;
    --z-modal: 50;
    --z-toast: 60;
}

/* ---- Base Resets for Storefront ---- */
.storefront-container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
}

/* ---- Section Headings ---- */
.section-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #F5F5F5;
}

.section-heading__icon {
    font-size: 28px;
    line-height: 1;
}

.section-heading__text {
    display: flex;
    flex-direction: column;
}

.section-heading__title {
    font-family: 'Inter', 'Sarabun', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: #171717;
    letter-spacing: -0.01em;
}

.section-heading__subtitle {
    font-size: 14px;
    color: #737373;
    font-weight: 400;
    margin-top: 2px;
}

/* ---- Badge Components ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.badge--online {
    background: #EFF6FF;
    color: #1D4ED8;
    border: 1px solid #BFDBFE;
}

.badge--onsite {
    background: #FFF7ED;
    color: #C2410C;
    border: 1px solid #FED7AA;
}

.badge--cpd-countable {
    background: #F0FDF4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.badge--free {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: 1px solid #34d399;
    padding: 4px 14px;
    font-size: 12px;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

.badge--new {
    background: linear-gradient(135deg, #EF4444, #DC2626);
    color: white;
    font-size: 10px;
    padding: 2px 8px;
    animation: pulseSoft 2s ease-in-out infinite;
}

.badge--trending {
    background: linear-gradient(135deg, #F59E0B, #D97706);
    color: white;
    font-size: 10px;
    padding: 2px 8px;
}

.badge--recommended {
    background: linear-gradient(135deg, #3B82F6, #2563EB);
    color: white;
    font-size: 10px;
    padding: 2px 8px;
}

.badge--status-open {
    background: #DCFCE7;
    color: #166534;
    border: 1px solid #BBF7D0;
}

.badge--status-full {
    background: #FEF3C7;
    color: #92400E;
    border: 1px solid #FDE68A;
}

.badge--status-cancel {
    background: #FEE2E2;
    color: #991B1B;
    border: 1px solid #FECACA;
}

.badge--status-shift {
    background: #E0E7FF;
    color: #3730A3;
    border: 1px solid #C7D2FE;
}

.badge--status-stop {
    background: #F3F4F6;
    color: #374151;
    border: 1px solid #D1D5DB;
}

.badge--pending {
    background: #FEF9C3;
    color: #854D0E;
    border: 1px solid #FEF08A;
}

.badge--discount {
    background: #DD030E;
    color: white;
    padding: 2px 8px;
    font-size: 10px;
}

/* ---- Button Components ---- */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    background: #DD030E;
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(221, 3, 14, 0.2);
}

.btn-primary:hover {
    background: #B91C1C;
    box-shadow: 0 4px 16px rgba(221, 3, 14, 0.3);
    transform: translateY(-1px);
    color: white;
    text-decoration: none;
}

.btn-outline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    background: white;
    color: #525252;
    border: 1px solid #D4D4D4;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    text-decoration: none;
}

.btn-outline:hover {
    background: #FAFAFA;
    border-color: #A3A3A3;
    color: #171717;
    text-decoration: none;
}

/* ---- Skeleton Loading ---- */
.skeleton {
    position: relative;
    overflow: hidden;
    background: #E5E5E5;
    border-radius: var(--radius-md);
}

.skeleton::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        left: -100%;
    }

    100% {
        left: 100%;
    }
}

@keyframes pulseSoft {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* ---- Card Skeleton ---- */
.card-skeleton {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid #E5E5E5;
    padding: 0;
    overflow: hidden;
}

.card-skeleton__image {
    width: 100%;
    height: 160px;
    background: #E5E5E5;
}

.card-skeleton__body {
    padding: 16px;
}

.card-skeleton__line {
    height: 12px;
    margin-bottom: 10px;
    border-radius: 6px;
}

.card-skeleton__line--title {
    width: 85%;
    height: 16px;
}

.card-skeleton__line--sub {
    width: 60%;
}

.card-skeleton__line--short {
    width: 40%;
}

/* ---- Horizontal Scroll Section ---- */
.horizontal-scroll-container {
    position: relative;
    width: 100%;
}

.horizontal-scroll {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding-bottom: 24px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* Firefox */
    scroll-snap-type: x mandatory;
    padding-left: 4px;
    padding-right: 15%;
    /* Creates the peeking effect for the next card */
}

/* Hide scrollbar completely across browsers */
.horizontal-scroll::-webkit-scrollbar {
    width: 0px !important;
    height: 0px !important;
    display: none !important;
    background: transparent !important;
}

.horizontal-scroll.is-dragging {
    scroll-behavior: auto;
    /* Disable smooth scrolling during drag */
    scroll-snap-type: none;
    /* Disable snap during drag */
    cursor: grabbing;
    cursor: -webkit-grabbing;
}

.horizontal-scroll>* {
    scroll-snap-align: start;
    flex-shrink: 0;
    user-select: none;
    /* Prevent text selection during drag */
}

/* Nav Buttons */
.scroll-nav-btn {
    position: absolute;
    top: calc(50% - 12px);
    /* Center vertically, offset padding-bottom */
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(4px);
    border: 1px solid #E5E5E5;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 20;
    transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
    color: #525252;
}

.scroll-nav-btn:hover {
    background: #DD030E;
    color: #FFFFFF;
    border-color: #DD030E;
    box-shadow: 0 8px 24px rgba(221, 3, 14, 0.3);
    transform: translateY(-50%) scale(1.1);
}

.scroll-nav-btn:active {
    transform: translateY(-50%) scale(0.95);
    box-shadow: 0 4px 12px rgba(221, 3, 14, 0.2);
}

.scroll-nav-btn--left {
    left: -35px;
}

.scroll-nav-btn--right {
    right: -35px;
}

@media (max-width: 768px) {
    .horizontal-scroll {
        padding-right: 25%;
        /* More peek on smaller screens */
    }
}

/* ---- Price Components ---- */
.price-original {
    text-decoration: line-through;
    color: #A3A3A3;
    font-size: 12px;
}

.price-discounted {
    color: #DD030E;
    font-weight: 700;
    font-size: 16px;
}

.price-normal {
    color: #171717;
    font-weight: 600;
    font-size: 15px;
}

/* ---- CPD Mini Table ---- */
.cpd-mini {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    font-size: 11px;
}

.cpd-mini__group {
    background: #FAFAFA;
    border: 1px solid #E5E5E5;
    border-radius: var(--radius-sm);
    padding: 6px 8px;
}

.cpd-mini__label {
    color: #737373;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 4px;
}

.cpd-mini__row {
    display: flex;
    justify-content: space-between;
    color: #404040;
    line-height: 1.6;
}

.cpd-mini__row span:first-child {
    color: #737373;
}

/* ---- Responsive Utilities ---- */
@media (max-width: 640px) {
    .section-heading__title {
        font-size: 16px;
    }

    .section-heading__icon {
        font-size: 24px;
    }
}

/* ============================================================
   TFAC LOADER — Modern Logo Shimmer + Mirror Reflection
   ============================================================ */

/* Container (block loader below grids/carousels) */
.tfac-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 20px 20px;
    gap: 14px;
    width: 100%;
}

/* Compact card-sized loader inside a carousel */
.tfac-loader--card {
    flex: 0 0 auto;
    width: 220px;
    min-height: 160px;
    padding: 20px 16px;
    border-radius: var(--radius-lg, 12px);
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px dashed var(--surface-200, #e2e8f0);
    margin-left: 4px;
}

/* Logo + shimmer + reflection wrapper */
.tfac-loader__logo-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    user-select: none;
}

/* Main logo */
.tfac-loader__logo {
    width: 96px;
    height: auto;
    display: block;
    animation: tfac-logo-pulse 2.4s ease-in-out infinite;
    filter: drop-shadow(0 6px 20px rgba(30, 80, 155, 0.28));
    position: relative;
    z-index: 1;
}

.tfac-loader--card .tfac-loader__logo {
    width: 72px;
}

/* Shimmer sweep overlay (sits ON TOP of logo) */
.tfac-loader__shimmer {
    position: absolute;
    top: 0;
    left: -10%;
    width: 120%;
    height: 100%;
    background: linear-gradient(
        105deg,
        transparent 25%,
        rgba(255, 255, 255, 0.82) 48%,
        rgba(255, 255, 255, 0.55) 52%,
        transparent 75%
    );
    animation: tfac-shimmer-sweep 2.4s ease-in-out infinite;
    pointer-events: none;
    mix-blend-mode: overlay;
    z-index: 2;
    border-radius: 4px;
}

/* Mirror reflection — flipped copy below logo */
.tfac-loader__reflection {
    width: 96px;
    height: auto;
    display: block;
    transform: scaleY(-1);
    opacity: 0.22;
    filter: blur(1.8px);
    -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, transparent 80%);
    mask-image: linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, transparent 80%);
    margin-top: -6px;
    pointer-events: none;
    animation: tfac-logo-pulse 2.4s ease-in-out infinite;
}

.tfac-loader--card .tfac-loader__reflection {
    width: 72px;
}

/* Loading text */
.tfac-loader__text {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--surface-400, #94a3b8);
    letter-spacing: 0.07em;
    text-transform: uppercase;
    animation: tfac-text-blink 2.4s ease-in-out infinite;
}

/* ---- Keyframes ---- */
@keyframes tfac-logo-pulse {
    0%, 100% { opacity: 0.72; transform: translateY(0) scale(1); }
    50%       { opacity: 1;    transform: translateY(-4px) scale(1.03); }
}

@keyframes tfac-shimmer-sweep {
    0%        { background-position: -200% 0; transform: translateX(-50%); }
    60%, 100% { background-position: 200% 0;  transform: translateX(50%); }
}

@keyframes tfac-text-blink {
    0%, 100% { opacity: 0.45; }
    50%       { opacity: 1; }
}

/* Sentinel (invisible trigger for IntersectionObserver) */
.scroll-sentinel {
    height: 1px;
    visibility: hidden;
    pointer-events: none;
}

/* "ไม่มีเพิ่มเติม" end-of-list indicator */
.no-more-courses {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px;
    color: var(--surface-400, #94a3b8);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.05em;
}

/* ---- Skeleton Fade Animation (lighter alternative to animate-pulse) ---- */
@keyframes skeleton-fade {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

.skeleton-fade {
    animation: skeleton-fade 3s ease-in-out infinite;
}

/* ---- Content Visibility for Below-Fold Sections ----
   Progressive enhancement: browsers that don't support
   content-visibility will simply render all sections normally.
   The first .course-tier-backdrop (above-the-fold) is excluded
   so it renders immediately in the initial viewport.            */
.course-tier-backdrop:not(:first-of-type) {
    content-visibility: auto;
    contain-intrinsic-size: auto 600px;
}
