/*
 * findkolonihave-statistik
 *
 * Colour is organised as two separate things, and keeping them apart is what stops
 * the charts from turning into a brand swatch:
 *
 *  - Brand colours dress the interface. The green from findkolonihave.dk, its dark
 *    green and its light mist appear on the header, the buttons and the focus rings,
 *    so the dashboard reads as part of the same site.
 *  - Chart colours are a separate, validated set. #72A656 only reaches 2.88:1 on
 *    white, so it is not safe as a mark; the series green is a slightly deeper step
 *    of the same hue. The brand orange is never a series colour at all: orange
 *    against green is the classic red-green confusion pair and measured ΔE 5.2 under
 *    simulated deuteranopia, well under the 8 target.
 *
 * Every chart value below was produced by the palette validator rather than chosen
 * by eye. Categorical is two slots because these charts never need more than two
 * (for sale against sold); both clear every check on all pairs in both modes. The
 * magnitude ramp is one hue, light to dark, which is the safe default for the
 * distributions and rankings that make up most of this dashboard.
 */

:root {
    color-scheme: light;

    /* Brand, from the Elementor kit on findkolonihave.dk. Interface only. */
    --brand-green: #72a656;
    --brand-green-dark: #456a4c;
    --brand-mist: #ecf2f3;
    --brand-ink: #0f172a;
    --brand-accent: #f04e23;

    /* Surfaces and ink. */
    --surface-page: #f6f8f7;
    --surface-1: #ffffff;
    --surface-2: #f2f5f3;
    --border: #dfe5e1;
    --border-strong: #c6d0c8;
    --text-primary: #0f172a;
    --text-secondary: #4a5568;
    --text-muted: #6b7280;

    /* Chart marks. Categorical: 2 slots, validated all-pairs on white.
       worst pair ΔE 25.0 CVD / 25.6 normal vision, both >= 3:1 contrast. */
    --series-1: #5f9440;
    --series-2: #2a78d6;
    /* A third slot exists but sits in the 6-8 CVD warn band, so it is legal only
       with direct labels. Nothing currently uses it. */
    --series-3: #c4416b;

    /* Magnitude ramp: one hue, light to dark. Validated as an ordinal ramp,
       lightest step 2.18:1 against white. */
    --seq-1: #8dbd72;
    --seq-2: #6fa352;
    --seq-3: #578b3c;
    --seq-4: #416f2c;
    --seq-5: #2d521e;

    --grid: #e8ece9;
    --axis: #b8c2ba;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 1px 3px rgb(15 23 42 / 4%);
    --gutter: 16px;
    --max-width: 1240px;
}

/* Dark mode is stepped for the dark surface and validated against it, not an
   automatic inversion of the light values. The media query follows the OS; the
   data-theme scope below follows the toggle and has to win either way. */
@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;
        --surface-page: #0e1319;
        --surface-1: #151b23;
        --surface-2: #1c232c;
        --border: #2a323d;
        --border-strong: #3a4450;
        --text-primary: #f2f5f7;
        --text-secondary: #b3bdc9;
        --text-muted: #8d97a3;
        --series-1: #5f9440;
        --series-2: #3987e5;
        --series-3: #d55181;
        --seq-1: #416f2c;
        --seq-2: #578b3c;
        --seq-3: #6fa352;
        --seq-4: #8dbd72;
        --seq-5: #a8ce92;
        --grid: #232b35;
        --axis: #3d4854;
        --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --surface-page: #0e1319;
    --surface-1: #151b23;
    --surface-2: #1c232c;
    --border: #2a323d;
    --border-strong: #3a4450;
    --text-primary: #f2f5f7;
    --text-secondary: #b3bdc9;
    --text-muted: #8d97a3;
    --series-1: #5f9440;
    --series-2: #3987e5;
    --series-3: #d55181;
    --seq-1: #416f2c;
    --seq-2: #578b3c;
    --seq-3: #6fa352;
    --seq-4: #8dbd72;
    --seq-5: #a8ce92;
    --grid: #232b35;
    --axis: #3d4854;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--surface-page);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
    margin: 0;
    line-height: 1.25;
    font-weight: 650;
    letter-spacing: -0.011em;
}

