/* ============================================================
   Shipment Tracker — application styles
   Bootstrap supplies the grid/reset only; all visual design below is ours.
   ============================================================ */

:root {
    /* Neutrals — slightly blue-tinted greys so they sit under the sapphire brand */
    --ink: #101929;
    --ink-soft: #56657c;
    --ink-faint: #8b98ad;
    --line: #e2e8f0;
    --line-soft: #eff3f8;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --canvas: #f1f4f9;

    /* Brand — sapphire, replaces the Blazor template purple */
    --brand: #1657c4;
    --brand-700: #0f429c;
    --brand-400: #3d84f0;
    --brand-300: #7db0ff;
    --brand-soft: #e8f0fe;
    --brand-tint: #f4f8ff;

    /* Sidebar */
    --sidebar-top: #0e1729;
    --sidebar-bottom: #16233c;

    /* Semantic */
    --ok: #12805c;
    --ok-soft: #dcf5ea;
    --warn: #a35c07;
    --warn-soft: #fdf0d9;
    --danger: #c62f2f;
    --danger-soft: #fdeaea;
    --info: #1657c4;

    --shadow-sm: 0 1px 2px rgba(16, 25, 41, .05);
    --shadow-md: 0 2px 6px rgba(16, 25, 41, .06), 0 8px 20px rgba(16, 25, 41, .05);
    --shadow-lg: 0 20px 55px rgba(10, 20, 40, .30);

    --radius: 10px;
    --radius-sm: 7px;
}

html, body {
    font-family: 'Inter', 'Segoe UI Variable Text', 'Segoe UI', -apple-system, 'Helvetica Neue', Arial, sans-serif;
    color: var(--ink);
    background: var(--canvas);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    color: var(--brand-700);
    text-decoration: underline;
}

h1 {
    font-size: 1.55rem;
    font-weight: 660;
    letter-spacing: -.018em;
    margin: 0;
}

h2 {
    font-size: 1rem;
    font-weight: 650;
    letter-spacing: -.008em;
    margin: 0;
}

h1:focus, h2:focus {
    outline: none;
}

.content {
    padding-top: 1.4rem;
    padding-bottom: 3.5rem;
}

.lead {
    color: var(--ink-soft);
    font-size: .885rem;
    line-height: 1.6;
    margin: .45rem 0 1.35rem;
    max-width: 74ch;
}

.hint, .small {
    color: var(--ink-faint);
    font-size: .785rem;
}

.text-muted { color: var(--ink-faint); }
.nowrap { white-space: nowrap; }
.num, .text-end { text-align: right; }

.empty {
    color: var(--ink-faint);
    font-size: .87rem;
    margin: .9rem 0;
    display: flex;
    align-items: center;
    gap: .45rem;
}

code {
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: .05rem .3rem;
    font-size: .82em;
    color: var(--brand-700);
}

/* ---------- Icons ---------- */

.ico {
    display: inline-block;
    vertical-align: -.14em;
    flex: 0 0 auto;
}

/* ---------- Page furniture ---------- */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: .3rem;
}

.head-meta {
    display: flex;
    gap: .55rem;
    flex-wrap: wrap;
    align-items: center;
    color: var(--ink-soft);
    font-size: .8rem;
    margin-top: .55rem;
}

.head-meta > span:not(.badge) {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .12rem .6rem;
}

.head-actions {
    display: flex;
    gap: .6rem;
    align-items: center;
    flex-wrap: wrap;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1.15rem;
    box-shadow: var(--shadow-sm);
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: .85rem;
}

.panel-head h2 {
    display: flex;
    align-items: center;
    gap: .45rem;
}

.link-more {
    font-size: .8rem;
    font-weight: 550;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
}

.result-count {
    font-size: .78rem;
    color: var(--ink-faint);
    margin: 0 0 .6rem;
}

/* ---------- Stat tiles ---------- */

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    gap: .8rem;
    margin-bottom: 1.2rem;
}

.stat-tile {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .15rem;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

/* Accent bar along the top edge rather than a heavy left border. */
.stat-tile::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: var(--line);
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 660;
    line-height: 1.15;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: .755rem;
    color: var(--ink-soft);
    line-height: 1.35;
}

.tile-transit::before { background: linear-gradient(90deg, var(--brand), var(--brand-400)); }
.tile-transit .stat-value { color: var(--brand); }

