﻿/** * Copyright (c) 2026 DNA Genics, S.L. All rights reserved.
 * 
 * Visual Timeline Component - Reusable horizontal timeline with customizable themes.
 * Supports CSS variable prefix theming and direct color overrides.
 */

/* ========================================
   CSS VARIABLES (Theme-agnostic defaults)
   ======================================== */
.vtl-timeline-wrapper {
    /* Background and container */
    --vtl-bg: rgba(45, 40, 36, 0.8);
    --vtl-border: rgba(168, 159, 145, 0.15);
    
    /* Accent colors */
    --vtl-accent: #c9a430;
    --vtl-accent-hover: #d4af37;
    
    /* Text colors */
    --vtl-text-primary: #faf8f5;
    --vtl-text-secondary: #a89f91;
    --vtl-text-muted: #8b7a6a;
    
    /* Line and marker colors */
    --vtl-line: #a89f91;
    --vtl-line-gradient-start: #8b6b4f;
    --vtl-line-gradient-end: #c9a430;
    
    /* Fonts */
    --vtl-font-display: 'Cormorant Garamond', serif;
    --vtl-font-body: 'Inter', sans-serif;
    
    /* Transitions */
    --vtl-transition-fast: 0.2s ease;
    --vtl-transition-medium: 0.3s ease;
    
    margin: 2rem 0;
}

/* ========================================
   TIMELINE CONTAINER
   ======================================== */
.vtl-timeline-container {
    background: var(--vtl-bg);
    border: 1px solid var(--vtl-border);
    border-radius: 12px;
    padding: 2rem;
    padding-top: 2.5rem; /* Extra space for cluster popups */
    overflow: visible; /* Allow cluster popups to overflow */
}

@media (max-width: 767px) {
    .vtl-timeline-container {
        padding: 1.5rem 1rem;
    }
}

/* ========================================
   TIMELINE HEADER
   ======================================== */
.vtl-timeline-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.vtl-timeline-title {
    font-family: var(--vtl-font-body);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--vtl-text-primary);
    margin: 0 0 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.vtl-timeline-title i {
    color: var(--vtl-accent);
}

.vtl-timeline-subtitle {
    font-size: 0.875rem;
    color: var(--vtl-text-secondary);
    margin: 0;
}

/* ========================================
   TIMELINE LEGEND
   ======================================== */
.vtl-timeline-legend {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
}

/* ========================================
   ZOOM CONTROLS
   ======================================== */
.vtl-zoom-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    margin: 1.5rem 0 1rem;
    padding: 0.5rem 0;
}

.vtl-zoom-label {
    font-size: 0.875rem;
    color: var(--vtl-text-secondary);
    margin-right: 0.25rem;
}

.vtl-zoom-btn {
    background: rgba(168, 159, 145, 0.1);
    border: 1px solid rgba(168, 159, 145, 0.2);
    color: var(--vtl-text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--vtl-transition-fast);
    padding: 0;
    font-size: 0.75rem;
}

.vtl-zoom-btn:hover:not(:disabled) {
    background: rgba(201, 164, 48, 0.2);
    border-color: var(--vtl-accent);
    color: var(--vtl-accent);
    transform: scale(1.1);
}

.vtl-zoom-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.vtl-zoom-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.vtl-zoom-level {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--vtl-accent);
    min-width: 2rem;
    text-align: center;
}

@media (max-width: 767px) {
    .vtl-zoom-controls {
        margin: 1rem 0 0.75rem;
        gap: 0.5rem;
    }
    
    .vtl-zoom-btn {
        width: 28px;
        height: 28px;
        font-size: 0.6875rem;
    }
    
    .vtl-zoom-label {
        font-size: 0.8125rem;
    }
    
    .vtl-zoom-level {
        font-size: 0.8125rem;
        min-width: 1.75rem;
    }
}

/* ========================================
   SCROLL WRAPPER
   ======================================== */
.vtl-scroll-wrapper {
    overflow-x: auto;
    overflow-y: visible;
    margin: 0;
    padding: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(201, 164, 48, 0.3) rgba(168, 159, 145, 0.1);
}

.vtl-scroll-wrapper::-webkit-scrollbar {
    height: 8px;
}

.vtl-scroll-wrapper::-webkit-scrollbar-track {
    background: rgba(168, 159, 145, 0.1);
    border-radius: 4px;
}

