/* ============================================================
   KSC design system — clean & industrial.
   Whitish + black; brand red only for: primary buttons, active
   nav indicator, focus rings, small badges, the logo.
   ============================================================ */
:root {
    --color-bg: #FAFAF8;
    --color-surface: #FFFFFF;
    --color-surface-2: #F2F1ED;
    --color-text: #141414;
    --color-text-muted: #6B6B6B;
    /* Sampled from the official mark (wwwroot/logo.png): #C61F0F is the diamond's
       fill. -strong is the same hue and saturation at ~84% lightness, the same
       relationship the previous pair used, so hover states darken identically. */
    --color-brand: #C61F0F;
    --color-brand-strong: #A61A0D;
    --color-border: #E4E2DE;
    --color-danger: #B3261E;
    --color-success: #1E7F4F;
    --color-warning: #B26A00;

    --font-sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;

    /* 8px spacing grid */
    --space-1: 8px;
    --space-2: 16px;
    --space-3: 24px;
    --space-4: 32px;
    --space-6: 48px;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;

    --shadow-1: 0 1px 2px rgba(20, 20, 20, 0.05);
    --shadow-2: 0 12px 40px rgba(20, 20, 20, 0.16);

    --ease: 0.16s ease;
    --sidebar-width: 248px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
}

body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

#app {
    height: 100%;
}

h1, h2, h3 {
    margin: 0 0 var(--space-2);
    font-weight: 650;
    line-height: 1.25;
    letter-spacing: -0.015em;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }

a {
    color: var(--color-text);
}

.page-sub {
    margin: -12px 0 var(--space-3);
    color: var(--color-text-muted);
}

:focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
}

.text-muted {
    color: var(--color-text-muted);
}

/* Hidden but still occupying its space. For controls that come and go inside a
   grid or flex row, where display:none would resize every sibling. */
.is-invisible {
    visibility: hidden;
}

/* Content from the previous query, still on screen while the next one runs.
   Dimmed so it doesn't read as current, and inert so a click can't land on a
   row that is about to be replaced. */
.is-stale {
    opacity: 0.5;
    pointer-events: none;
    transition: opacity var(--ease);
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    height: 40px;
    padding: 0 var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    font-weight: 550;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--ease), border-color var(--ease), color var(--ease), box-shadow var(--ease);
}

.btn:hover {
    border-color: #C9C6C0;
    background: #FDFDFC;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--color-brand);
    border-color: var(--color-brand);
    color: #FFFFFF;
}

.btn-primary:hover {
    background: var(--color-brand-strong);
    border-color: var(--color-brand-strong);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--color-text-muted);
}

.btn-ghost:hover {
    background: var(--color-surface-2);
    border-color: transparent;
    color: var(--color-text);
}

.btn-small {
    height: 32px;
    padding: 0 10px;
    font-size: 0.85rem;
}

.btn-lg {
    height: 52px;
    font-size: 1.02rem;
    border-radius: var(--radius);
}

.btn-block {
    width: 100%;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background var(--ease), color var(--ease);
}

.icon-btn:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}

.icon {
    flex-shrink: 0;
}

/* ---------- Forms ---------- */

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: var(--space-2);
    text-align: left;
}

.field label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="search"],
input[type="email"],
select,
textarea {
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    width: 100%;
    transition: border-color var(--ease), box-shadow var(--ease);
}

textarea {
    height: auto;
    padding: 10px 14px;
    resize: vertical;
}

/* iOS WebKit sizes date and time inputs from their native control and holds
   that intrinsic width against the `width: 100%` above, so they overflow their
   grid column and break alignment with the selects. Dropping the native
   appearance lets the shared sizing apply. Chromium already shrinks these
   correctly; this is a no-op there. */
input[type="date"],
input[type="datetime-local"],
input[type="time"] {
    -webkit-appearance: none;
    appearance: none;
    min-width: 0;
    max-width: 100%;
}

/* WebKit centres the value text inside the native control; the rest of the
   form is left-aligned. */
input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value {
    text-align: left;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-brand);
    /* rgb of --color-brand; kept literal because rgba() cannot take a hex var. */
    box-shadow: 0 0 0 3px rgba(198, 31, 15, 0.12);
}

.field-error {
    color: var(--color-danger);
    font-size: 0.85rem;
}

