/**
 * Timeline & Diff Components - Professional Design System
 * Enhanced visualization for policy timelines and comparisons
 */

/* ============================================
   CSS CUSTOM PROPERTIES (Scoped Overrides)
   ============================================ */

:root {
    --timeline-line: var(--border-subtle);
    --timeline-node-size: 16px;
    --timeline-node-border: 3px;
    --timeline-spacing: 100px;
    
    /* Significance Colors */
    --sig-low: #22c55e;
    --sig-medium: #eab308;
    --sig-high: #f97316;
    --sig-critical: #ef4444;
    
    /* Diff Colors */
    --diff-add-bg: rgba(34, 197, 94, 0.12);
    --diff-add-text: #166534;
    --diff-remove-bg: rgba(239, 68, 68, 0.12);
    --diff-remove-text: #991b1b;
}

[data-theme="dark"] {
    --diff-add-text: #4ade80;
    --diff-remove-text: #f87171;
    --diff-add-bg: rgba(34, 197, 94, 0.15);
    --diff-remove-bg: rgba(239, 68, 68, 0.15);
}

/* ============================================
   TIMELINE - HORIZONTAL (Desktop)
   ============================================ */

.visual-timeline {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-subtle) transparent;
}

.visual-timeline::-webkit-scrollbar {
    height: 6px;
}

.visual-timeline::-webkit-scrollbar-track {
    background: transparent;
}

.visual-timeline::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 3px;
}

.timeline-track {
    display: flex;
    align-items: center;
    min-width: max-content;
    padding: 1rem 0;
    position: relative;
    gap: 0;
}

/* The connecting line */
.timeline-track::before {
    content: '';
    position: absolute;
    left: calc(var(--timeline-node-size) / 2);
    right: calc(var(--timeline-node-size) / 2);
    top: 50%;
    height: 3px;
    background: linear-gradient(90deg, var(--border-subtle) 0%, var(--border-strong) 50%, var(--border-subtle) 100%);
    transform: translateY(-50%);
    z-index: 0;
    border-radius: 2px;
}

.timeline-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
    cursor: pointer;
    transition: transform 0.2s ease;
    min-width: var(--timeline-spacing);
    padding: 0 0.5rem;
}

.timeline-node:hover {
    transform: translateY(-2px);
}

.timeline-node:hover .timeline-node-dot {
    transform: scale(1.15);
}

/* Timeline Dot */
.timeline-node-dot {
    width: var(--timeline-node-size);
    height: var(--timeline-node-size);
    border-radius: 50%;
    border: var(--timeline-node-border) solid var(--brand-primary);
    background: var(--bg-surface);
    position: relative;
    z-index: 2;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Glow effect on hover/selected */
.timeline-node-dot::before {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: var(--brand-primary);
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: -1;
}

.timeline-node:hover .timeline-node-dot::before,
.timeline-node.selected .timeline-node-dot::before {
    opacity: 0.12;
}

/* Selected State */
.timeline-node.selected .timeline-node-dot {
    background: var(--brand-primary);
    transform: scale(1.2);
}

/* Compare State */
.timeline-node.compare .timeline-node-dot {
    border-color: var(--sig-high);
    background: var(--sig-high);
}

.timeline-node.compare .timeline-node-dot::before {
    background: var(--sig-high);
}

/* Significance Colors */
.timeline-node.sig-low .timeline-node-dot { border-color: var(--sig-low); }
.timeline-node.sig-medium .timeline-node-dot { border-color: var(--sig-medium); }
.timeline-node.sig-high .timeline-node-dot { border-color: var(--sig-high); }
.timeline-node.sig-critical .timeline-node-dot { border-color: var(--sig-critical); }

.timeline-node.sig-critical .timeline-node-dot::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--sig-critical);
    animation: pulse-ring 2s ease-out infinite;
}

