/* MST.NET shared responsive layer.
   Tokens and containment for the application shell and pages that are not
   already covered by component CSS. Does not restyle embedded Shiny apps. */

:root {
    /* Shell palette tokens (--mst-navy, --mst-blue, --mst-muted, --mst-surface, --mst-border,
       --mst-radius, ...) are defined once in app.css. These are the extra aliases the
       responsive layer and page styles use. */
    --mst-brand: var(--mst-navy-2);
    --mst-brand-2: var(--mst-blue-dark);
    --mst-accent: var(--mst-blue);
    --mst-ink: var(--mst-text);
    --mst-ground: var(--mst-bg);
    --mst-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 14px rgba(16, 24, 40, 0.06);
    --mst-focus: 2px solid var(--mst-accent);
}

html {
    overflow-x: clip;
}

body.mst-nav-open {
    overflow: hidden;
}

img,
svg,
video,
canvas,
iframe {
    max-width: 100%;
}

.shiny-iframe {
    max-width: 100%;
}

.row > [class*="col-"] {
    min-width: 0;
}

.table-responsive,
.rz-data-grid,
.rz-datatable,
.rz-chart {
    max-width: 100%;
}

.rz-data-grid,
.rz-datatable,
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-dialog {
    max-width: min(32rem, calc(100vw - 1rem));
    margin: 0.75rem auto;
}

.rz-dialog,
.blazored-modal {
    max-width: calc(100vw - 1rem);
}

:focus-visible {
    outline: var(--mst-focus);
    outline-offset: 2px;
}

input[type="file"] {
    max-width: 100%;
}

/* Page title for the plain Bootstrap screens (Admin), in the same ink as the
   Asset Intelligence and Request Logs headers. */
.mst-page-title {
    margin: 0.25rem 0 1rem;
    font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
    font-weight: 700;
    line-height: 1.2;
    color: var(--mst-ink);
}

/* Admin lists (users, roles, municipality groups): one card, clear rows. */
.mst-admin-list {
    border: 1px solid var(--mst-border);
    border-radius: var(--mst-radius);
    box-shadow: var(--mst-shadow);
    overflow: hidden;
}

.mst-admin-list > .list-group-item {
    padding: 0.85rem 1.1rem;
    border-color: var(--mst-border);
    overflow-wrap: anywhere;
}

.mst-admin-list > .list-group-item:hover {
    background: var(--mst-ground);
}

.mst-admin-list .btn-sm {
    min-width: 4.5rem;
}

/* Account settings menu: a side list on desktop, wrapping pills on a phone so the form
   isn't pushed below a screen of links and no item is hidden off to the side. */
.manage-nav .nav-link {
    border-radius: 8px;
}

@media (max-width: 767.98px) {
    .manage-nav {
        flex-direction: row !important;
        flex-wrap: wrap;
        gap: 0.4rem;
        margin-bottom: 1.25rem;
    }

    .manage-nav .nav-link {
        display: flex;
        align-items: center;
        min-height: 44px;
        white-space: nowrap;
        border: 1px solid var(--mst-border);
        background: var(--mst-surface);
    }

    .mst-admin-list .btn-sm {
        min-height: 2.5rem;
    }

}

/* Radzen grids use a fixed table layout that squeezes every column into the width available
   until figures are cut off or run into the next column (seen on phones and at 768px). Size
   columns to their content with a readable minimum instead; a grid that then does not fit is
   shown one card per row by js/mst-tables.js. */
.rz-data-grid .rz-grid-table-fixed {
    table-layout: auto;
}

.rz-data-grid .rz-grid-table th,
.rz-data-grid .rz-grid-table td {
    min-width: 6.5rem;
}

.rz-data-grid .rz-grid-table .rz-column-title-content {
    white-space: normal;
}

/* Radzen date picker: its calendar is a fixed 352px and the popup is placed at the input's left
   edge (inline style), so on a narrow phone the weekend columns, minutes and OK ran off-screen.
   Pin the popup to the screen edge and let the calendar take the width there is. */