.form-error {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--color-danger);
    font-size: 0.9rem;
    margin: 0 0 var(--space-2);
}

/* ---------- Badges & pills ---------- */

.badge {
    display: inline-block;
    padding: 1px 10px;
    border: 1px solid var(--color-brand);
    border-radius: 999px;
    color: var(--color-brand);
    font-size: 0.72rem;
    font-weight: 650;
    letter-spacing: 0.02em;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.pill-on {
    color: var(--color-success);
    background: rgba(30, 127, 79, 0.09);
}

.pill-off {
    color: var(--color-text-muted);
    background: rgba(20, 20, 20, 0.06);
}

/* ---------- Cards ---------- */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    padding: var(--space-3);
}

/* ---------- App shell ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px var(--space-2);
    text-decoration: none;
    border-bottom: 1px solid var(--color-border);
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-name {
    font-weight: 700;
    font-size: 0.98rem;
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--color-text-muted);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-1) 0 var(--space-2);
}

.nav-section {
    padding: 18px 20px 6px;
    font-size: 0.68rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--color-text-muted);
}

.sidebar-nav a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 1px var(--space-1);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    text-decoration: none;
    font-weight: 550;
    font-size: 0.93rem;
    transition: background var(--ease), color var(--ease);
}

.sidebar-nav a .icon {
    opacity: 0.8;
}

.sidebar-nav a:hover {
    color: var(--color-text);
    background: var(--color-surface-2);
}

/* Active nav: red indicator + red icon, neutral surface. */
.sidebar-nav a.active {
    color: var(--color-text);
    background: var(--color-surface-2);
}

.sidebar-nav a.active::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: var(--color-brand);
}

.sidebar-nav a.active .icon {
    color: var(--color-brand);
    opacity: 1;
}

.sidebar-foot {
    padding: 14px var(--space-2);
    border-top: 1px solid var(--color-border);
    font-size: 0.83rem;
    color: var(--color-text-muted);
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 60px;
    padding: 0 var(--space-3);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-spacer {
    flex: 1;
}

.nav-toggle {
    display: none;
}

.content {
    flex: 1;
    width: 100%;
    max-width: 1160px;
    margin-inline: auto;
    padding: var(--space-4) var(--space-3) var(--space-6);
}

/* ---------- User menu ---------- */

.user-menu {
    position: relative;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    font: inherit;
    cursor: pointer;
    transition: background var(--ease);
}

.user-chip:hover {
    background: var(--color-surface-2);
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--color-text);
    color: #FFFFFF;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.user-chip-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
}

.menu-pop {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 100;
    min-width: 230px;
    padding: 6px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background var(--ease);
}

.menu-item:hover {
    background: var(--color-surface-2);
}

.menu-item .icon {
    color: var(--color-text-muted);
}

/* ---------- Toolbar + tables ---------- */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
    flex-wrap: wrap;
}

.toolbar-filters {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.toolbar-filters select {
    width: auto;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    cursor: pointer;
    user-select: none;
    font-size: 0.92rem;
    color: var(--color-text-muted);
}

.checkbox-label input {
    accent-color: var(--color-brand);
    width: 16px;
    height: 16px;
}

/* A checkbox row inside a form. Deliberately not .field: that rule stacks its
   label above the control and bolds it, which is wrong when the label IS the
   control's caption. This only contributes the spacing .field would have. */
.field-check {
    margin-bottom: var(--space-2);
    text-align: left;
}

.table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    overflow: hidden;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 12px 14px;
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    white-space: nowrap;
    color: var(--color-text-muted);
    background: #F8F7F4;
    border-bottom: 1px solid var(--color-border);
}

.cell-nowrap {
    white-space: nowrap;
    color: var(--color-text-muted);
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background var(--ease);
}

.data-table tbody tr:hover {
    background: #FBFAF8;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table .row-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
    white-space: nowrap;
}

.inactive-row td {
    color: var(--color-text-muted);
}

.data-table .cell-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.disclosure {
    display: inline-flex;
    transition: transform var(--ease);
}

.disclosure.is-open {
    transform: rotate(180deg);
}

.empty-state {
    padding: var(--space-6);
    text-align: center;
    color: var(--color-text-muted);
}

.pill-info {
    color: #1F5C8B;
    background: rgba(31, 92, 139, 0.10);
}

