.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: block;
}

.htmx-request.htmx-indicator {
    display: block;
}

/* Left navigation. From lg up the page is two columns: a fixed-width
   sidebar that stays in view while the content scrolls, and the content.
   Below lg the sidebar's markup is an offcanvas drawer (see layout.html), so
   none of this applies and the content takes the full width. */
.app-content {
    min-width: 0; /* lets wide tables scroll inside instead of stretching the page */
}

/* Bootstrap sizes .container by the viewport's width, but next to the
   sidebar the content column is narrower than the viewport — a container
   would stick out and the page scroll sideways. Cap it at the column. */
.app-content .container {
    max-width: min(100%, 1320px);
}

/* Beside the sidebar the content starts at the sidebar instead of being
   centered in a wide window. Anonymous pages (no sidebar) stay centered. */
.app-sidebar ~ .app-content .container {
    margin-left: 0;
    /* The same gap beside the content as above it (the pages' py-4). */
    padding-inline: 1.5rem;
}

/* Phones: half the gap, on all four sides, so the content keeps the width.
   !important because the pages set their vertical padding with a utility
   class (py-4 / py-5). */
@media (max-width: 767.98px) {
    .app-sidebar ~ .app-content .container {
        padding-inline: 0.75rem;
    }

    .app-sidebar ~ .app-content main.container {
        padding-block: 0.75rem !important;
    }
}

.app-sidebar .offcanvas-body {
    flex-direction: column;
    gap: 1rem;
}

/* The logo (img/logo.svg, the Bulgarian lockup: mark + name). In the
   sidebar it fills the width; in the top bars it is sized by height. */
.app-sidebar-brand {
    display: block;
}

.app-logo {
    height: 2.5rem;
}

.app-logo-hero {
    width: min(100%, 20rem);
}

/* Landing and login: one column in the middle of the window, on a tinted
   page, with the logo in the content itself — so the anonymous top bar,
   which only carries the logo, is dropped on these pages. */
.app-centered {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
}

.app-centered-panel {
    width: min(100%, 24rem);
}

body:has(.app-centered) {
    background-color: var(--bs-tertiary-bg);
}

body:has(.app-centered) > header {
    display: none;
}

/* The account menu sits between the logo and the navigation, with a little
   more air than the sidebar's own gap gives. */
.app-sidebar-user {
    margin-block: 0.25rem 0.5rem;
}

/* What can be clicked in the account menu is in the primary colour, like
   the navigation's links (through the dropdown's own variables, so hover
   and focus keep working); headers and the current user's name are not. */
.app-sidebar-user .dropdown-menu {
    --bs-dropdown-link-color: var(--bs-primary);
    --bs-dropdown-link-hover-color: var(--bs-link-hover-color);
}

/* Bootstrap colours plain item text with the link colour too. */
.app-sidebar-user .dropdown-item-text {
    color: var(--bs-body-color);
}

/* The account menu grows with the longest name instead of following the
   button's width, so names are shown in full; only a name longer than the
   cap (or the window) wraps. It is positioned fixed (layout.html: the
   toggle's popper config) because the sidebar is a scroll box and would
   clip it — so its minimum is the sidebar's inner width in rem, not 100%,
   which would then mean the window. */
.app-sidebar-user .dropdown-menu {
    min-width: 13rem;
    width: max-content;
    max-width: min(36rem, calc(100vw - 2rem));
}

.app-sidebar-user .dropdown-item,
.app-sidebar-user .dropdown-item-text,
.app-sidebar-user .dropdown-header {
    padding-inline: 0.75rem;
}

.app-sidebar-user .dropdown-item {
    font-size: 0.9375rem;
    white-space: normal;
}

/* The drawer's body is a block by default; make it a column there too. */
.app-sidebar .offcanvas-body {
    display: flex;
}