a {
    color: var(--brand-green-dark);
}

:focus-visible {
    outline: 2px solid var(--brand-green);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.shell {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

/* ---------------------------------------------------------------- header ---- */

.site-header {
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
}

.site-header__inner {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 68px;
    padding: 12px 0;
    flex-wrap: wrap;
}

.site-header__logo {
    display: block;
    padding: 6px 10px;
    border-radius: 8px;
}

.site-header__logo img {
    display: block;
    width: auto;
    height: 34px;
}

/* The wordmark is dark ink on transparency, so on a dark header it disappears and
   only the house icon survives. A light chip behind it keeps the brand colours
   intact, which recolouring the image with a filter would not: inverting turns the
   green house grey-blue. Replace this rule with a light logo variant if one exists. */
@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) .site-header__logo {
        background: #ffffff;
    }
}

:root[data-theme="dark"] .site-header__logo {
    background: #ffffff;
}

.site-header__title {
    font-size: 1.0625rem;
    color: var(--text-secondary);
    font-weight: 550;
    padding-left: 16px;
    border-left: 1px solid var(--border);
}

.site-header__actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font: inherit;
    font-size: 0.875rem;
    color: var(--text-secondary);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
}

.theme-toggle:hover {
    border-color: var(--border-strong);
    color: var(--text-primary);
}

/* ------------------------------------------------------------------ intro --- */

.intro {
    padding: 28px 0 4px;
}

.intro h1 {
    font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2rem);
}

.intro p {
    margin: 8px 0 0;
    max-width: 62ch;
    color: var(--text-secondary);
}