/* Overdue severity. Brand red is reserved for chrome, so these are the
   semantic warning/danger hues, tinted the same way .pill-on is. */
.pill-warn {
    color: var(--color-warning);
    background: rgba(178, 106, 0, 0.10);
}

.pill-danger {
    color: var(--color-danger);
    background: rgba(179, 38, 30, 0.09);
}

.row-clickable {
    cursor: pointer;
}

.field-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
}

.form-row-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.form-section {
    margin: var(--space-3) 0 var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-border);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.section-heading {
    margin-top: var(--space-4);
}

/* ---------- Schedule editor ---------- */

.schedule-preview {
    margin: 0 0 var(--space-2);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    font-size: 0.9rem;
}

/* Seven fixed cells rather than a flex row, so Sun and Sat line up under each
   other whatever the label widths do at other zoom levels. */
.day-picker {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.day-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color var(--ease), background var(--ease);
}

.day-toggle:hover {
    border-color: var(--color-text-muted);
}

.day-toggle.is-on {
    border-color: var(--color-brand);
    background: var(--color-surface-2);
    color: var(--color-brand);
}

/* The box itself is redundant once the whole cell reads as pressed, but it stays
   in the DOM so the control is still reachable by keyboard and screen reader. */
.day-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

/* The scope picker. Two of these sit side by side in the editor: customers, and the
   locations that cascade from them. Fixed height on the scrolling half so ticking a
   customer grows the location list in place instead of shoving the form down. */
.scope-picker {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    overflow: hidden;
}

.scope-toolbar {
    padding: 8px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-2);
}

.scope-toolbar input[type="search"] {
    height: 34px;
}

.scope-list {
    height: 196px;
    overflow-y: auto;
}

.scope-row {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: 7px 12px;
    cursor: pointer;
}

.scope-row:hover {
    background: var(--color-surface-2);
}

.scope-row input {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    accent-color: var(--color-brand);
}

/* "All customers" overrides every name below it, so it stays put above the scroll area
   rather than scrolling away from them. */
.scope-row-all {
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-2);
}

.scope-group {
    position: sticky;
    top: 0;
    padding: 5px 12px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-2);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.scope-empty {
    margin: 0;
    padding: var(--space-2) 12px;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Recipients are a handful where customers are a hundred, so this list grows to fit
   instead of holding a fixed window open under three names. */
.scope-list-fit {
    height: auto;
    max-height: 220px;
}

/* The scope picker as a one-line control, for filter bars with no room for an open list.
   Not a .field: that uppercases every label inside it, and each row below is a label. */
.scope-select {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    text-align: left;
}

.scope-select > label {
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
}

.scope-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-1);
    height: 42px;
    padding: 0 12px 0 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--ease), box-shadow var(--ease);
}

.scope-select-trigger:hover {
    border-color: var(--color-text-muted);
}

.scope-select-trigger:focus-visible {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px rgba(198, 31, 15, 0.12);
}

.scope-select-value {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Wider than its column: a filter-bar column is too narrow for customer names. */
.scope-select-pop {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 100;
    width: max(100%, 260px);
    max-width: 340px;
    box-shadow: var(--shadow-2);
}

/* Overhanging the column would run off a phone screen. */
@media (max-width: 700px) {
    .scope-select-pop {
        width: 100%;
        max-width: none;
    }
}

/* The nested delivery table belongs to the row above it, so it is set back and
   tinted rather than reading as another run. */
.run-detail-row > td {
    padding: var(--space-2);
    background: var(--color-surface-2);
}

.run-detail-row .data-table {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

/* ---------- Filter bar ---------- */

/* Grid rather than flex so wrapped rows stay in aligned columns
   instead of leaving a stretched orphan field. */
.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    align-items: end;
    gap: var(--space-2);
    padding: var(--space-2);
    margin-bottom: var(--space-2);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
}

.filter-bar .field {
    margin-bottom: 0;
    min-width: 0;
}

.filter-bar > .btn {
    justify-self: start;
}

.filter-bar .field label {
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
}

/* ---------- Pager ---------- */

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-top: var(--space-2);
    flex-wrap: wrap;
}

.pager-buttons {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* ---------- Report summary ---------- */

/* Grid, not flex, so the tiles divide the bar evenly instead of huddling at the
   left edge of an otherwise empty card. Same auto-fit pattern as .filter-bar,
   so a third stat would slot in without touching this. */
.report-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    margin-bottom: var(--space-2);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
}

