/* ==========================================================================
   Timeline Slider - Grundlayout & Container
   ========================================================================== */
.timeline-slider-container {
    position: relative;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Verhindert Scrollbalken durch den Rechts-Ausbruch des Inhalts */
    overflow-x: clip; 
}

@media (min-width: 1025px) {
    .timeline-slider-container {
        /* Berechnet den Platz rechts außerhalb des Standard-Wrappers */
        margin-right: calc((100vw - 100%) / -2);
        width: auto;
    }
}

.timeline {
    width: 100%;
    overflow: visible; 
    --background: #f8f8f8;
    --accent: #d1121f;
    --accentgray: #ededed;
    --text: #383838;
    --line: #c4c4c4;
}

/* ==========================================================================
   Das Grid-System (Desktop)
   ========================================================================== */
.timeline ul {
    display: grid;
    /* Nutzt var(--items) + 1 für den unsichtbaren Spacer am Ende */
    grid-template-columns: repeat(calc(var(--items) + 1), calc(100% / var(--visible)));
    grid-template-rows: repeat(2, minmax(318px, auto));
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1);
    position: relative;
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Horizontale Hauptlinie */
.timeline ul::before {
    content: '';
    position: absolute;
    top: 318px; 
    /* Die Linie endet exakt beim letzten echten Item (ohne Spacer) */
    width: calc(var(--items) * (100% / var(--visible)));
    border-top: 3px solid var(--accentgray);
    z-index: 1;
    left: 0;
    min-width: 100%;
    transform: translateY(-50%);
}
.timeline ul::after {
    content: '';
    position: absolute;
    top: 318px; /* Gleiche Höhe wie die Linie */ 
    left: calc(var(--items) * (100% / var(--visible))); 
    width: 0;
    height: 0; 
    border-top: 18px solid transparent;
	border-bottom: 18px solid transparent;
	border-left: 24px solid var(--accentgray);
    transform: translateY(-50%);
    z-index: 1;
}

/* ==========================================================================
   Timeline Items & Spacer
   ========================================================================== */
.timeline ul li {
    --circle-size: 15px;
    grid-column: var(--index);
    position: relative;
    display: flex;
    flex-direction: column;
    z-index: 2;
    overflow: visible; 
    padding-left: 6px !important;
}

.timeline ul li::before {
    display: none;
}

/* Der unsichtbare Spacer am Ende */
.timeline ul li.timeline-spacer {
    visibility: hidden;
    pointer-events: none;
}

.timeline ul li.timeline-spacer::after,
.timeline ul li.timeline-spacer .line-connector {
    display: none !important;
}

/* Obere Items (Ungerade) */
.timeline ul li:nth-child(odd):not(.timeline-spacer) {
    grid-row: 1;
    justify-content: flex-end;
    padding-bottom: 83px;
}

/* Untere Items (Gerade) */
.timeline ul li:nth-child(even):not(.timeline-spacer) {
    grid-row: 2;
    justify-content: flex-start;
    padding-top: 77px;
}

/* Der Punkt auf der Linie */
.timeline ul li:not(.timeline-spacer):after {
    content: '';
    width: var(--circle-size);
    height: var(--circle-size);
    background: var(--accentgray);
    position: absolute;
    left: 0;
    border-radius: 50%;
    z-index: 5;
    transition: background 0.3s;
}

.timeline ul li:nth-child(odd):after { bottom: -11px; }
.timeline ul li:nth-child(even):after { top: -7px; }

/* Dedizierter Linien-Verbinder (Dotted Line) */
.line-connector {
    position: absolute;
    left: 7px; 
    width: 0;
    border-left: 2px dotted #cdcdcd;
    z-index: 1;
}

.timeline ul li:nth-child(odd) .line-connector {
    bottom: 0;
    height: 72px;
}

.timeline ul li:nth-child(even) .line-connector {
    top: 0;
    height: 72px;
}

/* Content Box Styling */
.timeline-item-content {
    padding: 0 15px 0 0;
    position: relative;
    z-index: 10;
    width: 179%; /* Breiter als die Grid-Zelle */
    max-width: 350px;
    pointer-events: auto;
}

.timeline ul li h3 {
    color: var(--accent);
    margin: 0 0 5px 0;
    font-family: 'Open Sans Condensed', sans-serif;
    font-weight: 700;
    font-size: 1.8rem;
    line-height: 1.2;
}

.timeline ul li p {
    margin: 0;
    font-size: 1rem;
	line-height: 1.7rem;
    color: var(--text); 
    text-wrap: pretty;
}

/* ==========================================================================
   Slider Controls (Buttons)
   ========================================================================== */
.timeline-controls {
    margin-top: 30px;
    display: flex;
    gap: 20px;
    justify-content: center;
    width: auto;
    position: relative;
    pointer-events: auto;
    transform: none;
    /* Zentriert die Buttons relativ zum Content-Wrapper */
    margin-right: calc((100vw - 100%) / 2); 
}

.timeline-btn {
    background: #d1121f;
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    cursor: pointer;
    border-radius: 50%;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease; 
}

.timeline-btn:hover:not(:disabled) {
    background: #000; 
}

.timeline-btn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
    filter: grayscale(1);
}

/* ==========================================================================
   Mobile Optimierung (Stacking Layout)
   ========================================================================== */
@media (max-width: 1024px) {
    .timeline-slider-container {
        margin-right: 0 !important;
    }
    
    .timeline ul {
        display: flex;
        flex-direction: column;
        grid-template-columns: none;
        grid-template-rows: none;
        transform: none !important; 
        padding-left: 50px !important; 
        padding-right: 0 !important;
        width: 100%;
    }

    /* Vertikale Linie statt Horizontal */
    .timeline ul::before {
        top: 10px;
        left: 6px;
        width: 3px;
        height: 100%;
        border-top: none;
        border-left: 3px solid var(--accentgray);
        transform: none;
    }
.timeline ul::after {
        top: auto;
        bottom: 0; /* Ganz unten am Ende der vertikalen Linie */
        left: 6px; /* Zentriert auf der 3px breiten Linie */
        transform: translateX(-35%); /* Feinjustierung der Mitte */
        border-left: 8px solid transparent;
        border-right: 8px solid transparent;
        border-top: 12px solid var(--accentgray); /* Dreieck nach unten */
        border-bottom: none;
    }
    .timeline ul li {
        width: 100%;
        margin-bottom: 40px !important;
        padding: 0 !important; 
        align-items: flex-start;
    }

    .timeline ul li:nth-child(odd),
    .timeline ul li:nth-child(even) {
        grid-row: auto;
        grid-column: auto;
        justify-content: flex-start;
        padding-bottom: 0;
        padding-top: 0;
    }

    .timeline ul li:after {
        left: -50px !important; 
        top: 10px !important;
        bottom: auto !important;
    }

    .line-connector {
        top: 17px !important;
        left: -38px !important;
        width: 36px; 
        height: 0 !important;
        border-left: none !important;
        border-top: 2px dotted #cdcdcd;
    }

    .timeline-item-content {
        width: 100%;
        max-width: 90%;
        padding-left: 10px;
    }

    .timeline-controls {
        display: none;
    }

    .timeline-spacer {
        display: none; /* Spacer auf Mobile nicht nötig */
    }
}