/*
 * Shoptimised Timeline
 * Horizontal alternating cards on desktop, vertical stack on mobile (<=768px).
 *
 * Layout decisions baked in (see planning conversation):
 *  - Cards 320px, left-aligned text, drop shadow
 *  - Active (newest) entry gets teal-tinted border + teal dot with glow
 *  - Dates anchored near the line (odd cards flip meta to card bottom)
 *  - Scroll-snap: mandatory per card
 *  - Gradient fades on line ends and scroller right edge
 *  - Year breaks: wider gap when year changes
 *  - 2px teal progress bar beneath the timeline
 */

/* Stop the Oxygen code-block wrapper from expanding to fit the horizontally-
   scrollable list. Without this, the wrapper's min-width:auto (flex-item
   default) is computed from its content's min-content, which includes the
   full scroll width. */
.ct-code-block:has(> .shoptimised-timeline) {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.shoptimised-timeline {
    --st-line:         rgba(214, 222, 232, 0.30);
    --st-line-strong:  rgba(214, 222, 232, 0.55);
    --st-dot:          #FFFFFF;
    --st-dot-ring:     #081836;
    --st-dot-active:   #29B688;
    --st-card-bg-1:    #0D2350;
    --st-card-bg-2:    #163870;
    --st-card-border:  rgba(87, 200, 227, 0.18);
    --st-card-active:  rgba(41, 182, 136, 0.55);
    --st-card-hover:   rgba(41, 182, 136, 0.60);
    --st-card-shadow:  0 12px 32px rgba(0, 0, 0, 0.35);
    --st-date:         #29B688;
    --st-title:        #FFFFFF;
    --st-body:         rgba(233, 239, 246, 0.82);
    --st-card-width:   320px;
    --st-gap:          32px;
    --st-gap-year:     72px;
    --st-edge-fade:    #081836;

    position: relative;
    width: 100%;
    box-sizing: border-box;
}

/* ---------- Scroller: mask for edge-fade + scroll snap ---------- */
.shoptimised-timeline__scroller {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 0;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 24px;
    /* Hide native scrollbar — progress bar beneath is the only scroll indicator */
    scrollbar-width: none;          /* Firefox */
    -ms-overflow-style: none;       /* legacy Edge */
    /* Edge-fade masks for scroll affordance — transparent at both ends */
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 48px, #000 calc(100% - 48px), transparent 100%);
            mask-image: linear-gradient(90deg, transparent 0, #000 48px, #000 calc(100% - 48px), transparent 100%);
}
.shoptimised-timeline__scroller {
    cursor: grab;
}
.shoptimised-timeline__scroller:focus-visible {
    outline: 2px solid var(--st-dot-active);
    outline-offset: -2px;
}
.shoptimised-timeline__scroller.is-dragging {
    cursor: grabbing;
    scroll-snap-type: none;
    user-select: none;
}
.shoptimised-timeline__scroller::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

/* ---------- List: horizontal row with centred line ---------- */
.shoptimised-timeline__list {
    list-style: none;
    display: flex;
    gap: var(--st-gap);
    margin: 0;
    padding: 32px 24px;
    position: relative;
    min-width: max-content;
    align-items: stretch;
}

/* Central horizontal line with gradient fade at both ends */
.shoptimised-timeline__list::before {
    content: '';
    position: absolute;
    left: 24px;
    right: 24px;
    top: 50%;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent 0,
        var(--st-line) 80px,
        var(--st-line-strong) 50%,
        var(--st-line) calc(100% - 80px),
        transparent 100%
    );
    pointer-events: none;
}

/* ---------- Item: grid cell containing card, connector, dot ---------- */
.shoptimised-timeline__list .shoptimised-timeline__item {
    flex: 0 0 var(--st-card-width);
    display: grid;
    grid-template-rows: 1fr 18px 22px 18px 1fr;
    grid-template-areas:
        "card-top"
        "conn-top"
        "dot"
        "conn-bot"
        "card-bot";
    justify-items: stretch;
    position: relative;
    scroll-snap-align: start;
    scroll-snap-stop: always;
}

/* Wider gap at year change */
.shoptimised-timeline__item--year-break {
    margin-left: calc(var(--st-gap-year) - var(--st-gap));
}

/* Odd items (1st, 3rd, ...) -> card above the line */
.shoptimised-timeline__list .shoptimised-timeline__item:nth-child(odd) .shoptimised-timeline__card {
    grid-area: card-top;
    align-self: end;
}
.shoptimised-timeline__list .shoptimised-timeline__item:nth-child(odd) .shoptimised-timeline__connector {
    grid-area: conn-top;
}

/* Even items -> card below the line */
.shoptimised-timeline__list .shoptimised-timeline__item:nth-child(even) .shoptimised-timeline__card {
    grid-area: card-bot;
    align-self: start;
}
.shoptimised-timeline__list .shoptimised-timeline__item:nth-child(even) .shoptimised-timeline__connector {
    grid-area: conn-bot;
}

.shoptimised-timeline__connector {
    width: 1px;
    background: var(--st-line-strong);
    justify-self: center;
    align-self: stretch;
}

/* ---------- Dot ---------- */
.shoptimised-timeline__dot {
    grid-area: dot;
    justify-self: center;
    align-self: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--st-dot);
    box-shadow: 0 0 0 3px var(--st-dot-ring);
    position: relative;
    z-index: 1;
}
.shoptimised-timeline__item--active .shoptimised-timeline__dot {
    background: var(--st-dot-active);
    box-shadow: 0 0 0 3px var(--st-dot-ring), 0 0 18px 3px rgba(41, 182, 136, 0.55);
}

