/*
 * Shared by the frontend and the backend: see app-shell.js for what the application shell is.
 */

/* ---- moving between pages -------------------------------------------------------------------
 * The browser keeps the old page on screen until the new one is ready, then fades it in. The
 * sidebar and the header are given names so they are swapped in place, not faded: they look as
 * if they never went away. Browsers without view transitions simply load pages as before. */
@view-transition {
    navigation: auto;
}

@media (prefers-reduced-motion: reduce) {
    @view-transition {
        navigation: none;
    }
}

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 140ms;
    animation-timing-function: ease-out;
}

.app-sidebar {
    view-transition-name: app-sidebar;
}

.app-header {
    view-transition-name: app-header;
}

.app-bottom-nav {
    view-transition-name: app-bottom-nav;
}

::view-transition-group(app-sidebar),
::view-transition-group(app-header),
::view-transition-group(app-bottom-nav),
::view-transition-new(app-sidebar),
::view-transition-new(app-header),
::view-transition-new(app-bottom-nav) {
    animation: none;
}

::view-transition-old(app-sidebar),
::view-transition-old(app-header),
::view-transition-old(app-bottom-nav) {
    animation: none;
    opacity: 0;
}

/* ---- loading bar ------------------------------------------------------------------------- */
.app-shell-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    height: 3px;
    background: #2f6fa8;
    transform: scaleX(0);
    transform-origin: 0 50%;
    opacity: 0;
    pointer-events: none;
    transition: transform .25s ease-out, opacity .3s ease;
}

.app-shell-progress.is-active {
    opacity: 1;
}

.app-shell-progress.is-done {
    opacity: 0;
    transition: transform .15s ease-out, opacity .3s ease .15s;
}

/* ---- touch ------------------------------------------------------------------------------- */
html {
    -webkit-tap-highlight-color: transparent;
}

/* a double tap on a control is two taps, not a zoom */
a,
button,
input,
select,
textarea,
label,
.btn,
.nav-link {
    touch-action: manipulation;
}

/* pressing a control shows at once that it was pressed */
.btn:active:not(:disabled):not(.disabled),
.app-bottom-nav-link:active {
    transform: scale(.97);
}

.btn {
    transition: transform .08s ease, color .15s ease-in-out, background-color .15s ease-in-out,
        border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}

/* ---- bottom navigation (phones) ----------------------------------------------------------
 * The same few places the header and the sidebar already lead to, within reach of a thumb. */
.app-bottom-nav {
    display: none;
}

@media (max-width: 767.98px) {
    .app-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1034;
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        min-height: 3.6rem;
        padding: .25rem .25rem calc(.25rem + env(safe-area-inset-bottom, 0px));
        background: #fff;
        border-top: 1px solid #dbe4ee;
    }

    /* the bar's measured height (app-shell.js); its usual height until the script has run */
    body:has(.app-bottom-nav),
    body.has-app-bottom-nav {
        padding-bottom: var(--app-bottom-nav-height, calc(3.6rem + env(safe-area-inset-bottom, 0px)));
    }

    /* The page is one screen tall with the bar's room in it, not under it, so a short page does
       not scroll into empty space. dvh is the screen as seen; vh counts the browser's address bar. */
    body:has(.app-bottom-nav) .app-wrapper,
    body:has(.app-bottom-nav) .app-main-wrapper,
    body.has-app-bottom-nav .app-wrapper,
    body.has-app-bottom-nav .app-main-wrapper {
        min-height: calc(100vh - var(--app-bottom-nav-height, calc(3.6rem + env(safe-area-inset-bottom, 0px))));
        min-height: calc(100dvh - var(--app-bottom-nav-height, calc(3.6rem + env(safe-area-inset-bottom, 0px))));
    }

    .app-bottom-nav {
        transition: transform .18s ease;
    }

    /* the on-screen keyboard is up: the bar steps aside so it does not cover the form */
    .app-typing .app-bottom-nav {
        transform: translateY(110%);
    }

    /* the drawer opens over the bar, as it opens over the rest of the page */
    body.sidebar-open .app-bottom-nav {
        z-index: 1030;
    }
}

.app-bottom-nav-link {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .15rem;
    padding: .3rem .15rem;
    border: 0;
    border-radius: .7rem;
    background: transparent;
    color: #5a6d82;
    font: inherit;
    font-size: .68rem;
    font-weight: 600;
    line-height: 1.1;
    text-decoration: none;
    -webkit-user-select: none;
    user-select: none;
    transition: color .15s ease, background-color .15s ease, transform .08s ease;
}

.app-bottom-nav-link > i {
    font-size: 1.25rem;
    line-height: 1;
}

/* a long label takes a second line rather than being cut */
.app-bottom-nav-label {
    max-width: 100%;
    overflow: hidden;
    text-align: center;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    /* with large system text a long word splits across the two lines instead of being cut */
    -webkit-hyphens: auto;
    hyphens: auto;
    overflow-wrap: anywhere;
}