@media (min-width: 992px) {
    .app-shell {
        display: flex;
    }

    .app-sidebar {
        flex: 0 0 15rem;
        position: sticky;
        top: 0;
        height: 100vh;
        overflow-y: auto;
        background-color: var(--bs-tertiary-bg);
        border-right: 1px solid var(--bs-border-color);
        /* Bootstrap's own shadow (what .shadow applies), cast onto the
           content; z-index keeps the content from painting over it. */
        box-shadow: var(--bs-box-shadow);
        z-index: 1;
    }

    .app-sidebar .offcanvas-lg,
    .app-sidebar .offcanvas-lg .offcanvas-body {
        height: 100%;
    }

    /* Bootstrap zeroes the body's padding once the drawer becomes static. */
    .app-sidebar .offcanvas-lg .offcanvas-body {
        padding: 1rem;
    }

    .app-content {
        flex: 1 1 auto;
    }
}

/* Label/value pairs on detail pages (ported from the Django app). */
.properties {
    display: grid;
    grid-template: auto / auto 1fr;
}

.properties > div {
    display: inline-block;
    margin-top: 0.2rem;
}

.properties > div:nth-child(2n) {
    margin-left: 1rem;
}

.properties > div:nth-child(2n+1) {
    font-weight: bolder;
}

/* Form and details cards keep one comfortable width whatever the window:
   they only get narrower when the content area itself is narrower. */
.app-card-column {
    max-width: 42rem;
}

/* Details card: one list group item per property — a fixed label column,
   then the value — padded like the card's header and footer. */
.detail-list > .list-group-item {
    display: grid;
    grid-template-columns: 9rem 1fr;
    column-gap: 1rem;
    align-items: baseline;
    padding: 0.75rem 1.5rem;
}

.detail-list > .list-group-item > div:first-child {
    font-weight: bolder;
}

/* A list inside a value is nested in the list group's <ul>, which would
   give it hollow bullets. */
.detail-list ul {
    list-style-type: disc;
}

/* Completed month rows keep the soft green the old app used. Bootstrap 5
   applies table variant backgrounds via this CSS variable, not
   background-color on the cells. */
.table-success {
    --bs-table-bg: #F1FFF7;
}

/* Column headers (incl. the sort links + carets) stay on one line. */
.table thead th {
    white-space: nowrap;
}

/* Before Select2 initializes, a native multi-select would render as a
   multi-row listbox and make the page jump; cap it to one control height
   (Select2 hides the original element right after init). */
select.js-select2[multiple],
select.js-select2-modal[multiple] {
    height: calc(1.5em + 0.75rem + 2px);
    overflow: hidden;
}

/* The select2 bootstrap-5 theme renders multi-selects two lines tall: the
   inline search is a full-width block row, and chips wrap inside their own
   <ul> while the search sits outside it. Overrides: the selection box is one
   wrapping flex row; display:contents dissolves the ul so chips and search
   share that flow — the cursor sits right after the last chip and rows only
   appear when chips genuinely wrap (spaced via row-gap). Chips lose the
   theme's vertical padding and unconditional bottom margin, keeping them at
   text height, centered, without growing the control. */
