/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

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

/* Header */
.header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

.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.1rem;
    opacity: 0.9;
}

/* Upload Section */
.upload-section {
    margin-bottom: 40px;
}

.upload-hint {
    margin-top: 15px;
    text-align: center;
    color: white;
    font-size: 0.9rem;
    opacity: 0.85;
}

.upload-hint code {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.upload-alt {
    margin-top: 6px;
    text-align: center;
    color: white;
    font-size: 0.95rem;
    opacity: 0.9;
}

.bundled-link {
    color: white;
    font-weight: 600;
    text-decoration: underline;
}

.bundled-link:hover {
    color: #4CAF50;
}

.upload-area {
    border: 3px dashed #fff;
    border-radius: 15px;
    padding: 60px 20px;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    cursor: pointer;
}

.upload-area:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.upload-area.dragover {
    background: rgba(255, 255, 255, 0.3);
    border-color: #4CAF50;
}

.upload-content {
    color: white;
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
    stroke-width: 2;
}

.upload-content h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
}

.upload-link {
    color: #4CAF50;
    text-decoration: underline;
    cursor: pointer;
}

/* Dashboard */
.dashboard {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

/* Which export is on screen */
.data-source {
    margin-bottom: 15px;
    color: #898781;
    font-size: 0.9rem;
}

.data-source a {
    color: #667eea;
}

.data-source[hidden] {
    display: none;
}

/* Data quality notice */
.data-notice {
    margin-bottom: 20px;
    padding: 12px 16px;
    border-radius: 8px;
    background: #fff8e6;
    border-left: 3px solid #eda100;
    color: #52514e;
    font-size: 0.9rem;
}

.data-notice[hidden] {
    display: none;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 25px;
    border-bottom: 1px solid #e1e0d9;
}

.tab-button {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 12px 20px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: #898781;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.tab-button:hover {
    color: #52514e;
}

.tab-button.is-active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.tab-panel[hidden] {
    display: none;
}

.tab-empty {
    padding: 60px 20px;
    text-align: center;
    color: #52514e;
    line-height: 1.8;
}

/* KPI tiles */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 35px;
}

.kpi-tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 20px 22px;
    background: #f8f9fa;
    border-radius: 12px;
    border-left: 3px solid #667eea;
}

.kpi-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #898781;
}

.kpi-value {
    font-size: 2.1rem;
    font-weight: 700;
    line-height: 1.2;
    color: #0b0b0b;
}

.kpi-note {
    font-size: 0.85rem;
    color: #52514e;
    min-height: 1.2em;
}

/* Stats Table */
.stats-table-container {
    margin-bottom: 40px;
    overflow-x: auto;
}

.table-caption {
    caption-side: bottom;
    padding-top: 10px;
    font-size: 0.8rem;
    color: #898781;
    text-align: left;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    border-radius: 12px;
    overflow: hidden;
}

.stats-table thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.stats-table th {
    padding: 15px;
    text-align: left;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.9rem;
}

.stats-table tbody tr {
    border-bottom: 1px solid #eee;
    transition: background 0.2s ease;
}

.stats-table tbody tr:hover {
    background: #f8f9fa;
}

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

.stats-table td {
    padding: 15px;
    font-size: 1rem;
    font-weight: 600;
}

.stats-table .period-label {
    font-weight: 700;
    color: #667eea;
}

.stats-table tbody td:not(.period-label) {
    text-align: left;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 30px;
}

.chart-container {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    min-height: 400px;
    position: relative;
}

.chart-container.full-width {
    grid-column: 1 / -1;
}