@media (max-width: 575.98px) {
    .rz-datepicker-popup-container.rz-popup {
        left: 0.5rem !important;
        max-width: calc(100vw - 1rem);
    }

    .rz-datepicker-popup-container .rz-calendar,
    .rz-datepicker-popup-container .rz-timepicker {
        width: min(352px, calc(100vw - 1rem));
    }

    .rz-datepicker-popup-container .rz-calendar-view {
        width: 100%;
    }

    .rz-datepicker-popup-container .rz-calendar-title {
        min-width: 0;
    }

    .rz-datepicker-popup-container .rz-calendar-month-dropdown {
        min-width: 0;
        flex: 1 1 auto;
    }

    .rz-datepicker-popup-container .rz-calendar-year-dropdown {
        flex: 0 0 auto;
    }

    .rz-datepicker-popup-container .rz-calendar-title .rz-dropdown {
        padding-left: 0.6rem;
        padding-right: 0.6rem;
    }

    .rz-datepicker-popup-container .rz-calendar-title .rz-dropdown-label {
        padding-right: 1.25rem;
    }

    .rz-datepicker-popup-container .rz-numeric {
        flex: 1 1 0;
        min-width: 0;
    }
}

@media (max-width: 767.98px) {
    .form-control,
    .form-select,
    .rz-textbox,
    .rz-dropdown {
        min-height: 2.75rem;
        font-size: 1rem;
    }

    article .btn {
        min-height: 2.75rem;
    }

    .rz-data-grid .btn,
    .rz-datatable .btn,
    .table .btn {
        min-height: 2.25rem;
    }

    h1 {
        font-size: clamp(1.45rem, 6vw, 2rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .spinner-border,
    .spinner-grow {
        animation-duration: 0.75s !important;
        animation-iteration-count: infinite !important;
    }
}

/* ---- Tables wider than their space: one card per row ----
   js/mst-tables.js adds .mst-stack only to a table that does not fit, and labels each cell
   from its column header (data-label). Tables that fit are untouched. The class is repeated
   in selectors to outrank the component table styles (.ai-table, .ai-report-table, Radzen)
   without !important. */
/* Screen only: printed reports and plan documents keep their tables. */
@media screen {
    table.mst-stack.mst-stack {
        display: block;
        width: 100%;
        min-width: 0;
        table-layout: auto;
    }

    table.mst-stack.mst-stack > colgroup {
        display: none;
    }

    /* Headers stay for screen readers; sortable ones become a row of tappable chips. */
    table.mst-stack.mst-stack > thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    table.mst-stack.mst-stack--sortable > thead {
        position: static;
        display: block;
        width: auto;
        height: auto;
        overflow: visible;
        clip-path: none;
        white-space: normal;
        margin-bottom: 0.5rem;
    }

    table.mst-stack.mst-stack--sortable > thead > tr {
        display: flex;
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    table.mst-stack.mst-stack--sortable > thead th {
        display: block;
        width: auto;
        min-width: 0;
        height: auto;
        padding: 0.15rem 0.6rem;
        border: 1px solid var(--mst-border);
        border-radius: 999px;
        background: var(--mst-surface);
        font-size: 0.78rem;
    }

    table.mst-stack.mst-stack--sortable > thead th > div,
    table.mst-stack.mst-stack--sortable > thead th .rz-column-title,
    table.mst-stack.mst-stack--sortable > thead th .rz-column-title-content {
        min-height: 0;
        padding: 0;
        line-height: 1.6;
    }

    table.mst-stack.mst-stack--sortable > thead th:not(.rz-sortable-column):not(:has(button, a[href], input, select)) {
        display: none;
    }

    table.mst-stack.mst-stack > tbody,
    table.mst-stack.mst-stack > tfoot {
        display: block;
    }

    table.mst-stack.mst-stack tr {
        display: block;
        padding: 0.65rem 0;
        border-bottom: 1px solid var(--mst-border);
    }

    table.mst-stack.mst-stack > tbody > tr:last-child {
        border-bottom: 0;
    }

    table.mst-stack.mst-stack > tfoot > tr {
        border-top: 2px solid var(--mst-border);
        border-bottom: 0;
    }

    table.mst-stack.mst-stack td,
    table.mst-stack.mst-stack tbody th,
    table.mst-stack.mst-stack tfoot th,
    table.mst-stack.mst-stack td.num,
    table.mst-stack.mst-stack th.num {
        display: flow-root;
        width: auto;
        min-width: 0;
        max-width: none;
        padding: 0.15rem 0;
        border: 0;
        text-align: right;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    table.mst-stack.mst-stack td::before,
    table.mst-stack.mst-stack tbody th::before,
    table.mst-stack.mst-stack tfoot th::before {
        content: attr(data-label);
        float: left;
        max-width: 55%;
        margin-right: 0.75rem;
        text-align: left;
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--mst-muted);
        overflow-wrap: normal;
    }

    /* Block content in a value cell (a meter with its figure, a note) goes under the label
       instead of being squeezed beside it. */
    table.mst-stack.mst-stack td > div {
        clear: both;
    }

    /* The first cell names the row. */
    table.mst-stack.mst-stack > tbody > tr > :first-child,
    table.mst-stack.mst-stack > tfoot > tr > :first-child {
        display: block;
        padding-bottom: 0.3rem;
        text-align: left;
        font-weight: 600;
    }

    table.mst-stack.mst-stack > tbody > tr > :first-child::before,
    table.mst-stack.mst-stack > tfoot > tr > :first-child::before,
    table.mst-stack.mst-stack td[colspan]:not([colspan="1"])::before {
        content: none;
    }

    /* A rank column stays beside its label rather than becoming the row title. */
    table.mst-stack.mst-stack tr > .ai-table__rank:first-child,
    table.mst-stack.mst-stack tr > [data-mst-rank]:first-child {
        display: inline-block;
        width: auto;
        padding: 0 0.5rem 0 0;
        color: var(--mst-muted);
    }

    table.mst-stack.mst-stack tr > .ai-table__rank:first-child + td,
    table.mst-stack.mst-stack tr > [data-mst-rank]:first-child + td {
        display: inline;
        font-weight: 600;
        text-align: left;
    }

    table.mst-stack.mst-stack tr > .ai-table__rank:first-child + td::before,
    table.mst-stack.mst-stack tr > [data-mst-rank]:first-child + td::before {
        content: none;
    }

    /* A labelled number first (e.g. a grade): keep it as a labelled line and let the next cell,
       moved above it, name the row. */
    table.mst-stack.mst-stack > tbody > tr:has(> [data-mst-numfirst]:first-child) {
        display: flex;
        flex-direction: column;
    }

    table.mst-stack.mst-stack > tbody > tr > [data-mst-numfirst]:first-child {
        display: flow-root;
        padding-bottom: 0.15rem;
        text-align: right;
        font-weight: inherit;
    }

    table.mst-stack.mst-stack > tbody > tr > [data-mst-numfirst]:first-child::before {
        content: attr(data-label);
    }

    table.mst-stack.mst-stack > tbody > tr > [data-mst-numfirst]:first-child + * {
        order: -1;
        display: block;
        padding-bottom: 0.3rem;
        text-align: left;
        font-weight: 600;
    }

    table.mst-stack.mst-stack > tbody > tr > [data-mst-numfirst]:first-child + *::before {
        content: none;
    }

    /* Detail rows and messages that span the table. */
    table.mst-stack.mst-stack td[colspan]:not([colspan="1"]) {
        display: block;
        text-align: left;
    }

    table.mst-stack.mst-stack .rz-cell-data {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }
}