.vtl-scroll-wrapper::-webkit-scrollbar-thumb {
    background: rgba(201, 164, 48, 0.3);
    border-radius: 4px;
}

.vtl-scroll-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(201, 164, 48, 0.5);
}

@media (max-width: 767px) {
    .vtl-scroll-wrapper {
        margin: 0 -1rem;
        padding: 0 1rem;
    }
}

.vtl-timeline-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--vtl-text-primary);
}

.vtl-timeline-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background-color: var(--era-color);
}

/* ========================================
   TIMELINE TRACK
   ======================================== */
.vtl-timeline-track {
    position: relative;
    height: 260px;
    margin: 2rem 0;
    margin-top: 3rem; /* Extra space for cluster popups above the track */
    min-width: 100%;
    width: 100%;
    transition: width var(--vtl-transition-medium);
}

@media (max-width: 767px) {
    .vtl-timeline-track {
        height: 200px;
    }
}

/* ========================================
   ERA BACKGROUND SEGMENTS
   ======================================== */
.vtl-timeline-eras-bg {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 8px;
    transform: translateY(-50%);
    display: flex;
    border-radius: 4px;
    overflow: hidden;
}

.vtl-timeline-era-bg {
    position: absolute;
    height: 100%;
    opacity: 0.6;
}

/* ========================================
   TIMELINE LINE
   ======================================== */
.vtl-timeline-line {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(to right, var(--vtl-line-gradient-start), var(--vtl-line-gradient-end));
    transform: translateY(-50%);
    border-radius: 1px;
}

/* ========================================
   TIMELINE MARKERS
   ======================================== */
.vtl-timeline-markers {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
}

.vtl-timeline-marker {
    position: absolute;
    transform: translateX(-50%);
}

.vtl-timeline-marker-dot {
    width: 12px;
    height: 12px;
    background: var(--vtl-accent);
    border: 3px solid var(--vtl-bg);
    border-radius: 50%;
    margin: 0 auto;
}

.vtl-timeline-marker-label {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--vtl-text-primary);
    white-space: nowrap;
}

/* ========================================
   TIMELINE SAMPLE POINTS
   ======================================== */
.vtl-timeline-samples-track {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* ========================================
   TIMELINE CLUSTERS
   ======================================== */
.vtl-timeline-cluster {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    z-index: 15;
}

.vtl-timeline-cluster-badge {
    width: 32px;
    height: 32px;
    background: var(--vtl-bg);
    border: 3px solid var(--vtl-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    transition: all var(--vtl-transition-fast);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.vtl-timeline-cluster:hover .vtl-timeline-cluster-badge {
    transform: scale(1.2);
    border-color: var(--vtl-text-primary);
    box-shadow: 0 4px 12px rgba(201, 164, 48, 0.5);
}

.vtl-cluster-count {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--vtl-accent);
    line-height: 1;
}

.vtl-timeline-cluster:hover .vtl-cluster-count {
    color: var(--vtl-text-primary);
}

/* ========================================
   CLUSTER POPUP (Desktop)
   ======================================== */
.vtl-cluster-popup {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--vtl-bg);
    border: 1px solid var(--vtl-border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    min-width: 280px;
    max-width: 320px;
    max-height: 400px;
    display: none;
    z-index: 100;
    overflow: hidden;
}

.vtl-cluster-popup.open {
    display: block;
    animation: vtl-popup-fade-in 0.2s ease;
}

/* Desktop portal mode (popup moved to <body> to avoid clipping) */
.vtl-cluster-popup.vtl-portal {
    position: absolute;
    bottom: auto;
    left: 0;
    top: 0;
    transform: none;
    z-index: 10002;
}

.vtl-cluster-popup.vtl-portal.open {
    animation: vtl-popup-fade-in-portal 0.2s ease;
}

@keyframes vtl-popup-fade-in-portal {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes vtl-popup-fade-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.vtl-cluster-popup-header {
    padding: 1rem;
    border-bottom: 1px solid var(--vtl-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.2);
}

.vtl-cluster-popup-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--vtl-text-primary);
}

.vtl-cluster-popup-close {
    background: transparent;
    border: none;
    color: var(--vtl-text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all var(--vtl-transition-fast);
}

.vtl-cluster-popup-close:hover {
    background: rgba(201, 164, 48, 0.2);
    color: var(--vtl-accent);
}

.vtl-cluster-popup-list {
    max-height: 320px;
    overflow-y: auto;
    padding: 0.5rem;
}

.vtl-cluster-popup-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--vtl-transition-fast);
    margin-bottom: 0.25rem;
}

