/**
 * Timeline / Our History Block Styles
 *
 * Vertical timeline with connected milestone cards featuring:
 * - Design system integration (matches existing card blocks)
 * - Subtle hover and scroll animations
 * - Full accessibility support
 * - Reduced motion support
 *
 * @package TMW_Blocks
 * @since 1.0.0
 */

/* ==========================================================================
   Preview Mode Styles
   ========================================================================== */

.timeline-preview-content .timeline-preview-title {
    margin-bottom: var(--space-xs);
}

.timeline-preview-content .timeline-preview-subtitle {
    margin-bottom: var(--space-md);
}

.timeline-preview-content .timeline-preview-list {
    list-style: none;
    padding: 0;
}

.timeline-preview-content .timeline-preview-item {
    margin-bottom: var(--space-xs);
}

/* ==========================================================================
   CSS Custom Properties (for responsive alignment calculations)
   ========================================================================== */

/* ==========================================================================
   Block Container
   ========================================================================== */

.timeline-history-block {
    --timeline-marker-width: 40px;
    --timeline-marker-center: calc(var(--timeline-marker-width) / 2); /* 20px */
    --timeline-dot-size: 16px;
    --timeline-dot-center: calc(var(--timeline-dot-size) / 2); /* 8px */
    --timeline-line-width: 2px;
    --timeline-line-offset: calc(var(--timeline-line-width) / 2); /* 1px */

    position: relative;
}

/* ==========================================================================
   Preview Mode Styling
   ========================================================================== */

.timeline-history-preview {
    background: var(--color-white);
    border: var(--border-width-thin) dashed var(--color-border);
    border-radius: var(--radius-card);
    padding: var(--space-lg);
}

/* Section Header */
.timeline-history-block .section-title {
    text-align: center;
    max-width: var(--max-width-content-lg);
    margin: 0 auto var(--space-md);
}

.timeline-history-block .section-subtitle {
    text-align: center;
    max-width: var(--max-width-content-lg);
    font-size: var(--font-size-lead);
}

.timeline-container {
    margin: 0 auto;
    position: relative; /* Position context for .timeline-line */
    box-sizing: border-box;
    overflow: visible;
}

/* ==========================================================================
   Timeline Vertical Line
   ========================================================================== */

.timeline-line {
    position: absolute;

    /* Position line to align with marker centers */
    left: calc(var(--timeline-marker-center) - var(--timeline-line-offset));
    top: calc(var(--space-lg) + var(--timeline-dot-center));
    bottom: 30px;
    width: var(--timeline-line-width);
    background: var(--color-border);
    z-index: 1;
}

/* Animated line reveal on scroll */
.timeline-line::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 0;
    background: var(--color-primary);
    transition: height 0.8s ease-out;
}

/* Trigger line animation when timeline is in view */
.timeline-history-block.in-view .timeline-line::before {
    height: 100%;
}

/* ==========================================================================
   Timeline Entries Container
   ========================================================================== */

.timeline-entries {
    position: relative;
    z-index: 2;

    /* flex-col utility class provides: display: flex; flex-direction: column */
    gap: var(--space-xl);
    overflow: visible;
}

/* ==========================================================================
   Individual Timeline Entry
   ========================================================================== */

.timeline-entry {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: var(--space-lg);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

/* Staggered fade-in animation when entries come into view */
.timeline-history-block.in-view .timeline-entry {
    opacity: 1;
    transform: translateY(0);
}

/* Add staggered delay for sequential appearance */
.timeline-history-block.in-view .timeline-entry:nth-child(1) {
    transition-delay: 0.1s;
}

.timeline-history-block.in-view .timeline-entry:nth-child(2) {
    transition-delay: 0.2s;
}

.timeline-history-block.in-view .timeline-entry:nth-child(3) {
    transition-delay: 0.3s;
}

.timeline-history-block.in-view .timeline-entry:nth-child(4) {
    transition-delay: 0.4s;
}

.timeline-history-block.in-view .timeline-entry:nth-child(5) {
    transition-delay: 0.5s;
}

.timeline-history-block.in-view .timeline-entry:nth-child(n+6) {
    transition-delay: 0.6s;
}

/* ==========================================================================
   Timeline Marker (Dot)
   ========================================================================== */

.timeline-marker {
    flex-shrink: 0;
    width: var(--timeline-marker-width);
    height: var(--timeline-marker-width);
    position: relative;
    z-index: 3;
    margin-top: var(--space-lg); /* Aligns dot with card content */
}

.timeline-dot {
    width: var(--timeline-dot-size);
    height: var(--timeline-dot-size);
    background: var(--color-white);
    border: 2px solid var(--color-primary);
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    transition: all var(--transition-base);
    box-shadow: 0 0 0 0 rgba(var(--color-primary-rgb), 0.3);
}

/* Pulse animation on marker when card is hovered or focused */
.timeline-entry:hover .timeline-dot,
.timeline-entry:focus-visible .timeline-dot {
    transform: translateX(-50%) scale(1.3);
    border: 3px solid var(--color-white);
    box-shadow: 0 0 0 8px rgba(var(--color-primary-rgb), 0.1);
    background: var(--color-primary);
}

/* Focus visible state for keyboard navigation - highlight the dot */
.timeline-entry:focus {
    outline: none;
}

.timeline-entry:focus-visible {
    outline: none;
}

.timeline-entry:focus-visible .timeline-dot {
    transform: translateX(-50%) scale(1.3);
    border: 3px solid var(--color-white);
    box-shadow: 0 0 0 4px var(--color-primary), 0 0 0 8px rgba(var(--color-primary-rgb), 0.3);
    background: var(--color-primary);
}

/* ==========================================================================
   Timeline Card
   ========================================================================== */

.timeline-card {
    flex: 1;
    background: var(--color-white);
    padding: var(--space-lg);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-default);
    border-width: 1px 1px 1px 4px;
    border-style: solid;
    border-color: transparent;
    transition: all var(--transition-base);
    position: relative;
    overflow: visible;
}