.chart-container h3 {
    margin-bottom: 20px;
    color: #333;
    font-size: 1.2rem;
    text-align: center;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.chart-subtitle {
    margin-top: -14px;
    margin-bottom: 18px;
    text-align: center;
    font-size: 0.85rem;
    color: #898781;
}

/* Previous/Next pager above a paged chart */
.chart-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.chart-nav .chart-range {
    font-size: 1rem;
    min-width: 190px;
}

/* Sub-tabs (milestone style switch) */
.subtabs {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 18px;
}

.subtab-button {
    background: white;
    border: 1px solid #e1e0d9;
    border-radius: 999px;
    padding: 7px 18px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: #898781;
    cursor: pointer;
    transition: all 0.2s ease;
}

.subtab-button:hover {
    color: #52514e;
    border-color: #c3c2b7;
}

.subtab-button.is-active {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

.chart-empty {
    padding: 40px 20px;
    text-align: center;
    color: #898781;
    font-size: 0.95rem;
}

/* Milestones / data tables */
.milestones-container {
    margin-top: 40px;
    background: #f8f9fa;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.milestones-container h3 {
    margin-bottom: 20px;
    color: #333;
    font-size: 1.2rem;
    text-align: center;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.table-scroll {
    max-height: 420px;
    overflow-y: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
}

.data-table th {
    position: sticky;
    top: 0;
    background: #667eea;
    color: white;
    padding: 12px 15px;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.data-table td {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    font-size: 0.95rem;
}

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

.data-table tbody tr:hover {
    background: #f8f9fa;
}

.data-table a {
    color: #667eea;
    text-decoration: none;
}

.data-table a:hover {
    text-decoration: underline;
}

.data-table .grade-cell {
    font-weight: 700;
    color: #667eea;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.data-table .capitalize {
    text-transform: capitalize;
}


/* Heatmap */
.heatmap-year-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.heatmap-nav-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.heatmap-nav-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.heatmap-nav-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.5;
}

.heatmap-year-display {
    font-size: 1.3rem;
    font-weight: bold;
    color: #667eea;
    min-width: 80px;
    text-align: center;
}

.heatmap-display {
    margin-bottom: 20px;
}

/* Grid and month labels are one content-width block, centred as a unit. It
   scrolls rather than being clipped when the year is wider than the card. */
.heatmap-calendar {
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    overflow-x: auto;
}

.heatmap-wrapper {
    display: flex;
    gap: 5px;
    padding: 10px 0;
}

.heatmap-grid {
    display: flex;
    gap: 2px;
}

.heatmap-day-labels {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-right: 10px;
    font-size: 0.7rem;
    color: #666;
    padding-top: 0;
}

.heatmap-day-labels div {
    height: 12px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 5px;
}

.heatmap-week {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.heatmap-day {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background: #ebedf0;
    transition: all 0.2s ease;
}

.heatmap-day:hover {
    transform: scale(1.2);
    z-index: 10;
    position: relative;
}

/* Single-hue sequential ramp, light -> dark (see VIZ.ramp in js/utils.js) */
.heatmap-day.level-1 { background: #9ec5f4; }
.heatmap-day.level-2 { background: #5598e7; }
.heatmap-day.level-3 { background: #256abf; }
.heatmap-day.level-4 { background: #104281; }
.heatmap-day.outside-year { background: transparent; }

.heatmap-summary {
    margin-top: 12px;
    text-align: center;
    font-size: 0.85rem;
    color: #52514e;
}

.heatmap-month-labels {
    display: flex;
    gap: 2px;
    margin-left: 55px;
    font-size: 0.7rem;
    color: #666;
    margin-top: 5px;
}

.heatmap-month-label {
    width: 12px;
    text-align: left;
    font-weight: bold;
}

.heatmap-legend {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    font-size: 0.8rem;
    color: #666;
}

.heatmap-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Loading */
.loading {
    text-align: center;
    color: white;
    padding: 40px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

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

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

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .chart-container {
        padding: 15px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-value {
        font-size: 2rem;
    }

    .heatmap {
        grid-template-columns: repeat(53, 10px);
    }

    .heatmap-day {
        width: 10px;
        height: 10px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .upload-area {
        padding: 40px 15px;
    }

    .upload-icon {
        width: 48px;
        height: 48px;
    }
}

/* Chart specific styles */
canvas {
    max-width: 100%;
    height: auto;
}

/* Tooltip styles */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.tooltip.show {
    opacity: 1;
}