/* folded and small phones: a word like "Applications" must still fit its tab */
@media (max-width: 339.98px) {
    .app-bottom-nav {
        padding-left: 0;
        padding-right: 0;
    }

    .app-bottom-nav-link {
        padding-left: 0;
        padding-right: 0;
        font-size: .6rem;
    }
}

.app-bottom-nav-link:hover,
.app-bottom-nav-link:focus-visible {
    color: #15344f;
    background: #eef3f8;
}

.app-bottom-nav-link.is-active {
    color: #1d5a94;
}

.app-bottom-nav-link.is-active > i {
    transform: translateY(-1px);
}

.app-bottom-nav-link.is-danger > i {
    color: #c9302c;
}

.app-bottom-nav-badge {
    position: absolute;
    top: .15rem;
    left: calc(50% + .35rem);
    min-width: 1.1rem;
    height: 1.1rem;
    padding: 0 .3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #dc3545;
    color: #fff;
    font-size: .62rem;
    font-weight: 700;
    line-height: 1;
}

/* ---- phones: give the width to the content ---------------------------------------------------
 * On a desktop each panel inside a panel adds its own padding; on a 390px screen three of them
 * take a fifth of the width before any text. Inner boxes keep a small, even inset instead. */
@media (max-width: 575.98px) {
    main .row {
        --bs-gutter-x: .75rem;
    }

    main .container,
    main .container-fluid {
        padding-left: .4rem;
        padding-right: .4rem;
    }

    main .card-body,
    main .card-header,
    main .card-footer,
    main .accordion-body,
    main .accordion-button,
    main .modal-body {
        padding-left: .75rem;
        padding-right: .75rem;
    }

    main .tab-content {
        padding-left: 0;
        padding-right: 0;
    }

    main td.ps-4,
    main th.ps-4 {
        padding-left: .75rem !important;
    }

    main td.pe-4,
    main th.pe-4 {
        padding-right: .75rem !important;
    }
}

/* ---- list filters on phones ---------------------------------------------------------------
 * Below 768px a list's filters fold behind a Filters button, with a chip for each one in use
 * (app-shell.js); opened, they show where they were. Larger screens keep them in the table. */
.app-filter-bar,
.app-filter-foot {
    display: none;
}