/* Separates the numbers now that they sit further apart. Only where the tiles
   are side by side — once the grid collapses to one column the rule would hang
   off the left edge of a stacked tile instead of dividing anything. */
@media (min-width: 701px) {
    .report-stat + .report-stat {
        padding-left: var(--space-2);
        border-left: 1px solid var(--color-border);
    }
}

.report-stat {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.report-stat-value {
    font-size: 1.7rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.report-stat-label {
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
}

/* ---------- Audit timeline ---------- */

.timeline {
    list-style: none;
    margin: 0;
    padding: 0 0 0 var(--space-1);
}

.timeline-entry {
    position: relative;
    display: flex;
    gap: var(--space-2);
    padding-bottom: var(--space-3);
}

/* Connecting rail between markers. */
.timeline-entry:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 5px;
    top: 18px;
    bottom: 0;
    width: 2px;
    background: var(--color-border);
}

.timeline-marker {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
}

.timeline-current .timeline-marker {
    background: var(--color-brand);
    border-color: var(--color-brand);
}

.timeline-body {
    flex: 1;
    min-width: 0;
}

.timeline-head {
    display: flex;
    align-items: baseline;
    gap: var(--space-1);
    flex-wrap: wrap;
}

.timeline-reason {
    margin: 4px 0 8px;
    font-style: italic;
    color: var(--color-text-muted);
}

.timeline-origin .timeline-head strong,
.timeline-current .timeline-head strong {
    font-weight: 650;
}

.diff-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.diff-list li {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-wrap: wrap;
    font-size: 0.92rem;
}

.diff-field {
    min-width: 120px;
    color: var(--color-text-muted);
}

.diff-old {
    padding: 1px 8px;
    border-radius: 4px;
    background: rgba(179, 38, 30, 0.08);
    color: var(--color-danger);
    text-decoration: line-through;
}

.diff-new {
    padding: 1px 8px;
    border-radius: 4px;
    background: rgba(30, 127, 79, 0.10);
    color: var(--color-success);
    font-weight: 550;
}

.diff-arrow {
    color: var(--color-text-muted);
}

@media (max-width: 700px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* ---------- Modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 20, 0.45);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2);
    z-index: 200;
}

.modal-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    padding: var(--space-3);
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-card-wide {
    max-width: 680px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.modal-head h2 {
    margin: 0;
    font-size: 1.1rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-1);
    margin-top: var(--space-3);
}

/* ---------- Banners ---------- */

.banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px var(--space-2);
    border-radius: var(--radius-sm);
    border: 1px solid;
    font-size: 0.93rem;
}

.banner .icon {
    margin-top: 2px;
}

.banner-warning {
    border-color: rgba(178, 106, 0, 0.35);
    background: rgba(178, 106, 0, 0.06);
    color: #7A4A00;
}

.banner-danger {
    border-color: rgba(179, 38, 30, 0.35);
    background: rgba(179, 38, 30, 0.05);
    color: var(--color-danger);
}

.banner-success {
    border-color: rgba(30, 127, 79, 0.35);
    background: rgba(30, 127, 79, 0.06);
    color: #14603B;
    margin-bottom: var(--space-2);
}

.badge-self {
    margin-left: 6px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--color-surface-2);
    color: var(--color-text-muted);
    font-size: 0.68rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.lock-note {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    font-size: 0.82rem;
    white-space: nowrap;
}

.banner + .banner,
.banner + .card,
.card + .banner {
    margin-top: var(--space-2);
}

.error-ref {
    margin-top: 4px;
    font-size: 0.85rem;
    opacity: 0.85;
}

.error-ref code {
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(20, 20, 20, 0.07);
    font-size: 0.85rem;
    user-select: all;
}

/* ---------- Login ---------- */

.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2);
    background:
        radial-gradient(900px 480px at 50% -10%, #FFFFFF 0%, rgba(255, 255, 255, 0) 65%),
        var(--color-bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: var(--space-4);
    border-radius: var(--radius-lg);
}

/* block, or the img's inline baseline adds a descender gap under the mark. */
.ksc-logo {
    display: block;
    object-fit: contain;
}

/* ApiStatusBanner sits between the brand block and the form; the danger banner
   inside the form (ErrorAlert) keeps its own spacing from .field above it. */
.login-card .banner-warning {
    margin-bottom: var(--space-3);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-bottom: var(--space-4);
    text-align: center;
}

.login-brand h1 {
    margin: 10px 0 0;
    font-size: 1.3rem;
}

.login-brand p {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--color-text-muted);
}