.tile-done::before { background: linear-gradient(90deg, var(--ok), #34b487); }
.tile-done .stat-value { color: var(--ok); }

.tile-risk::before { background: linear-gradient(90deg, var(--danger), #ef6b6b); }
.tile-risk {
    background: linear-gradient(180deg, var(--danger-soft), var(--surface) 70%);
    border-color: #f4cfcf;
}
.tile-risk .stat-value { color: var(--danger); }

/* ---------- Tables ---------- */

/*
   Every data table lives in one of these. A table is the one thing that cannot
   reflow below its content width, so it gets its own horizontal scroller rather
   than pushing the whole page sideways.
*/
.table-scroll {
    overflow-x: auto;
    /* Bleed to the panel edges so the scroll track lines up with the card. */
    margin: 0 -1.2rem;
    padding: 0 1.2rem;
    scrollbar-width: thin;
}

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

.table th {
    text-align: left;
    font-weight: 620;
    font-size: .705rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ink-faint);
    border-bottom: 1px solid var(--line);
    padding: .5rem .65rem;
    white-space: nowrap;
}

.table td {
    padding: .58rem .65rem;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}

.table tbody tr {
    transition: background-color .1s ease;
}

.table tbody tr:hover {
    background: var(--brand-tint);
}

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

/* Tables whose cells hold inputs need a floor width, or the fields collapse. */
.table-form { min-width: 34rem; }

.row-risk {
    background: linear-gradient(90deg, var(--danger-soft), transparent 60%);
}

.row-risk:hover {
    background: var(--danger-soft);
}

.row-muted td {
    opacity: .5;
}

/* ---------- Badges & pills ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .17rem .55rem;
    border-radius: 999px;
    font-size: .715rem;
    font-weight: 620;
    line-height: 1.45;
    white-space: nowrap;
}

.badge-ok, .status-completed {
    background: var(--ok-soft);
    color: var(--ok);
    box-shadow: inset 0 0 0 1px rgba(18, 128, 92, .16);
}

.badge-late {
    background: var(--danger-soft);
    color: var(--danger);
    box-shadow: inset 0 0 0 1px rgba(198, 47, 47, .16);
}

.badge-muted {
    background: var(--line-soft);
    color: var(--ink-faint);
    box-shadow: inset 0 0 0 1px var(--line);
}

.status-draft {
    background: var(--line-soft);
    color: var(--ink-soft);
    box-shadow: inset 0 0 0 1px var(--line);
}

.status-intransit {
    background: var(--brand-soft);
    color: var(--brand);
    box-shadow: inset 0 0 0 1px rgba(22, 87, 196, .16);
}

.role-pill {
    display: inline-block;
    border-radius: 999px;
    padding: .02rem .42rem;
    font-size: .63rem;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.role-admin { background: var(--brand-soft); color: var(--brand); }
.role-operator { background: var(--ok-soft); color: var(--ok); }
.role-viewer { background: var(--line-soft); color: var(--ink-soft); }
.role-none { background: var(--warn-soft); color: var(--warn); }

/* ---------- Progress meter ---------- */

.progress-wrap {
    display: flex;
    align-items: center;
    gap: .55rem;
    min-width: 118px;
}

.progress-track {
    flex: 1;
    height: 6px;
    background: var(--line-soft);
    border-radius: 999px;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(16, 25, 41, .04);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--brand), var(--brand-400));
    border-radius: 999px;
    transition: width .3s ease;
}

.progress-fill.is-complete {
    background: linear-gradient(90deg, var(--ok), #34b487);
}

.progress-label {
    font-size: .735rem;
    font-weight: 600;
    color: var(--ink-soft);
    min-width: 2.5rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ---------- Tracking matrix ---------- */

.matrix-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.matrix {
    border-collapse: separate;
    border-spacing: 0;
    font-size: .82rem;
    min-width: 100%;
}

.matrix th, .matrix td {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    padding: .5rem .6rem;
    min-width: 138px;
    vertical-align: middle;
}

.matrix tr:last-child th, .matrix tr:last-child td {
    border-bottom: none;
}

.matrix thead th {
    background: linear-gradient(180deg, #f9fbfd, #f2f6fa);
    text-align: left;
    vertical-align: top;
    position: sticky;
    top: 0;
    z-index: 3;
}

.matrix .matrix-label {
    position: sticky;
    left: 0;
    z-index: 4;
    background: var(--surface-alt);
    min-width: 168px;
    width: 168px;
    font-size: .705rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ink-soft);
    text-align: left;
    box-shadow: 1px 0 0 var(--line);
}

.stage-order {
    display: inline-grid;
    place-items: center;
    background: var(--brand);
    color: #fff;
    border-radius: 50%;
    width: 1.25rem;
    height: 1.25rem;
    font-size: .66rem;
    font-weight: 700;
    margin-right: .4rem;
    vertical-align: middle;
}

.stage-name {
    font-weight: 600;
    font-size: .785rem;
}

.tag {
    display: inline-block;
    margin-top: .35rem;
    padding: .06rem .42rem;
    border-radius: 4px;
    font-size: .625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.tag-current {
    background: var(--brand);
    color: #fff;
}

.cell-done { background: var(--ok-soft); }
.cell-late { background: var(--danger-soft); }
.cell-risk { background: var(--warn-soft); }
.cell-current { box-shadow: inset 0 0 0 2px var(--brand); }

.cell-input {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    padding: .22rem .35rem;
    font: inherit;
    color: inherit;
    border-radius: 5px;
    transition: background-color .12s ease, border-color .12s ease;
}

.cell-input:hover {
    border-color: var(--line);
    background: rgba(255, 255, 255, .8);
}

.cell-input:focus {
    outline: none;
    border-color: var(--brand);
    background: #fff;
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.doc-count {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.legend {
    display: flex;
    gap: .85rem;
    font-size: .73rem;
    color: var(--ink-soft);
    flex-wrap: wrap;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: .32rem;
}

.swatch {
    width: .72rem;
    height: .72rem;
    border-radius: 3px;
    display: inline-block;
    border: 1px solid var(--line);
}

.swatch-done { background: var(--ok-soft); }
.swatch-late { background: var(--danger-soft); }
.swatch-risk { background: var(--warn-soft); }
.swatch-current { background: #fff; box-shadow: inset 0 0 0 2px var(--brand); }

/* ---------- Forms ---------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(238px, 1fr));
    gap: .95rem;
    margin-bottom: 1rem;
}

.form-grid > label, .filter-grid > label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    font-size: .775rem;
    font-weight: 620;
    color: var(--ink-soft);
}

.form-grid .span-2 { grid-column: span 2; }

.form-control, .form-select {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: .42rem .6rem;
    font-size: .85rem;
    font-family: inherit;
    font-weight: 400;
    color: var(--ink);
    background: var(--surface);
    width: 100%;
    transition: border-color .12s ease, box-shadow .12s ease;
}

.form-control::placeholder { color: var(--ink-faint); }

.form-control:hover, .form-select:hover { border-color: #c9d4e3; }

.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.form-control:disabled {
    background: var(--surface-alt);
    color: var(--ink-faint);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2356657c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='m6 9 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right .5rem center;
    background-size: .9rem;
    padding-right: 1.9rem;
}

.form-select.sm {
    padding: .24rem 1.7rem .24rem .4rem;
    font-size: .78rem;
}

.form-control.short { max-width: 118px; }

label.check {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .8rem;
    font-weight: 500;
    color: var(--ink-soft);
    cursor: pointer;
}

/* Checkboxes are the smallest touch targets in the app; keep them thumb-sized. */
input[type="checkbox"] {
    accent-color: var(--brand);
    width: 1.15rem;
    height: 1.15rem;
    cursor: pointer;
}

label.check input[type="checkbox"] {
    flex: 0 0 auto;
}

/* A bare checkbox in a table has no label to extend its hit area, so pad the cell. */
.table td > input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    margin: .25rem 0;
}

.mt-1 { margin-top: .4rem; }

.input-row { display: flex; gap: .4rem; }

.inline-form {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: .75rem;
    padding-top: .75rem;
    border-top: 1px dashed var(--line);
}

/*
   .form-control is width:100%, which as a flex-basis would put every field on
   its own row. Re-base them so they share the row and only wrap when genuinely
   out of space.
*/
.inline-form .form-control,
.inline-form .form-select {
    width: auto;
    flex: 1 1 11rem;
    min-width: 0;
}

.inline-form .form-control.short {
    flex: 0 1 7rem;
}

.inline-form .btn {
    flex: 0 0 auto;
}

.form-actions {
    display: flex;
    gap: .6rem;
    margin-bottom: 2rem;
}

.filters .filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    gap: .75rem;
    align-items: end;
}

/*
   `.filter-grid > label` stacks its label text above the field. A checkbox row
   is the exception — it has to override that column direction, and out-specifies
   the generic rule, so it cannot rely on `label.check` alone.
*/
.filters .filter-grid label.check {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    min-height: 2.15rem;
}

.stage-preview {
    border-top: 1px dashed var(--line);
    padding-top: .8rem;
}

.stage-preview-label {
    font-size: .775rem;
    font-weight: 600;
    color: var(--ink-soft);
}

.stage-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    list-style: none;
    padding: 0;
    margin: .5rem 0 0;
    counter-reset: chip;
}

.chip {
    background: var(--brand-soft);
    color: var(--brand-700);
    border-radius: 999px;
    padding: .2rem .65rem;
    font-size: .74rem;
    font-weight: 500;
    counter-increment: chip;
}

.chip::before {
    content: counter(chip) ". ";
    opacity: .55;
    font-weight: 700;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    padding: .42rem .85rem;
    font-size: .84rem;
    font-family: inherit;
    font-weight: 560;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.35;
    transition: background-color .12s ease, border-color .12s ease, box-shadow .12s ease, transform .06s ease;
}

.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled {
    opacity: .48;
    cursor: not-allowed;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.btn-primary {
    background: linear-gradient(180deg, var(--brand-400), var(--brand));
    border-color: var(--brand-700);
    color: #fff;
    box-shadow: 0 1px 2px rgba(15, 66, 156, .3);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(180deg, var(--brand), var(--brand-700));
    color: #fff;
}

.btn-outline {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--brand-400);
    color: var(--brand);
    background: var(--brand-tint);
}

.btn-danger-outline {
    background: var(--surface);
    border-color: var(--line);
    color: var(--danger);
}

.btn-danger-outline:hover:not(:disabled) {
    border-color: #eab6b6;
    background: var(--danger-soft);
}

.btn-sm { padding: .28rem .65rem; font-size: .785rem; min-height: 1.95rem; }

/* Row-level actions stay compact but must remain comfortably tappable. */
.btn-xs { padding: .2rem .55rem; font-size: .725rem; min-height: 1.7rem; }

.btn-block {
    width: 100%;
    padding: .58rem;
    font-size: .92rem;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    background: none;
    color: var(--ink-soft);
    cursor: pointer;
    transition: background-color .12s ease, color .12s ease;
}

.icon-btn:hover {
    background: var(--brand-soft);
    color: var(--brand);
}

.upload-btn {
    position: relative;
    overflow: hidden;
    font-weight: 560;
}

.visually-hidden-file {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* ---------- Alerts ---------- */

.alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-radius: var(--radius-sm);
    padding: .6rem .9rem;
    font-size: .85rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    box-shadow: var(--shadow-sm);
}

.alert-success {
    background: var(--ok-soft);
    border-color: #b5e6d0;
    color: #0d5f45;
}

.alert-danger {
    background: var(--danger-soft);
    border-color: #f2c4c4;
    color: #8f2222;
}

.alert-body {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.alert-close {
    display: grid;
    place-items: center;
    background: none;
    border: none;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: .55;
    padding: .2rem;
}

.alert-close:hover { opacity: 1; }

/* ---------- Documents ---------- */

.stage-docs {
    border-top: 1px solid var(--line-soft);
    padding: .7rem 0;
}

.stage-docs:first-of-type { border-top: none; }

.stage-docs-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: .85rem;
}

.doc-list {
    list-style: none;
    padding: 0;
    margin: .5rem 0 0;
}

.doc-list li {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .35rem .5rem;
    border-radius: 6px;
    font-size: .82rem;
}

.doc-list li:hover { background: var(--surface-alt); }

.doc-meta {
    color: var(--ink-faint);
    font-size: .735rem;
}

/* ---------- Notification bell + centre ---------- */

.bell {
    position: relative;
    display: grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 8px;
    color: var(--ink-soft);
    margin-right: .35rem;
    transition: background-color .12s ease, color .12s ease;
}

.bell:hover {
    background: var(--brand-soft);
    color: var(--brand);
    text-decoration: none;
}

.bell-badge {
    position: absolute;
    top: .1rem;
    right: .05rem;
    background: var(--danger);
    color: #fff;
    border: 2px solid var(--surface);
    border-radius: 999px;
    font-size: .6rem;
    font-weight: 700;
    padding: 0 .22rem;
    min-width: 1.05rem;
    height: 1.05rem;
    line-height: .95rem;
    text-align: center;
}

.notif-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.notif {
    display: flex;
    align-items: flex-start;
    gap: .85rem;
    padding: .7rem .6rem;
    border-radius: 8px;
    border-bottom: 1px solid var(--line-soft);
}

.notif:last-child { border-bottom: none; }

.notif.is-unread {
    background: var(--brand-tint);
    box-shadow: inset 3px 0 0 var(--brand-400);
}

.notif.is-read .notif-message { color: var(--ink-soft); }

.notif-type {
    flex: 0 0 auto;
    min-width: 6rem;
    text-align: center;
    border-radius: 5px;
    padding: .15rem .4rem;
    font-size: .655rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.type-updatedue { background: var(--brand-soft); color: var(--brand); }
.type-atrisk { background: var(--danger-soft); color: var(--danger); }
.type-stagecompleted { background: var(--ok-soft); color: var(--ok); }
.type-shipmentcompleted { background: var(--ok-soft); color: var(--ok); }

.notif-body { flex: 1; min-width: 0; }

.notif-message {
    margin: 0;
    font-size: .86rem;
    line-height: 1.45;
}

.notif-meta {
    font-size: .735rem;
    color: var(--ink-faint);
}

/* ---------- Top bar user chip ---------- */

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    padding: .2rem .6rem .2rem .25rem;
    border-radius: 999px;
    margin-right: .3rem;
}

.avatar {
    display: grid;
    place-items: center;
    width: 1.95rem;
    height: 1.95rem;
    border-radius: 50%;
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .02em;
    flex: 0 0 auto;
}

.user-chip-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    gap: .1rem;
}

.user-chip-name {
    font-size: .82rem;
    font-weight: 600;
    color: var(--ink);
}

.user-chip-role { align-self: flex-start; }

@media (max-width: 640.98px) {
    .user-chip-text { display: none; }
}

/* ---------- Login ---------- */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background:
        radial-gradient(1100px 620px at 12% -8%, rgba(61, 132, 240, .35), transparent 60%),
        radial-gradient(900px 520px at 105% 110%, rgba(22, 87, 196, .38), transparent 62%),
        linear-gradient(155deg, var(--sidebar-top) 0%, var(--sidebar-bottom) 60%, #1d3a63 100%);
}

.login-shell {
    width: 100%;
    max-width: 440px;
}

.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 2rem 1.9rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, .5);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: .85rem;
    margin-bottom: 1.5rem;
}

.login-mark {
    display: grid;
    place-items: center;
    width: 2.9rem;
    height: 2.9rem;
    border-radius: 12px;
    background: linear-gradient(140deg, var(--brand-400), var(--brand-700));
    color: #fff;
    box-shadow: 0 6px 18px rgba(22, 87, 196, .35);
    flex: 0 0 auto;
}

.login-brand h1 {
    font-size: 1.22rem;
    margin: 0;
}

.login-brand p {
    margin: .18rem 0 0;
    font-size: .765rem;
    color: var(--ink-faint);
}

.field {
    display: flex;
    flex-direction: column;
    gap: .32rem;
    margin-bottom: .9rem;
}

.field label {
    font-size: .775rem;
    font-weight: 620;
    color: var(--ink-soft);
}

.login-card .check { margin-bottom: 1.1rem; }

.demo-block {
    margin-top: 1.7rem;
    border-top: 1px dashed var(--line);
    padding-top: 1.1rem;
}

.demo-head {
    display: flex;
    flex-direction: column;
    margin-bottom: .7rem;
}

.demo-head span {
    display: flex;
    align-items: center;
    gap: .35rem;
    font-size: .74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ink-soft);
}