@media (max-width: 767.98px) {
    table > thead > tr.filters[data-app-filters]:not(.is-open) {
        display: none !important;
    }

    .app-filter-bar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: .4rem;
        margin: 0 0 .65rem;
    }

    .app-filter-toggle,
    .app-filter-chip {
        display: inline-flex;
        align-items: center;
        gap: .4rem;
        max-width: 100%;
        min-height: 2.5rem;
        border: 1px solid #d5dfe9;
        background: #fff;
        color: #1f3b57;
        line-height: 1.2;
    }

    .app-filter-toggle {
        padding: .4rem .85rem;
        border-radius: .5rem;
        font-size: .88rem;
        font-weight: 600;
    }

    .app-filter-toggle[aria-expanded="true"] {
        border-color: #9dbbd8;
        background: #eef4fb;
    }

    .app-filter-count {
        min-width: 1.35rem;
        padding: 0 .35rem;
        border-radius: 999px;
        background: var(--bs-link-color, #245f8f);
        color: #fff;
        font-size: .75rem;
        line-height: 1.35rem;
        text-align: center;
    }

    .app-filter-chip {
        gap: .3rem;
        padding: .3rem .65rem .3rem .75rem;
        border-color: #c9daea;
        border-radius: 999px;
        background: #eef4fb;
        font-size: .82rem;
        text-align: left;
    }

    .app-filter-chip-name {
        flex: none;
        color: #5f7084;
    }

    .app-filter-chip-value {
        min-width: 0;
        overflow: hidden;
        font-weight: 600;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-filter-chip .bi {
        flex: none;
        margin-left: .15rem;
        color: #5f7084;
        font-size: .75rem;
    }

    .app-filter-clear {
        min-height: 2.5rem;
        padding: .3rem .5rem;
        border: 0;
        background: transparent;
        color: var(--bs-link-color, #245f8f);
        font-size: .82rem;
        font-weight: 600;
    }
}

/* ---- lists on phones ----------------------------------------------------------------------
 * Below 480px the grid library stacks a row's cells into a centred column. Each row becomes a
 * card instead, every value beside its column's name (set by app-shell.js), and the column names
 * that sort the list stay as a row of buttons above the cards. Same breakpoint as the library's. */
@media (max-width: 480px) {
    table.table.kv-table-wrap {
        min-width: 0 !important;
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
        background: transparent;
    }

    table.table.kv-table-wrap > thead,
    table.table.kv-table-wrap > tbody {
        display: block;
        background: transparent;
    }

    /* column names: only those that sort, as buttons that wrap */
    table.table.kv-table-wrap > thead > tr:not(.filters) {
        display: flex;
        flex-wrap: wrap;
        gap: .4rem;
        padding: .15rem 0 .65rem;
        background: transparent;
        border: 0;
    }

    table.table.kv-table-wrap > thead > tr:not(.filters):not(:has(a)) {
        display: none;
    }

    table.table.kv-table-wrap > thead > tr:not(.filters) > th {
        display: none;
    }

    table.table.kv-table-wrap > thead > tr:not(.filters) > th:has(a) {
        display: block;
        width: auto !important;
        min-width: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        font-size: .78rem;
        text-align: left;
    }

    table.table.kv-table-wrap > thead > tr:not(.filters) > th > a {
        display: inline-flex;
        align-items: center;
        gap: .25rem;
        padding: .3rem .7rem;
        border: 1px solid #d5dfe9;
        border-radius: .4rem;
        background: #fff;
        white-space: nowrap;
        text-decoration: none;
    }

    table.table.kv-table-wrap > thead > tr:not(.filters) > th > a.asc,
    table.table.kv-table-wrap > thead > tr:not(.filters) > th > a.desc {
        border-color: #9dbbd8;
        background: #eef4fb;
    }

    /* filters, once their Filters button opens them: a card of labelled fields right under it,
       above the sort buttons */
    table.table.kv-table-wrap > thead {
        display: flex;
        flex-direction: column;
    }

    table.table.kv-table-wrap > thead > tr.filters {
        display: block;
        order: -1;
        margin-bottom: .75rem;
        padding: .35rem 0;
        border: 1px solid #dbe4ee;
        border-radius: .5rem;
        background: #f8fbfe;
    }

    table.table.kv-table-wrap > thead > tr.filters > td.app-filter-foot {
        display: flex;
        justify-content: flex-end;
        padding-top: .5rem !important;
    }

    table.table.kv-table-wrap > thead > tr.filters > td {
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        padding: .3rem .85rem !important;
        border: 0 !important;
        background: transparent !important;
        text-align: left;
        font-size: .9rem;
    }

    table.table.kv-table-wrap > thead > tr.filters > td:not(:has(input, select, textarea)) {
        display: none;
    }

    table.table.kv-table-wrap > thead > tr.filters > td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: .2rem;
        color: #5f7084;
        font-size: .8rem;
        font-weight: 600;
    }

    /* each record: a card */
    table.table.kv-table-wrap > tbody > tr {
        display: block;
        margin: 0 0 .75rem;
        border: 1px solid #dbe4ee;
        border-radius: .5rem;
        /* every card alike: the stripes of a table mean nothing between cards */
        background: #fff !important;
        box-shadow: 0 1px 3px rgba(20, 40, 60, .05);
        overflow: hidden;
    }

    /* A cell becomes a two-column table: the name is one column and, as a table wraps
       whatever else it holds in one cell, the whole value (text, badges, links) the other. */
    table.table.kv-table-wrap > tbody > tr > td,
    table.table.kv-table-wrap > tbody > tr > td:first-child {
        display: table;
        table-layout: fixed;
        width: 100% !important;
        min-width: 0 !important;
        margin: 0;
        padding: .55rem .85rem !important;
        border: 0;
        border-top: 1px solid #eef2f6;
        background: transparent !important;
        box-shadow: none !important;
        --bs-table-bg-type: transparent;
        --bs-table-bg-state: transparent;
        text-align: left;
        font-size: .9rem;
        overflow-wrap: anywhere;
    }

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

    table.table.kv-table-wrap > tbody > tr > td[data-label]::before {
        content: attr(data-label);
        display: table-cell;
        width: 34%;
        padding-right: .75rem;
        color: #5f7084;
        font-size: .8rem;
        font-weight: 500;
        line-height: 1.45;
    }

    /* a cell with no column name (the row's buttons, a serial number) takes the whole width */
    table.table.kv-table-wrap > tbody > tr > td:not([data-label]) {
        display: block;
    }

    table.table.kv-table-wrap > tbody > tr > td.backend-table-action-cell,
    table.table.kv-table-wrap > tbody > tr > td.action-column,
    table.table.kv-table-wrap > tbody > tr > td.kv-align-center:not([data-label]) {
        display: flex;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: .35rem;
        background: #f8fbfe !important;
    }

    table.table.kv-table-wrap > tbody > tr > td.backend-table-action-cell::before,
    table.table.kv-table-wrap > tbody > tr > td.action-column::before {
        margin-right: auto;
    }

    /* a list with nothing in it */
    table.table.kv-table-wrap > tbody > tr > td[colspan] {
        display: block;
        text-align: center;
    }
}

/* ---- installed application ----------------------------------------------------------------
 * Opened from its icon there is no browser bar above the page; on a phone the header must
 * clear the status bar. */
@media (display-mode: standalone) {
    .app-header {
        padding-top: env(safe-area-inset-top, 0px);
    }
}

@media print {
    .app-shell-progress,
    .app-bottom-nav {
        display: none !important;
    }
}

/* ---- table toolbars ------------------------------------------------------------------------
 * TableWidget puts the actions views hand it (Add New, Add Schedule, ...) above the table. They
 * arrive in whatever style each view used; here they line up on the right, like a page's own
 * actions, at one size, the first as the main action and any others plain. */
.backend-table-widget .kv-panel-before {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem 1rem;
    padding: .25rem 0 .75rem;
    border: 0;
    background: transparent;
}

/* an empty description takes no room; a real one stays on the left */
.backend-table-widget .kv-panel-before > em:empty,
.backend-table-widget .kv-panel-before > .clearfix {
    display: none;
}

.backend-table-widget .kv-panel-before > em {
    order: -1;
    flex: 1 1 auto;
    color: #64748b;
    font-style: normal;
}

.backend-table-widget .kv-grid-toolbar {
    float: none !important;
    margin: 0;
}

.backend-table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem;
}