/* ---------- Inspector flow ---------- */

.flow {
    max-width: 560px;
    margin-inline: auto;
}

.flow .btn-lg {
    margin-bottom: var(--space-1);
}

.flow-steps {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: var(--space-3);
}

.step {
    display: flex;
    align-items: center;
    gap: 8px;
}

.step-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1.5px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 0.78rem;
    font-weight: 650;
    background: var(--color-surface);
}

.step-label {
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.step.current .step-dot {
    border-color: var(--color-brand);
    background: var(--color-brand);
    color: #FFFFFF;
}

.step.current .step-label {
    color: var(--color-text);
}

.step.done .step-dot {
    border-color: var(--color-text);
    background: var(--color-text);
    color: #FFFFFF;
}

.step-line {
    flex: 1;
    height: 1.5px;
    background: var(--color-border);
    min-width: 12px;
}

.step-line.done {
    background: var(--color-text);
}

.hidden {
    display: none;
}

/* Full-screen scanner. Inline, the preview opened below two full-width buttons and was
   roughly half off-screen on a 375x553 phone; scanning is the primary path here, so it
   takes the whole screen instead. The compound .qr-overlay.hidden is deliberate — a bare
   .hidden ties on specificity with .qr-overlay and loses on source order. */
.qr-overlay {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: #000000;
    display: block;
}

.qr-overlay.hidden {
    display: none;
}

.qr-overlay-video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* pointer-events: none so the reticle never swallows a tap meant for Cancel. */
.qr-overlay-mask {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    pointer-events: none;
}

/* The outsized spread dims everything outside the reticle without a second element. */
.qr-overlay-frame {
    width: min(68vw, 260px);
    aspect-ratio: 1;
    border: 3px solid #FFFFFF;
    border-radius: var(--radius-lg);
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45);
}

.qr-overlay-hint {
    margin: 0;
    padding: 0 var(--space-3);
    color: #FFFFFF;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.qr-overlay-tap {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    min-width: 200px;
}

/* Thumb-reachable, and clear of the home indicator — needs viewport-fit=cover. */
.qr-overlay-cancel {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
    min-width: 180px;
}

.tank-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.tank-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-1);
}

.tank-card-number {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.tank-card p {
    margin: 0;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-top: var(--space-1);
}

/* `flex: 1` alone (basis 0) keeps both buttons on one line no matter how narrow
   the screen gets, and `.btn` is nowrap, so the row overflowed the viewport on
   phones — iOS Safari responds by scaling the whole page down to fit. The
   min-width raises each button's hypothetical size to its label width, which is
   what the wrap decision is made against, so a row that cannot fit breaks onto
   two full-width lines. Where the row does fit, basis 0 still splits the space
   evenly, keeping the equal-width buttons on desktop. */
.btn-row .btn {
    flex: 1 1 0;
    min-width: max-content;
}

.review-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px var(--space-3);
    margin: 0;
}

.review-list dt {
    color: var(--color-text-muted);
    font-size: 0.88rem;
}

.review-list dd {
    margin: 0;
    font-weight: 550;
    overflow-wrap: anywhere;
}

.success-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    margin: var(--space-3) 0;
    text-align: center;
}

.success-hero .success-ring {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(30, 127, 79, 0.1);
    color: var(--color-success);
}

.success-hero h1 {
    margin: var(--space-1) 0 0;
}

.inspection-card {
    margin-bottom: var(--space-2);
    transition: border-color var(--ease);
}

.inspection-card:hover {
    border-color: #C9C6C0;
}

.inspection-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-1);
}

.inspection-card .tank-tag {
    font-weight: 700;
    letter-spacing: -0.01em;
}

.inspection-card .inspection-when {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    white-space: nowrap;
}

/* The measurement is the point of the row, so it leads. Tabular figures keep
   the numbers aligned down the list. */
.level-readout {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: 10px;
}

