/* ==========================================================================
   Internal UI — shell, layout and shared components.

   Hand-written, no framework: the screens are dense tables and forms, and a
   utility framework would be more bytes than the whole stylesheet. Custom
   properties carry the palette so a later dark theme is a variable swap
   rather than a rewrite.

   Naming: block__element--modifier, prefixed where a name could collide with
   a Vue island's own classes (C7, C10). There are no scoped styles without a
   build step, so the convention is the whole discipline.

   Everything in this file is generic — reused across two or more domains, or
   part of the page shell itself. A domain's own screens (measurement,
   consumption, tasks, switch, the week-calendar grid) have their own file
   under this same directory, loaded alongside this one; see `base.html`.

   File structure (search for the header, in order):
     1. Fonts + tokens
     2. Base / reset
     3. Utilities (u-*)
     4. App shell (layout, sidebar, topbar, main)
     5. Shared components (badges, buttons, forms, tables, panels, etc.)

   Z-INDEX SCALE — every stacking value in this file, low to high. Add new
   fixed/absolute elements to this list instead of picking an arbitrary
   number; two unrelated elements fighting over "big enough to definitely
   be on top" is how stacking bugs happen.
     10   in-page dropdowns (.nav-user__dropdown)
     40   fixed bar behind the topbar content (.topbar::before)
     50   fixed topbar content (.breadcrumbs, .options, .sidebar-toggle-label,
          .options-menu__trigger and its mobile dropdown)
     90   mobile sidebar backdrop
     100  mobile sidebar itself (must beat the backdrop and the topbar)
     200  htmx progress bar (always the top-most thing on the page)
   ========================================================================== */

/* Fonts are self-hosted — vendor/fonts/fonts.css, linked from base.html's
   <head>, not @import'd here. @import (even of a local file) still blocks
   on this file parsing first; a <link> lets the browser's preload scanner
   fetch it in parallel with this file instead. */

/* ==========================================================================
   1. Tokens
   ========================================================================== */

:root[data-theme="light"] {
    color-scheme: light;
}
:root[data-theme="dark"] {
    color-scheme: dark;
}

