:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #64748b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --warning-bg: #fef9c3;
    --warning-text: #854d0e;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
    --header-gradient: linear-gradient(135deg, #4f46e5 0%, #8b5cf6 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    line-height: 1.6;
}

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

/* Header */
.header {
    background: var(--header-gradient);
    color: white;
    padding: 40px 0;
    margin-bottom: 40px;
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.2);
}

.header h1 {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.025em;
}

.subtitle {
    opacity: 0.9;
    font-size: 1rem;
    font-weight: 500;
}

/* Controls */
.time-window-selector {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 32px;
    padding: 8px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    width: fit-content;
}

.btn {
    padding: 10px 0;
    width: 100px;
    min-width: 100px;
    max-width: 100px;
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #f5f3ff;
}

.btn-primary {
    padding: 10px 0;
    width: 100px;
    min-width: 100px;
    max-width: 100px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    background: var(--primary-color);
    color: white;
    border: 1px solid var(--primary-color);
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: white;
    transform: translateY(-1px);
}

/* Interval Section */
.interval-section {
    background: white;
    padding: 32px;
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 32px;
}

.interval-analysis-block h3 {
    color: var(--primary-color);
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.interval-analysis-block .meta {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

/* Table Styling */
.interval-table-wrapper {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.interval-matrix-meta {
    padding: 10px 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    background: #f8fafc;
}

.interval-table {
    width: auto;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
    table-layout: fixed;
}

.interval-table th,
.interval-table td {
    padding: 8px 6px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    width: 50px;
    min-width: 50px;
    max-width: 50px;
}

.interval-table th:last-child,
.interval-table td:last-child {
    border-right: none;
}

.interval-table thead th {
    background: #f8fafc;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.03em;
    position: sticky;
    top: 0;
}

/* Header Position Colors (Alternating) */
.interval-table thead th.header-odd {
    background-color: #e0e7ff;
    color: #3730a3;
}

.interval-table thead th.header-even {
    background-color: #c7d2fe;
    color: #312e81;
}

.interval-table tbody tr:last-child td {
    border-bottom: none;
}

.interval-table .position-header {
    background: #f8fafc;
    font-weight: 600;
    color: var(--primary-color);
    width: 60px;
    min-width: 60px;
    max-width: 60px;
}

.interval-table tbody td {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

/* Heatmap Colors */
.interval-recent {
    background-color: #ecfdf5;
    color: #047857;
}

.interval-medium {
    background-color: #fffbeb;
    color: #b45309;
}

.interval-long {
    background-color: #fef2f2;
    color: #b91c1c;
}

.interval-very-long {
    background-color: #4b5563;
    color: #f3f4f6;
    font-weight: 700;
}

.interval-table .no-data {
    color: #cbd5e1;
    background-color: #f8fafc;
}

/* Legend */
.interval-legend {
    display: flex;
    gap: 24px;
    margin-top: 24px;
    padding: 16px;
    background: #f8fafc;
    border-radius: 12px;
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.legend-color.recent {
    background: #ecfdf5;
    border-color: #047857;
}

.legend-color.medium {
    background: #fffbeb;
    border-color: #b45309;
}

.legend-color.long {
    background: #fef2f2;
    border-color: #b91c1c;
}

.legend-color.very-long {
    background: #4b5563;
    border-color: #1f2937;
}

/* Loading & Footer */
.loading-spinner {
    text-align: center;
    padding: 48px;
    color: var(--primary-color);
}

.footer {
    text-align: center;
    padding: 40px 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: auto;
}

/* Responsive - Tablet */
@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }

    .header {
        padding: 24px 0;
        margin-bottom: 24px;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .interval-section {
        padding: 20px;
        margin-bottom: 20px;
    }

    .time-window-selector {
        width: 100%;
    }
}

/* Responsive - Mobile */
@media (max-width: 600px) {
    /* Global spacing optimization */
    .container {
        padding: 0 12px;
    }

    .header {
        padding: 16px 0;
        margin-bottom: 16px;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .subtitle {
        font-size: 0.875rem;
    }

    /* Buttons - compact grid layout */
    .time-window-selector {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        width: 100%;
        padding: 8px;
        margin-bottom: 20px;
    }

    .btn,
    .btn-primary {
        width: 100%;
        min-width: unset;
        max-width: unset;
        padding: 12px 4px;
        font-size: 0.8rem;
    }

    /* Section compact */
    .interval-section {
        padding: 16px;
        border-radius: 12px;
        margin-bottom: 16px;
    }

    .interval-analysis-block h3 {
        font-size: 1rem;
    }

    .interval-analysis-block .meta {
        display: flex;
        flex-direction: column;
        gap: 4px;
        align-items: flex-start;
        margin-bottom: 16px;
        padding-bottom: 12px;
        font-size: 0.8rem;
    }

    /* Table - extreme compact to fit all 11 columns without scrolling */
    .interval-table-wrapper {
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
        overflow-x: hidden; /* Disable horizontal scroll */
    }

    .interval-table {
        width: 100%;
        table-layout: fixed;
        font-size: 0.65rem;
    }

    .interval-table th,
    .interval-table td {
        width: auto;
        min-width: unset;
        max-width: unset;
        padding: 5px 1px;
    }

    /* First column (number label) slightly wider */
    .interval-table th:first-child,
    .interval-table td:first-child {
        width: 32px;
        min-width: 32px;
        font-size: 0.6rem;
    }

    .interval-table .position-header {
        width: 32px;
        min-width: 32px;
        max-width: unset;
    }

    .interval-table thead th {
        font-size: 0.55rem;
        padding: 4px 1px;
        letter-spacing: -0.02em;
    }

    /* Legend - 2x2 grid */
    .interval-legend {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 12px;
        margin-top: 16px;
    }

    .legend-item {
        font-size: 0.75rem;
        gap: 6px;
    }

    .legend-color {
        width: 16px;
        height: 16px;
        border-radius: 4px;
    }

    /* Footer compact */
    .footer {
        padding: 24px 0;
        font-size: 0.8rem;
    }

    .loading-spinner {
        padding: 32px;
    }
}
