/* Timeline Container */
.timeline-container {
    position: relative;
    width: 100%;
    height: 400px;
    overflow-x: auto;
    overflow-y: visible;
    padding: 100px 50px;
    margin: 20px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.3) transparent;
    cursor: grab;
    background: linear-gradient(to bottom, #fafafa 0%, #ffffff 100%);
    border-radius: 8px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.timeline-container:active {
    cursor: grabbing;
}

/* Webkit scrollbar styling */
.timeline-container::-webkit-scrollbar {
    height: 8px;
}

.timeline-container::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

.timeline-container::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.3);
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.timeline-container::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0,0,0,0.5);
}

/* Timeline Main Container */
#timeline-main {
    position: relative;
    height: 100%;
    min-width: 100%;
}

/* Year Grid */
.year-grid {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 0;
}

.year-line {
    position: absolute;
    top: 0;
    width: 1px;
    height: 100%;
    background: rgba(0,0,0,0.1);
    z-index: 0;
}

.year-label {
    position: absolute;
    top: -30px;
    width: 40px;
    text-align: center;
    font-size: 11px;
    color: #999;
    font-weight: 500;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Timeline Line */
.timeline-line {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(to right, #ddd, #ccc, #ddd);
    transform: translateY(-50%);
    border-radius: 2px;
    z-index: 2;
}

/* Leadership Periods */
.leadership-layer {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 1;
}

.leadership-period {
    position: absolute;
    height: 500px;
    background: linear-gradient(135deg, rgba(255,215,0,0.15) 0%, rgba(255,215,0,0.25) 100%);
    border: 1px solid rgba(255,215,0,0.4);
    border-radius: 15px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    transition: all 0.3s ease;
    cursor: help;
}

.leadership-period:hover {
    background: linear-gradient(135deg, rgba(255,215,0,0.25) 0%, rgba(255,215,0,0.35) 100%);
    border-color: rgba(255,215,0,0.6);
    transform: translateY(-50%) translateZ(0) scale(1.02);
}

.leadership-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    color: #666;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Timeline Events */
.timeline-event {
    position: absolute;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 3;
}

.timeline-event:hover {
    z-index: 10;
}

/* Event Icon */
.timeline-event-icon {
    border-radius: 50%;
    background: #fff;
    border: 2px solid #666;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    font-family: 'Font Awesome 5 Free';
}

.timeline-event-icon:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Event type styling */
.timeline-event[data-type="leadership"] .timeline-event-icon {
    border-color: #ffd700;
    background: linear-gradient(135deg, #fff8dc 0%, #fffacd 100%);
    box-shadow: 0 2px 8px rgba(255,215,0,0.3);
}

.timeline-event[data-type="discovery"] .timeline-event-icon {
    border-color: #4caf50;
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    box-shadow: 0 2px 8px rgba(76,175,80,0.3);
}

.timeline-event[data-type="invention"] .timeline-event-icon {
    border-color: #ff9800;
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    box-shadow: 0 2px 8px rgba(255,152,0,0.3);
}

.timeline-event[data-type="foundation"] .timeline-event-icon {
    border-color: #2196f3;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    box-shadow: 0 2px 8px rgba(33,150,243,0.3);
}

.timeline-event[data-type="publication"] .timeline-event-icon {
    border-color: #9c27b0;
    background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
    box-shadow: 0 2px 8px rgba(156,39,176,0.3);
}

.timeline-event[data-type="collaboration"] .timeline-event-icon {
    border-color: #009688;
    background: linear-gradient(135deg, #e0f2f1 0%, #b2dfdb 100%);
    box-shadow: 0 2px 8px rgba(0,150,136,0.3);
}

.timeline-event[data-type="crisis"] .timeline-event-icon {
    border-color: #f44336;
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
    box-shadow: 0 2px 8px rgba(244,67,54,0.3);
}

/* Event Bubble */
.timeline-event-bubble {
    position: absolute;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 
        0 4px 20px rgba(0,0,0,0.15),
        0 1px 3px rgba(0,0,0,0.1);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
}

.timeline-event-bubble::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
}

.timeline-event-bubble.above::before {
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 8px 8px 0 8px;
    border-color: #fff transparent transparent transparent;
}

.timeline-event-bubble.below::before {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0 8px 8px 8px;
    border-color: transparent transparent #fff transparent;
}

/* Display mode variations */
.timeline-event-bubble[data-display-mode="detailed"] {
    padding: 12px;
    width: 220px;
    max-width: 220px;
}

.timeline-event-bubble[data-display-mode="medium"] {
    padding: 8px;
    width: 180px;
    max-width: 180px;
}

/* Show bubble on hover */
.timeline-event:hover .timeline-event-bubble {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0) scale(1);
}

/* Bubble content styling */
.timeline-event-bubble h4 {
    margin: 0 0 6px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
}

.timeline-event-bubble p {
    margin: 0 0 6px;
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

.timeline-event-year {
    font-size: 11px;
    color: #999;
    font-weight: 500;
    margin-top: 4px;
}

/* Prevent bubble edge overflow */
.timeline-event:nth-child(-n+3) .timeline-event-bubble {
    transform: translateX(0);
    left: 0;
}

.timeline-event:nth-last-child(-n+3) .timeline-event-bubble {
    transform: translateX(-100%);
    left: 100%;
}

/* Animation for bubble appearance */
@keyframes bubbleAppear {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(5px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

.timeline-event:hover .timeline-event-bubble {
    animation: bubbleAppear 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Compact mode - no bubbles, just enhanced icons */
.timeline-event[data-display-mode="compact"] .timeline-event-bubble {
    display: none;
}

.timeline-event[data-display-mode="compact"] .timeline-event-icon {
    width: 20px;
    height: 20px;
}

.timeline-event[data-display-mode="compact"] .timeline-event-icon i {
    font-size: 10px;
}

/* Loading state */
.timeline-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 4;
    text-align: center;
}

.timeline-loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error state */
.timeline-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 4;
    text-align: center;
    color: #f44336;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.timeline-error h3 {
    margin: 0 0 8px;
    color: #f44336;
}

.timeline-error p {
    margin: 0;
    color: #666;
}

/* Timeline controls */
.timeline-controls {
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    padding: 15px;
    border-bottom: 1px solid #e0e0e0;
    border-radius: 8px 8px 0 0;
    margin-bottom: 10px;
}

/* Modal enhancements */
.event-modal-content {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.event-year {
    font-size: 14px;
    color: #666;
    font-weight: 600;
    margin-bottom: 12px;
    padding: 4px 8px;
    background: #f5f5f5;
    border-radius: 4px;
    display: inline-block;
}

.event-description {
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    margin-bottom: 12px;
}

.event-leader,
.event-impact {
    font-size: 13px;
    color: #666;
    margin-bottom: 8px;
}

.event-leader strong,
.event-impact strong {
    color: #333;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .timeline-container {
        height: 300px;
        padding: 80px 20px;
    }

    .timeline-event-bubble {
        width: 160px;
        max-width: 160px;
        padding: 8px;
    }

    .timeline-event-bubble[data-display-mode="detailed"] {
        width: 160px;
        padding: 10px;
    }

    .timeline-event-bubble[data-display-mode="medium"] {
        width: 140px;
        padding: 8px;
    }

    .timeline-event-bubble h4 {
        font-size: 13px;
    }

    .timeline-event-bubble p {
        font-size: 11px;
    }

    .year-label {
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .timeline-container {
        padding: 60px 15px;
    }

    .timeline-event-bubble {
        width: 140px;
        max-width: 140px;
    }

    .timeline-event-icon {
        width: 20px;
        height: 20px;
    }

    .timeline-event-icon i {
        font-size: 10px;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .timeline-line {
        height: 2px;
    }

    .year-line {
        width: 0.5px;
    }
}

/* Dark mode support (if implemented) */
@media (prefers-color-scheme: dark) {
    .timeline-container {
        background: linear-gradient(to bottom, #ececec 0%, #fcfcfc 100%);
    }

    .timeline-line {
        background: linear-gradient(to right, #555, #666, #555);
    }

    .timeline-event-bubble {
        background: #333;
        border-color: #555;
        color: #fff;
    }

    .timeline-event-bubble h4 {
        color: #fff;
    }

    .timeline-event-bubble p {
        color: #ccc;
    }

    .timeline-event-year {
        color: #999;
    }

    .year-label {
        color: #888;
    }
}

/* Print styles */
@media print {
    .timeline-container {
        height: auto;
        overflow: visible;
        background: white;
        box-shadow: none;
    }

    .timeline-event-bubble {
        opacity: 1 !important;
        visibility: visible !important;
        position: relative !important;
        display: block !important;
        margin: 10px 0;
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .timeline-controls {
        display: none;
    }
}

/* Focus styles for accessibility */
.timeline-event:focus,
.timeline-event:focus-visible {
    outline: 2px solid #4caf50;
    outline-offset: 2px;
}

.timeline-event:focus .timeline-event-bubble,
.timeline-event:focus-visible .timeline-event-bubble {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