/* Subtle hover effect */
.timeline-entry:hover .timeline-card {
    transform: translateY(calc(-1 * var(--transform-offset-sm)));
    box-shadow: var(--shadow-lg);
    border-left-color: var(--color-primary);
}

/* ==========================================================================
   Card Content
   ========================================================================== */

.timeline-subtitle {
    font-size: var(--font-size-lead);
    margin: 0 0 var(--space-xs) 0;
    letter-spacing: 0.5px;
}

.timeline-title {
    margin: 0 0 var(--space-sm) 0;
}

.timeline-description {
    line-height: var(--line-height-normal);
    overflow: visible;
}

.timeline-description p:last-of-type {
    margin-bottom: 0;
}

/* ==========================================================================
   Accessibility: Reduced Motion Support
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .timeline-entry,
    .timeline-card,
    .timeline-dot,
    .timeline-line::before     {
        transition: none;
        animation: none;
    }

    .timeline-entry {
        opacity: 1;
        transform: none;
    }

    .timeline-history-block.in-view .timeline-entry {
        transition-delay: 0s;
    }
}

/* ==========================================================================
   Responsive: Tablet (1024px and below)
   ========================================================================== */

@media (width <=1024px) {
    .timeline-entries {
        gap: var(--space-lg);
    }

    /* Line position automatically adjusts via custom properties */
}

/* ==========================================================================
   Dark Background Support
   Uses global dark-bg-detection.js system with [data-dark-bg="true"]
   ========================================================================== */

/* Timeline line - use light color on dark backgrounds */
[data-dark-bg="true"] .timeline-history-block .timeline-line,
.timeline-history-block[data-dark-bg="true"] .timeline-line {
    background: color-mix(in srgb, var(--dark-bg-text) 30%, transparent);
}

/* Animated line fill - use light color */
[data-dark-bg="true"] .timeline-history-block .timeline-line::before,
.timeline-history-block[data-dark-bg="true"] .timeline-line::before {
    background: var(--dark-bg-text);
}

/* Timeline dot - invert colors for dark backgrounds */
[data-dark-bg="true"] .timeline-history-block .timeline-dot,
.timeline-history-block[data-dark-bg="true"] .timeline-dot {
    background: transparent;
    border-color: var(--dark-bg-text);
}

/* Timeline dot hover state on dark background */
[data-dark-bg="true"] .timeline-history-block .timeline-entry:hover .timeline-dot,
[data-dark-bg="true"] .timeline-history-block .timeline-entry:focus-visible .timeline-dot,
.timeline-history-block[data-dark-bg="true"] .timeline-entry:hover .timeline-dot,
.timeline-history-block[data-dark-bg="true"] .timeline-entry:focus-visible .timeline-dot {
    background: var(--dark-bg-text);
    border-color: var(--dark-bg-text);
}

/* Section header text on dark backgrounds */
[data-dark-bg="true"] .timeline-history-block .section-title,
[data-dark-bg="true"] .timeline-history-block .section-subtitle,
.timeline-history-block[data-dark-bg="true"] .section-title,
.timeline-history-block[data-dark-bg="true"] .section-subtitle {
    color: var(--dark-bg-heading);
}

/* ==========================================================================
   Responsive: Mobile (768px and below)
   ========================================================================== */

@media (width <=768px) {
    .timeline-history-block {
        /* Override custom properties for mobile sizes */
        --timeline-marker-width: 28px;
        --timeline-marker-center: calc(var(--timeline-marker-width) / 2); /* 14px */
        --timeline-dot-size: 14px;
        --timeline-dot-center: calc(var(--timeline-dot-size) / 2); /* 7px */
    }

    .timeline-entry {
        gap: var(--space-xs);
    }

    .timeline-line {
        left: 0;
        top: calc(var(--space-md) + var(--timeline-dot-center));
        bottom: 20px;
    }

    .timeline-marker {
        margin-top: var(--space-md); /* Match card padding on mobile */
    }

    .timeline-dot {
        border-width: 2px;
        left: 0;
    }

    .timeline-card {
        padding: var(--space-md);
    }

    .timeline-subtitle {
        font-size: var(--font-size-body);
    }

    /* Reduce stagger delay on mobile for faster appearance */
    .timeline-history-block.in-view .timeline-entry:nth-child(1) {
        transition-delay: 0.05s;
    }

    .timeline-history-block.in-view .timeline-entry:nth-child(2) {
        transition-delay: 0.1s;
    }

    .timeline-history-block.in-view .timeline-entry:nth-child(3) {
        transition-delay: 0.15s;
    }

    .timeline-history-block.in-view .timeline-entry:nth-child(4) {
        transition-delay: 0.2s;
    }

    .timeline-history-block.in-view .timeline-entry:nth-child(5) {
        transition-delay: 0.25s;
    }

    .timeline-history-block.in-view .timeline-entry:nth-child(n+6) {
        transition-delay: 0.3s;
    }
}