@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* Timeline Labels */
.timeline-node-label {
    margin-top: 0.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.timeline-node-date {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.timeline-node-badge {
    font-size: 0.6rem;
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

/* ============================================
   TIMELINE - VERTICAL (Mobile)
   ============================================ */

.vertical-timeline {
    position: relative;
    padding-left: 2.5rem;
}

.vertical-timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, var(--brand-primary) 0%, var(--border-subtle) 100%);
    border-radius: 2px;
}

.vertical-timeline-item {
    position: relative;
    padding-bottom: 2rem;
    padding-left: 1.5rem;
}

.vertical-timeline-item:last-child {
    padding-bottom: 0;
}

.vertical-timeline-dot {
    position: absolute;
    left: -2.5rem;
    top: 0.25rem;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 3px solid var(--brand-primary);
    z-index: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.vertical-timeline-dot:hover {
    transform: scale(1.1);
}

.vertical-timeline-dot.selected {
    background: var(--brand-primary);
    transform: scale(1.2);
}

.vertical-timeline-dot.compare {
    border-color: var(--sig-high);
    background: var(--sig-high);
}

/* ============================================
   VERSION CARDS
   ============================================ */

.version-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.version-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--border-subtle);
    transition: all 0.2s ease;
}

.version-card:hover {
    border-color: var(--brand-primary);
    box-shadow: var(--shadow-md);
    transform: translateX(4px);
}

.version-card:hover::before {
    background: var(--brand-primary);
}

.version-card.selected {
    border-color: var(--brand-primary);
    background: var(--brand-surface);
}

.version-card.selected::before {
    background: var(--brand-primary);
    width: 6px;
}

.version-card.compare {
    border-color: var(--sig-high);
    background: rgba(249, 115, 22, 0.04);
}

.version-card.compare::before {
    background: var(--sig-high);
    width: 6px;
}

.version-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    gap: 1rem;
}

.version-date {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    font-family: var(--font-display);
}

.version-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.version-badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