/* ---------- Card ---------- */
.shoptimised-timeline__card {
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--st-card-bg-1) 0%, var(--st-card-bg-2) 100%);
    border: 1px solid var(--st-card-border);
    border-radius: 14px;
    padding: 22px 24px;
    width: var(--st-card-width);
    max-width: 100%;
    box-sizing: border-box;
    box-shadow: var(--st-card-shadow);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    overflow: hidden;
    text-align: left;
}
.shoptimised-timeline__card:hover {
    transform: translateY(-4px);
    border-color: var(--st-card-hover);
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.45);
}

/* Active card gets a teal-tinted border */
.shoptimised-timeline__item--active .shoptimised-timeline__card {
    border-color: var(--st-card-active);
}

/* Card flex order: thumb → date → title → body, for all cards */
.shoptimised-timeline__thumb-wrap { order: 1; }
.shoptimised-timeline__meta       { order: 2; }
.shoptimised-timeline__title      { order: 3; }
.shoptimised-timeline__body       { order: 4; }

/* ---------- Thumbnail header ---------- */
.shoptimised-timeline__thumb-wrap:empty {
    display: none;
}
.shoptimised-timeline__thumb-wrap:not(:empty) {
    margin: -22px -24px 16px;
    line-height: 0;
}
.shoptimised-timeline__thumb {
    display: block;
    width: 100%;
    height: auto;
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
}

/* ---------- Meta row: icon + date ---------- */
.shoptimised-timeline__meta {
    display: flex;
    align-self: flex-start;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    margin: 0 0 10px;
    padding: 0;
    color: var(--st-date);
    text-align: left;
}
.shoptimised-timeline__date {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    line-height: 1.2;
}

/* ---------- Title + body ---------- */
.shoptimised-timeline__title {
    color: var(--st-title);
    font-family: 'Baloo 2', sans-serif;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.25;
    margin: 0 0 12px;
}
.shoptimised-timeline__body {
    color: var(--st-body);
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    line-height: 1.55;
}
.shoptimised-timeline__body p {
    margin: 0;
}
.shoptimised-timeline__body p + p {
    margin-top: 10px;
}

/* ---------- Progress bar ---------- */
.shoptimised-timeline__progress {
    height: 2px;
    background: rgba(214, 222, 232, 0.15);
    margin: 8px 24px 0;
    border-radius: 2px;
    overflow: hidden;
}
.shoptimised-timeline__progress-fill {
    height: 100%;
    width: 0%;
    background: var(--st-dot-active);
    transition: width 0.1s linear;
}

/* ---------- Header row: year nav (left) + arrow controls (right) ---------- */
.shoptimised-timeline__header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 0 0 12px 24px;
}
.shoptimised-timeline__controls {
    margin-left: auto;   /* pushes arrows to the right edge, even if no chips */
    display: inline-flex;
    gap: 8px;
}