:root {
    /* color */
    /* Theme: follows the OS; theme.js pins it with data-theme="light|dark" on <html>.
       Every colour that differs between themes is one light-dark(light, dark) value. */
    color-scheme: light dark;
    --bg: light-dark(#f6f7f9, #0f1115);
    --surface: light-dark(#ffffff, #171a21);
    --surface-subtle: light-dark(#f9fafb, #1c2029);
    --border: light-dark(#e4e7ec, #2a2f3a);
    /* the edge of an input, select or textarea: 3:1 on the page and the card (WCAG 1.4.11),
       which `--border` (1.2:1) is not — that one only separates areas. The lightest shades
       that still make 3:1 on every background (`--bg` in light, `--surface-subtle` in dark):
       any lighter fails `test_colour_contrast.py`. */
    --border-control: light-dark(#89909b, #636b7b);
    /* hovered outline of a button-like control: a step darker than `--border`, not `--muted` */
    --border-hover: color-mix(in srgb, var(--border) 60%, var(--muted));
    --text: light-dark(#0b0b0d, #e7e9ee);
    --heading: light-dark(#011c27, #f2f4f8);
    --secondary: light-dark(#555a64, #b0b7c4);
    --muted: light-dark(#666d79, #8b93a3); /* 4.5:1 even on `--tint-neutral` pills */
    /* solid status fills keep one value in both themes so white badge text stays readable */
    --info: #0776a2;
    --accent: #fec502;
    /* What marks a selected state drawn in the accent — the active tab's underline, the
       active nav link's bar, a ticked filter tag's and a pressed button's border, today's
       cell. The yellow is 1.6:1 on white, so the light theme draws it dark gold (5.3:1,
       WCAG 1.4.11); the dark theme keeps the yellow. The fills stay `--accent`. */
    --accent-edge: light-dark(#946008, #fec502);
    /* 5.3:1 under white badge text (`badge--warning`); was #b3730b, 3.9:1, below AA. One
       value in both themes, like the other fills, so it is too dark for text on the dark
       surface: text in the warning colour is `--warning-text`, which follows the theme.
       That darker light value is the amber clients/templates/clients/_document_styles.html's
       `.kind--changed` already uses. `test_colour_contrast.py` holds both to AA. */
    --warning: #946008;
    --warning-text: light-dark(#8a5000, #f0b455);
    --critical: #c42741;
    --ok: #567b2d;
    /* Text in those two colours. The fills keep one value under white text, which on the
       dark surface is 3.1:1 (critical) and 3.5:1 (ok) — too little for an error message. */
    --critical-text: light-dark(#c42741, #ff7b8e);
    --ok-text: light-dark(#567b2d, #8fc25a);
    --link: light-dark(#045676, #6cc1e6);

    /* pale fills for hover/active rows and status pills */
    --tint-hover: light-dark(#f3f4f7, #1f232d);
    --tint-active: light-dark(#ffefbc, #4a3e12);
    --tint-drop: light-dark(#fff9e3, #2d2810);
    --tint-warn: light-dark(#fff4e0, #3a2d12);
    --tint-ok: light-dark(#e6f4ea, #1c2f1b);
    --tint-neutral: light-dark(#f2f2f2, #252a35);
    --tint-crit: light-dark(#fdecea, #3a1a20);
    --tint-info: light-dark(#e3f1f8, #15303c);
    --on-accent: #0b0b0d;

    /* shape */
    --radius: 6px;
    --shadow-color: light-dark(rgba(16, 24, 40, 0.08), rgba(0, 0, 0, 0.5));
    --shadow-sm: 0 1px 2px var(--shadow-color);
    --shadow-md: 0 1px 2px var(--shadow-color), 0 4px 12px var(--shadow-color);
    /* Every keyboard focus is one 2px outline in this colour (`:focus-visible` below): dark
       blue on the light theme, where the yellow accent is 1.6:1 on white, yellow on the
       dark. 3:1 or more on every background (WCAG 1.4.11; `test_colour_contrast.py`). */
    --focus: light-dark(#045676, #fec502);

    /* spacing scale — also exposed as .u-gap-* utilities below */
    --gap-xs: 4px; /* inside a form field: label, control, help, error */
    --gap-sm: 16px;
    --gap-md: 32px;
    --gap-lg: 64px;
    --gap: var(--gap-sm); /* legacy alias, still used by a few components */

    /* type */
    --font: "IBM Plex Sans", system-ui, sans-serif;
    --heading-font: "Montserrat", system-ui, sans-serif;
    --data-font: "IBM Plex Mono", monospace;

    /* layout */
    --sidebar-width: 270px;
    /* Was 1000px — on anything 1440px or wider (most desktop monitors now) that
       left a large dead gap on both sides of every page's content, in a tool
       that's mostly dense tables. Still capped, not 100%: an uncapped form or
       settings panel on an ultrawide monitor is its own readability problem. */
    --content-max-width: 1440px;
    --topbar-height: 125px;
    --topbar-bar-height: 56px; /* rendered height of the fixed breadcrumbs/options row */
    --topbar-bar-top: 6px; /* centres the 44px options row in that bar */
}

/* ==========================================================================
   2. Base / reset
   ========================================================================== */

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

body {
    font-family: var(--font);
    font-size: 16px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--heading);
    font-family: var(--heading-font);
}
h1 {
    font-size: 28px;
    letter-spacing: -0.015em;
    font-weight: 700;
}
/* A section heading sits under the page's tabs: it must not outweigh them or the title. */
h2 {
    font-size: 18px;
    letter-spacing: -0.01em;
    font-weight: 700;
}
h3,
.heading--tile {
    font-size: 16px;
    letter-spacing: -0.005em;
    font-weight: 600;
}

a {
    color: var(--link);
}
/* Three lines tall whatever `rows` the widget sets; drag it taller for a long text. */
textarea {
    height: calc(3lh + 14px); /* + padding 6 + 6 and border 1 + 1 */
    resize: vertical;
    font-family: inherit;
}

/* Monochrome UI icons: the SVG is a mask over currentColor, so one file follows the
   text colour in both themes (an <img> keeps its baked-in fill). */
.icon {
    display: inline-block;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    background-color: currentColor;
    mask: center / contain no-repeat;
}
.icon--expand-all {
    mask-image: url("../icons/expand-all.svg");
}
.icon--sidebar-close {
    mask-image: url("../icons/sidebar-close.svg");
}
.icon--flip {
    transform: scaleX(-1);
}
/* Reopen button: only visible while the sidebar is collapsed on desktop */
.sidebar-open-btn {
    display: none;
}

@media (min-width: 768px) {
    html[data-sidebar-collapsed] .sidebar {
        display: none;
    }

    html[data-sidebar-collapsed] .layout {
        grid-template-columns: 1fr; /* remove if .layout is flexbox */
    }

    html[data-sidebar-collapsed] .sidebar-open-btn {
        display: inline-flex;
    }
}

/* Every <ul> defaults to no bullets/no default spacing — this is an app of
   nav lists, card grids, and timelines, not prose, so the browser's default
   list styling is never what's wanted. Prose content (e.g. rendered rich
   text) should opt back in explicitly rather than this being the default. */
ul {
    list-style: none;
}

/* Keyboard users must be able to skip the sidebar; it is 20-odd links on every page. */
.skip-link {
    position: absolute;
    left: -9999px;
}
.skip-link:focus {
    left: var(--gap-sm);
    top: var(--gap-sm);
    z-index: 100;
    background: var(--surface);
    padding: 8px 12px;
    border: 2px solid var(--focus);
}

/* The one focus indicator: controls do not replace it with a ring or a border of their own. */
:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}
/* After a page change `shell/announce.js` puts focus on its h1 (or <main>) for a screen
   reader to start from. A heading is not a control, and a ring around the title after every
   navigation would only be noise; the next Tab still goes on from there. */
#main:focus-visible,
#main h1[tabindex="-1"]:focus-visible {
    outline: none;
}

/* ==========================================================================
   3. Utilities (u-*)
   ========================================================================== */

.u-w-100 {
    width: 100%;
}
/* A side column next to a `.u-w-100` one: holds its width instead of shrinking to content. */
.u-w-40 {
    width: 40%;
    flex-shrink: 0;
}

.u-flex {
    display: flex;
}
.u-flex--column {
    flex-direction: column;
}
.u-flex--wrap {
    flex-wrap: wrap;
}
.u-flex--between {
    justify-content: space-between;
}
.u-flex--evenly {
    justify-content: space-evenly;
}
.u-flex--end {
    justify-content: flex-end;
}

.u-align--end {
    align-items: flex-end;
}

.u-align--start {
    align-items: flex-start;
}

.u-flex--center {
    align-items: center;
}
.u-flex--start {
    align-items: flex-start;
}

/* A stacked column, 32 apart; a u-gap-* class below overrides the distance. */
.u-stack {
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
}

.u-gap-16 {
    gap: var(--gap-sm);
}
.u-gap-32 {
    gap: var(--gap-md);
}
.u-gap-64 {
    gap: var(--gap-lg);
}
/* Side-by-side spacing for wrapping rows/grids: items stack 16 apart, sit 32 apart. */
.u-gap-16.u-column-gap-32 {
    column-gap: var(--gap-md);
}
/* The same for sections: 64 apart when they stack on a narrow screen, 32 side by side. */
.u-gap-64.u-column-gap-32 {
    column-gap: var(--gap-md);
}

/* --- spacing rule ----------------------------------------------------------------------
   One rule for every screen, so templates rarely need a gap class:
     64  between sections            — children of `main`, sections inside a tab panel
     32  inside a section            — title, divider, content (sections, fieldsets, tabs)
     16  inside content, stacked     — rows of a grid, list items, form field rows
     32  side by side, at any level  — grid columns, items in a wrapping row
   Forms follow it on their own (see "forms"), with 4 inside a field.
   A u-gap-* class still overrides it where a component genuinely needs something else. */
main section,
.tab-panel {
    flex-direction: column;
    gap: var(--gap-md);
}
main section:not(.tab-panel) {
    display: flex;
}
.tab-panel:has(> section) {
    gap: var(--gap-lg);
}
.u-grid:not([class*="u-gap-"]) {
    gap: var(--gap-sm) var(--gap-md);
}
/* A slot that is filled later (htmx polling) must not cost a gap while it is empty. */
.u-hide-when-empty:not(:has(*)) {
    display: none;
}
ul.plain:not([class*="u-gap-"]) {
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
}

.u-grid {
    display: grid;
}
.u-grid--cols-2 {
    grid-template-columns: repeat(2, 1fr);
}
.u-grid--cols-3 {
    grid-template-columns: repeat(3, 1fr);
}
.u-grid--cols-4 {
    grid-template-columns: repeat(4, 1fr);
}
.u-grid--cols-6 {
    grid-template-columns: repeat(6, 1fr);
}
.u-grid--cols-12 {
    grid-template-columns: repeat(12, 1fr);
}
.u-span-2 {
    grid-column: span 2;
}
.u-span-3 {
    grid-column: span 3;
}
.u-span-4 {
    grid-column: span 4;
}
.u-span-5 {
    grid-column: span 5;
}
.u-span-6 {
    grid-column: span 6;
}
.u-span-8 {
    grid-column: span 8;
}
.u-span-9 {
    grid-column: span 9;
}
.u-span-10 {
    grid-column: span 10;
}
.u-span-12 {
    grid-column: span 12;
}

/* Visual weight only, matching headings and card titles. For emphasis that
   means something ("this matters"), use <strong> instead. */
.u-bold {
    font-weight: 600;
}

/* Text alignment. start/end rather than left/right, like `.u-flex--end`. */
.u-text-start {
    text-align: start;
}
.u-text-center {
    text-align: center;
}
.u-text-end {
    text-align: end;
}

/* Value rendering: NULL and zero must never look the same — the measurement
   model treats them as different facts and the UI is the last place that
   distinction can be lost. */
.u-missing {
    color: var(--muted);
    font-style: italic;
}
.u-value {
    font-variant-numeric: tabular-nums;
}
/* A short value that reads wrong when split, e.g. a "from – to" period in a table cell. */
.u-nowrap {
    white-space: nowrap;
}
/* A table too wide for its card (an invoice's line items, every list from
   `partials/lists/_table.html`) scrolls inside it instead of spilling past its edge — what
   every table does at 1024 px and below. Above that, a table with long unbreakable values or
   nowrap cells has no other way to fit. */
.u-scroll-x {
    overflow-x: auto;
}
/* The same for every other data table: its parent scrolls, so a table wider than the card
   (a contract's PPEs with three row actions, between 1025 and ~1400 px) never widens the
   page — which would scroll the whole column sideways, under the fixed sidebar. Not a
   form: a search's results drop below the field and must not be clipped. */
:not(form, td):has(> table.data) {
    overflow-x: auto;
}
.u-yes {
    color: var(--ok-text);
}
.u-no {
    color: var(--critical-text);
}

.u-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.muted {
    color: var(--muted);
}
.divider {
    width: 100%;
    height: 1px;
    background-color: var(--border);
}

/* ==========================================================================
   4. App shell
   ========================================================================== */

.layout {
    display: flex;
    min-height: 100vh;
}

/* --- sidebar -------------------------------------------------------------- */

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: var(--gap-sm) 0 0;
    display: flex;
    flex-direction: column;

    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow: hidden; /* .nav-sections scrolls on its own below, so .nav-user stays pinned to
                          the visible bottom instead of the bottom of the scrolled content */
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* let .nav-sections shrink and scroll instead of overflowing the sidebar */
}
.sidebar ul {
    margin: 0;
    padding: 0;
}

.nav-sections {
    overflow-y: auto; /* if nav content ever gets taller than the viewport, this scrolls on
                          its own — .nav-user is a sibling, not a child, so it never scrolls
                          out of view with it */
    overflow-x: hidden; /* long usernames must truncate, never force a horizontal scrollbar */
    min-height: 0;
}

/* checkbox-hack mobile toggle: no JS needed to open/close the sidebar */
.sidebar-toggle-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0; /* the global `input` rule makes it 100% wide, which overflowed the page */
    height: 0;
}

/* hamburger button — hidden on desktop, shown only under the 768px breakpoint */
.sidebar-toggle-label {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 44px;
    height: 44px;
    padding: 13px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--surface);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    box-sizing: border-box;
}
.sidebar-toggle-label span {
    display: block;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
}

/* backdrop behind the open mobile sidebar; hidden entirely on desktop */
.sidebar-backdrop {
    display: none;
}

.brand {
    font-family: var(--heading-font);
    margin-bottom: var(--gap-md);
    padding: 0 24px; /* same inset as .nav-link */
}
.brand a {
    text-decoration: none;
    align-items: center;
    color: var(--heading);
}
.brand__logo {
    /* the SVG is a single black shape: used as a mask so it takes the text colour in either theme */
    flex-shrink: 0;
    width: 47px;
    height: 24px;
    margin-right: 12px;
    background-color: var(--heading);
    mask: url("../images/logo.svg") center / contain no-repeat;
}

.nav-section {
    margin-bottom: var(--gap-sm);
}
.nav-heading {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
    margin: 0 0 4px;
    padding: 0 var(--gap-sm);
}

.nav-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 24px;
    color: var(--text);
    text-decoration: none;
}
.nav-link:hover {
    background-color: var(--tint-hover);
}
.nav-link.is-active {
    font-weight: 600;
    border-left: 3px solid var(--accent-edge);
}
/* Pending screens stay visible but read as "not yet" rather than as a broken link. */
.nav-link.is-pending {
    color: var(--muted);
}

/* user menu, pinned to the bottom of the sidebar */
.nav-user {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding: 12px;
    gap: 4px;
    align-items: center;
    position: relative;
}
.nav-user__menu {
    flex: 1;
}
/* the user's initial, so the trigger reads as "you" and not as another nav link */
.nav-user__avatar {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--accent);
    color: var(--heading);
    font-size: 13px;
    font-weight: 700;
}
.nav-user__menu {
    gap: 4px;
    min-width: 0; /* let the trigger's long-username ellipsis kick in instead of overflowing the row */
}
.nav-user__action-btn,
.theme-toggle,
.sidebar-open-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    color: var(--secondary);
    background-color: transparent;
    border: transparent;
    border-radius: var(--radius);
    cursor: pointer;
}
.nav-user__action-btn:hover,
.theme-toggle:hover,
.sidebar-open-btn:hover {
    background-color: var(--tint-hover);
}
.nav-user__trigger {
    display: flex;
    gap: 8px;
    color: var(--text);
    background-color: transparent;
    padding: 4px 6px;
    border-radius: var(--radius);
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
/* Two lines, then an ellipsis. Breaks between words; only a word too long for the line
   (a first name on the narrow sidebar, an email login) is hyphenated or split. */
.nav-user__name {
    flex: 1;
    min-width: 0;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.25;
    hyphens: auto;
    hyphenate-limit-chars: 10 4 4;
    overflow-wrap: break-word;
}

.nav-user__trigger:hover {
    background-color: var(--tint-hover);
}
.nav-user__trigger .icon {
    display: none;
}
.nav-user__trigger::-webkit-details-marker {
    display: none;
}
.nav-user__trigger::marker {
    content: "";
}
.nav-user__dropdown {
    position: absolute;
    bottom: 110%;
    left: 2%;
    width: 90%;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 10; /* see z-index scale at top of file */
}
/* The running version, last in the user menu: small and quiet, under a rule. */
.nav-user__version {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.nav-user__version .nav-link {
    color: var(--muted);
    font-size: 0.85em;
}

/* Rendered Markdown (release notes): the opt-in back to prose the `ul` reset above
   asks for. Spacing follows the rule: 32 above a heading, 16 between blocks. */
.prose > * + * {
    margin-top: 16px;
}
.prose > :is(h2, h3) {
    margin-top: 32px;
}
.prose ul,
.prose ol {
    list-style: disc;
    padding-left: 24px;
}
.prose ol {
    list-style: decimal;
}
.prose table {
    border-collapse: collapse;
}
.prose :is(th, td) {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.link-button {
    background: none;
    border: none;
    /* `--accent` is a border/background color, not text — ~1.6:1 on white,
       far below WCAG AA. */
    color: var(--heading);
    cursor: pointer;
    padding: 0;
    font: inherit;
}
.link-button--full {
    display: flex;
    align-items: center;
    width: 100%;
    color: var(--text);
    text-decoration: none;
    background: none;
    border: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

/* file upload dropzone: one row, an input's height; the field's hint sits under it as
   `.form__help`, like any other field's */
.file-drop {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 4px 12px;
    border: 1px solid var(--border-control); /* the file input's edge: it is hidden inside */
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
}
.file-drop:hover,
.file-drop:has(input:focus-visible) {
    border-color: var(--accent);
    background: var(--tint-hover);
}
/* its input is hidden inside, so the drop zone shows the focus */
.file-drop:has(input:focus-visible) {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}
.file-drop.is-dragover {
    border-color: var(--accent);
    background: var(--tint-drop);
}
.file-drop input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.file-drop__icon {
    line-height: 1;
}
.file-drop__label {
    font-weight: 600;
    color: var(--heading);
}
.file-drop__filename {
    margin-left: auto;
    font-size: 13px;
    font-family: var(--data-font);
    color: var(--ok-text);
}

/* --- topbar + main content --------------------------------------------- */
/*
   The topbar image is decorative and scrolls normally with the page.
   The breadcrumbs pill, hamburger button, and page-options slot are fixed
   to the viewport independently of it, so they stay visible near the top
   of the screen no matter how far the page has scrolled. `main` carries
   top padding equal to the fixed bar's height so page content never
   starts underneath it.
*/
code {
    white-space: normal;
    overflow-wrap: anywhere;
}
.content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width); /* room for the fixed sidebar */
    /* Clears the fixed .breadcrumbs/.options bar for the whole column — #messages
       renders before main, and needs the same clearance main does. The 24 under the bar
       sits between the scale's 32 and 16 on purpose: 32 read as too loose here. */
    margin-top: calc(var(--topbar-bar-height) + 24px);
    /* keeps <main>'s border from butting up against the sidebar's own border */
    padding: 0 var(--gap-md);
}
.sidebar-open-btn {
    display: none;
}

@media (min-width: 800px) {
    html[data-sidebar-collapsed] .sidebar {
        display: none;
    }

    html[data-sidebar-collapsed] .content {
        margin-left: 0;
    }
    html[data-sidebar-collapsed] .topbar::before {
        left: 0;
    }

    html[data-sidebar-collapsed] main {
        max-width: 90%;
    }

    /* no sidebar to clear, and the card fills 90% of the column instead of all of it —
       the same `--card-inset` rule then keeps the breadcrumbs and options on its edges */
    html[data-sidebar-collapsed] .breadcrumbs,
    html[data-sidebar-collapsed] .options,
    html[data-sidebar-collapsed] .options-menu__trigger {
        --sidebar-width: 0px;
        --card-fill: 0.9;
        --card-max-width: 100%; /* `main` has no 1440 cap while collapsed: 90% of the column is all that limits it */
    }

    html[data-sidebar-collapsed] .sidebar-open-btn {
        display: inline-flex;
    }
}

.breadcrumbs__container {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* The bar behind the fixed breadcrumbs and options: without it the page scrolls through
   the trail instead of under it. Only as tall as the row itself, so it takes as little of
   the screen as it can, and its last quarter fades out so the content doesn't stop at a
   hard edge. */
.topbar::before {
    content: "";
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-bar-height);
    background: linear-gradient(to bottom, var(--bg) 75%, transparent);
    z-index: 40; /* see z-index scale at top of file */
}

.topbar {
    position: static;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background-size: cover;
    bottom: 0;
    background-position: center 60%;
    gap: var(--gap-sm);
    height: var(--topbar-height);
    width: 90%;
    margin: auto;
}

/* The fixed breadcrumbs and options start and end where the content card does: `.content`
   pads 32 on both sides, and `main` is centred once it hits its max width. `%` is the
   viewport's width here, as these are position: fixed. The options trigger takes the
   options' slot when they fold behind it, so it gets the same edge. */
.breadcrumbs,
.options,
.options-menu__trigger {
    --card-max-width: var(--content-max-width);
    --card-fill: 1; /* share of the column the card takes (0.9 with the sidebar collapsed) */
    --card-inset: calc(
        var(--gap-md) +
            (
                (100% - var(--sidebar-width) - 2 * var(--gap-md)) -
                    min(
                        var(--card-max-width),
                        (100% - var(--sidebar-width) - 2 * var(--gap-md)) *
                            var(--card-fill)
                    )
            ) /
            2
    );
}
.breadcrumbs {
    position: fixed;
    top: var(--topbar-bar-top);
    left: calc(var(--sidebar-width) + var(--card-inset));
    z-index: 50; /* see z-index scale at top of file */
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px; /* as tall as the options row, so the trail is centred against it */
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

.options {
    position: fixed;
    top: var(--topbar-bar-top);
    right: var(--card-inset);
    z-index: 50; /* see z-index scale at top of file */
}

/* options-menu: checkbox-hack, same mechanism as .sidebar-toggle-input — see the
   comment in base.html for why this isn't a <details>. On desktop .options always
   shows inline (the rule above) and the trigger stays hidden; only under the 768px
   breakpoint does the trigger appear and .options become a dropdown behind it. */
.options-toggle-input {
    /* fixed, not absolute: the topbar is the last thing in the document, so an absolutely
       positioned checkbox sits at the bottom of the page and focusing it (clicking the
       trigger) scrolled the whole page down to it */
    position: fixed;
    top: 0;
    left: 0;
    opacity: 0;
    pointer-events: none;
    width: 0; /* the global `input` rule makes it 100% wide, which overflowed the page */
    height: 0;
}
.options-menu__trigger {
    display: none;
    cursor: pointer;
}

/* Desktop overflow: options_menu.js sets html[data-options-collapsed] when the inline
   options would run into the breadcrumbs or off-screen; they then collapse behind the
   trigger just like on mobile (week_calendar.css), only anchored to the desktop slot.
   Never set under the mobile breakpoint, so this doesn't fight the mobile rules. */
html[data-options-collapsed] .options-toggle-input:not(:checked) ~ .options {
    display: none;
}
html[data-options-collapsed] .options-menu__trigger {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    position: fixed;
    top: var(--topbar-bar-top);
    right: var(--card-inset);
    z-index: 50; /* see z-index scale at top of file */
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--surface);
    box-sizing: border-box;
}
html[data-options-collapsed] .options-menu__trigger span {
    display: block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text);
}
html[data-options-collapsed] .options-toggle-input:checked ~ .options {
    position: fixed;
    top: calc(
        var(--topbar-bar-top) + 44px + 8px
    ); /* below the 44px trigger, plus a gap */
    right: var(--card-inset);
    left: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: max-content;
    max-width: min(360px, 80vw);
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    box-shadow: var(--shadow-md);
    z-index: 50; /* see z-index scale at top of file */
}
html[data-options-collapsed] .options .button {
    white-space: normal; /* long labels wrap inside the dropdown instead of widening it */
    text-align: left;
}

.user form {
    margin: 0;
}

main {
    padding: var(--gap-md);
    width: 100%;
    max-width: var(--content-max-width);
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--surface);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: var(--gap-lg);
}

.lede {
    color: var(--muted);
    max-width: 60ch;
    margin-top: 0;
}

/* --- submenu (tab bar under a page header) ------------------------------ */

.submenu {
    position: relative; /* contains the tabs' visually-hidden radios so they can't widen the page */
    border-bottom: 1px solid var(--border);
}
.submenu__list {
    display: flex;
    margin: 0;
    padding: 0;
}
.submenu__list .is-active {
    color: var(--heading);
    box-shadow: inset 0 -2px 0 var(--accent-edge);
}
/* Tabs are as wide as their label, left-aligned. The `<li>` is the flex item, so it is
   what shrinks (never scrolls) once the bar runs out of room. */
.submenu__list > li {
    flex: 0 1 auto;
    min-width: 0;
}
/* A squeezed tab's label first spills into its own padding, so a few pixels short costs
   nothing; `safe` keeps a label that no longer fits starting at its first letter, cut
   only at the end, instead of centred and losing letters at both ends. */
.submenu__link {
    color: var(--text);
    text-decoration: none;
    display: flex;
    cursor: pointer;
    justify-content: safe center;
    align-items: center;
    height: 44px;
    padding: 0 24px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* error marker next to a tab's label (`_section_tabs.html`): small, so it stays inside
   the tab */
.submenu__link .badge {
    margin-left: 8px;
    padding: 0 6px;
    font-size: 11px;
    line-height: 18px;
}
/* A step tab that saves the page's form before leaving (`_stepper.html`) is a button:
   same look as the link, none of the button chrome. */
button.submenu__link {
    width: 100%;
    border: 0;
    border-radius: 0;
    background: none;
    font: inherit;
    box-shadow: none;
}

/* --- htmx feedback ------------------------------------------------------- */

/* Every swap shows progress. Without it a slow query looks like a dead click, and
   people click again. */
.progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.2s ease;
    z-index: 200; /* see z-index scale at top of file — always the top-most layer */
}
.htmx-request .progress,
.progress.htmx-request {
    transform: scaleX(0.7);
}

/* --- messages ------------------------------------------------------------- */

/* Same box as <main> (width, centring), so a message lines up with the page edge. */
.messages {
    width: 100%;
    max-width: var(--content-max-width);
    margin: 0 auto;
}
/* Space before main, but only when there's actually a message to separate from
   it — an empty #messages (the common case) must not shift main down at all. */
.messages:has(.message) {
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
    margin-bottom: var(--gap-lg);
}
/* No margin of its own: a message sits in a stack, and the stack's gap is the spacing. */
.message {
    padding: 8px 12px;
    border-left: 3px solid var(--border);
}
/* tone colours: see "callouts" below */
/* a form's own error summary: the first thing to read after a failed save */
.form > .message--error {
    padding: 12px 16px;
    font-weight: 600;
}

/* lock-note: "this can't be changed here" banner (signed contract, used or archived price
   list), plus `--open` for "changes go to the open annex". Only for that — any other page-level
   callout is a .message. It belongs to the page heading: it sits in one
   `<div class="u-stack u-gap-16">` with the header, never on its own in `main`, where it would
   get the 64 section gap. The lock icon comes from here, not from the template. Same
   left-border convention as .message; capped width so the sentence doesn't run the whole
   width of the page. */
.lock-note {
    max-width: 70ch;
    margin: 0;
    padding: 12px 16px;
    border-left: 3px solid var(--border);
    line-height: 1.5;
}
.lock-note:not(.lock-note--open)::before {
    content: "🔒 ";
    content: "🔒 " / "";
}

/* ==========================================================================
   5. Shared components
   ========================================================================== */

/* --- radio-hack panel switching ------------------------------------------- */
/* Generic pattern: a hidden radio's checked state, read via :has(), toggles a
   sibling-or-descendant panel with a matching data-* attribute. Used by the
   client-mode picker (agreement_prepare) and by any local section-tabs group
   (e.g. contract_detail). Both instances below share this one mechanism —
   only the attribute they match on differs. */

.client-mode-panel,
.pricing-panel,
.price-mode-panel,
.period-price-panel,
.period-source,
.tab-panel {
    display: none;
}

/* pricing-panel / period-price-panel: each PPE row's own billing model and price
   (`ppe_row.html`, `period_row.html`) — one `.ppe-row` per PPE, each with its own
   `scenario_type`/`price_mode` radios, so every rule below is scoped to
   `.ppe-row:has(...)`, not the whole form. Matched on the radio's `name` by
   *suffix* (`[name$="-scenario_type"]`), not an exact name: each row's own input
   is formset-prefixed (`ppe-0-scenario_type`, `ppe-1-scenario_type`, …), and one
   rule this way covers every row without one copy per index. A period can change the
   model, so its panel follows `data-active-scenario` (`period_editor.js`), the model in
   force for that period. One line per model registered in billing
   (`billing/scenarios/`); a new model needs its line here and its panel in
   `ppe_row.html`/`period_row.html`. The per-tariff prices show only once a tariff fills
   their slot (`:has(> * > *)`), so an empty one costs no gap under the radios. */
.ppe-row:has(input[name$="-scenario_type"][value="fix_price"]:checked)
    .pricing-panel[data-scenario="fix_price"],
.ppe-period[data-active-scenario="fix_price"] .period-price-panel[data-scenario="fix_price"],
.ppe-period[data-active-scenario="fix_price"] .period-source,
.ppe-period[data-active-scenario="spot_price"] .period-price-panel[data-scenario="spot_price"],
.ppe-row:has(input[name$="-price_mode"][value="tariffs"]:checked)
    .price-mode-panel[data-mode="tariffs"]:has(> * > *) {
    display: block;
}
/* Per-tariff pricing already quotes every zone up front for this PPE
   (#tariff-prices-N), so the first period's own price fields are moot under it. A later
   period keeps them: it can keep those prices (blank), take a flat price, or name a
   tariff for new zone prices (`PeriodChainBuilder`).
   Only for fix_price: `price_mode` keeps its default ("tariffs") checked even once the
   PPE is on spot pricing, where it means nothing — without this scope it also hid the
   spot margin field. `[data-scenario]` (present on both panels) rather than the bare class: without
   it, this rule is *less* specific than the scenario rule above (that one also
   matches a `[data-scenario="..."]` attribute), so under the default
   "tariffs"+"fix_price" combination the scenario rule's `display: block` always
   won regardless of source order, and the panel never actually hid. */
.ppe-row:has(input[name$="-scenario_type"][value="fix_price"]:checked):has(
        input[name$="-price_mode"][value="tariffs"]:checked
    )
    .ppe-period:first-child
    .period-price-panel[data-scenario] {
    display: none;
}

/* client-mode-panel: matched on the radio's `value`, not a positional id —
   robust to Django re-ordering ClientMode.choices. `~=` so one panel can serve
   several modes (`data-mode="lead new"`). */
fieldset:has(input[name="client_mode"][value="existing"]:checked)
    .client-mode-panel[data-mode~="existing"],
fieldset:has(input[name="client_mode"][value="lead"]:checked)
    .client-mode-panel[data-mode~="lead"],
fieldset:has(input[name="client_mode"][value="new"]:checked)
    .client-mode-panel[data-mode~="new"] {
    display: block;
}

/* client-search: the agreement-prepare wizard's client combobox — a text input
   plus an htmx-filled dropdown of matches, standing in for a `<select>` that does
   not scale to every active client. */
.client-search,
.search-multi {
    position: relative;
}
.client-search__results,
.search-multi__results {
    position: absolute;
    z-index: 20;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 240px;
    overflow-y: auto;
}
.client-search__results:empty,
.search-multi__results:empty {
    display: none;
    border: none;
}
.client-search__option,
.search-multi__option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 8px;
    border: none;
    background: none;
    font: inherit;
    white-space: normal;
    cursor: pointer;
}
.client-search__option:hover,
.client-search__option:focus,
.search-multi__option:hover,
.search-multi__option:focus {
    background: var(--bg);
}
/* „Brak wyników.”: a row of the dropdown, inset like the options it stands in for. */
.client-search__results > .form__help,
.search-multi__results > .form__help {
    padding: 6px 8px;
    font-size: inherit;
}

/* search-multi: the .client-search combobox above, picking several: the picked ones sit
   above the input as removable chips. */
.search-multi__chips:not(:has(.search-multi__chip)) {
    display: none;
}
/* Two classes: `.badge` comes later in this file and would win a tie. */
.badge.search-multi__chip {
    display: inline-flex;
    gap: 8px;
    text-transform: none;
    letter-spacing: normal;
    /* `.badge` does not wrap: a long client name would push the page sideways on a phone. */
    white-space: normal;
    overflow-wrap: anywhere;
}
.search-multi__remove {
    flex: none;
    padding: 0;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

/* ppe-search: each PPE row's own number field, same combobox mechanics as
   .client-search above, plus a status badge for whether the typed number resolved
   to an existing PPE (fields filled) or a new one (fields left blank to edit). */
.ppe-search {
    position: relative;
}
.ppe-search__results {
    position: absolute;
    z-index: 20;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 240px;
    overflow-y: auto;
}
.ppe-search__results:empty {
    display: none;
    border: none;
}
.ppe-search__option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 8px;
    border: none;
    background: none;
    font: inherit;
    white-space: normal;
    cursor: pointer;
}
.ppe-search__option:hover,
.ppe-search__option:focus {
    background: var(--bg);
}
.ppe-search__status {
    margin-top: 4px;
}
.ppe-search__status:empty {
    display: none;
}

/* ppe-card: one saved PPE in the flow's PPE list — its summary on the left, actions on
   the right. */
.ppe-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 32px;
    width: 100%;
    max-width: 100%;
    padding: 16px;
    border: 1px solid var(--border, #e5e0d0);
    border-radius: 8px;
}
.ppe-card__summary {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}
/* A wide table scrolls inside the card, never the whole page on a phone. */
.ppe-card__periods {
    overflow-x: auto;
}
.ppe-card__title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
}

/* ppe-attach: the "Dodaj PPE" top bar — same combobox mechanics as .ppe-search
   above, reused rather than duplicated (`.ppe-search__results`/`__option` class
   names), just scoped under its own wrapper. */
.ppe-attach {
    position: relative;
}
.form--inline > .form__field.ppe-attach {
    flex-grow: 3; /* the search gets the room, not the copy-from select */
}
.ppe-attach__results {
    position: absolute;
    z-index: 20;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 240px;
    overflow-y: auto;
}
.ppe-attach__results:empty {
    display: none;
    border: none;
}

/* tab-panel: any page's local section-tabs group. The radio's `name` is the
   page-specific group (e.g. "contract-tabs"); the `value` and the panel's
   `data-tab` must match. Add one line per tab, no new CSS mechanism needed
   for a page that wants its own set of tabs — a tab without its line never shows
   (`test_every_tab_panel_has_a_show_rule`). */
main:has(.section-tab-input[value="overview"]:checked)
    .tab-panel[data-tab="overview"],
main:has(.section-tab-input[value="ppe"]:checked) .tab-panel[data-tab="ppe"],
main:has(.section-tab-input[value="annexes"]:checked)
    .tab-panel[data-tab="annexes"],
main:has(.section-tab-input[value="log"]:checked) .tab-panel[data-tab="log"],
main:has(.section-tab-input[value="edit"]:checked) .tab-panel[data-tab="edit"] {
    display: flex;
}
main:has(.section-tab-input[value="act"]:checked) .tab-panel[data-tab="act"],
main:has(.section-tab-input[value="new"]:checked) .tab-panel[data-tab="new"],
main:has(.section-tab-input[value="history"]:checked)
    .tab-panel[data-tab="history"],
main:has(.section-tab-input[value="zones"]:checked)
    .tab-panel[data-tab="zones"],
main:has(.section-tab-input[value="assignment"]:checked)
    .tab-panel[data-tab="assignment"],
main:has(.section-tab-input[value="changes"]:checked)
    .tab-panel[data-tab="changes"] {
    display: flex;
}
main:has(.section-tab-input[value="next"]:checked) .tab-panel[data-tab="next"],
main:has(.section-tab-input[value="activation"]:checked)
    .tab-panel[data-tab="activation"],
main:has(.section-tab-input[value="case_history"]:checked)
    .tab-panel[data-tab="case_history"] {
    display: flex;
}
main:has(.section-tab-input[value="imports"]:checked)
    .tab-panel[data-tab="imports"],
main:has(.section-tab-input[value="batches"]:checked)
    .tab-panel[data-tab="batches"] {
    display: flex;
}

main:has(.section-tab-input[value="readings"]:checked)
    .tab-panel[data-tab="readings"],
main:has(.section-tab-input[value="assigns"]:checked)
    .tab-panel[data-tab="assigns"],
main:has(.section-tab-input[value="technical"]:checked)
    .tab-panel[data-tab="technical"],
main:has(.section-tab-input[value="own-osd"]:checked)
    .tab-panel[data-tab="own-osd"],
main:has(.section-tab-input[value="csire"]:checked)
    .tab-panel[data-tab="csire"] {
    display: flex;
}

main:has(.section-tab-input[value="ksef"]:checked) .tab-panel[data-tab="ksef"],
main:has(.section-tab-input[value="audit"]:checked)
    .tab-panel[data-tab="audit"],
main:has(.section-tab-input[value="corrects"]:checked)
    .tab-panel[data-tab="corrects"],
main:has(.section-tab-input[value="lines"]:checked)
    .tab-panel[data-tab="lines"],
main:has(.section-tab-input[value="emails"]:checked)
    .tab-panel[data-tab="emails"],
main:has(.section-tab-input[value="notes"]:checked)
    .tab-panel[data-tab="notes"] {
    display: flex;
}
main:has(.section-tab-input[value="invoices"]:checked)
    .tab-panel[data-tab="invoices"],
main:has(.section-tab-input[value="tasks"]:checked) .tab-panel[data-tab="tasks"],
main:has(.section-tab-input[value="documents"]:checked)
    .tab-panel[data-tab="documents"],
main:has(.section-tab-input[value="contracts"]:checked)
    .tab-panel[data-tab="contracts"],
main:has(.section-tab-input[value="checks"]:checked) .tab-panel[data-tab="checks"] {
    display: flex;
}
/* client create/edit form: adds "address" and "contacts"; "client" and "billing" are
   shared with the tabs around it.
   contract create/edit form (C8): "contract" is shared with the agreement-prepare
   wizard's own tab above — same reasoning, the selector only cares about the DOM
   on the page it's rendered on. */
main:has(.section-tab-input[value="period"]:checked)
    .tab-panel[data-tab="period"],
main:has(.section-tab-input[value="address"]:checked)
    .tab-panel[data-tab="address"],
main:has(.section-tab-input[value="contacts"]:checked)
    .tab-panel[data-tab="contacts"],
main:has(.section-tab-input[value="billing"]:checked)
    .tab-panel[data-tab="billing"] {
    display: flex;
}
/* task card: adds "links" and "comments"; "act" and "history" are shared with the tabs above. */
main:has(.section-tab-input[value="links"]:checked)
    .tab-panel[data-tab="links"],
main:has(.section-tab-input[value="comments"]:checked)
    .tab-panel[data-tab="comments"] {
    display: flex;
}
/* agreement-prepare wizard (A3): "ppe" is shared with contract detail's own tab
   above — the selector only cares about the DOM on the page it's rendered on. */
main:has(.section-tab-input[value="client"]:checked)
    .tab-panel[data-tab="client"],
main:has(.section-tab-input[value="contract"]:checked)
    .tab-panel[data-tab="contract"],
main:has(.section-tab-input[value="pricing"]:checked)
    .tab-panel[data-tab="pricing"],
main:has(.section-tab-input[value="summary"]:checked)
    .tab-panel[data-tab="summary"] {
    display: flex;
}
.ppe-list {
    white-space: unset !important;
    display: block !important;
    text-align: right;
}
/* highlight the label of whichever local section-tab is checked */
.submenu__link:has(.section-tab-input:checked) {
    color: var(--heading);
    box-shadow: inset 0 -2px 0 var(--accent-edge);
}

/* --- labels --------------------------------------------------------------- */

.label,
.form__field label:not(.filters__tag) {
    color: var(--secondary);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
/* A fixed height: Polish capitals with diacritics would otherwise push their input 1px
   below the one beside it. */
.label {
    line-height: 17px;
}

/* --- badges ----------------------------------------------------------------- */

/* Badge colour rule — ask: does it name the object's *category*, or describe its *state*?
     gray (plain `.badge`)      a category / identity that never changes with the object's life:
                                type, direction, source, operator code, scenario, file kind, tags
     `.badge--info` (blue)      a neutral state or step in a process, no good/bad verdict:
                                prospect/task/switch status, current vindication step, "wstrzymana"
     status colour              a state with a verdict. A model status enum uses
                                `badge status--<value>` (tables: `status_class` in tables/base.py);
                                an ad-hoc verdict uses `.badge--success` (ok / done),
                                `.badge--warning` (needs attention) or `.badge--error` (failed / blocked).
   Quick test: remove the badge — do you lose the state, or only a label? State → info or a status
   colour. Label → gray. Never use `badge--info` for a category. */
.badge {
    display: inline;
    align-items: center;
    height: min-content;
    padding: 4px 10px;

    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;

    color: var(--secondary);
    background: var(--tint-neutral);
    border-radius: var(--radius);

    white-space: nowrap;
}
table.data .badge {
    padding: 2px 5px;

    font-size: 10px;
}
.badge--success {
    background-color: var(--ok);
    color: white;
}
.badge--error {
    background-color: var(--critical);
    color: white;
}
.badge--info {
    background-color: var(--info);
    color: white;
}

.badge--warning {
    background-color: var(--warning);
    color: white;
}

/* A badge that opens its details (a <button>): the badge look, plus a pointer. */
.badge--button {
    border: none;
    font-family: inherit;
    cursor: pointer;
}
.badge--button:hover {
    text-decoration: underline;
}
/* A badge that opens what it names (an <a>): underlined only on hover, like the button. */
a.badge {
    text-decoration: none;
}
a.badge:hover {
    text-decoration: underline;
}

/* A reading changed since its file was sent: green = a value appeared, red = it is gone,
   yellow = a different value. The "Wysłano" / "Teraz" columns say the same in text. */
.sent-change--added td {
    background: var(--tint-ok);
}
.sent-change--removed td {
    background: var(--tint-crit);
}
.sent-change--changed td {
    background: var(--tint-active);
}

/* Status pills. Colour is a hint, never the only signal — the label is
   always there, because roughly one man in twelve cannot rely on colour. */
.status {
    padding: 1px 8px;
    border-radius: 10px;
    border: 1px solid var(--border);
    font-size: 12px;
}
.status--draft {
    background: var(--bg);
}
.status--pending_signature {
    background: var(--tint-warn);
    border-color: var(--warning);
}
.status--active {
    background: var(--tint-ok);
    border-color: var(--ok);
}
.status--terminated,
.status--archived {
    background: var(--tint-neutral);
    color: var(--muted);
}
.status--issued,
.status--not_submitted {
    background: var(--tint-neutral);
}
.status--paid,
.status--accepted,
.status--signed,
.status--correction_accepted {
    background: var(--tint-ok);
    border-color: var(--ok);
}
.status--cancelled,
.status--rejected,
.status--correction_rejected {
    background: var(--tint-neutral);
    color: var(--muted);
}
.status--generating_xml,
.status--submitted,
.status--correction_generating_xml,
.status--correction_submitted {
    background: var(--tint-warn);
    border-color: var(--warning);
}
.status--correcting,
.status--correction_required {
    background: var(--tint-warn);
    border-color: var(--warning);
}

/* CSIRE message statuses (outbound and inbound share the namespace). */
.status--built,
.status--validated,
.status--sent,
.status--peeked,
.status--stored,
.status--dequeued {
    background: var(--bg);
}
.status--acked,
.status--processed {
    background: var(--tint-ok);
    border-color: var(--ok);
}
.status--failed,
.status--needs_review {
    background: var(--tint-warn);
    border-color: var(--warning);
}
.status--failed_permanent,
.status--invalid {
    background: var(--tint-crit);
    border-color: var(--critical);
    color: var(--critical-text);
}

/* Pre-invoice control verdict (`internal_ui.services.billing.preflight.PreflightVerdict`). */
.status--held {
    background: var(--tint-neutral);
}
.status--blocked {
    background: var(--tint-crit);
    border-color: var(--critical);
    color: var(--critical-text);
}
.status--overridden {
    background: var(--tint-warn);
    border-color: var(--warning);
}
.status--ready {
    background: var(--tint-ok);
    border-color: var(--ok);
}
/* `billing.DriftStatus` — the „Do korekty” list. */
.status--open {
    background: var(--tint-warn);
    border-color: var(--warning);
}
.status--dismissed {
    background: var(--tint-neutral);
    color: var(--muted);
}
.status--resolved {
    background: var(--tint-ok);
    border-color: var(--ok);
}

/* Priority pills. Same colour-is-a-hint rule as .status. */
.prio--critical {
    background-color: black;
    color: white;
}
.prio--high {
    background-color: var(--critical);
    color: white;
}
.prio--normal {
    background-color: var(--ok);
    color: white;
}
.prio--low {
    background-color: #11b5f7;
    /* dark, not white: white on this light blue is 2.3:1 */
    color: var(--on-accent);
}

/* --- buttons ------------------------------------------------------------------
   The button rule — one look for every button, picked by where it sits and what it does:
     size    regular for the page and its forms: the options bar (`{% block options %}`),
             a `.toolbar` outside tabs, a form's own buttons. `--small` inside content: row
             actions, a value row, a card's header, a line of text, and a tab's content — its
             `.toolbar` and loose buttons (a form inside a tab keeps its own buttons regular).
     colour  gray (no modifier) for a neutral action or a link to another view; `--primary`
             for the group's one next step; `--danger` for what deletes, rejects or ends.
             No other colours, never both modifiers.
     order   gray first, then red, then the yellow one last, at the right.
     place   page-level actions live in the options bar, never in the title row by the <h1>.
   A group (options bar, toolbar, form, row actions) has at most one yellow; an action that
   can't be taken yet stays its colour, faded, with a `title` saying why.
   `internal_ui/tests/test_buttons.py` guards it; `RowActions` refuses a spec that breaks it. */

.button {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    height: min-content;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    font: inherit;
    font-weight: 500;
}
.button:hover {
    background: var(--tint-hover);
    border-color: var(--border-hover);
}
.button--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}
.button--primary:hover {
    background: color-mix(in srgb, var(--accent) 88%, black);
    border-color: color-mix(in srgb, var(--accent) 88%, black);
}
/* A toggle that is on (the week calendar's zone palette): its fill alone is 1.6:1 on white. */
.button[aria-pressed="true"],
.button[aria-pressed="true"]:hover {
    border-color: var(--accent-edge);
}
.button--danger {
    background: var(--critical);
    border-color: var(--critical);
    color: #fff;
}
.button--danger:hover {
    background: color-mix(in srgb, var(--critical) 88%, black);
    border-color: color-mix(in srgb, var(--critical) 88%, black);
}
.button--small {
    padding: 2px 8px;
    font-size: 13px;
}
/* An action that exists but can't be taken yet. Rendered as an <a> without href
   plus a `title` saying why — not `pointer-events: none`, which would also kill
   the tooltip that explains it. */
.button[aria-disabled="true"],
.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.cards {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-md);
    padding: 0;
    margin: 0;
    align-items: stretch;
}
.cards li {
    flex: 1 1 180px;
    min-width: 280px;
}
/* Cards of figures only (a list's totals): each card starts as wide as its figures in one row,
   so two cards share a line only when both fit whole, and otherwise each takes its own. */
.cards--figures > li {
    flex: 1 1 auto;
}
.cards li:has(.card--wide) {
    flex: 1 1 100%;
    min-width: 0;
}
/* Wide cards stack with no box between them, so they sit apart like sections. */
.cards:has(.card--wide) {
    row-gap: var(--gap-lg);
}
.card {
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
    height: 100%;
}
/* A small tile with no title to hang a divider on: the one card that keeps its box. */
.card--tile {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: var(--gap-sm);
    position: relative;
    isolation: isolate;
    overflow: hidden;
}

/* Callouts — one rule for every box that flags a state with a coloured left border
   (messages, the contract lock-note, warning/critical cards): the border carries the tone
   and the background is the same tone, lightened. A new callout only sets `--tone` and
   `--tone-tint` (modifier below) and lists itself in the second rule; it never colours
   its own border or background. */
.message--error,
.card--critical {
    --tone: var(--critical);
    --tone-tint: var(--tint-crit);
}
.message--warning,
.card--warning,
.lock-note {
    --tone: var(--warning);
    --tone-tint: var(--tint-warn);
}
.message--success {
    --tone: var(--ok);
    --tone-tint: var(--tint-ok);
}
.message--info,
.lock-note--open {
    --tone: var(--info);
    --tone-tint: var(--tint-info);
}
.message,
.lock-note,
.card--warning,
.card--critical {
    border-left-color: var(--tone, var(--border));
    background-color: var(--tone-tint, transparent);
}
.card__value {
    font-size: 24px;
    font-weight: 700;
}
/* The tile's number again, as decoration behind its content: in the tone of its border, placed
   against the tile's edges rather than its padding, and cropped by them. A neutral tile's
   border colour would be invisible here, so it falls back to muted. */
.card__backdrop-value {
    position: absolute;
    z-index: -1;
    right: 8px;
    bottom: -24px;
    color: var(--tone, var(--muted));
    font-size: 144px;
    font-weight: 700;
    line-height: 1;
    opacity: 0.15;
    pointer-events: none;
    user-select: none;
}
.card__hint {
    color: var(--muted);
    font-size: 13px;
    margin: 4px 0 0;
}
.card__stats {
    display: flex;
    gap: var(--gap-md);
    flex-wrap: wrap;
}
/* Equal shares of the row, each at least as wide as its figure (an amount never breaks), so a
   row wraps only when its figures really don't fit side by side. */
.card__stat {
    flex: 1 1 0;
}
/* A heading belongs to what's under it: 16 to that, 64 from the group above. The card's own
   gap is 32, so these only adjust it. */
.card > .card__stats + h4 {
    margin-top: var(--gap-md);
}
.card > h4 + * {
    margin-top: calc(-1 * var(--gap-sm));
}
/* A group of figures inside a wide card (heading + its stats), framed like `main` so each
   group reads on its own. */
.card__group {
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
    padding: var(--gap-md);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
/* Framed groups sit 64 apart, like sections; the card's own gap is 32, so this adds the rest. */
.card__group + .card__group {
    margin-top: var(--gap-md);
}
.card__chart {
    position: relative;
    height: 280px;
}
/* „Dane wykresu”: a chart's figures as a table, folded under it (`_trend_chart.html`). */
.card__data[open] > summary {
    margin-bottom: 16px;
}
.card__value a {
    color: inherit;
}
/* Figures that only give context next to the card's main one: a step smaller and lighter,
   and underlined only on hover. */
.card__stats--secondary .card__value {
    font-size: 20px;
    font-weight: 600;
}
.card__stats--secondary .card__value a {
    text-decoration: none;
}
.card__stats--secondary .card__value a:hover {
    text-decoration: underline;
}
/* A tile's trend row. Same two colours as `to_invoice` and `invoiced` in
   consumption_chart.js. */
.card__trend {
    display: block;
    width: 100%;
    height: 64px;
}
.card__trend path {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
    /* The SVG stretches to the card, so without this the line's width would stretch too. */
    vector-effect: non-scaling-stroke;
}
.card__trend-to-invoice {
    stroke: #a6640a;
}
.card__trend-invoiced {
    stroke: #1a5fb4;
}
.card__trend-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 32px;
    padding: 0;
    margin: 0;
    list-style: none;
    color: var(--muted);
    font-size: 13px;
}
/* These sit inside a `.cards` list, whose `li` rules are meant for whole cards. Specific
   enough to also beat the narrow-screen one further down this file. */
.cards .card__trend-legend li {
    flex: none;
    min-width: 0;
}
/* A piece of the line it names. */
.card__trend-key {
    display: inline-block;
    width: 16px;
    height: 3px;
    margin-right: 8px;
    vertical-align: middle;
    border-radius: 2px;
}
.card__trend-key--to-invoice {
    background-color: #a6640a;
}
.card__trend-key--invoiced {
    background-color: #1a5fb4;
}
/* Webkit and Firefox each style the bar through their own pseudo-elements, and a selector
   list holding both would be dropped whole, so the fill is declared twice. */
.billing-progress {
    --progress-fill: var(--accent);
    appearance: none;
    display: block;
    width: 100%;
    height: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--tint-hover);
    box-shadow: var(--shadow-sm);
}
.billing-progress::-webkit-progress-bar {
    background: transparent;
}
.billing-progress::-webkit-progress-value {
    background: var(--progress-fill);
}
.billing-progress::-moz-progress-bar {
    background: var(--progress-fill);
}
.activity {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 0;
    margin: 0;
    list-style: none;
}
.activity__row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 32px;
    row-gap: 4px;
}
.activity__row time {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

/* --- tables --------------------------------------------------------------------- */
table.data {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

table.data thead {
    background: var(--surface-subtle);
}

table.data th,
table.data td {
    padding: 12px 14px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

table.data th {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--muted);
}

table.data td {
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

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

/* Date-range rule — a period of days is one „Okres” cell, never an „Od” and a „Do” column:
   `{{ start|date_range:end }}` for an inclusive end, `{{ start|date_range_half_open:end }}`
   for a stored half-open end (the first day after; the cell shows the last day, never the
   stored one), `DateRange(..., end_exclusive=...)` in a Python table spec. It prints as
   short as the period lines up: `2026` a calendar year, `2026-08` a month, `2026-01 –
   2026-03` whole months, `2026-01-15 – 2026-03-10` otherwise, `od 2026-01-15` with no end;
   non-breaking spaces keep it on one line. Times inside one day (15-minute intervals) are
   not periods and keep their own columns. `test_periods_are_one_okres_cell` guards it. */

/* Row actions — one look for every action on a table row: `button button--small`
   (`--primary` for the row's one next step, `--danger` for removing or rejecting), inside
   `<td><div class="row-actions">` in the row's last cell, under an empty `<th>`. A plain link
   in a table only opens the row's object (its number, its name); it is never an action. A
   disabled action is the usual `aria-disabled` + `title`. Python table specs use `RowActions`
   (tables/base.py), which renders the same markup. 16 between buttons rather than the
   spacing rule's 32 side by side: small buttons in one cell, like `.toolbar`. */
.row-actions {
    display: flex;
    gap: var(--gap-sm);
    justify-content: flex-end;
    align-items: center;
    white-space: nowrap;
}
.row-actions form {
    display: flex;
    gap: var(--gap-sm);
    align-items: center;
    margin: 0;
}

.u-word-break {
    overflow-wrap: anywhere;
}
/* Figures right-align so digits line up column-wise; that is most of what
   makes a dense financial table readable. */
table.data td.num,
table.data th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Dense tables — a day of 15-minute slots, a file preview: many rows, short values. */
table.data--compact th,
table.data--compact td {
    padding: 3px 8px;
    font-size: 13px;
    vertical-align: middle;
}
table.data--compact th {
    font-size: 11px;
}
table.data--compact .button--small {
    padding: 0 6px;
    font-size: 12px;
    line-height: 1.6;
}

table.data--nested {
    margin: 4px 0;
}
table.data--nested th,
table.data--nested td {
    padding: 4px 8px;
    font-size: 12px;
}
.row--failed td {
    background: var(--tint-crit);
}
.row--superseded td {
    color: var(--muted);
}
/* A table too wide for its container scrolls on its own — the measurement heat
   map, the task calendar, the consumption portfolio breakdown all wrap their
   table in this rather than letting it overflow the page. One with nothing focusable inside
   is itself a tab stop with a name (`tabindex="0" role="region" aria-label`), or a keyboard
   could not scroll it (axe `scrollable-region-focusable`). */
.heat-scroll {
    overflow-x: auto;
}

/* --- empty / notice / confirm states -------------------------------------------- */

.empty {
    padding: 32px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.empty__title {
    font-weight: 600;
    margin: 0;
}
.empty__hint {
    color: var(--muted);
    margin: 4px 0 0;
}

.notice {
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
    border-radius: var(--radius);
    padding: var(--gap-sm);
}
.notice--denied {
    border-color: var(--critical);
}
.notice ol.clauses {
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
    margin: 0;
}
.notice ol.clauses li {
    margin-bottom: 4px;
}

.confirm {
    background: var(--surface);
    border: 1px solid var(--critical);
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
    border-radius: var(--radius);
    padding: var(--gap-sm);
}
.confirm__question {
    font-weight: 600;
}
.confirm__consequence {
    color: var(--critical-text);
}

/* --- pagination ------------------------------------------------------------------ */

/* Centred under the table: `_pagination.html` under every list, and `_step_nav.html`, the
   same row of buttons. */
.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--gap-sm);
    align-items: center;
    padding: 8px 0;
}
.pagination__status {
    color: var(--muted);
    font-size: 13px;
}
/* The day, month or period the screen is showing: its subject, not a footnote. */
.pagination__status--current {
    color: var(--text);
    font-size: inherit;
    font-weight: 600;
}
/* A muted footnote under a table, e.g. the calendar's "Pokazano N najpilniejszych z M". */
.table-count {
    color: var(--muted);
    font-size: 12px;
    margin: 4px 0 0;
}

/* --- login ------------------------------------------------------------------------ */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 40px 32px;
    width: 360px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
}
.login-card__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
}
.login-card__brand h1 {
    margin: 0;
    font-size: 20px;
}
.login-card__brand .brand__logo {
    margin: 0 0 8px;
    width: 64px;
    height: 32px;
}
.login-card__hint {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}
.login-card__form {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
}
/* "lub" between the two ways in, drawn as a line with the word in the middle */
.login-card__divider {
    display: flex;
    align-items: center;
    gap: var(--gap-sm);
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}
.login-card__divider::before,
.login-card__divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--border);
}
.login-card label {
    display: block;
    margin-top: 12px;
    font-size: 13px;
    color: var(--secondary);
}
.login-card input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-control);
    border-radius: var(--radius);
    font: inherit;
}
.login-card button {
    margin-top: 16px;
    width: 100%;
}
.login-card .message {
    margin: 0 0 4px;
}

/* --- MFA enrolment ---------------------------------------------------------------- */

/* QR on white in both themes: authenticator apps read dark-on-light reliably, and an
   inverted code is the usual reason "it won't scan". */
.mfa-qr {
    width: 216px;
    padding: 8px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.mfa-qr svg {
    display: block;
    width: 100%;
    height: auto;
}
.mfa-codes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px 32px;
    max-width: 480px;
}
.mfa-codes code {
    font-size: 16px;
    letter-spacing: 0.08em;
}

/* --- toolbar ------------------------------------------------------------------------ */

.toolbar {
    display: flex;
    gap: var(--gap-sm);
    align-items: center;
    position: relative;
    flex-wrap: wrap;
}
.toolbar form {
    margin: 0;
}

/* --- form fields (inputs / selects, shared by filters + forms) ----------------------- */

input,
select,
textarea {
    font: inherit;
    font-size: 16px;
    color: var(--text);
    background-color: var(--surface);
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border-control);
    border-radius: var(--radius);
    box-sizing: border-box;
}
input,
select {
    height: 38px;
}
/* Native file picker: same field box as the other inputs, with its button styled to match
   the app's buttons instead of the browser's default grey one. */
input[type="file"] {
    height: auto;
    padding: 4px;
    color: var(--secondary);
}
input[type="file"]::file-selector-button {
    margin-right: 12px;
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--tint-neutral);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}
input[type="file"]::file-selector-button:hover {
    background: var(--tint-hover);
    border-color: var(--border-hover);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    border-color: var(--info);
}

/* --- filters (filter bar above a list) ------------------------------------------------ */

.filters {
    display: flex;
    align-items: flex-end;
    gap: var(--gap-md);
}
/* A hand-written filter row of several fields (`.filters__grid--row` + `.filters__actions`):
   the fields keep room for one 9rem field before the buttons beside them move to the next
   line, instead of squeezing every field to a sliver on a phone. A single full-width field
   and its button stay one row. */
.filters:has(> .filters__grid--row) {
    flex-wrap: wrap;
}
.filters > .filters__grid--row {
    min-width: min(100%, 9rem);
}
.filters__grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: var(--gap-md);
}
.filters__field {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    width: 100%;
}
/* The list filter bar (`_filters.html`): the container its tag groups measure, see the
   narrow bar rule after `.filters__tags`. */
.filters--bar {
    container: filter-bar / inline-size;
}
/* The list filter bar's top row: each field takes its share of the row by its
   `FilterSpec.span` (`--span`), never narrower than 2.5rem a column (so a span-6 search keeps
   room to read what was typed), and moves to the next row only when it no longer fits; that
   row is then its own, full width. So the filters are one row wherever they fit, at any
   screen width. A tag group is as wide as its tags: not stretched to its span, never
   squeezed below its labels, and the other fields share what it leaves. The fold under
   "Więcej filtrów" is not a row but a grid: see `.filters__more`. */
.filters__grid--row {
    display: flex;
    flex-wrap: wrap;
}
.filters__grid--row > .filters__field {
    flex: var(--span, 4) 1 0;
    min-width: min(100%, max(9rem, var(--span, 4) * 2.5rem));
}
.filters__grid--row > .filters__field--tags {
    flex: 0 0 auto;
    width: max-content;
    min-width: 0;
    max-width: 100%;
}
/* the caption is the control's <label>, so the pair stays one column as before */
.filters__field > label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.filters__actions {
    flex-shrink: 0;
}
/* The filter bar's last line (`_filters.html`): "Więcej filtrów" on the left, "Wyczyść
   filtry" on the right. The fold opens in place underneath, by the fold rule below. */
.filters__footer {
    display: flex;
    align-items: flex-start;
    gap: var(--gap-md);
    width: 100%;
}
/* The fold rule — the open "Więcej filtrów" fold: a 12-column grid, each field exactly its
   `FilterSpec.span` (`--span`), a new line every 12 columns, and nothing stretched to fill
   a line — leftover columns stay empty, so a span keeps its width and the columns line up.
   Controls line up along the bottom, so a label that wraps never pushes its control out of
   line; lines 16 apart, fields 32 (spacing rule). A bar under 768 wide (it is the
   container) makes it two columns: a `--wide` field (span 6+) takes the line, the rest
   half. A date range's two halves sit side by side, and a tag group is wide
   (`test_folded_filters_keep_their_lines`). Not a flex row like the top one: folds hold
   more than 12 columns, and a row would squeeze them and stretch the last one. */
.filters__more {
    flex: 1;
    container-type: inline-size;
}
.filters__more > summary {
    width: max-content;
    font-size: 14px;
}
.filters__more > .filters__grid {
    margin-top: var(--gap-md);
    row-gap: var(--gap-sm);
    align-items: end;
}
.filters__more .filters__field {
    grid-column: span var(--span, 4);
}
@container (max-width: 767px) {
    .filters__more > .filters__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .filters__more .filters__field {
        grid-column: span 1;
    }
    .filters__more .filters__field--wide {
        grid-column: 1 / -1;
    }
}
.filters__clear {
    flex-shrink: 0;
    margin-left: auto;
}
/* With a fold, "Wyczyść filtry" leaves the flow and sits at the right of the summary's
   line, so the fold's fields take the bar's whole width. Without one it stays in the flow,
   alone on the line underneath the filters. */
.filters__footer:has(.filters__more) {
    position: relative;
}
.filters__footer:has(.filters__more) > .filters__clear {
    position: absolute;
    top: 0;
    right: 0;
}

/* filters__tags: a segmented-control style radio group (used for saved views etc.).
   Each option looks like a `.button`, the checked one like a `.button--primary`. */
.filters__tags {
    display: flex;
    height: 38px;
    border-radius: var(--radius);
}
/* Each tag starts at its own text width and the row's spare room is shared out on top, so a
   group of short codes (PPE, PPB) doesn't take the width its longest label would need. */
.filters__tag {
    position: relative;
    flex: 1 1 auto;
    cursor: pointer;
}
/* Neighbours share one border, so a hovered option can colour all four of its sides. */
.filters__tag + .filters__tag {
    margin-left: -1px;
}
.filters__tag input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.filters__tag span {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px; /* `tag_group_width` counts it: change both */
    font-size: 16px;
    font-weight: 500;
    text-transform: none;
    height: 100%;
    color: var(--text);
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
}
/* A form's radio pill with a note („TPA” + „dystrybucja przez OSD”): the note smaller on a
   line of its own, both lines inside the group's 38 like any other input. */
.filters__tag span:has(> .filters__tag-note) {
    flex-direction: column;
    line-height: 18px;
}
.filters__tag-note {
    font-size: 11px;
    font-weight: 400;
    line-height: 13px;
    color: var(--muted);
}
.filters__tag input:checked + span .filters__tag-note {
    color: inherit;
}
.filters__tag:first-child span {
    border-top-left-radius: var(--radius);
    border-bottom-left-radius: var(--radius);
}
.filters__tag:last-child span {
    border-top-right-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}
.filters__tag:hover span {
    z-index: 1;
    background: var(--tint-hover);
    border-color: var(--border-hover);
}
.filters__tag input:checked + span {
    z-index: 1;
    background: var(--accent);
    border-color: var(--accent-edge);
    color: var(--on-accent);
}
.filters__tag:hover input:checked + span {
    background: color-mix(in srgb, var(--accent) 88%, black);
}
.filters__tag input:focus-visible + span {
    z-index: 2;
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}
/* On a list filter bar a tag's label stays on one line: the group takes its width instead. */
.filters--bar .filters__tag span {
    white-space: nowrap;
}
/* The narrow bar rule: a tag group too wide for the narrowest list filter bar (`--stacks`,
   `FilterBar.stacks`) stacks its tags, full width, on a bar under 688, as every group does
   on a phone (the 768 media rule), instead of running past the card. Every group fits one
   row of a 688 bar (`TAG_GROUP_MAX_WIDTH`, `test_tag_groups_fit_the_bar`). */
@container filter-bar (max-width: 687px) {
    .filters__grid--row > .filters__field--stacks {
        flex-basis: 100%;
    }
    .filters__field--stacks .filters__tags {
        flex-direction: column;
        height: auto;
    }
    .filters__field--stacks .filters__tag + .filters__tag {
        margin-top: -1px;
        margin-left: 0;
    }
    .filters__field--stacks .filters__tag span {
        min-height: 38px;
    }
    .filters__field--stacks .filters__tag:not(:first-child) span {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
    }
    .filters__field--stacks .filters__tag:not(:last-child) span {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
    .filters__field--stacks .filters__tag:first-child span {
        border-top-right-radius: var(--radius);
    }
    .filters__field--stacks .filters__tag:last-child span {
        border-bottom-left-radius: var(--radius);
    }
}

/* --- key/value description lists ------------------------------------------------------- */

dl {
    display: grid;
    grid-template-columns: fit-content(35%) minmax(0, 1fr); /* labels as wide as the longest one, not a fixed slice */
    align-content: start;
    gap: 16px var(--gap-sm);
    width: 100%;
    margin: 0;
}

/* Two label/value pairs per row, still one grid — so row heights stay even
   without the gap mismatches multiple side-by-side `dl` boxes produce. */
.dl--cols-2 {
    grid-template-columns: repeat(2, fit-content(35%) minmax(0, 1fr));
    column-gap: var(--gap-md);
}

/* No `min-width: 0` here: the label column is then never narrower than a label's longest
   word, so a label wraps between words („Adres / korespondencyjny”), never inside one. */
dt {
    overflow-wrap: break-word;

    color: var(--secondary);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
dd {
    min-width: 0;
    margin: 0;

    display: flex;
    justify-content: flex-end;
    text-align: right;

    overflow-wrap: break-word;
}
/* --- forms --------------------------------------------------------------------------- */

/* A form spaces itself by the spacing rule, so its tag carries no layout class
   (`test_form_tags_carry_no_layout_class`):
     32  between its blocks — errors, tab strip, tab panel, fieldsets, a table, the actions
     16  between field rows inside a block (`.form__grid`); 32 between fields side by side
      4  inside a field — label, control, help, error
   A form made of sections (the agreement summary) puts 64 between them, like a tab panel. */
.form {
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
    width: 100%;
}
.form:has(> section) {
    gap: var(--gap-lg);
}

/* A one-row form: a field or two and its button (add a grid area, assign a task, a note).
   Fields share the row and wrap once narrower than 12rem; everything sits on the last
   baseline, so the button lines up with the input under its label. */
.form--inline {
    display: flex;
    width: auto; /* in a row beside text it takes its own width, not the row's */
    flex-direction: row;
    flex-wrap: wrap;
    align-items: last baseline;
    gap: var(--gap-sm) var(--gap-md);
}
.form--inline > .form__field,
.form--inline > input,
.form--inline > select,
.form--inline > textarea {
    flex: 1 1 12rem;
}

.form__grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--gap-sm) var(--gap-md);
}
/* A field given no span takes the whole row: a plain list of fields is a grid of rows. */
.form__grid > .form__field:not([class*="u-span-"], [style*="grid-column"]) {
    grid-column: 1 / -1;
}
/* A swapped-in group of fields (the terms form's config fields) that lays its fields out on the
   form's own grid, so they share rows with the fields around them instead of starting a row
   of their own. */
.form__grid-slot {
    display: contents;
}
.form__field {
    display: flex;
    flex-direction: column;
    gap: var(--gap-xs);
}
/* A row `show_when.js` hid because it does not apply to the answers above it. */
.form__field[hidden] {
    display: none;
}
.form__field label {
    font-size: 13px;
    color: var(--muted);
}
.form__field input:not([type="checkbox"]),
.form__field select,
.form__field textarea {
    font: inherit;
    padding: 6px 8px;
    border: 1px solid var(--border-control);
    border-radius: var(--radius);
}
/* The form checkbox, scoped to form fields only — this must NOT be a bare
   `input[type="checkbox"]` rule, or it silently restyles every checkbox on the page,
   including the mobile sidebar toggle and any hidden checkbox-hack inputs elsewhere. */
.form__field input[type="checkbox"] {
    appearance: none;
    flex-shrink: 0; /* a label that wraps must not squeeze the box */
    width: 19px;
    height: 19px;
    border: 1px solid var(--border-control);
    border-radius: var(--radius);
    cursor: pointer;
}
/* Ticked is the mark, not the fill: the yellow is 1.6:1 on white, the dark mark on it 12:1. */
.form__field input[type="checkbox"]:checked {
    background: var(--accent)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='%23111' stroke-width='2'/%3E%3C/svg%3E")
        center / 60% no-repeat;
}

.form__help {
    font-size: 12px;
    color: var(--muted);
    margin: 0;
}
/* Always rendered, so a script or screen reader has it to point at, but an empty one takes
   no room: reserving its height put 36 between field rows instead of the rule's 16. */
.form__help:empty,
.form__error:empty {
    display: none;
}
.form__error {
    color: var(--critical-text);
    font-size: 13px;
    line-height: 1.3;
    min-height: 1.3em;
    margin: 0;
}
.form__required {
    color: var(--critical-text);
}
.form__field:has(.form__error:not(:empty)) input:not([type="checkbox"]),
.form__field:has(.form__error:not(:empty)) select,
.form__field:has(.form__error:not(:empty)) textarea {
    border-color: var(--critical);
}
.form__field:has(.form__error:not(:empty)) input[type="checkbox"] {
    border-color: var(--critical);
    border-width: 2px;
}
.form__actions {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    gap: var(--gap-md);
}

/* fieldset: a themed group of fields within a form — no box, just a divider + label.
   No browser padding or margin either: an unlabeled group lines up with a labelled one.
   The divider only makes sense under a visible legend; the 32 after it is the form's gap. */
.fieldset {
    border: none;
    margin: 0;
    padding: 0;
    min-width: 0;
}
.fieldset:has(legend) {
    border-bottom: 1px solid var(--border);
    padding-bottom: var(--gap-md);
}
/* The last group before the buttons draws no line: a form has no divider above its actions. */
.fieldset:has(legend):has(+ .form__actions),
.form > .tab-panel > .fieldset:has(legend):last-child {
    border-bottom: 0;
    padding-bottom: 0;
}
.fieldset legend {
    padding: 0;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: var(--gap-md);
}
/* --- timeline ------------------------------------------------------------------------- */
ul {
    margin: 0;
    padding: 0;
}
.timeline-row {
    padding: 0 0 var(--gap-md);
    margin: 0 0 var(--gap-md);
    border-bottom: 1px solid var(--border);
}
.timeline-row:last-child {
    border-bottom: none;
}
.timeline-row dd {
    justify-content: flex-start;
}
/* `.timeline` is the log/comment list: a vertical rail with a dot per entry, markup in
   partials/timeline/_entry.html. `.timeline-row` below is the older divider-separated
   row, still used for plain key/value blocks. */
.timeline {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
    padding-left: 24px;
    list-style: none;
}
.timeline::before {
    content: "";
    position: absolute;
    top: 6px;
    bottom: 6px;
    left: 5px;
    width: 2px;
    background: var(--border);
}
.timeline:has(> .muted:only-child) {
    padding-left: 0;
}
.timeline:has(> .muted:only-child)::before {
    display: none;
}
.timeline__entry {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.timeline__entry::before {
    content: "";
    position: absolute;
    top: 4px;
    left: -24px;
    width: 12px;
    height: 12px;
    box-sizing: border-box;
    border: 2px solid var(--muted);
    border-radius: 50%;
    background: var(--surface);
}
.timeline__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: var(--gap-sm);
}
.timeline__who {
    font-weight: 600;
    color: var(--heading);
}
.timeline__when {
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.timeline__action {
    font-weight: 500;
}
.timeline__label {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.timeline__body {
    margin: 0;
    max-width: 70ch;
    overflow-wrap: anywhere;
}
.timeline__body .badge {
    margin-left: 8px;
    vertical-align: middle;
}
.timeline__meta {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.plain {
    margin: 0;
    padding: 0;
}

/* --- misc ---------------------------------------------------------------------------- */

details summary {
    cursor: pointer;
    /* `--accent` is a border/background color, not text — ~1.6:1 on white,
       far below WCAG AA. `--heading` is the dark color headings already use. */
    color: var(--heading);
}
pre {
    background: var(--bg);
    padding: 8px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: 12px;
}

/* ==========================================================================
   6. Page-specific styles
   ========================================================================== */

/* --- supplier-switch board (Vue island) --------------------------------- */
.board {
    position: relative;
}
.board__columns {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
    flex-wrap: wrap;
    align-items: flex-start;
}
.board__column {
    flex: 1 1 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    min-height: 500px;
    min-width: 200px;
}
/* A column the state machine will not accept, shown while dragging: the
   refusal comes before the drop, not as an error afterwards. */
.board__column.is-blocked {
    opacity: 0.45;
}
.board__heading {
    margin: 0 0 8px;
    display: flex;
    justify-content: space-between;
}

.board__card {
    background-color: var(--bg);
    border-left: 3px solid var(--accent);
    padding: 8px;
    margin-bottom: 8px;
    cursor: grab;
}
.board__card.is-breached {
    border-left-color: var(--critical);
}
.board__title {
    font-weight: 600;
    text-decoration: none;
    /* a flex item beside the priority badge: without these a word with no break in it (a
       PPE number) holds the title at its width and pushes the badge out of the card */
    min-width: 0;
    overflow-wrap: anywhere;
}
.board__meta {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--muted);
    margin: 4px 0 0;
}
.board__empty {
    color: var(--muted);
    text-align: center;
    margin: 0;
}

/* Breached and approaching deadlines are different problems needing
   different responses — B10 alerts on them separately, and the UI must not
   merge them. Every list renders them through `{% deadline %}` (templatetags/dates.py); a late
   row is never tinted as well. */
.deadline {
    font-variant-numeric: tabular-nums;
}
.deadline--approaching {
    /* `--warning` is ~3.9:1 on white, failing WCAG AA for normal-size text;
       `--warning-text` is the darker amber that passes. */
    color: var(--warning-text);
    font-weight: 600;
}
.deadline--breached {
    color: var(--critical-text);
    font-weight: 700;
}

/* --- ingestion monitoring (delivery heat map) --------------------------- */

.heat-scroll {
    overflow-x: auto;
}
table.heat th.heat__day {
    text-align: center;
    font-size: 11px;
    padding: 4px 2px;
}
.heat__cell {
    text-align: center !important;
    padding: 4px 2px;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}
.heat__cell--ok {
    color: var(--ok-text);
}
/* The only filled cell on the grid. "Expected but missing" is the state
   this whole screen exists to surface, so it must be visible without
   reading a legend. */
.heat__cell--missing {
    background: var(--critical);
    color: #fff;
    font-weight: 700;
}
.heat__cell--extra {
    color: var(--warning-text);
}

/* --- task calendar (C4) -------------------------------------------------- */
/* Server-rendered table, same choice as the delivery-heat view above: no
   charting library, and a day that needs attention must be obvious without
   reading a legend. */

table.calendar {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
table.calendar th.heat__day {
    border-bottom: 1px solid var(--border);
}
.calendar__cell {
    border: 1px solid var(--border);
    vertical-align: top;
    padding: 4px;
    height: 90px;
    width: 14.28%;
    min-width: 0; /* let table-layout: fixed win over content's intrinsic width */
    overflow: hidden;
}
/* A day outside the shown month, kept in the grid so the week rows line up
   rather than collapsing — but visually receded, so it doesn't compete with
   this month's days. */
.calendar__cell--outside {
    background: var(--bg);
    color: var(--muted);
}
.calendar__cell--today {
    border-color: var(--accent-edge);
    border-width: 2px;
}
.calendar__date {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 2px;
}
.calendar__task {
    display: block;
    font-size: 13px;
    margin-bottom: 2px;
    padding: 4px;
    background: var(--surface);
    border-left: 3px solid var(--accent);
    text-decoration: none;
    color: inherit;
    width: 100%;
    min-width: 0; /* required alongside white-space:nowrap for ellipsis to actually clip */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* A task still open on a day that has already passed — the fact this
   screen exists to surface, so it must not look like every other task on
   the grid. */
.calendar__task--breached {
    border-left-color: var(--critical);
    background: var(--tint-crit);
}
.calendar__task.prio--critical {
    border-left-color: black;
}
.calendar__task.prio--high {
    border-left-color: var(--critical);
}
.calendar__task.prio--normal {
    border-left-color: var(--ok);
}
.calendar__task.prio--low {
    border-left-color: #11b5f7;
}

/* --- standard profile factor curve: server-rendered SVG bars --------------- */

.chart {
    width: 100%;
    height: auto;
    max-height: 180px;
    margin: var(--gap-sm) 0;
}
.chart__bar {
    fill: var(--accent);
}
.chart__bar:hover {
    fill: var(--accent-dark, var(--accent));
}

/* --- A14/C7: the week-calendar grid --------------------------------------- */

.calendar-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.calendar-grid {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
}
.calendar-grid th,
.calendar-grid td {
    border: 1px solid var(--border);
    padding: 0;
    text-align: center;
}
.calendar-grid th[scope="col"] {
    padding: 2px 4px;
    color: var(--secondary);
    font-weight: 400;
}
.calendar-grid th[scope="row"] {
    padding: 2px 8px;
    text-align: left;
    white-space: nowrap;
    font-weight: 600;
    background: var(--surface);
}
.calendar-cell {
    width: 40px;
    height: 40px;
    cursor: pointer;
    user-select: none;
}
.calendar-cell:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
}
/* a zone's pastel fill is light in both themes, so a dark outline shows on it */
.calendar-cell[class*="zone-"]:not(.zone-empty):focus-visible {
    outline-color: #0b0b0d;
}

.calendar-cell.zone-empty {
    background: var(--bg);
}
.calendar-cell.zone-total {
    background: #cfe8ff;
}
.calendar-cell.zone-dzienna {
    background: #ffe8a3;
}
.calendar-cell.zone-nocna {
    background: #b9c4e0;
}
.calendar-cell.zone-szczyt {
    background: #f6a3a3;
}
.calendar-cell.zone-pozaszczyt {
    background: #a3e6b8;
}
.calendar-cell.zone-dzienna_szczytowa {
    background: #f5c26b;
}
.calendar-cell.zone-dzienna_pozaszczytowa {
    background: #f5e26b;
}
.calendar-cell.zone-nocna_pozaszczytowa {
    background: #9bb8e6;
}

/* ==========================================================================
   7. Responsive

   Breakpoints:
     1024px — sidebar narrows, 12-col grids fall back to 6-col (spans halve
              their effective weight, so a 12-col layout doesn't fully
              collapse before it needs to).
     768px  — sidebar becomes an off-canvas panel opened by the hamburger
              button, all multi-column grids stack to a single column,
              tables scroll horizontally instead of squeezing.
   ========================================================================== */

@media (max-width: 1024px) {
    :root {
        --sidebar-width: 220px;
    }

    main {
        padding-left: var(--gap-md);
        padding-right: var(--gap-md);
        gap: var(--gap-md);
    }

    .u-grid--cols-12,
    .filters,
    .filters__grid,
    .form__grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
    /* halve every 12-col span so existing span-N markup still reads sensibly
       on a 6-col grid, instead of every item overflowing to its own row */
    .u-span-3 {
        grid-column: span 2;
    }
    .u-span-4 {
        grid-column: span 2;
    }
    .u-span-6 {
        grid-column: span 3;
    }
    .u-span-8 {
        grid-column: span 4;
    }
    .u-span-9 {
        grid-column: span 5;
    }
    .u-span-10 {
        grid-column: span 5;
    }
    .u-span-12 {
        grid-column: span 6;
    }

    table.data {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

@media (max-width: 768px) {
    .layout {
        flex-direction: column;
    }

    /* sidebar becomes an off-canvas panel, opened via the checkbox-hack toggle */
    .sidebar {
        width: 260px;
        max-width: 80vw;
        border-right: 1px solid var(--border);
        border-bottom: none;
        padding: var(--gap-sm) 0 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow-md);
        z-index: 100; /* see z-index scale — above the backdrop and the topbar */
    }
    .layout:has(.sidebar-toggle-input:checked) .sidebar {
        transform: translateX(0);
    }

    .sidebar nav {
        flex-direction: column;
        flex-wrap: nowrap;
    }
    .nav-user {
        margin-top: auto;
        border-top: 1px solid var(--border);
    }

    .sidebar-toggle-label {
        display: flex;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 50; /* see z-index scale at top of file — same tier as .breadcrumbs/.options */
    }

    .layout:has(.sidebar-toggle-input:checked) .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 90; /* see z-index scale — below the sidebar, above the topbar */
    }

    .content {
        margin-left: 0;
        margin-top: calc(var(--topbar-bar-height) + var(--gap-sm));
        padding: 0 var(--gap-sm) var(--gap-sm);
    }
    /* No trail to keep readable here, and the hamburger and options trigger carry their
       own surface — the page can just scroll under them. */
    .topbar::before {
        display: none;
    }

    /* The sidebar's hamburger + nav already answer "where am I" on mobile, and
       screen space is tight — the breadcrumb trail adds nothing there. */
    .breadcrumbs {
        display: none;
    }

    /* .options itself only appears as a dropdown once the checkbox is checked — the
       trigger button stands in until then. */
    .options-toggle-input:not(:checked) ~ .options {
        display: none;
    }
    .options-menu__trigger {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        position: fixed;
        top: 16px;
        right: 16px;
        z-index: 50; /* see z-index scale at top of file */
        width: 44px;
        height: 44px;
        padding: 10px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background-color: var(--surface);
        box-shadow: var(--shadow-sm);
        box-sizing: border-box;
        cursor: pointer;
    }
    /* pages with no page options have nothing to open */
    .topbar:not(:has(.options > *)) .options-menu__trigger {
        display: none;
    }
    .options-menu__trigger span {
        display: block;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--text);
    }
    .options-toggle-input:checked ~ .options {
        position: fixed;
        top: 68px; /* below the 44px trigger at top:16px, plus a gap */
        right: 16px;
        left: auto;
        flex-direction: column;
        align-items: stretch;
        max-width: 80vw;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 8px;
        box-shadow: var(--shadow-md);
        z-index: 50; /* see z-index scale at top of file */
    }

    main {
        padding: var(--gap-sm);
        gap: var(--gap-md);
    }

    h1 {
        font-size: 24px;
    }

    /* headers (title + badges), inline forms and button rows wrap instead of overflowing */
    .u-flex--between,
    .u-flex.u-gap-16 {
        flex-wrap: wrap;
    }

    /* the 4-column key/value grid has no room for two pairs side by side */
    .dl--cols-2 {
        grid-template-columns: fit-content(40%) minmax(0, 1fr);
    }

    /* tabs scroll sideways on their own rail instead of shrinking into the ellipsis */
    .submenu {
        overflow-x: auto;
    }
    .submenu__list > li {
        flex: 0 0 auto;
    }

    /* touch targets; a label longer than the phone (a download named after its file) wraps
       inside its button instead of widening the page */
    .button {
        min-height: 44px;
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    .button--small {
        min-height: 36px;
    }
    input,
    select {
        height: 44px;
    }

    .u-grid--cols-2,
    .u-grid--cols-3,
    .u-grid--cols-4,
    .u-grid--cols-6,
    .u-grid--cols-12,
    .filters,
    .filters__grid,
    .form__grid {
        grid-template-columns: minmax(
            0,
            1fr
        ); /* `1fr` alone lets wide inputs push the grid past the page */
    }
    .filters__field,
    .form__field {
        grid-column: 1 / -1 !important; /* overrides the per-field inline `style="grid-column: span N"` */
    }
    .filters__grid--row > .filters__field {
        flex-basis: 100%;
    }
    .u-span-3,
    .u-span-4,
    .u-span-6,
    .u-span-8,
    .u-span-9,
    .u-span-10,
    .u-span-12 {
        grid-column: span 1;
    }

    .cards li {
        min-width: 0;
        flex-basis: 100%;
    }

    /* segmented-control filter tags stack vertically instead of squeezing */
    .filters__tags {
        flex-direction: column;
        height: auto;
    }
    .filters__tag + .filters__tag {
        margin-top: -1px;
        margin-left: 0;
    }
    .filters__tag span {
        height: 44px;
        border-radius: 0 !important;
    }
    .filters__tag:first-child span {
        border-top-left-radius: var(--radius) !important;
        border-top-right-radius: var(--radius) !important;
    }
    .filters__tag:last-child span {
        border-bottom-left-radius: var(--radius) !important;
        border-bottom-right-radius: var(--radius) !important;
    }

    table.data {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    table.calendar,
    table.calendar tbody,
    table.calendar tr {
        width: max-content;
        min-width: 100%;
    }

    .board__columns {
        padding-bottom: 12px;
    }
    .board__column {
        flex: 0 0 260px;
    } /* stop columns from being crushed on a scroll rail */
}

/* --- checkboxes with their label beside them (partials/forms/_form_field.html) ---------------- */

.form__field label.form__check {
    display: flex;
    align-items: center;
    gap: var(--gap-sm);
    cursor: pointer;
    color: var(--text);
    font-size: 14px;
    letter-spacing: normal;
    text-transform: none;
}
/* A box in a repeatable row has no label above it: it skips the label line of the fields
   beside it (17 line + the field's gap), so its top edge lines up with their inputs'. */
.formset-row .form__field:has(.form__check) {
    justify-content: flex-start;
    padding-top: calc(17px + var(--gap-xs));
}
/* The dropzone is a control, not a label: its text reads like an input's. */
.form__field label.file-drop {
    color: var(--text);
    font-size: 14px;
    letter-spacing: normal;
    text-transform: none;
}

/* ppe-row: one PPE on the contract (agreement-prepare, A3) — its own master data
   plus the list of dated periods below. */
.ppe-row {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.ppe-row__title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}
/* Inline next to the number now, not below a search input — no top margin. */
.ppe-row__title .ppe-search__status {
    margin-top: 0;
}
.ppe-row__periods {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
/* ppe-period: one dated version of a PPE's tariff, trade fee, price, and
   technical parameters. Its own border nested inside `.ppe-row`'s, so a PPE
   with several periods still reads as one PPE with a history, not a list of
   unrelated boxes. */
.ppe-period {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    background: var(--bg);
}
.ppe-period__header {
    gap: 16px;
}
.ppe-period__from {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
}
.ppe-period__technical[open] > summary {
    margin-bottom: 16px;
}
.ppe-period__group {
    margin: 0;
    font-size: 14px;
}
/* No row of its own, and so no gap, until a tariff brings a period's zone prices in. */
.ppe-period [data-zone-fields]:not(:has(*)) {
    display: none;
}
/* Only a prosumer has an installation to describe. The values stay in the form while
   hidden, so ticking the box by mistake and back loses nothing. */
.ppe-period:not(:has(input[name$="-is_prosumer"]:checked)) .ppe-period__prosumer {
    display: none;
}
/* Only with the PPE's own zone prices to keep: on a fixed price quoted per tariff. */
.ppe-period__keep-zones {
    display: none;
}
.ppe-row:has(input[name$="-scenario_type"][value="fix_price"]:checked):has(
        input[name$="-price_mode"][value="tariffs"]:checked
    )
    .ppe-period__keep-zones {
    display: block;
}

/* "Adres korespondencyjny taki sam jak siedziba": the copied address is not asked for. */
.fieldset:has(input[name="same_as_registered"]:checked)
    .form__field:has([name^="correspondence_"]) {
    display: none;
}

/* --- repeatable rows (partials/forms/_formset_row.html) --------------------------------------- */

.formset-row__note,
.formset-row__undo-label {
    display: none;
}
.formset-row:has(input[name$="-DELETE"]:checked) .formset-row__note,
.formset-row:has(input[name$="-DELETE"]:checked) .formset-row__undo-label {
    display: inline;
}
.formset-row:has(input[name$="-DELETE"]:checked) .formset-row__remove-label {
    display: none;
}
.formset-row:has(input[name$="-DELETE"]:checked)
    .form__field:not(:has(.formset-row__remove)) {
    opacity: 0.4;
    text-decoration: line-through;
}
.form__field label.formset-row__remove {
    justify-content: center;
    cursor: pointer;
    color: #fff;
    font-size: inherit;
    letter-spacing: normal;
    text-transform: none;
}
.formset-row__remove:has(input:focus-visible) {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}
.formset-row:has(input[name$="-DELETE"]:checked)
    .form__field
    label.formset-row__remove {
    background: none;
    color: var(--muted);
    border-color: var(--border);
}

/* --- PUP bulk-file preview: one PP per (very long) line, so scroll, never wrap ---- */

.pup-preview {
    max-height: 480px;
    overflow: auto;
    white-space: pre;
    font-size: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--gap-sm);
    margin: 0;
}

.pup-file td,
.pup-file th {
    white-space: nowrap;
}
.pup-dialog {
    margin: auto; /* the global reset zeroes the UA centring of a modal dialog */
    width: min(720px, 92vw);
    max-height: 85vh;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: var(--gap-sm);
}
.pup-dialog::backdrop {
    background: rgb(0 0 0 / 40%);
}
.pup-dialog__body {
    max-height: 70vh;
    overflow: auto;
    margin-top: 16px;
}
.pup-dialog__missing td {
    color: var(--muted);
    font-style: italic;
}

/* A code with its meaning in a tooltip (`code_meaning`): dotted, like an <abbr>. */
.u-code {
    text-decoration: underline dotted;
    text-underline-offset: 2px;
    cursor: help;
}

/* --- reduced motion --------------------------------------------------------------- */

/* Somebody whose system asks for less motion gets every change of state at once: the
   progress bar and the narrow screen's sliding sidebar jump instead of gliding. The charts
   do the same in their scripts (`consumption_chart.js`; `meter_month_chart.js` never
   animates). Everything else here is still. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0s !important;
        animation-duration: 0s !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }
}