.vtl-cluster-popup-item:hover {
    background: rgba(201, 164, 48, 0.15);
    transform: translateX(4px);
}

.vtl-cluster-popup-item:last-child {
    margin-bottom: 0;
}

.vtl-cluster-popup-item img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--vtl-accent);
    flex-shrink: 0;
}

.vtl-cluster-popup-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(201, 164, 48, 0.2);
    border: 2px solid var(--vtl-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--vtl-accent);
    flex-shrink: 0;
}

.vtl-cluster-popup-info {
    flex: 1;
    min-width: 0;
}

.vtl-cluster-popup-name {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--vtl-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vtl-cluster-popup-date {
    display: block;
    font-size: 0.75rem;
    color: var(--vtl-accent);
    margin-top: 0.25rem;
}

/* ========================================
   CLUSTER BOTTOM SHEET (Mobile)
   ======================================== */
@media (max-width: 991px) {
    .vtl-cluster-popup {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        transform: translateY(100%);
        min-width: auto;
        max-width: none;
        max-height: 80vh;
        border-radius: 24px 24px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        z-index: 10001; /* Above mobile bottom nav */
        background: #1a1816; /* Solid opaque background for mobile */
    }
    
    .vtl-cluster-popup.open {
        transform: translateY(0);
        animation: vtl-bottom-sheet-slide-up 0.3s ease;
    }
    
    @keyframes vtl-bottom-sheet-slide-up {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
    
    .vtl-cluster-popup-header {
        padding: 1.25rem 1rem;
        position: relative;
        background: #252220; /* Solid darker header background */
    }
    
    .vtl-cluster-popup-header::before {
        content: '';
        position: absolute;
        top: 0.5rem;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--vtl-text-secondary);
        border-radius: 2px;
        opacity: 0.5;
    }
    
    .vtl-cluster-popup-list {
        max-height: calc(80vh - 80px);
        padding: 0.5rem 1rem 1rem;
    }
    
    .vtl-cluster-popup-item {
        padding: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .vtl-cluster-popup-item img,
    .vtl-cluster-popup-placeholder {
        width: 48px;
        height: 48px;
    }
    
    .vtl-cluster-popup-name {
        font-size: 1rem;
        color: #faf8f5; /* --vtl-text-primary - explicit color since CSS vars lost when moved to body */
    }
    
    .vtl-cluster-popup-date {
        font-size: 0.875rem;
        color: #c9a430; /* --vtl-accent - explicit color since CSS vars lost when moved to body */
    }
    
    .vtl-cluster-popup-title {
        color: #faf8f5; /* --vtl-text-primary - explicit color since CSS vars lost when moved to body */
    }
    
    .vtl-cluster-popup-close {
        color: #a89f91; /* --vtl-text-secondary - explicit color since CSS vars lost when moved to body */
    }
    
    .vtl-cluster-popup-close:hover {
        color: #c9a430; /* --vtl-accent - explicit color since CSS vars lost when moved to body */
    }
}

/* Cluster backdrop overlay (mobile) */
.vtl-cluster-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999; /* Below popup */
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--vtl-transition-medium);
}

.vtl-cluster-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

@media (min-width: 992px) {
    .vtl-cluster-backdrop {
        display: none !important;
    }
}

.vtl-timeline-sample-point {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    z-index: 10;
}

.vtl-timeline-sample-dot {
    width: 16px;
    height: 16px;
    background: var(--vtl-accent);
    border: 3px solid var(--vtl-bg);
    border-radius: 50%;
    position: relative;
    z-index: 2;
    transition: all var(--vtl-transition-fast);
}

.vtl-timeline-sample-point:hover .vtl-timeline-sample-dot {
    transform: scale(1.3);
    background: var(--vtl-text-primary);
}

.vtl-timeline-sample-connector {
    position: absolute;
    left: 50%;
    width: 1px;
    background: var(--vtl-accent);
    transform: translateX(-50%);
    opacity: 0.5;
}

.vtl-timeline-sample-card {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    text-align: center;
    opacity: 0.8;
    transition: all var(--vtl-transition-fast);
}

.vtl-timeline-sample-point:hover .vtl-timeline-sample-card {
    opacity: 1;
    transform: translateX(-50%) scale(1.1);
}

.vtl-timeline-portrait-wrapper {
    position: relative;
    display: inline-block;
}