.backend-table-toolbar > .btn,
.backend-table-toolbar > .btn-group > .btn,
.backend-table-toolbar > .dropdown > .btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    min-height: 2.25rem;
    padding: .375rem .85rem;
    border: 1px solid #cfd9e3;
    border-radius: .5rem;
    background: #fff;
    color: #1e3a56;
    font-size: .875rem;
    font-weight: 600;
    line-height: 1.2;
    box-shadow: none;
}

.backend-table-toolbar > .btn:hover,
.backend-table-toolbar > .btn:focus-visible,
.backend-table-toolbar > .btn-group > .btn:hover,
.backend-table-toolbar > .dropdown > .btn:hover {
    border-color: #a9bccf;
    background: #f3f7fb;
    color: #1e3a56;
}

/* the first action is the main one: filled */
.backend-table-toolbar > .btn:first-child:not(.btn-danger),
.backend-table-toolbar > .btn-group:first-child > .btn,
.backend-table-toolbar > .dropdown:first-child > .btn {
    border-color: var(--app-action, #245f8f);
    background: var(--app-action, #245f8f);
    color: #fff;
}

.backend-table-toolbar > .btn:first-child:not(.btn-danger):hover,
.backend-table-toolbar > .btn:first-child:not(.btn-danger):focus-visible,
.backend-table-toolbar > .btn-group:first-child > .btn:hover,
.backend-table-toolbar > .dropdown:first-child > .btn:hover {
    border-color: var(--app-action-hover, #1d4f78);
    background: var(--app-action-hover, #1d4f78);
    color: #fff;
}

.backend-table-toolbar > .btn-danger {
    border-color: #dc3545;
    background: #fff;
    color: #b02a37;
}

/* what holds an action back, said where its button would be */
.backend-table-toolbar > span,
.backend-table-toolbar > .text-muted {
    color: #64748b;
    font-size: .875rem;
}

@media (max-width: 575.98px) {
    /* on a phone the main action spans the width, within reach */
    .backend-table-widget .kv-panel-before,
    .backend-table-toolbar {
        justify-content: stretch;
    }

    .backend-table-widget .kv-grid-toolbar,
    .backend-table-widget .kv-grid-toolbar > .btn-group,
    .backend-table-toolbar,
    .backend-table-toolbar > .btn:first-child {
        width: 100%;
    }

    .backend-table-toolbar > .btn:first-child {
        justify-content: center;
    }
}

/* the panel footer holds the pager: with one page of results there is none, and no footer */
.backend-table-widget .card-footer:not(:has(.pagination, .summary, a, button, input, select)) {
    display: none;
}

/* ---- stage steps on phones: one row that scrolls sideways ---------------------------------
 * custom.css wraps them onto as many rows as they need, one or two steps a row, so a process of
 * six steps pushed the stage itself a screen down. One row instead: each step a fixed width with
 * its name on up to two lines, the current one in view (app-shell.js), and a faded edge where
 * more steps lie beyond. The carousel's swipe is off (common.js), so a swipe scrolls the row.
 * Tablets get the same row: custom.css wrapped the steps onto a second line there. */
@media (max-width: 991.98px) {
    .process-widget .md-stepper-horizontal .carousel-inner {
        display: flex !important;
        flex-wrap: nowrap;
        justify-content: flex-start;
        width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .process-widget .md-stepper-horizontal .carousel-inner::-webkit-scrollbar {
        display: none;
    }

    .process-widget .md-stepper-horizontal .carousel-inner[data-more="end"] {
        -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
        mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
    }

    .process-widget .md-stepper-horizontal .carousel-inner[data-more="start"] {
        -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 2.5rem), transparent);
        mask-image: linear-gradient(to left, #000 calc(100% - 2.5rem), transparent);
    }

    .process-widget .md-stepper-horizontal .carousel-inner[data-more="start end"] {
        -webkit-mask-image: linear-gradient(to right, transparent, #000 2.5rem, #000 calc(100% - 2.5rem), transparent);
        mask-image: linear-gradient(to right, transparent, #000 2.5rem, #000 calc(100% - 2.5rem), transparent);
    }

    .process-widget .md-stepper-horizontal .carousel-item {
        display: block !important;
        flex: 0 0 6.25rem;
        width: 6.25rem;
        min-width: 0;
        margin: 0;
        float: none;
        transform: none !important;
        scroll-snap-align: center;
    }

    /* a few steps share the width rather than leaving it empty on the right */
    .process-widget .md-stepper-horizontal .carousel-item:first-child:nth-last-child(-n + 3),
    .process-widget .md-stepper-horizontal .carousel-item:first-child:nth-last-child(-n + 3) ~ .carousel-item {
        flex: 1 1 0;
        width: auto;
    }

    .process-widget .md-stepper-horizontal .md-step {
        height: 100%;
        padding: .45rem .25rem .5rem;
    }

    .process-widget .md-stepper-horizontal .md-step .md-step-circle {
        width: 30px;
        height: 30px;
        line-height: 30px;
        font-size: 12px;
    }

    .process-widget .md-stepper-horizontal .md-step .md-step-bar-left,
    .process-widget .md-stepper-horizontal .md-step .md-step-bar-right {
        top: 22px;
    }

    .process-widget .md-stepper-horizontal .md-step .md-step-title {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        margin-top: .3rem;
        font-size: .75rem;
        line-height: 1.25;
        text-align: center;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    /* the row has a first and a last step; each sits alone in its carousel item */
    .process-widget .md-stepper-horizontal .carousel-item:first-child .md-step-bar-left,
    .process-widget .md-stepper-horizontal .carousel-item:last-child .md-step-bar-right {
        display: none;
    }
}

/* ---- buttons in a stage's work and in dialogs: one shape, three sizes ----------------------
 * The components (application, review, payment, inspection, signature ...) wrote their buttons at
 * Bootstrap's 38px / 16px, the applicant side at 42px with a lift on hover, small ones at 34px
 * with other corners, while the rest of the application is 36px / 14px. The same shape for all
 * of them: 36px, 30px for a small one, 44px for the one large "submit" call; colours unchanged.
 * Buttons that belong to another control (an input group, a grid's row icons, the table
 * toolbar, the stage row) keep their own rules. */
:is(.process-content, .modal-content) .btn:not(.btn-link, .btn-close, .input-group .btn, .backend-table-action-cell .btn, .kv-panel-before .btn, .stage-actions .btn, .pagination .btn) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 2.25rem;
    padding: .375rem .875rem;
    font-size: .875rem;
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: normal;
    box-shadow: none;
    transform: none;
}

:is(.process-content, .modal-content) :not(.btn-group, .btn-group-vertical, .input-group) > .btn:not(.btn-link, .btn-close, .backend-table-action-cell .btn, .kv-panel-before .btn, .stage-actions .btn) {
    border-radius: .5rem;
}

:is(.process-content, .modal-content) .btn:not(.btn-link, .btn-close, .input-group .btn, .backend-table-action-cell .btn, .kv-panel-before .btn, .stage-actions .btn):hover {
    box-shadow: none;
    transform: none;
}

:is(.process-content, .modal-content) .btn.btn-sm:not(.btn-link, .input-group .btn, .backend-table-action-cell .btn, .kv-panel-before .btn, .stage-actions .btn) {
    min-height: 1.875rem;
    padding: .25rem .625rem;
    font-size: .8125rem;
}

:is(.process-content, .modal-content) .btn.btn-lg:not(.btn-link, .input-group .btn) {
    min-height: 2.75rem;
    padding: .5rem 1.25rem;
    font-size: .9375rem;
}

/* the actions above the stage row (associated documents, test capabilities) are page actions */
.process-content .primary-action > .btn.btn-sm:not(.btn-link, .input-group .btn) {
    min-height: 2.25rem;
    padding: .375rem .875rem;
    font-size: .875rem;
}

/* "Close" at the foot of a dialog reads as a button, at the same size as the one beside it */
.modal-footer .btn-default {
    border: 1px solid var(--bs-border-color, #dee2e6);
    background: #fff;
    color: #334155;
}

.modal-footer .btn-default:hover {
    background: #f1f5f9;
}

/* the decisions of a stage (approve, return, reject ...) under the stage row */
.stage-decision {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .5rem 0 1rem;
}

/* a dialog's own action row ends on the right, wherever its form put it */
.modal-body .process-inline-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem;
}

/* a stage form's Pause / Save and Continue end on the right in both portals */
.process-form-foot > .process-inline-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    width: 100%;
    justify-content: flex-end;
    gap: .5rem;
}

/* the payment actions are a row like the others, not a box inside the page */
.payment-action-panel.workspace-surface {
    padding: .25rem 0 .75rem;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.payment-action-panel > .payment-action-row {
    justify-content: center;
}

@media (max-width: 767.98px) {
    :is(.process-content, .modal-content) .btn:not(.btn-sm, .btn-link, .btn-close, .input-group .btn, .backend-table-action-cell .btn, .kv-panel-before .btn, .stage-actions .btn) {
        min-height: 2.5rem;
    }

    /* the decisions stack, the first (the main one) on top */
    .stage-decision {
        flex-direction: column;
        align-items: stretch;
    }

    :is(.process-inline-actions, .payment-action-row) > .btn {
        flex: 1 1 auto;
    }
}

/* ---- the lines between the stage steps ------------------------------------------------------
 * common.css hides the line before the first step and after the last with .md-step:first-child /
 * :last-child, but every step sits alone in its carousel item, so each one was both and no line
 * showed anywhere. The first and last are the carousel's items. */
.process-widget .md-stepper-horizontal .carousel-item .md-step .md-step-bar-left,
.process-widget .md-stepper-horizontal .carousel-item .md-step .md-step-bar-right {
    display: block;
}

.process-widget .md-stepper-horizontal .carousel-item:first-child .md-step .md-step-bar-left,
.process-widget .md-stepper-horizontal .carousel-item:last-child .md-step .md-step-bar-right {
    display: none;
}

/* a line is drawn in two halves, one by each step it joins, and each step coloured its own left
 * half: the line between two finished steps came out half grey, half green. The whole line now
 * takes the state of the step it leaves - green after a finished step, grey after the rest. */
.process-widget .md-stepper-horizontal .carousel-item .md-step .md-step-bar-left,
.process-widget .md-stepper-horizontal .carousel-item .md-step .md-step-bar-right {
    border-top-color: #e2e8f0;
}

.process-widget .md-stepper-horizontal .carousel-item .md-step.done .md-step-bar-right,
.process-widget .md-stepper-horizontal .carousel-item:has(> .md-step.done) + .carousel-item .md-step .md-step-bar-left {
    border-top-color: rgba(var(--bs-success-rgb), .55);
}

/* a long process has narrow steps: their names wrap under the circle instead of running into
 * the next one ("InspectionReview Inspection") */
@media (min-width: 768px) {
    .process-widget .md-stepper-horizontal .md-step .md-step-title {
        white-space: normal;
        text-align: center;
        line-height: 1.25;
    }

}

/* with names that wrap, the steps share the width a laptop leaves them (ten fit 700px); the
 * 100px each had pushed the last ones out of sight, with no way to scroll to them by mouse */
@media (min-width: 992px) {
    .process-widget .md-stepper-horizontal .carousel-item {
        min-width: 0;
    }

    .process-widget .md-stepper-horizontal .md-step {
        padding-right: .2rem;
        padding-left: .2rem;
    }
}

/* ---- a table as a value in a details list (DetailViewWidget) ----------------------------------
 * The label takes a row of its own and the table the whole width below it, instead of a narrow
 * value column beside a label that floats halfway down the table. */
.detail-view > tbody > tr > th.detail-table-label {
    width: auto !important;
    text-align: left !important;
    vertical-align: bottom !important;
    border-bottom: 0;
}

.detail-view > tbody > tr > td.detail-table-value {
    width: auto !important;
    padding-top: .25rem;
}

/* a wide table scrolls sideways within its row instead of stretching the whole list */
.detail-view > tbody > tr > td.detail-table-value > .kv-attribute {
    contain: inline-size;
    overflow-x: auto;
}

.detail-view > tbody > tr > td.detail-table-value .table {
    margin-bottom: 0;
}

/* One even frame around the table. Without it the rows draw their lines in the text colour (the
 * backend clears the table's border colour), the header has no side lines where the rows have
 * them, and rounded corners clip the top line. Phones show the rows as cards instead. */
@media (min-width: 481px) {
    .detail-view > tbody > tr > td.detail-table-value .kv-grid-container {
        border: 1px solid var(--clr-border, #dee2e6);
        border-radius: .5rem;
    }

    .detail-view > tbody > tr > td.detail-table-value .kv-grid-table {
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .detail-view > tbody > tr > td.detail-table-value .kv-grid-table > * > tr {
        border-color: var(--clr-border, #dee2e6);
    }

    .detail-view > tbody > tr > td.detail-table-value .kv-grid-table > * > tr > * {
        border-color: var(--clr-border, #dee2e6) !important;
        border-style: solid;
        border-width: 0 1px;
    }

    .detail-view > tbody > tr > td.detail-table-value .kv-grid-table > * > tr > :first-child {
        border-left-width: 0;
    }

    .detail-view > tbody > tr > td.detail-table-value .kv-grid-table > * > tr > :last-child {
        border-right-width: 0;
    }

    .detail-view > tbody > tr > td.detail-table-value .kv-grid-table > :first-child > tr:first-child {
        border-top-width: 0;
    }

    .detail-view > tbody > tr > td.detail-table-value .kv-grid-table > :last-child > tr:last-child {
        border-bottom-width: 0;
    }
}

/* ==== the stage page in both portals: what is asked in short notes at the top, the decisions
 * and the form's buttons in a bar that stays at the foot of the screen ==== */
/* ---- the stage page: the card says what is asked, the bar under the work holds the decisions --
 * (_stage_task_notes.php, _stage_decision_bar.php) */
.stage-task-notes {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    margin-top: .5rem;
    padding-top: .5rem;
    border-top: 1px solid #edf1f5;
}

/* a box of its own when there is no stage card to hold it (applicants, or no access to the office) */
.stage-task-notes.is-standalone {
    margin: 0 0 .75rem;
    padding: 0;
    border: 0;
}

.stage-task-note {
    --note-tone: #2563eb;
    --note-bg: #eff6ff;
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    padding: .5rem .75rem;
    border-left: 3px solid var(--note-tone);
    border-radius: .375rem;
    background: var(--note-bg);
    font-size: .875rem;
}

.stage-task-note.is-danger { --note-tone: #dc2626; --note-bg: #fef2f2; }
.stage-task-note.is-warning { --note-tone: #d97706; --note-bg: #fffbeb; }
.stage-task-note.is-success { --note-tone: #16a34a; --note-bg: #f0fdf4; }

.stage-task-note > .fa {
    margin-top: .2rem;
    color: var(--note-tone);
}

.stage-task-note-title {
    color: var(--admin-shell-heading, #173f65);
    font-weight: 600;
}

.stage-task-note-body {
    color: #334155;
}

.stage-task-note-body ul {
    margin: .15rem 0 0;
    padding-left: 1.1rem;
}

.stage-decision-bar {
    position: sticky;
    bottom: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    margin-top: 1rem;
    padding: .65rem .85rem;
    border: 1px solid var(--admin-shell-border, #dbe4ee);
    border-radius: .625rem;
    background: #fff;
    box-shadow: 0 -6px 16px -10px rgba(15, 23, 42, .25);
}

.stage-decision-bar > .stage-decision {
    flex: 1 1 auto;
    justify-content: flex-end;
    padding: 0;
}

/* what the decisions wait for, on the left of them */
.stage-decision-bar-notes,
.stage-decision-bar .basic-completion-notes {
    flex: 1 1 14rem;
    order: -1;
    width: auto !important;
    color: #64748b;
    font-size: .8125rem;
    text-align: left !important;
}

/* a document to be read before deciding on it (pdf-viewer.js, data-read-first) */
.document-read-state {
    margin-top: 2px;
    color: #b45309;
    font-size: 12.5px;
    font-weight: 600;
}

.document-read-state.is-read {
    color: #067647;
}

[data-read-first] {
    opacity: .45;
    filter: grayscale(.6);
    pointer-events: none;
    user-select: none;
}

/* "I have checked the preview" under the document of a review, with why it waits */
.review-document-confirm {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem 1rem;
    margin-top: .75rem;
}

.review-document-confirm-copy {
    flex: 1 1 14rem;
    min-width: 0;
    text-align: right;
}

/* what the one deciding should have in view (who they sign as ...), after the notes */
.stage-decision-bar-info {
    flex: 1 1 16rem;
    order: -1;
    min-width: 0;
}

.stage-decision-bar-notes .fw-semibold {
    color: #b91c1c;
}

/* associated documents an option warns about, confirmed before the stage ends (_stage_completion_warnings.php) */
.stage-decision-bar .stage-completion-warnings,
.stage-decision-bar .stage-completion-confirmed {
    flex: 1 1 14rem;
    order: -1;
    margin: 0 !important;
    font-size: .8125rem;
}
.stage-decision-bar .stage-completion-warnings {
    padding: .5rem .75rem;
}
.stage-completion-warnings ul {
    padding-left: 1.1rem;
    margin-bottom: .25rem !important;
}

/* decisions held back until what the notes list is done */
.stage-decision .stage-decision-completes[inert] {
    opacity: .45;
    filter: grayscale(.6);
    pointer-events: none;
    user-select: none;
}

/* the payment actions keep their own rows inside the bar */
.stage-decision-bar .payment-action-stack {
    flex: 1 1 100%;
}

.stage-decision-bar .payment-action-panel.workspace-surface {
    padding: 0;
}

/* at the right end, like the decisions of every other stage */
.stage-decision-bar .payment-action-panel > .payment-action-row {
    justify-content: flex-end;
}

/* the payment's head: its type small, the amount as the title */
.payment-stage-amount {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.payment-item-formula {
    cursor: help;
}

/* the invoice's status in its own colour: a later grey chip rule of the staff theme won over these */
.application-meta-chip.application-meta-chip-warning {
    background: #fff6e6;
    color: #8a5a00;
    border-color: #f5ddab;
}

.application-meta-chip.application-meta-chip-danger {
    background: #fdecea;
    color: #9f2a1f;
    border-color: #f3c6c1;
}

/* the Application form's Pause / Save and Continue stay in sight like the decisions of other stages */
/* hidden would make the panel a scroller of its own and hold the buttons; clip cuts the same */
.process-content .process-form-panel:not(.modal-body *) {
    overflow: clip;
}

.process-content .process-form-foot:not(.modal-body *) {
    position: sticky;
    bottom: 0;
    z-index: 20;
    padding: .65rem .85rem;
    border: 1px solid var(--admin-shell-border, #dbe4ee);
    border-radius: .625rem;
    background: #fff;
    box-shadow: 0 -6px 16px -10px rgba(15, 23, 42, .25);
}

@media (max-width: 767.98px) {
    /* above the bottom tab bar; the main decision across the width, the others sharing a row under it */
    .stage-decision-bar,
    .process-content .process-form-foot:not(.modal-body *) {
        bottom: var(--app-bottom-nav-height, calc(3.6rem + env(safe-area-inset-bottom, 0px)));
        padding: .5rem .6rem;
    }

    .app-typing .stage-decision-bar,
    .app-typing .process-content .process-form-foot:not(.modal-body *) {
        bottom: 0;
    }

    .stage-decision-bar > .stage-decision {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .stage-decision-bar > .stage-decision > .btn {
        flex: 1 1 0;
        min-width: 0;
        white-space: normal;
    }

    .stage-decision-bar > .stage-decision > .btn:first-child {
        flex-basis: 100%;
    }

    .stage-decision-bar-notes,
    .stage-decision-bar .basic-completion-notes,
    .stage-decision-bar .stage-completion-warnings,
    .stage-decision-bar .stage-completion-confirmed {
        flex-basis: 100%;
    }

}

/* ---- header "More": links the header has no room for (common/views/_app_header_more.php) ---
 * Ranges: md below 768px, xl below 1280px, md-xl from 768 to 1279px. In its range an item is in
 * the menu and the header's own link (app-header-moved-*) is hidden; out of it, the reverse. The
 * menu shows only where one of its items is in it. Not done with :has(), so that browsers
 * without it never lose the links. .app-header in front outranks Bootstrap's d-*-flex. */
.app-header .app-header-more,
.app-header .app-header-more-md,
.app-header .app-header-more-xl,
.app-header .app-header-more-md-xl {
    display: none !important;
}

@media (max-width: 767.98px) {
    .app-header .app-header-more.app-header-more-has-md,
    .app-header .app-header-more.app-header-more-has-xl {
        display: flex !important;
    }

    .app-header .app-header-more-md,
    .app-header .app-header-more-xl {
        display: revert !important;
    }

    .app-header .app-header-moved-md,
    .app-header .app-header-moved-xl {
        display: none !important;
    }
}

@media (min-width: 768px) and (max-width: 1279.98px) {
    .app-header .app-header-more.app-header-more-has-xl,
    .app-header .app-header-more.app-header-more-has-md-xl {
        display: flex !important;
    }

    .app-header .app-header-more-xl,
    .app-header .app-header-more-md-xl {
        display: revert !important;
    }

    .app-header .app-header-moved-xl,
    .app-header .app-header-moved-md-xl {
        display: none !important;
    }
}

.app-header-more {
    align-items: center;
    list-style: none;
}

.app-header-more-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    min-height: 2.5rem;
    border: 0;
    background: transparent;
}

.app-header-more-toggle > .bi {
    font-size: 1.25rem;
    line-height: 1;
}

/* a count inside the menu shows as a dot, so it is not lost when its link moves in there */
.app-header-more-dot {
    position: absolute;
    top: .4rem;
    right: .4rem;
    width: .5rem;
    height: .5rem;
    border-radius: 50%;
    background: #dc3545;
    box-shadow: 0 0 0 2px #fff;
}

.app-header-more-menu {
    min-width: 13rem;
}

.app-header-more-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    min-height: 2.75rem;
    white-space: normal;
}

.app-header-more-menu .dropdown-item > .bi,
.app-header-more-menu .dropdown-item > .fa,
.app-header-more-menu .dropdown-item > .fas {
    width: 1.25rem;
    text-align: center;
    flex: 0 0 auto;
}

.app-header-more-menu form {
    margin: 0;
}

.app-header-more-menu button.dropdown-item {
    width: 100%;
    text-align: left;
}

.app-header-more-menu .dropdown-item-text {
    color: var(--bs-secondary-color, #6c757d);
    font-size: .85rem;
}