.freshness {
    margin-top: 10px;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* ----------------------------------------------------------------- filters -- */

/* One row above the charts, sticky, so a filter change is always visible as the
   cause of the numbers moving underneath it. */
.filters {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 20px 0 24px;
    padding: 12px 0;
    background: color-mix(in srgb, var(--surface-page) 92%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.filters__bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.filters__row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
}

/* The toggle only exists on narrow screens; on a desktop the panel is always open
   and the button would be a control that does nothing useful. */
.filters__toggle {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    min-height: 40px;
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 550;
    color: var(--text-primary);
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.filters__toggle:hover {
    border-color: var(--text-muted);
}

/* Says how many filters are set, so a collapsed panel never hides the fact that
   the numbers below are a subset. */
.filters__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.75rem;
    font-weight: 650;
    color: #ffffff;
    background: var(--brand-green-dark);
    border-radius: 999px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.field > label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.field select,
.field input[type="search"] {
    font: inherit;
    font-size: 0.9375rem;
    padding: 8px 10px;
    min-height: 40px;
    color: var(--text-primary);
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    max-width: 100%;
}

.field--grow {
    flex: 1 1 180px;
}

.filters__reset {
    font: inherit;
    font-size: 0.875rem;
    padding: 9px 14px;
    min-height: 40px;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.filters__reset:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.filters__count {
    flex-basis: 100%;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.filters__count strong {
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- stat tiles -- */

/* A single number is a stat tile, not a one-bar chart. */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.tile {
    padding: 16px 18px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.tile__label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.tile__value {
    margin-top: 4px;
    font-size: 1.875rem;
    font-weight: 660;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
}

.tile__note {
    margin-top: 2px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- sections --- */

.section {
    margin-bottom: 40px;
    scroll-margin-top: 90px;
}

.section__head {
    margin-bottom: 14px;
}

.section__head h2 {
    font-size: 1.25rem;
}

.section__head p {
    margin: 5px 0 0;
    max-width: 70ch;
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
}

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

/* ------------------------------------------------------------------ cards --- */

.card {
    display: flex;
    flex-direction: column;
    padding: 16px 18px 18px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 0;
}

.card__title {
    font-size: 0.9375rem;
    font-weight: 620;
}

.card__sub {
    margin-top: 3px;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.card__canvas {
    position: relative;
    margin-top: 14px;
    height: 280px;
}

.card__canvas--tall {
    height: 380px;
}

.card canvas {
    max-width: 100%;
}

/* Shown instead of a chart when a filter leaves too little data to be honest. */
.card__empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 20px;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-muted);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
}

/* ------------------------------------------------------------------ table --- */

/* Every chart has a table behind it. That is the accessibility fallback and also
   the honest way to show a long tail of foreninger. */
.card__toggle {
    align-self: flex-start;
    margin-top: 12px;
    padding: 5px 10px;
    font: inherit;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.card__toggle:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.data-table {
    margin-top: 12px;
    max-height: 320px;
    overflow: auto;
}

.data-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table th,
.data-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table th {
    position: sticky;
    top: 0;
    background: var(--surface-1);
    font-weight: 620;
    color: var(--text-secondary);
}

.data-table td.num,
.data-table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

[hidden] {
    display: none !important;
}

/* ------------------------------------------------------------------ notes --- */

.note {
    margin-top: 12px;
    padding: 10px 12px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    background: var(--surface-2);
    border-left: 3px solid var(--brand-green);
    border-radius: var(--radius-sm);
}

.coverage {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
    gap: 10px 20px;
    margin-top: 6px;
    font-size: 0.875rem;
}

.coverage__item {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.coverage__value {
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}

/* A bar behind the coverage percentage, same hue as the magnitude ramp. */
.meter {
    position: relative;
    height: 6px;
    margin-top: 6px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.meter__fill {
    position: absolute;
    inset: 0 auto 0 0;
    background: var(--seq-3);
    border-radius: 999px;
}

/* ----------------------------------------------------------------- footer --- */

.site-footer {
    margin-top: 8px;
    padding: 28px 0 40px;
    border-top: 1px solid var(--border);
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.site-footer p {
    margin: 0 0 8px;
    max-width: 78ch;
}

/* ---------------------------------------------------------------- loading --- */

.state {
    padding: 48px 0;
    text-align: center;
    color: var(--text-secondary);
}

.state__error {
    color: var(--brand-accent);
}

/* Below this width the six controls filled most of the viewport, so the panel
   collapses behind the toggle and the result count stays visible on its own. */
@media (max-width: 760px) {
    .filters__toggle {
        display: inline-flex;
    }

    .filters__panel {
        display: none;
        padding-top: 12px;
    }

    .filters__panel.is-open {
        display: block;
        /* Capped so an open panel cannot itself become the whole screen. */
        max-height: 60vh;
        overflow-y: auto;
    }

    .filters__row .field {
        flex: 1 1 100%;
    }

    .filters__reset {
        width: 100%;
    }

    .filters__count {
        flex-basis: auto;
        margin: 0;
    }
}

@media (max-width: 600px) {
    /* Logo, label and toggle on one line. nowrap rather than relying on the parts
       happening to fit: at 390px the row is about 280px wide, so there is room, but
       a longer toggle label should shrink the row rather than break it. */
    .site-header__inner {
        flex-wrap: nowrap;
        gap: 10px;
        min-height: 0;
        padding: 10px 10px;
    }

    .site-header__logo {
        padding: 5px 8px;
        flex-shrink: 0;
    }

    .site-header__logo img {
        height: 26px;
    }

    /* The label is the only part that may shrink. min-width: 0 is required for that:
       a flex item defaults to min-width: auto and so refuses to go below its content
       width, which is what pushed the toggle off the right edge entirely. */
    .site-header__title {
        padding-left: 10px;
        font-size: 0.9375rem;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .site-header__actions {
        flex-shrink: 0;
    }

    .theme-toggle {
        padding: 6px 10px;
        font-size: 0.8125rem;
        white-space: nowrap;
    }

    .card__canvas {
        height: 240px;
    }

    .field--grow {
        flex-basis: 100%;
    }
    #filters > .shell {
        padding: 0px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
