/* CSS Variables for Theming */
:root {
    /* Light theme colors */
    --bg-primary: #f7fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #edf2f7;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #a0aec0;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e0;
    --accent-primary: #4299e1;
    --accent-hover: #3182ce;
    --success-color: #48bb78;
    --error-color: #e53e3e;
    --warning-color: #ed8936;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-medium: rgba(0, 0, 0, 0.15);
    --header-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --chart-bg: #ffffff;
    --chart-text: #2d3748;
    --chart-grid: #e2e8f0;
}

/* Dark theme colors */
[data-theme="dark"] {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #a0aec0;
    --border-color: #4a5568;
    --border-hover: #718096;
    --accent-primary: #63b3ed;
    --accent-hover: #4299e1;
    --success-color: #68d391;
    --error-color: #fc8181;
    --warning-color: #f6ad55;
    --shadow-light: rgba(0, 0, 0, 0.3);
    --shadow-medium: rgba(0, 0, 0, 0.4);
    --header-bg: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
    --chart-bg: #2d3748;
    --chart-text: #f7fafc;
    --chart-grid: #4a5568;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--header-bg);
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px;
}

/* Header */
header {
    margin-bottom: 15px;
    color: white;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-text {
    text-align: center;
    flex: 1;
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
}

.theme-icon {
    font-size: 20px;
    transition: transform 0.3s ease;
}

.theme-toggle:hover .theme-icon {
    transform: rotate(20deg);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

header p {
    font-size: 1.2rem;
    opacity: 0.9;
}

/* Main Content */
main {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 30px var(--shadow-medium);
    margin-bottom: 10px;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

/* Sections */
section {
    margin-bottom: 20px;
}

section h3 {
    color: var(--text-primary);
    margin-bottom: 15px;
    font-size: 1.3rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

/* Upload Section */
.upload-section {
    background: var(--bg-tertiary);
    padding: 15px;
    border-radius: 8px;
    border: 2px dashed var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.file-upload {
    margin-bottom: 20px;
}

.file-label {
    display: block;
    cursor: pointer;
    padding: 15px 20px;
    background: var(--accent-primary);
    color: white;
    border-radius: 6px;
    text-align: center;
    transition: all 0.3s ease;
    font-weight: 500;
}

.file-label:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.file-label input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.file-info {
    margin-top: 10px;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    min-height: 20px;
    transition: background-color 0.3s ease;
}

.file-info.loaded {
    background: var(--success-color);
    color: white;
    border-left: 4px solid var(--success-color);
}

.file-info.error {
    background: var(--error-color);
    color: white;
    border-left: 4px solid var(--error-color);
}

/* Clear Saved Data Button */
.clear-saved-button {
    padding: 8px 16px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.clear-saved-button:hover {
    background: #c53030;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(229, 62, 62, 0.3);
}

.clear-saved-button:active {
    transform: translateY(0);
}

.clear-saved-button:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Dropzone Styles */
.dropzone-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 15px;
}

.dropzone-wrapper {
    display: flex;
    flex-direction: column;
}

.dropzone-wrapper h4 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-size: 1rem;
    font-weight: 600;
}

.dropzone {
    border: 2px dashed var(--border-color) !important;
    border-radius: 8px !important;
    background: var(--bg-secondary) !important;
    padding: 12px !important;
    text-align: center !important;
    transition: all 0.3s ease !important;
    cursor: pointer !important;
    min-height: 80px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.dropzone:hover,
.dropzone.dz-drag-hover {
    border-color: var(--accent-primary) !important;
    background: var(--bg-tertiary) !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-light);
}

.dropzone .dz-message {
    margin: 0 !important;
    color: var(--text-secondary) !important;
}

.dropzone-icon {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.dropzone-text {
    font-size: 0.9rem;
    line-height: 1.4;
}

.dropzone-text strong {
    color: var(--text-primary);
    display: block;
    margin-bottom: 4px;
}


/* Dropzone uploaded file styles */
.dropzone .dz-preview {
    display: none !important;
}

.dropzone.dz-started .dz-message {
    display: block !important;
}

.dropzone.dz-success {
    border-color: var(--success-color) !important;
    background: rgba(72, 187, 120, 0.1) !important;
}

.dropzone.dz-success .dz-message {
    color: var(--success-color) !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.dropzone.dz-error {
    border-color: var(--error-color) !important;
    background: rgba(229, 62, 62, 0.1) !important;
}

.dropzone.dz-error .dz-message {
    color: var(--error-color) !important;
    display: block !important;
    visibility: visible !important;
}

/* Remove file button styling */
.dropzone .dz-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.dropzone .dz-remove:hover {
    background: #c53030;
}

/* Controls Section */
.controls-section {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
}

.control-item {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
    flex-wrap: wrap;
}

.control-item label {
    font-weight: 500;
    color: var(--text-primary);
    min-width: 120px;
}

[data-theme="dark"] .control-item label {
    color: var(--text-primary);
}

.control-item input[type="text"],
.control-item select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    flex-grow: 1;
    max-width: 300px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.3s ease, background-color 0.3s ease;
}

.control-item input[type="text"]:focus,
.control-item select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.control-item input[type="checkbox"] {
    margin-right: 8px;
}

button {
    padding: 8px 16px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

button:hover {
    background: var(--accent-hover);
}

button:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* Results Section */
.results-section {
    min-height: 400px;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
}

.tab-button {
    padding: 12px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.tab-button.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

.tab-button:hover {
    color: var(--accent-primary);
    background: var(--bg-tertiary);
}

/* Tab Content */
.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

#chart-container {
    min-height: 500px;
    max-height: none;
    background: var(--chart-bg);
    border-radius: 6px;
    padding: 15px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    width: 100%;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    position: relative;
    resize: vertical;
    /* Allow manual vertical resizing */
}

/* Ensure plotly charts are fully responsive */
#chart-container .plotly-div {
    width: 100% !important;
    height: 100% !important;
}

#chart-container .plot-container {
    width: 100% !important;
    height: 100% !important;
}

#summary-content {
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

#raw-content {
    max-height: 500px;
    overflow-y: auto;
}

#raw-data {
    background: #2d3748;
    color: #e2e8f0;
    padding: 20px;
    border-radius: 6px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Status Messages */
.status-message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 6px;
    font-weight: 500;
    max-width: 400px;
    z-index: 1000;
    transform: translateX(500px);
    transition: transform 0.3s ease;
}

.status-message.show {
    transform: translateX(0);
}

.status-message.success {
    background: #c6f6d5;
    color: #2f855a;
    border-left: 4px solid #38a169;
}

.status-message.error {
    background: #fed7d7;
    color: #c53030;
    border-left: 4px solid #e53e3e;
}

.status-message.info {
    background: #bee3f8;
    color: #2b6cb0;
    border-left: 4px solid #4299e1;
}

/* Context Alert */
.context-alert {
    background: var(--warning-color);
    color: white;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    border-left: 4px solid #ed8936;
    position: relative;
    transition: all 0.3s ease;
}

.context-alert.hidden {
    display: none;
}

.context-alert-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.context-alert-title {
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-alert-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.context-alert-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.context-differences {
    list-style: none;
    margin: 0;
    padding: 0;
}

.context-difference {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 8px;
}

.context-difference:last-child {
    margin-bottom: 0;
}

.difference-field {
    font-weight: 600;
    margin-bottom: 4px;
}

.difference-values {
    font-size: 0.9rem;
    opacity: 0.9;
}

.impact-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-left: 8px;
}

.impact-high {
    background: #e53e3e;
    color: white;
}

.impact-medium {
    background: #ed8936;
    color: white;
}

.impact-low {
    background: #68d391;
    color: #22543d;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    main {
        padding: 20px;
    }

    .header-content {
        flex-direction: column;
        text-align: center;
    }

    .header-text {
        order: 1;
    }

    .theme-toggle {
        order: 0;
        align-self: flex-end;
        margin-bottom: 10px;
    }

    header h1 {
        font-size: 2rem;
    }

    .control-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .control-item label {
        min-width: auto;
    }

    .dropzone-container {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .control-item input[type="text"],
    .control-item select {
        max-width: none;
        width: 100%;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .tab-button {
        flex: 1;
        min-width: 120px;
    }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #4299e1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Chart specific styles */
.benchmark-group {
    margin-bottom: 20px;
    padding: 15px;
    background: white;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.benchmark-group h4 {
    color: #4a5568;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

/* Comparison highlights */
.improvement {
    color: #38a169;
    font-weight: bold;
}

.regression {
    color: #e53e3e;
    font-weight: bold;
}

.neutral {
    color: #718096;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Global drag and drop visual feedback */
body.drag-over-page {
    position: relative;
}

body.drag-over-page::before {
    content: 'Drop files into the upload areas above';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(66, 153, 225, 0.1);
    backdrop-filter: blur(2px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: var(--accent-primary);
    text-align: center;
    border: 4px dashed var(--accent-primary);
    box-sizing: border-box;
    pointer-events: none;
}

/* Dark theme overrides for summary and controls */
[data-theme="dark"] .benchmark-group {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .controls-section {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] #summary-content {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

/* Table View Styles */
.table-wrapper {
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 10px;
}

.table-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.3rem;
    border: none;
    padding: 0;
}

.table-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.table-search {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    min-width: 200px;
    transition: border-color 0.3s ease, background-color 0.3s ease;
}

.table-search:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

.table-search::placeholder {
    color: var(--text-muted);
}

.table-count {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.table-container {
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
}

.benchmark-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--bg-secondary);
}

.benchmark-table th {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
    text-align: left;
    padding: 12px 15px;
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    transition: background-color 0.3s ease;
}

.benchmark-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background-color 0.2s ease;
}

.benchmark-table th.sortable:hover {
    background: var(--border-hover);
}

.benchmark-table th .sort-icon {
    margin-left: 8px;
    opacity: 0.5;
    font-size: 0.8rem;
    transition: opacity 0.2s ease;
}

.benchmark-table th.sortable:hover .sort-icon {
    opacity: 1;
}

.benchmark-table th.sort-asc .sort-icon::before {
    content: '↑';
    opacity: 1;
    color: var(--accent-primary);
}

.benchmark-table th.sort-desc .sort-icon::before {
    content: '↓';
    opacity: 1;
    color: var(--accent-primary);
}

.benchmark-table th.sort-asc .sort-icon,
.benchmark-table th.sort-desc .sort-icon {
    opacity: 1;
}

.benchmark-table td {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: background-color 0.2s ease;
}

.benchmark-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.benchmark-table tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .benchmark-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.benchmark-table tbody tr:nth-child(even):hover {
    background: var(--bg-tertiary);
}

.benchmark-table td.improvement {
    color: var(--success-color);
    font-weight: 600;
}

.benchmark-table td.regression {
    color: var(--error-color);
    font-weight: 600;
}

.benchmark-table td[data-value=""] {
    color: var(--text-muted);
    font-style: italic;
}

/* Table responsive behavior */
@media (max-width: 768px) {
    .table-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .table-controls {
        justify-content: space-between;
    }

    .table-search {
        min-width: 150px;
        flex: 1;
    }

    .benchmark-table {
        font-size: 0.8rem;
    }

    .benchmark-table th,
    .benchmark-table td {
        padding: 8px 10px;
    }

    .table-container {
        max-height: 500px;
    }
}

/* Table empty state */
.table-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-style: italic;
}

/* Table loading state */
.table-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    color: var(--text-secondary);
}

.table-loading .loading {
    margin-right: 10px;
}