.demo-head small {
    font-size: .705rem;
    color: var(--warn);
    margin-top: .1rem;
}

.demo-buttons {
    display: grid;
    gap: .45rem;
}

.demo-btn {
    display: flex;
    align-items: center;
    gap: .7rem;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface-alt);
    padding: .5rem .75rem;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: border-color .12s ease, background-color .12s ease, transform .06s ease;
}

.demo-btn:hover {
    background: var(--surface);
    border-color: var(--brand-400);
    box-shadow: var(--shadow-sm);
}

.demo-btn:active { transform: translateY(1px); }

.demo-avatar {
    display: grid;
    place-items: center;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 8px;
    color: #fff;
    flex: 0 0 auto;
}

.demo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.demo-role {
    font-size: .805rem;
    font-weight: 640;
    color: var(--ink);
}

.demo-email {
    font-size: .715rem;
    color: var(--ink-faint);
    overflow: hidden;
    text-overflow: ellipsis;
}

.role-admin .demo-avatar { background: linear-gradient(140deg, var(--brand-400), var(--brand-700)); }
.role-operator .demo-avatar { background: linear-gradient(140deg, #34b487, var(--ok)); }
.role-viewer .demo-avatar { background: linear-gradient(140deg, #97a5b8, #64748b); }

.login-foot {
    margin: 1.3rem 0 0;
    font-size: .74rem;
    color: var(--ink-faint);
    text-align: center;
    line-height: 1.5;
}

/* ---------- Misc cells ---------- */

.user-cell {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-weight: 550;
}

.denied-panel {
    max-width: 46rem;
    text-align: center;
    padding: 2.2rem 1.5rem;
}

.denied-mark {
    display: inline-grid;
    place-items: center;
    width: 3.2rem;
    height: 3.2rem;
    border-radius: 50%;
    background: var(--warn-soft);
    color: var(--warn);
    margin-bottom: .9rem;
}

.denied-panel .btn {
    margin-top: .5rem;
}

/* ---------- Validation / framework leftovers ---------- */

.valid.modified:not([type=checkbox]) {
    outline: none;
    border-color: var(--ok);
}

.invalid {
    border-color: var(--danger) !important;
}

.validation-message, .text-danger {
    color: var(--danger);
    font-size: .775rem;
}

.blazor-error-boundary {
    background: #7f1d1d;
    border-radius: var(--radius-sm);
    padding: 1rem;
    color: #fff;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* ============================================================
   Responsive
   Breakpoints follow the shell: the sidebar collapses at 640px, so the
   content area is widest-constrained just above that.
   ============================================================ */

/*
   Column priority utilities. Tables always scroll, but dropping the
   lower-value columns first means small screens usually do not have to.

   These key off the *content* width, not the viewport: the 246px sidebar makes
   the content area narrower at a 700px viewport than at 640px, where the
   sidebar collapses and the content goes full-bleed. A viewport media query
   gets that backwards, so `main` becomes the query container instead.
*/
main {
    container-type: inline-size;
    container-name: content;
}

@container content (max-width: 820px) {
    .hide-md { display: none !important; }
}

@container content (max-width: 560px) {
    .hide-sm { display: none !important; }
}

@media (max-width: 900px) {
    .form-grid .span-2 { grid-column: span 1; }
}

@media (max-width: 760px) {
    h1 { font-size: 1.32rem; }

    .content {
        padding-top: 1rem;
        padding-bottom: 2.5rem;
    }

    .panel {
        padding: .9rem .95rem;
        border-radius: 9px;
    }

    /* Keep the bleed in step with the reduced panel padding. */
    .table-scroll {
        margin: 0 -.95rem;
        padding: 0 .95rem;
    }

    .page-head {
        gap: .7rem;
    }

    .stat-row {
        grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
        gap: .6rem;
    }

    .stat-value { font-size: 1.35rem; }

    /* Full-width primary actions read better than half-width ones on a phone. */
    .page-head > .btn,
    .form-actions .btn {
        flex: 1 1 auto;
    }

    .form-actions { flex-wrap: wrap; }

    .filters .filter-grid {
        grid-template-columns: 1fr;
    }

    /* The sticky first column has to give up room on a narrow screen. */
    .matrix .matrix-label {
        min-width: 116px;
        width: 116px;
        font-size: .66rem;
    }

    .matrix th, .matrix td {
        min-width: 122px;
        padding: .42rem .45rem;
    }

    .notif {
        flex-wrap: wrap;
        gap: .5rem;
    }

    .notif-type { min-width: 0; }

    .notif-body { flex: 1 1 100%; }

    .doc-list li {
        flex-wrap: wrap;
    }

    .stage-docs-head {
        flex-wrap: wrap;
        gap: .5rem;
    }

    .legend { font-size: .68rem; gap: .55rem; }

    .login-card {
        padding: 1.4rem 1.15rem;
        border-radius: 13px;
    }

    .login-brand { gap: .65rem; }
    .login-brand h1 { font-size: 1.08rem; }

    .demo-email { font-size: .68rem; }
}

/* Long filenames must not force the document list wider than its panel. */
.doc-list li > a {
    overflow-wrap: anywhere;
    min-width: 0;
}

@media (max-width: 420px) {
    .stat-row { grid-template-columns: 1fr 1fr; }

    .head-meta { gap: .35rem; font-size: .74rem; }

    .inline-form .form-control,
    .inline-form .form-select { flex: 1 1 100%; }

    .inline-form .form-control.short { flex: 1 1 45%; }

    .inline-form .btn { width: 100%; }
}