.level-step {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.level-step-label {
    font-size: 0.68rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
}

.level-step-value {
    font-size: 1.25rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

/* Renders empty when LevelDisplay.Unit is blank — don't leave its margin behind. */
.level-unit:empty {
    display: none;
}

.level-unit {
    margin-left: 3px;
    color: var(--color-text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0;
}

/* The reading that matters now is the one after filling; the earlier value is
   reference. */
.level-step.is-before .level-step-value {
    color: var(--color-text-muted);
    font-weight: 550;
}

.level-readout .level-arrow {
    padding-bottom: 3px;
    color: var(--color-text-muted);
}

/* Was "Location (Customer) — TankType", which nests parentheses as soon as a
   name contains any of its own. Separated and demoted instead. */
.inspection-card .inspection-meta {
    margin: 8px 0 0;
    color: var(--color-text-muted);
    font-size: 0.88rem;
    line-height: 1.45;
}

.inspection-meta .sep {
    padding: 0 7px;
    opacity: 0.5;
}

.inspection-card .inspection-note {
    margin: 10px 0 0;
    padding-left: 10px;
    border-left: 2px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* ---------- Home quick actions ---------- */

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: var(--space-2);
}

.action-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: var(--space-2) var(--space-2);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    text-decoration: none;
    transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
}

.action-card:hover {
    border-color: #C9C6C0;
    box-shadow: 0 4px 16px rgba(20, 20, 20, 0.07);
    transform: translateY(-1px);
}

.action-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    color: var(--color-text);
    flex-shrink: 0;
}

.action-card strong {
    display: block;
    font-weight: 650;
}

.action-card span.action-desc {
    display: block;
    margin-top: 2px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* flex-start above is for the two-line title + description. A card with only a
   title is one line next to a 42px icon, and top-aligning leaves it floating
   above the icon's centre. */
.action-card:not(:has(.action-desc)) {
    align-items: center;
}

/* ---------- QR label + print ---------- */

.qr-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
}

.qr-view img {
    image-rendering: pixelated;
    max-width: 100%;
}

.qr-tank-number {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

@media print {
    body * {
        visibility: hidden;
    }

    .qr-print-area,
    .qr-print-area * {
        visibility: visible;
    }

    .qr-print-area {
        position: fixed;
        inset: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: #FFFFFF;
    }
}

/* ---------- Health indicator ---------- */

.health-indicator {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-muted);
}

.health-dot.healthy { background: var(--color-success); }
.health-dot.degraded { background: var(--color-warning); }
.health-dot.down { background: var(--color-danger); }

/* ---------- Mobile: drawer navigation ---------- */

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100vh;
        z-index: 300;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-2);
    }

    .drawer-backdrop {
        position: fixed;
        inset: 0;
        z-index: 250;
        background: rgba(20, 20, 20, 0.35);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.22s ease;
    }

    .drawer-backdrop.open {
        opacity: 1;
        pointer-events: auto;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .topbar {
        padding: 0 var(--space-2);
    }

    .content {
        padding: var(--space-3) var(--space-2) var(--space-6);
    }

    .user-chip-name {
        display: none;
    }
}

@media (min-width: 1025px) {
    .drawer-backdrop {
        display: none;
    }
}

/* ---------- Blazor boot / error UI ---------- */

.loading-shell {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
}

.loading-brand {
    margin-bottom: var(--space-2);
    font-size: 12px;
    letter-spacing: 2px;
}

.loading-tank {
    width: 150px;
    height: auto;
}

/* transform-box: view-box resolves percentages against the nested SVG's viewBox
   (90x170), so translateY(100%) is exactly one tank-height down — empty — and 0
   is full. Stated explicitly because the initial value has differed between
   engines, and getting it wrong silently mis-scales the fill rather than erroring. */
.loading-liquid {
    transform-box: view-box;
    transform: translateY(calc(100% - var(--blazor-load-percentage, 0%)));
    transition: transform 0.15s ease-out;
}

.loading-wave {
    transform-box: view-box;
    animation: loading-wave 2s linear infinite;
}

@keyframes loading-wave {
    from { transform: translateX(0); }
    to { transform: translateX(-60px); }
}

.loading-caption {
    margin-top: 14px;
    font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
    .loading-wave {
        animation: none;
    }

    .loading-liquid {
        transition: none;
    }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 12px var(--space-3);
    background: var(--color-surface);
    border-top: 3px solid var(--color-danger);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 12px;
    top: 8px;
    cursor: pointer;
}