.vtl-timeline-sample-card img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--vtl-accent);
    background: var(--vtl-bg);
}

.vtl-timeline-sample-info {
    margin-top: 0.25rem;
}

.vtl-timeline-sample-name {
    display: block;
    font-size: 0.5625rem;
    font-weight: 600;
    color: var(--vtl-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60px;
}

.vtl-timeline-sample-date {
    display: block;
    font-size: 0.5rem;
    color: var(--vtl-accent);
}

.vtl-timeline-sample-era {
    display: block;
    font-size: 0.5rem;
    color: var(--vtl-text-secondary);
    opacity: 0.8;
    margin-top: 0.125rem;
}

/* ========================================
   CROWN BADGE & HIGHLIGHTED SAMPLES
   ======================================== */
.vtl-timeline-crown-badge {
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #ffd700 0%, #c9a430 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(201, 164, 48, 0.5);
    z-index: 15;
}

.vtl-timeline-crown-badge .dna-icon {
    width: 12px;
    height: 12px;
    color: #1a1a1a;
}

/* Highlighted sample point */
.vtl-timeline-sample-point.vtl-highlighted .vtl-timeline-sample-dot {
    border-color: #ffd700;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.5);
}

.vtl-timeline-sample-point.vtl-highlighted .vtl-timeline-sample-card {
    border-color: rgba(255, 215, 0, 0.3);
}

/* Cluster popup highlighted item */
.vtl-cluster-popup-item.vtl-highlighted {
    background: rgba(201, 164, 48, 0.15);
    border-left: 3px solid #c9a430;
    padding-left: calc(0.75rem - 3px);
}

.vtl-cluster-popup-crown {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    color: #c9a430;
    z-index: 5;
}

.vtl-cluster-popup-crown .dna-icon {
    width: 16px;
    height: 16px;
}

.vtl-cluster-popup-era {
    display: block;
    font-size: 0.7rem;
    color: var(--vtl-text-secondary);
    opacity: 0.8;
    margin-top: 0.125rem;
}

/* ========================================
   TIMELINE FOOTER
   ======================================== */
.vtl-timeline-footer {
    margin-top: 2rem;
    text-align: center;
}

.vtl-timeline-note {
    font-size: 0.8125rem;
    color: var(--vtl-text-secondary);
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.vtl-timeline-note i {
    color: var(--vtl-accent);
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */
@media (max-width: 991px) {
    .vtl-timeline-sample-card {
        display: none;
    }
    
    .vtl-timeline-sample-connector {
        display: none;
    }
    
    .vtl-timeline-sample-dot {
        width: 20px;
        height: 20px;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
.vtl-timeline-sample-point:focus {
    outline: 2px solid var(--vtl-accent);
    outline-offset: 4px;
    border-radius: 50%;
}

.vtl-timeline-sample-point:focus .vtl-timeline-sample-dot {
    outline: none;
}

.vtl-timeline-cluster:focus {
    outline: 2px solid var(--vtl-accent);
    outline-offset: 4px;
    border-radius: 50%;
}

.vtl-timeline-cluster:focus .vtl-timeline-cluster-badge {
    outline: none;
}

.vtl-cluster-popup-item:focus {
    outline: 2px solid var(--vtl-accent);
    outline-offset: -2px;
    border-radius: 8px;
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .vtl-timeline-wrapper {
        break-inside: avoid;
    }
    
    .vtl-zoom-controls {
        display: none;
    }
    
    .vtl-scroll-wrapper {
        overflow: visible;
    }
    
    .vtl-timeline-track {
        width: 100% !important;
    }
    
    .vtl-timeline-sample-card {
        display: block;
        opacity: 1;
    }
    
    .vtl-timeline-sample-point:hover .vtl-timeline-sample-card {
        transform: translateX(-50%);
    }
    
    /* Expand clusters in print */
    .vtl-cluster-popup {
        display: block !important;
        position: static !important;
        transform: none !important;
        box-shadow: none;
        border: 1px solid #ccc;
        margin-top: 0.5rem;
    }
    
    .vtl-cluster-popup-header {
        display: none;
    }
    
    .vtl-cluster-popup-list {
        max-height: none;
    }
}

/* ========================================
   REDUCED MOTION
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .vtl-timeline-sample-dot,
    .vtl-timeline-sample-card {
        transition: none;
    }
    
    .vtl-timeline-track {
        transition: none;
    }
}