/* Badge Variants */
.badge-sig-low { background: rgba(34, 197, 94, 0.1); color: #166534; border: 1px solid rgba(34, 197, 94, 0.2); }
.badge-sig-medium { background: rgba(234, 179, 8, 0.1); color: #854d0e; border: 1px solid rgba(234, 179, 8, 0.2); }
.badge-sig-high { background: rgba(249, 115, 22, 0.1); color: #9a3412; border: 1px solid rgba(249, 115, 22, 0.2); }
.badge-sig-critical { background: rgba(239, 68, 68, 0.1); color: #991b1b; border: 1px solid rgba(239, 68, 68, 0.2); }
.badge-wayback { background: var(--bg-panel); color: var(--text-secondary); border: 1px solid var(--border-subtle); }
.badge-live { background: rgba(34, 197, 94, 0.1); color: #166534; border: 1px solid rgba(34, 197, 94, 0.2); }

[data-theme="dark"] .badge-sig-low { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
[data-theme="dark"] .badge-sig-medium { background: rgba(234, 179, 8, 0.15); color: #fbbf24; }
[data-theme="dark"] .badge-sig-high { background: rgba(249, 115, 22, 0.15); color: #fb923c; }
[data-theme="dark"] .badge-sig-critical { background: rgba(239, 68, 68, 0.15); color: #f87171; }

.version-summary {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.version-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.version-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.75rem;
}

.category-tag {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    background: var(--brand-surface);
    color: var(--brand-primary);
    border-radius: var(--radius-sm);
    font-weight: 500;
}

/* ============================================
   DIFF VIEWER
   ============================================ */

.diff-viewer {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.diff-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
    gap: 1rem;
}

.diff-header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.diff-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    font-family: var(--font-display);
}

.diff-controls {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.diff-mode-btn {
    padding: 0.5rem 0.875rem;
    font-size: 0.8rem;
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    font-weight: 500;
}

.diff-mode-btn:hover {
    border-color: var(--border-strong);
    color: var(--text-primary);
    background: var(--bg-panel);
}

.diff-mode-btn.active {
    background: var(--brand-primary);
    color: white;
    border-color: var(--brand-primary);
}

.diff-stats {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-body);
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.85rem;
    font-family: var(--font-mono);
}

.diff-stat {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.diff-stat-added { color: var(--sig-low); }
.diff-stat-removed { color: var(--sig-critical); }
.diff-stat-changed { color: var(--sig-high); }

/* Side by Side View */
.diff-side-by-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    height: 60vh;
    min-height: 400px;
}

.diff-pane {
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.7;
}

.diff-pane:first-child {
    border-right: 1px solid var(--border-subtle);
}

.diff-pane-header {
    position: sticky;
    top: 0;
    padding: 0.625rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    z-index: 1;
    border-bottom: 1px solid var(--border-subtle);
}

.diff-pane.old .diff-pane-header {
    background: var(--diff-remove-bg);
    color: var(--diff-remove-text);
}

.diff-pane.new .diff-pane-header {
    background: var(--diff-add-bg);
    color: var(--diff-add-text);
}

.diff-content {
    padding: 1rem 1.25rem;
}

/* Diff Lines */
.diff-line {
    display: flex;
    padding: 0.2rem 0;
    border-radius: var(--radius-sm);
    margin: 0 -0.5rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

.diff-line-num {
    width: 3.5rem;
    text-align: right;
    padding-right: 1rem;
    color: var(--text-muted);
    user-select: none;
    flex-shrink: 0;
    font-size: 0.75rem;
}

.diff-line-content {
    flex: 1;
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-line.added {
    background: var(--diff-add-bg);
}

.diff-line.added .diff-line-content {
    color: var(--diff-add-text);
}

.diff-line.removed {
    background: var(--diff-remove-bg);
}

.diff-line.removed .diff-line-content {
    color: var(--diff-remove-text);
    text-decoration: line-through;
    text-decoration-color: var(--diff-remove-text);
}

/* Unified View */
.diff-unified {
    height: 60vh;
    min-height: 400px;
    overflow-y: auto;
    padding: 1.25rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.7;
}

.diff-hunk {
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.diff-hunk-header {
    background: var(--bg-panel);
    color: var(--brand-primary);
    font-weight: 500;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.diff-line-prefix {
    display: inline-block;
    width: 1.5rem;
    color: inherit;
    user-select: none;
    font-weight: 600;
}

/* Word-Level Diff */
.diff-word-view {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
    line-height: 1.9;
    font-size: 0.9rem;
}

.diff-word {
    display: inline;
    padding: 0.1rem 0.25rem;
    border-radius: 3px;
    margin: 0 1px;
}

.diff-word.added {
    background: var(--diff-add-bg);
    color: var(--diff-add-text);
    border-bottom: 2px solid var(--diff-add-text);
}

.diff-word.removed {
    background: var(--diff-remove-bg);
    color: var(--diff-remove-text);
    text-decoration: line-through;
}

/* Search Highlight */
.search-highlight {
    background: #fef08a;
    color: #854d0e;
    border-radius: 2px;
    padding: 0 0.15rem;
    font-weight: 500;
}

[data-theme="dark"] .search-highlight {
    background: rgba(254, 240, 138, 0.3);
    color: #fef08a;
}

/* ============================================
   COMPARE PANELS
   ============================================ */

.compare-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.compare-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.compare-panel-selector {
    padding: 1rem 1.25rem;
    border-bottom: 2px solid var(--border-subtle);
    background: var(--bg-panel);
}

.compare-panel-selector label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.compare-panel-content {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
    max-height: 55vh;
    font-size: 0.85rem;
    line-height: 1.7;
}

/* ============================================
   COMPARE FORM
   ============================================ */

.compare-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.compare-field {
    flex: 1;
    min-width: 200px;
}

.compare-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.compare-field select {
    width: 100%;
}

/* ============================================
   STAT CARDS
   ============================================ */

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
    transition: all 0.2s ease;
}

.stat-card:hover {
    border-color: var(--brand-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ============================================
   LOADING STATES
   ============================================ */

.skeleton {
    background: linear-gradient(90deg, var(--bg-panel) 25%, var(--bg-surface) 50%, var(--bg-panel) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 900px) {
    .compare-panels {
        grid-template-columns: 1fr;
    }
    
    .diff-side-by-side {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .diff-side-by-side .diff-pane:first-child {
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
        max-height: 40vh;
    }
    
    .diff-side-by-side .diff-pane:last-child {
        max-height: 40vh;
    }
}

@media (max-width: 640px) {
    .diff-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
    }
    
    .diff-controls {
        width: 100%;
        justify-content: flex-start;
    }
    
    .diff-stats {
        flex-wrap: wrap;
        gap: 0.75rem;
    }
    
    .visual-timeline {
        display: none;
    }
    
    .version-card-header {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .version-badges {
        justify-content: flex-start;
    }
    
    .compare-form {
        flex-direction: column;
    }
    
    .compare-field {
        width: 100%;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.mobile-only {
    display: none !important;
}

@media (max-width: 640px) {
    .mobile-only {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
}

/* ============================================
   ENHANCED MOBILE RESPONSIVE (Timeline/Diff)
   ============================================ */

@media (max-width: 768px) {
    /* Timeline stats - 2x2 grid on mobile */
    .timeline-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }
    
    .stat-card {
        padding: 0.875rem !important;
    }
    
    .stat-card > div:first-child {
        font-size: 1.25rem !important;
    }
    
    /* Version cards mobile optimization */
    .version-card {
        padding: 1rem !important;
    }
    
    .version-card > div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }
    
    .version-card > div:first-child > div:last-child {
        display: flex;
        gap: 1rem;
        font-size: 0.75rem !important;
    }
    
    .version-badges {
        justify-content: flex-start !important;
    }
    
    /* Diff viewer mobile */
    .diff-viewer {
        border-radius: var(--radius-md);
    }
    
    .diff-header {
        padding: 1rem !important;
    }
    
    .diff-title {
        font-size: 0.9rem !important;
    }
    
    .diff-controls {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
        margin-bottom: -0.25rem;
    }
    
    .diff-mode-btn {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.75rem !important;
        white-space: nowrap;
    }
    
    .diff-stats {
        padding: 0.625rem 1rem !important;
        gap: 1rem !important;
        font-size: 0.8rem !important;
    }
    
    .diff-unified,
    .diff-word-view {
        padding: 1rem !important;
        max-height: 50vh !important;
        font-size: 0.75rem !important;
    }
    
    .diff-line-num {
        width: 2.5rem !important;
        padding-right: 0.5rem !important;
        font-size: 0.65rem !important;
    }
    
    /* Compare panels stacked */
    .compare-panels {
        gap: 1rem !important;
    }
    
    .compare-panel-selector {
        padding: 0.875rem 1rem !important;
    }
    
    .compare-panel-content {
        padding: 1rem !important;
        max-height: 40vh !important;
        font-size: 0.85rem !important;
    }
    
    /* Compare form mobile */
    .compare-form {
        gap: 0.75rem !important;
    }
    
    .compare-field {
        min-width: 0 !important;
    }
    
    .compare-field label {
        font-size: 0.7rem !important;
    }
    
    /* Vertical timeline optimization */
    .vertical-timeline {
        padding-left: 2rem !important;
    }
    
    .vertical-timeline::before {
        left: 6px !important;
        width: 2px !important;
    }
    
    .vertical-timeline-dot {
        left: -2rem !important;
        width: 14px !important;
        height: 14px !important;
        border-width: 2px !important;
    }
    
    .vertical-timeline-item {
        padding-bottom: 1.5rem !important;
        padding-left: 1rem !important;
    }
}

@media (max-width: 480px) {
    /* Extra small screen adjustments */
    .timeline-stats {
        gap: 0.5rem !important;
    }
    
    .stat-card {
        padding: 0.75rem !important;
    }
    
    .stat-card > div:first-child {
        font-size: 1.125rem !important;
    }
    
    .stat-card > div:last-child {
        font-size: 0.65rem !important;
    }
    
    .version-date {
        font-size: 0.9rem !important;
    }
    
    .version-badge {
        font-size: 0.6rem !important;
        padding: 0.15rem 0.4rem !important;
    }
    
    .version-summary {
        font-size: 0.8rem !important;
        -webkit-line-clamp: 3 !important;
    }
    
    .version-meta {
        font-size: 0.7rem !important;
        gap: 0.75rem !important;
    }
}
