/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 2.5em;
    font-weight: 300;
}

header p {
    color: #666;
    font-size: 1.1em;
}

/* Controls */
.controls {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    align-items: end;
    position: relative;
    z-index: 100;
}

.control-group {
    display: flex;
    flex-direction: column;
}

.control-group label {
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.control-group select,
.control-group button {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.control-group select:focus,
.control-group button:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.control-group select:disabled {
    background-color: #f8f9fa;
    color: #6c757d;
}

.checkbox-group {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-weight: normal !important;
}

.checkbox-label input[type="checkbox"] {
    margin: 0;
}

button.info-button {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 2px;
    margin-left: 6px;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    vertical-align: middle;
}

button.info-button:hover {
    background: #e9ecef;
    color: #495057;
}

button.info-button svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

button {
    background: #3498db;
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

button:hover:not(:disabled) {
    background: #2980b9;
}

button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

/* Slider styles */
.slider {
    width: 100%;
    height: 5px;
    border-radius: 5px;
    background: #ddd;
    outline: none;
    opacity: 0.7;
    transition: opacity 0.2s;
    -webkit-appearance: none;
}

.slider:hover {
    opacity: 1;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: none;
}

/* Table filters */
.table-filters {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 4px;
}

.table-filters input,
.table-filters select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.file-list-section h4 {
    margin-bottom: 15px;
    color: #2c3e50;
}

/* Status */
.status {
    background: #e8f4fd;
    border: 1px solid #bee5eb;
    color: #0c5460;
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
    text-align: center;
}

/* Tabs */
.tabs {
    margin-bottom: 20px;
}

.tab-buttons {
    display: flex;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
}

.tab-button {
    flex: 1;
    padding: 15px 20px;
    background: #f8f9fa;
    border: none;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    color: #666;
    transition: all 0.2s;
    border-right: 1px solid #dee2e6;
}

.tab-button:last-child {
    border-right: none;
}

.tab-button:hover {
    background: #e9ecef;
    color: #495057;
}

.tab-button.active {
    background: #3498db;
    color: white;
}

.tab-button.active:hover {
    background: #2980b9;
}

.status.error {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.status.success {
    background: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

/* Legend */
.legend {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.legend h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.legend-items {
    display: flex;
    gap: 25px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
}

.legend-color.unchanged {
    background: #95a5a6;
}

.legend-color.decreased {
    background: #27ae60;
}

.legend-color.increased {
    background: #e74c3c;
}

/* Visualization */
.visualization {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    overflow: hidden;
}

.chart-container {
    position: relative;
    min-height: 600px;
    z-index: 1;
}

#metric-chart {
    max-height: 800px;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
    z-index: 1;
    margin-top: -10px;
    padding-top: 15px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px 10px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    position: relative;
    z-index: 50;
}

.version-label {
    font-weight: 600;
    color: #495057;
    font-size: 1.1em;
}

.chart-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
    z-index: 200;
}

.chart-info {
    color: #666;
    font-size: 14px;
    font-style: italic;
}


/* Interactive elements */
.chart-container .node rect {
    transition: stroke-width 0.2s;
}

.chart-container .node:hover rect {
    stroke-width: 2px;
}

.chart-container .link {
    transition: stroke-opacity 0.2s;
}

.chart-container .link:hover {
    stroke-opacity: 1 !important;
}

/* Details */
.details {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.details h3 {
    margin-bottom: 20px;
    color: #2c3e50;
}

.summary {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 4px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.summary-item:last-child {
    margin-bottom: 0;
}

.file-list {
    max-height: 800px;
    overflow-y: auto;
    position: relative;
    z-index: 1;
}

.file-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 10px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-bottom: 2px solid #adb5bd;
    font-weight: 600;
    color: #495057;
    position: sticky;
    top: 0;
    z-index: 10;
}

.file-name-header {
    flex: 1;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.file-sizes-header {
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 0.9em;
}

.size-value-header,
.size-change-header {
    min-width: 80px;
    text-align: center;
    font-size: 0.85em;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
}

.file-item:hover {
    background-color: #f8f9fa;
}

.file-item:last-child {
    border-bottom: none;
}

.file-name {
    flex: 1;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    word-break: break-all;
}

.file-name-tooltip {
    cursor: help;
}

.file-sizes {
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 0.9em;
}

.size-value {
    min-width: 80px;
    text-align: right;
}

.size-change {
    min-width: 60px;
    text-align: right;
    font-weight: 500;
}

.size-change.positive {
    color: #e74c3c;
}

.size-change.negative {
    color: #27ae60;
}

.size-change.neutral {
    color: #95a5a6;
}

/* Sortable headers */
.sortable-header {
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sortable-header:hover {
    background-color: #e9ecef;
    color: #495057;
}

.sortable-header:active {
    background-color: #dee2e6;
}

/* Sort direction indicators */
.sortable-header::after {
    content: '';
    opacity: 0.3;
    margin-left: 0.5em;
}

.sortable-header:hover::after {
    opacity: 0.6;
}

/* Ensure Plotly tooltips remain readable with classic styling */
.plotly .hovertext {
    background: #FFFFDD !important;
    color: black !important;
    border: 1px solid #333 !important;
}

.plotly .hovertext text {
    fill: black !important;
}

/* Override any colorful tooltip backgrounds */
g.hovertext {
    background: #FFFFDD !important;
}

g.hovertext rect {
    fill: #FFFFDD !important;
    stroke: #333 !important;
}

g.hovertext text {
    fill: black !important;
}

/* Safari scrollbar fixes */
.file-list::-webkit-scrollbar {
    width: 8px;
}

.file-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.file-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.file-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

#metric-chart::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#metric-chart::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#metric-chart::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

#metric-chart::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Ensure scrollable areas have proper isolation */
.file-list, #metric-chart {
    isolation: isolate;
}

/* Plotly modebar (chart controls) fixes - keep on right with spacing from scrollbar */
.modebar {
    position: absolute !important;
    right: 20px !important;
    top: 10px !important;
    z-index: 300 !important;
}

.modebar-group {
    position: relative !important;
    z-index: 300 !important;
}

.modebar-btn {
    z-index: 300 !important;
}

/* Prevent scrollbars from covering Plotly controls */
.plotly > div {
    position: relative;
}

.plotly .modebar-container {
    position: relative !important;
    z-index: 300 !important;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 10px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s;
    max-width: 300px;
    line-height: 1.4;
}

.tooltip.visible {
    opacity: 1;
}

/* Responsive design */
@media (max-width: 768px) {
    .controls {
        grid-template-columns: 1fr;
    }
    
    .legend-items {
        flex-direction: column;
        gap: 10px;
    }
    
    .chart-header {
        padding: 15px 20px 10px;
    }
    
    .file-sizes {
        flex-direction: column;
        gap: 5px;
        align-items: flex-end;
    }
}

/* Loading state */
.loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Timeline Modal Styles */
.timeline-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.timeline-modal {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow: hidden;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { 
        opacity: 0;
        transform: scale(0.95) translateY(-20px);
    }
    to { 
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.timeline-modal-header {
    padding: 25px 30px 20px;
    border-bottom: 1px solid #e1e5e9;
    background: #f8f9fa;
    position: relative;
}

.timeline-modal-header h3 {
    margin: 0 0 10px 0;
    color: #2c3e50;
    font-size: 1.4em;
    font-weight: 600;
    word-break: break-all;
    padding-right: 40px;
}

.timeline-modal-summary {
    color: #666;
    font-size: 14px;
}

.timeline-modal-close {
    position: absolute;
    top: 20px;
    right: 25px;
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.timeline-modal-close:hover {
    background: #f0f0f0;
    color: #666;
}

.timeline-modal-body {
    padding: 25px 30px 30px;
    max-height: calc(90vh - 120px);
    overflow-y: auto;
}

.timeline-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    color: #666;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #f0f0f0;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

.timeline-loading p {
    margin: 0;
    font-size: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .timeline-modal {
        width: 95%;
        margin: 20px;
        max-height: calc(100vh - 40px);
    }
    
    .timeline-modal-header {
        padding: 20px;
    }
    
    .timeline-modal-header h3 {
        font-size: 1.2em;
        padding-right: 35px;
    }
    
    .timeline-modal-close {
        top: 15px;
        right: 15px;
        font-size: 20px;
        width: 26px;
        height: 26px;
    }
    
    .timeline-modal-body {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .timeline-modal {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }
    
    .timeline-modal-header h3 {
        font-size: 1.1em;
        line-height: 1.3;
    }
}