/*
Copyright: (c) 2026 Jörn Menne
Licensed under the Apache License, Version 2.0
See NOTICE file for details.
*/

/* Tab switch between chart and tables, styled like the buttons on the other pages */
/* Page title: visible here, since the stats page has no map above it */
h1 {
    margin: 1.5rem 0 0;
    padding: 1rem 0;
    font-size: 1.75rem;
}

[role="tablist"] {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    padding: 0.75rem;

    [role="tab"] {
        min-height: 2.75rem;
        padding: 0.5rem 1.25rem;

        font: inherit;
        font-weight: bold;
        color: var(--color-txt);
        background-color: #fff;
        border: 2px solid var(--field-border);
        border-radius: var(--border-radius);
        cursor: pointer;

        transition: background-color var(--dur), box-shadow var(--dur), translate var(--dur);

        /* Only on devices with a real pointer, so taps don't leave a stuck hover */
        @media (hover: hover) {
            &:hover {
                background-color: #f4f4f4;
                box-shadow: 1px 3px 6px var(--color-shadow);
            }
        }

        /* Lift on hover only without reduced motion; the shadow and colour change stay */
        @media (hover: hover) and (prefers-reduced-motion: no-preference) {
            &:hover {
                translate: 0 -2px;
            }
        }

        &[aria-selected="true"] {
            color: var(--color-header-txt);
            background-color: var(--dark-blue);
            border-color: var(--dark-blue);
        }

        /* The default ring is --dark-blue, invisible next to the selected tab's own background */
        &:focus-visible {
            outline: 3px solid var(--dark-blue);
            outline-offset: 3px;
        }
    }
}

[role="tabpanel"][hidden], 
[role="tablist"][hidden]{
    display: none;
}

/* Tab switch: the new panel fades in, and with motion allowed it also slides up slightly.
   Under reduced motion base-style.css sets --dur to 0s, so the switch is instant. */
[role="tabpanel"]:not([hidden]) {
    animation: panel-fade var(--dur) ease-out;
}

@media (prefers-reduced-motion: no-preference) {
    [role="tabpanel"]:not([hidden]) {
        animation-name: panel-slide;
    }
}

@keyframes panel-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes panel-slide {
    from {
        opacity: 0;
        transform: translateY(0.5rem);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* Dashboard: headline figure above two chart cards, side by side on wide screens */
#chart-panel {
    display: grid;
    gap: 1rem;
    max-width: 80rem;
    margin-inline: auto;
    padding: 0 0.75rem 1.5rem;

    &[hidden] {
        display: none;
    }
}

.total-row {
    display: flex;
    justify-content: center;
}

.total {
    display: grid;
    justify-items: center;
    padding: 1rem 2rem;

    background-color: #fff;
    border-radius: var(--border-radius);
    border-left: 10px solid var(--dark-blue);
    box-shadow: 1px 1px 3px 1px var(--color-shadow);
}

.total-value {
    font-size: 2.5rem;
    font-weight: bold;
    line-height: 1.1;
}

.total-label {
    font-weight: bold;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    align-items: start;

    @media (min-width: 1100px) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.card {
    /* min-width keeps the grid cell from growing with the wide chart; the chart scrolls instead */
    min-width: 0;
    padding: 1rem;

    background-color: #fff;
    border-radius: var(--border-radius);
    box-shadow: 1px 1px 3px 1px var(--color-shadow);

    h2 {
        margin: 0.25rem 0 0.5rem;
        font-size: 1.1rem;
    }
}

/* Chart: centred, scrolls sideways on narrow screens instead of pushing the page wider.
   "safe center" keeps the left edge reachable when the chart is wider than its box. */
#sunburst,
#status-pie {
    display: flex;
    justify-content: safe center;
    max-width: 100%;
    overflow-x: auto;
    padding: 1rem 0.75rem;
}

/* Tables: one column on phones, the two tables side by side from tablet width on */
#table-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 1.5rem;
    align-items: start;
    max-width: 60rem;
    margin-inline: auto;
    padding: 0 0.75rem 1.5rem;

    /* Keeps the panel hidden on the chart tab; the display set above would otherwise override the hidden attribute */
    &[hidden] {
        display: none;
    }

    h2 {
        margin: 1.5rem 0 0.5rem;
        font-size: 1.1rem;
    }

    @media (min-width: 600px) {
        grid-template-columns: 1fr 1fr;

        /* Headline figure spans both columns; each table block takes one column, in source order */
        > .total-row {
            grid-column: 1 / -1;
        }
    }

    /* Heading and table stay together, so the visual order matches the source order */
    .table-block {
        min-width: 0;
    }

    table {
        width: 100%;
        margin-bottom: 1rem;

        background-color: #fff;
        border-collapse: collapse;
        border-radius: var(--border-radius);
        box-shadow: 1px 1px 3px 1px var(--color-shadow);
        overflow: hidden;
    }

    th,
    td {
        padding: 0.6rem 0.75rem;
        text-align: left;
        border-bottom: 1px solid var(--gray);
    }

    th {
        font-weight: bold;
        color: var(--color-header-txt);
        background-color: var(--color-header-bg);
    }

    /* Row headers (category / status names) look like normal cells, not like the column header */
    th[scope="row"] {
        font-weight: normal;
        color: inherit;
        background-color: transparent;
    }

    /* Counts are right-aligned so the digits line up */
    th:last-child,
    td:last-child {
        text-align: right;
        font-variant-numeric: tabular-nums;
    }

    /* Category tree: each level is indented, top-level categories are bold */
    .level-0 th[scope="row"] {
        font-weight: bold;
    }

    .level-1 th[scope="row"] {
        padding-left: 2rem;
    }

    .level-2 th[scope="row"] {
        padding-left: 3.5rem;
    }

    .level-3 th[scope="row"] {
        padding-left: 5rem;
    }

    tbody tr:nth-child(even) {
        background-color: #f5f5f5;
    }

    tbody tr:hover {
        background-color: #fffbf0;
    }

    tr:last-child td {
        border-bottom: 0;
    }
}
