/* ===========================
   Tokens
   Metric colors match the chart lines in index.js
   =========================== */

:root {
    color-scheme: light;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e4e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --track: #e5e9f0;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 6px 20px rgba(15, 23, 42, 0.06);

    --up: #15803d;
    --up-bg: #dcfce7;
    --down: #b91c1c;
    --down-bg: #fee2e2;
    --flat: #64748b;
    --flat-bg: #eef1f6;

    --head-bg: #1e293b;
    --head-text: #f8fafc;
    --latest-bg: rgba(37, 99, 235, 0.07);
    --hover-bg: rgba(15, 23, 42, 0.04);
    --focus: #2563eb;

    --lines: #198754;
    --statements: #0d6efd;
    --functions: #fd7e14;
    --branches: #dc3545;

    --radius: 14px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body.dark {
    color-scheme: dark;

    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #182339;
    --border: #25324a;
    --text: #f1f5f9;
    --muted: #9aa8bd;
    --track: #25324a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);

    --up: #4ade80;
    --up-bg: rgba(74, 222, 128, 0.14);
    --down: #f87171;
    --down-bg: rgba(248, 113, 113, 0.16);
    --flat: #9aa8bd;
    --flat-bg: #25324a;

    --head-bg: #0f1829;
    --head-text: #e2e8f0;
    --latest-bg: rgba(96, 165, 250, 0.1);
    --hover-bg: rgba(255, 255, 255, 0.04);
    --focus: #60a5fa;
}

/* ===========================
   Base
   =========================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition:
        background 0.3s ease,
        color 0.3s ease;
}

h1,
h2,
p {
    margin: 0;
}

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

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

/* ===========================
   Header
   =========================== */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.topbar h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.subtitle {
    color: var(--muted);
    font-size: 14px;
}

.btn-theme {
    flex-shrink: 0;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    transition:
        background 0.2s ease,
        border-color 0.2s ease;
}

.btn-theme:hover {
    background: var(--surface-2);
    border-color: var(--muted);
}

/* ===========================
   Cards
   =========================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition:
        background 0.3s ease,
        border-color 0.3s ease;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.metric-card {
    position: relative;
    padding: 20px 20px 18px;
    overflow: hidden;
    --accent: var(--text);
}

.metric-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--accent);
}

.metric-lines {
    --accent: var(--lines);
}

.metric-statements {
    --accent: var(--statements);
}

.metric-functions {
    --accent: var(--functions);
}

.metric-branches {
    --accent: var(--branches);
}

.metric-title,
.insight-title {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.metric-title {
    margin-bottom: 8px;
}

.metric-value {
    font-size: 40px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.metric-delta {
    margin-top: 8px;
    font-size: 14px;
    font-weight: 600;
}

.metric-small {
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.progress {
    height: 6px;
    margin-top: 14px;
    border-radius: 999px;
    background: var(--track);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: inherit;
    background: var(--accent, var(--text));
    transition: width 0.8s ease;
}

.insights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.insight-card {
    padding: 16px 20px;
}

.insight-value {
    margin-top: 4px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}

/* ===========================
   Delta indicators (shared by cards and table)
   =========================== */

.up {
    color: var(--up);
}

.down {
    color: var(--down);
}

.badge-up,
.badge-down,
.badge-neutral {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.badge-up {
    background: var(--up-bg);
    color: var(--up);
}

.badge-down {
    background: var(--down-bg);
    color: var(--down);
}

.badge-neutral {
    background: var(--flat-bg);
    color: var(--flat);
}

/* ===========================
   Chart
   =========================== */

.chart-card,
.table-card {
    padding: 20px;
    margin-bottom: 16px;
}

.section-title {
    margin-bottom: 14px;
    font-size: 16px;
    font-weight: 600;
}

.chart-wrap {
    position: relative;
    height: 380px;
}

/* ===========================
   Table
   =========================== */

.table-scroll {
    max-height: 70vh;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-variant-numeric: tabular-nums;
}

.table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 12px 14px;
    background: var(--head-bg);
    color: var(--head-text);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-align: left;
    white-space: nowrap;
    border-top: 3px solid var(--head-accent, transparent);
}

.col-lines {
    --head-accent: var(--lines);
}

.col-statements {
    --head-accent: var(--statements);
}

.col-functions {
    --head-accent: var(--functions);
}

.col-branches {
    --head-accent: var(--branches);
}

.col-date {
    min-width: 130px;
}

.table tbody td {
    padding: 12px 14px;
    vertical-align: top;
    border-top: 1px solid var(--border);
}

.table tbody tr:first-child td {
    border-top: 0;
}

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

/* newest report is the first row */
.table tbody tr:first-child {
    background: var(--latest-bg);
}

.row-date {
    font-weight: 700;
    white-space: nowrap;
}

.row-meta {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.coverage-cell {
    min-width: 170px;
    --accent: var(--text);
}

.coverage-cell.metric-lines {
    --accent: var(--lines);
}

.coverage-cell.metric-statements {
    --accent: var(--statements);
}

.coverage-cell.metric-functions {
    --accent: var(--functions);
}

.coverage-cell.metric-branches {
    --accent: var(--branches);
}

.coverage-percent {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
}

.coverage-delta {
    margin: 2px 0 4px;
    font-size: 13px;
    font-weight: 600;
}

.coverage-total {
    color: var(--muted);
    font-size: 13px;
}

.coverage-cell .badge-row {
    margin-top: 6px;
}

.coverage-cell .progress {
    height: 5px;
    margin-top: 8px;
}

/* ===========================
   Error banner (history.json failed to load)
   =========================== */

.alert-error {
    margin: 16px 20px 0;
    padding: 12px 16px;
    border: 1px solid var(--down);
    border-radius: 10px;
    background: var(--down-bg);
    color: var(--down);
    font-weight: 600;
}

/* ===========================
   Scrollbars
   =========================== */

::-webkit-scrollbar {
    height: 10px;
    width: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--muted);
    border-radius: 999px;
}

/* ===========================
   Responsive and motion
   =========================== */

@media (max-width: 640px) {
    .container {
        padding: 16px 12px 32px;
    }

    .topbar h1 {
        font-size: 21px;
    }

    .metric-value {
        font-size: 32px;
    }

    .insight-value {
        font-size: 20px;
    }

    .chart-card,
    .table-card {
        padding: 14px;
    }

    .chart-wrap {
        height: 280px;
    }

    .coverage-cell {
        min-width: 140px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}