.select2-container--bootstrap-5 .select2-selection--multiple {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    row-gap: 0.25rem;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered {
    display: contents;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-search {
    display: inline-flex;
    width: auto;
    min-width: 4rem;
    flex-grow: 1;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-search .select2-search__field {
    width: 100%;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered .select2-selection__choice {
    /* Exactly one text line tall (the 1px borders draw inside), so a chip
       never grows the control: empty and selected are both 38px. */
    height: 1.5em;
    box-sizing: border-box;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered .select2-selection__choice .select2-selection__choice__remove {
    width: 1rem;
    height: 1rem;
    margin-right: 0.5rem;
    border-radius: 0.25rem;
}

/* Inverted danger look on hover: red square, white x (the theme's own glyph
   with the fill flipped). */
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered .select2-selection__choice .select2-selection__choice__remove:hover {
    background: var(--bs-danger) url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23fff'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e") center/0.5rem auto no-repeat;
}

/* bootstrap-datepicker ships Bootstrap 3 looks: a fixed small font and its
   own blue. Give the popup the page's font size (the selector repeats the
   library's, which a bare .datepicker would lose to) and the chosen month
   the page's primary colour. */
.datepicker.dropdown-menu {
    font-size: var(--bs-body-font-size);
    padding: 0.75rem;
}

/* The year in the header, which is also the button to the year grid. */
.datepicker .datepicker-switch {
    font-size: 1.25rem;
}

/* Room between the header row (arrows, year) and the grid below it. It is
   padding on the grid's cell, not on the header cells: those get a hover
   background, which padding there would stretch downwards. The selector has
   to outrank the library's own cell padding. */
.datepicker.dropdown-menu .datepicker-months tbody td,
.datepicker.dropdown-menu .datepicker-years tbody td,
.datepicker.dropdown-menu .datepicker-decades tbody td,
.datepicker.dropdown-menu .datepicker-centuries tbody td {
    padding-top: 0.75rem;
}

/* Month and year cells: the library makes them 54px tall and a quarter of a
   narrow table wide, so the highlight was much taller than the text. A lower
   cell in a wider table gives it even padding all round. */
.datepicker.dropdown-menu table {
    width: 15rem;
}

.datepicker table tr td span {
    height: 2.25rem;
    line-height: 2.25rem;
}

.datepicker table tr td span.active {
    /* !important: the library styles every hover/focus/disabled combination
       of .active with its own, longer selectors. */
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
}

/* Yearly plan grid (location details, monthly report): each test is one
   line — text, then the notes icon — and the cell's content starts at the
   top, so rows of different heights line up. */
.plan-cell {
    vertical-align: top;
}

/* The notes icon follows the text of its bullet. */
.plan-test-text + .bi {
    margin-inline-start: 0.25rem;
}

/* The editable line is a link; its underline sits on the label only, not
   on the template's whitespace around it. */
a.plan-test-text {
    text-decoration: none;
}

a.plan-test-text .plan-test-label {
    text-decoration: underline;
}

/* The add button sits at the bottom of its cell, so the buttons of a row
   line up whatever the cells hold. It is taken out of the flow and the cell
   reserves its room: the button's height (a btn-sm, 1.9375rem) plus the
   cell's own 0.25rem below it, and 0.5rem more under a list of tests. */
.plan-cell:has(.plan-add) {
    position: relative;
    padding-bottom: 2.1875rem;
}

.plan-cell:has(.plan-test):has(.plan-add) {
    padding-bottom: 2.6875rem;
}

.plan-add {
    position: absolute;
    bottom: 0.25rem;
    left: 0.25rem;
}

/* Files dropdown: its list is a table filling the menu edge to edge (the
   menu's own padding would leave the stripes floating), cells centered
   against the delete button, no line under the last row. The menu is capped
   to the window: a long name wraps instead of pushing the delete buttons
   off screen, and a long list scrolls inside the menu. */
.files-menu {
    width: max-content; /* as wide as its longest name, up to the cap */
    max-width: min(48rem, calc(100vw - 2rem));
}

.files-menu:has(table) {
    padding: 0;
    max-height: min(28rem, 70vh);
    overflow-y: auto; /* also clips the stripes to the rounded corners */
}

.files-menu td {
    vertical-align: middle;
    padding: 0.375rem 0.75rem;
    white-space: nowrap;
}

.files-menu td:first-child {
    white-space: normal;
    overflow-wrap: break-word;
}

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

/* Select2's open list gets the same shadow as Bootstrap's dropdown menus
   (.shadow); the selector matches the theme's own so it is not outweighed. */
.select2-container--bootstrap-5 .select2-dropdown {
    box-shadow: var(--bs-box-shadow);
}

/* A dialog's button while its request is running: htmx puts .htmx-request
   on the form that was submitted (or on the button, when the button makes
   the request itself, like Delete), and the button swaps its icon for a
   spinner. Only that button: Delete sits inside the form too. */
.app-busy {
    display: none;
}

form.htmx-request [type="submit"] .app-busy,
button.htmx-request .app-busy {
    display: inline-block;
}

form.htmx-request [type="submit"] .app-idle,
button.htmx-request .app-idle {
    display: none;
}