/* ---------- Arrow buttons ---------- */
.shoptimised-timeline__nav {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: var(--st-card-bg-1);
    border: 1.5px solid var(--st-card-border);
    color: #FFFFFF;
    transition: background-color 0.2s ease, border-color 0.2s ease,
                color 0.2s ease, transform 0.15s ease, opacity 0.2s ease,
                box-shadow 0.2s ease;
}
.shoptimised-timeline__nav svg { width: 14px; height: 14px; }

.shoptimised-timeline__nav:hover:not([aria-disabled="true"]),
.shoptimised-timeline__nav:focus-visible {
    background: var(--st-dot-active);
    border-color: var(--st-dot-active);
    outline: none;
    transform: scale(1.05);
}
.shoptimised-timeline__nav:focus-visible {
    box-shadow: 0 0 0 3px var(--st-dot-ring),
                0 0 0 5px var(--st-dot-active);
}
.shoptimised-timeline__nav[aria-disabled="true"] {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

/* ---------- Year navigator (desktop only) ---------- */
.shoptimised-timeline__years {
    margin: 0;
    flex: 0 1 auto;
}
.shoptimised-timeline__years-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
}
.shoptimised-timeline__year-chip {
    appearance: none;
    background: transparent;
    border: 1px solid var(--st-card-border);
    color: var(--st-body);
    border-radius: 999px;
    padding: 6px 14px;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.shoptimised-timeline__year-chip:hover,
.shoptimised-timeline__year-chip:focus-visible {
    border-color: var(--st-dot-active);
    color: #FFFFFF;
    outline: none;
}
.shoptimised-timeline__year-chip.is-active {
    background: var(--st-dot-active);
    border-color: var(--st-dot-active);
    color: var(--st-card-bg-1);
}

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
    .shoptimised-timeline__card,
    .shoptimised-timeline__progress-fill,
    .shoptimised-timeline__nav,
    .shoptimised-timeline__year-chip {
        transition: none;
    }
    .shoptimised-timeline__card:hover {
        transform: none;
    }
    .shoptimised-timeline__nav:hover:not([aria-disabled="true"]) {
        transform: none;
    }
    .shoptimised-timeline__scroller {
        scroll-snap-type: none;
    }
}

/* ---------- Mobile (<=768px): vertical stack ---------- */
@media (max-width: 768px) {
    .shoptimised-timeline__scroller {
        overflow-x: hidden;
        scroll-snap-type: none;
        -webkit-mask-image: none;
                mask-image: none;
    }

    .shoptimised-timeline__list {
        flex-direction: column;
        gap: 28px;
        padding: 16px 8px 16px 40px;
        min-width: 0;
    }

    /* Vertical line on the left */
    .shoptimised-timeline__list::before {
        left: 16px;
        right: auto;
        top: 24px;
        bottom: 24px;
        width: 1px;
        height: auto;
        background: linear-gradient(
            180deg,
            transparent 0,
            var(--st-line) 32px,
            var(--st-line-strong) 50%,
            var(--st-line) calc(100% - 32px),
            transparent 100%
        );
    }

    .shoptimised-timeline__list .shoptimised-timeline__item {
        flex: 0 0 auto;
        grid-template-rows: auto;
        grid-template-columns: 24px 1fr;
        grid-template-areas: "dot card";
        column-gap: 20px;
    }

    .shoptimised-timeline__item--year-break {
        margin-left: 0;
        margin-top: 12px;
    }

    /* Reset odd/even placements — all cards on the right */
    .shoptimised-timeline__list .shoptimised-timeline__item:nth-child(odd) .shoptimised-timeline__card,
    .shoptimised-timeline__list .shoptimised-timeline__item:nth-child(even) .shoptimised-timeline__card {
        grid-area: card;
        align-self: start;
    }

    .shoptimised-timeline__list .shoptimised-timeline__item .shoptimised-timeline__dot {
        grid-area: dot;
        justify-self: center;
        align-self: start;
        margin-top: 20px;
    }
    .shoptimised-timeline__list .shoptimised-timeline__item .shoptimised-timeline__connector {
        display: none;
    }

    .shoptimised-timeline__card {
        width: 100%;
    }

    .shoptimised-timeline__progress {
        display: none;
    }

    .shoptimised-timeline__header {
        display: none;
    }
}
