/* ═══════════════════════════════════════════════════════════
   IG Transport — design system
   Ledger paper, carbon-copy indigo, railway signal semantics.
   Type: Newsreader (titles, document numbers, figures)
         Instrument Sans (interface)
   ═══════════════════════════════════════════════════════════ */

:root {
    /* Paper & ink */
    --paper: #F4F6F3;
    --surface: #FFFFFF;
    --surface-sunk: #F8F9F7;
    --ink: #1A2130;
    --ink-2: #4A5365;
    --ink-3: #7A8394;
    --rule: #E1E5DF;
    --rule-strong: #CBD1C9;

    /* Carbon indigo — the one brand colour */
    --carbon: #2C3782;
    --carbon-deep: #222B68;
    --carbon-tint: #ECEEF8;
    --carbon-wash: #F5F6FC;

    /* Signals */
    --go: #1F7A4D;
    --go-tint: #E6F3EC;
    --caution: #8F5E10;
    --caution-dot: #D39A2C;
    --caution-tint: #FBF3DF;
    --stop: #B3362B;
    --stop-deep: #962B22;
    --stop-tint: #FBEBE9;

    /* Type */
    --font-ui: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-doc: 'Newsreader', 'Iowan Old Style', Georgia, serif;

    /* Layout */
    --sidebar-width: 256px;
    --header-height: 60px;
    --tabbar-height: 62px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --control-h: 42px;

    --shadow-pop: 0 12px 32px -8px rgba(26, 33, 48, 0.22), 0 2px 6px rgba(26, 33, 48, 0.06);
    --shadow-sheet: 0 24px 64px -12px rgba(26, 33, 48, 0.35);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

    /* Aliases kept for inline styles in templates */
    --border: var(--rule);
    --border-color: var(--rule);
    --text-secondary: var(--ink-3);
    --text-heading: var(--ink);
    --navy-400: var(--ink-3);
    --amber-500: var(--caution-dot);
    --blue-500: var(--carbon);
}

/* ─── Reset & base ────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background-color: var(--paper);
    -webkit-font-smoothing: antialiased;
    font-variant-numeric: tabular-nums;
}

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

a:hover {
    color: var(--carbon-deep);
}

h1, h2, h3 {
    color: var(--ink);
}

h3 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.005em;
}

small {
    display: block;
    margin-top: 6px;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--ink-3);
}

hr {
    border: 0;
    border-top: 1px solid var(--rule);
}

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

::selection {
    background: var(--carbon);
    color: #fff;
}

/* ─── App shell ───────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ─── Sidebar ─────────────────────────────────────────── */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--rule);
    z-index: 200;
    transition: transform 0.28s var(--ease-out);
}

.sidebar-brand {
    padding: 20px 20px 16px;
}

.sidebar-brand a {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
}

.brand-icon {
    width: 36px;
    height: 36px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--radius-md);
    background: var(--carbon);
    color: #fff;
    font-size: 0.875rem;
}

.sidebar-brand h2 {
    font-family: var(--font-doc);
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.01em;
}

.brand-sub {
    margin-top: 2px;
    font-size: 0.75rem;
    color: var(--ink-3);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 4px 12px 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--rule-strong) transparent;
}

.nav-section {
    margin-top: 16px;
}

.nav-section-title {
    padding: 0 10px 6px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--ink-3);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 38px;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.9063rem;
    font-weight: 500;
    color: var(--ink-2);
    cursor: pointer;
    user-select: none;
}

.nav-item span {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-item i {
    width: 18px;
    flex: none;
    text-align: center;
    font-size: 0.875rem;
    color: var(--ink-3);
}

.nav-item:hover {
    background: var(--surface-sunk);
    color: var(--ink);
}

.nav-item.active {
    background: var(--carbon-tint);
    color: var(--carbon);
}

.nav-item.active i {
    color: var(--carbon);
}

.nav-dropdown > .nav-item {
    justify-content: space-between;
}

.nav-dropdown .dropdown-arrow {
    width: auto;
    font-size: 0.625rem;
    transition: transform 0.2s var(--ease-out);
}

.nav-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    display: none;
    margin: 2px 0 4px 18px;
    padding-left: 10px;
    border-left: 1px solid var(--rule);
}

.nav-dropdown.open .nav-dropdown-menu {
    display: block;
}

.nav-dropdown-menu .nav-item {
    min-height: 34px;
    font-size: 0.875rem;
    font-weight: 400;
}

.nav-dropdown-menu .nav-item i {
    font-size: 0.75rem;
}

.sidebar-footer {
    padding: 10px 12px 12px;
    border-top: 1px solid var(--rule);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-md);
    cursor: pointer;
}

.sidebar-user:hover {
    background: var(--surface-sunk);
}

.sidebar-avatar {
    width: 34px;
    height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--carbon-tint);
    color: var(--carbon);
    font-family: var(--font-doc);
    font-size: 1rem;
    font-weight: 600;
}

.sidebar-user-info {
    min-width: 0;
}

.sidebar-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: var(--ink-3);
    text-transform: capitalize;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 33, 48, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 190;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ─── Main column & top bar ───────────────────────────── */
.main-content {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-width);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 32px;
    background: rgba(244, 246, 243, 0.88);
    backdrop-filter: saturate(1.4) blur(10px);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--rule);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.mobile-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--ink);
    font-size: 1rem;
    cursor: pointer;
}

.mobile-toggle:hover {
    background: var(--surface);
}

.branch-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    max-width: 240px;
    padding: 0 12px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--surface);
    font-size: 0.8438rem;
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
}

.branch-selector:hover {
    border-color: var(--rule-strong);
}

.branch-selector span {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.branch-selector i:first-child {
    font-size: 0.75rem;
    color: var(--carbon);
}

/* ─── Dropdowns ───────────────────────────────────────── */
.dropdown {
    position: relative;
    min-width: 0;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 220px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s var(--ease-out), visibility 0.15s;
    z-index: 300;
}

.dropdown.open > .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: none;
}

@media (hover: hover) and (pointer: fine) {
    .dropdown:hover > .dropdown-menu {
        opacity: 1;
        visibility: visible;
        transform: none;
    }
    /* bridge the gap so the menu survives the pointer crossing it */
    .dropdown-menu::before {
        content: '';
        position: absolute;
        inset: -8px 0 auto 0;
        height: 8px;
    }
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 38px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--ink);
}

.dropdown-item i {
    width: 16px;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--ink-3);
}

.dropdown-item:hover {
    background: var(--surface-sunk);
    color: var(--ink);
}

.dropdown-item.active {
    background: var(--carbon-tint);
    color: var(--carbon);
    font-weight: 600;
}

.dropdown-item.active i {
    color: var(--carbon);
}

/* ─── Mobile tab bar ──────────────────────────────────── */
.tabbar {
    display: none;
}

/* ─── Container & page header ─────────────────────────── */
.container {
    max-width: 1360px;
    margin: 0 auto;
    padding: 32px 32px 64px;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
}

.page-header h1 {
    font-family: var(--font-doc);
    font-size: 2rem;
    font-weight: 500;
    line-height: 1.15;
    letter-spacing: -0.015em;
}

.page-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.inline-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.inline-filters .form-control {
    width: auto;
    min-width: 170px;
}

.container > h3,
.section-title {
    margin: 32px 0 12px;
    font-family: var(--font-doc);
    font-size: 1.3125rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.form-container h3 {
    margin: 10px 0 14px;
    padding-top: 24px;
    border-top: 1px solid var(--rule);
}

.lede {
    max-width: 70ch;
    margin-bottom: 16px;
    color: var(--ink-2);
}

/* ─── Tooltips (data-tooltip) ─────────────────────────── */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    z-index: 50;
    width: max-content;
    max-width: 240px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    background: var(--ink);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.35;
    text-align: left;
    white-space: normal;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease, transform 0.12s ease;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

td.actions [data-tooltip]:last-child::after {
    left: auto;
    right: 0;
    transform: translateX(0) translateY(4px);
}

td.actions [data-tooltip]:last-child:hover::after,
td.actions [data-tooltip]:last-child:focus-visible::after {
    transform: translateX(0) translateY(0);
}

/* ─── Pagination ──────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.pagination-info {
    font-size: 0.8438rem;
    color: var(--ink-2);
}

.pagination-links {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pagination-gap {
    padding: 0 4px;
    color: var(--ink-3);
}

/* ─── Buttons ─────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--control-h);
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9063rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn i {
    font-size: 0.8125rem;
}

.btn-primary {
    background: var(--carbon);
    color: #fff;
}

.btn-primary:hover {
    background: var(--carbon-deep);
    color: #fff;
}

.btn-secondary {
    background: var(--surface);
    border-color: var(--rule-strong);
    color: var(--ink);
}

.btn-secondary:hover {
    background: var(--surface-sunk);
    border-color: var(--ink-3);
    color: var(--ink);
}

.btn-info {
    background: var(--carbon-tint);
    color: var(--carbon);
}

.btn-info:hover {
    background: #DEE1F3;
    color: var(--carbon-deep);
}

.btn-danger {
    background: var(--stop);
    color: #fff;
}

.btn-danger:hover {
    background: var(--stop-deep);
    color: #fff;
}

.btn-sm {
    min-height: 34px;
    padding: 0 12px;
    font-size: 0.8438rem;
}

/* Row actions: quiet until used */
.btn-icon,
td .btn-sm {
    width: 34px;
    min-height: 34px;
    padding: 0;
    border-color: transparent;
    background: transparent;
    color: var(--ink-2);
}

.btn-icon:hover,
td .btn-sm:hover {
    background: var(--carbon-tint);
    color: var(--carbon);
}

.btn-icon.btn-danger:hover,
td .btn-sm.btn-danger:hover {
    background: var(--stop-tint);
    color: var(--stop);
}

/* ─── Surfaces ────────────────────────────────────────── */
.card,
.table-container,
.form-container,
.filters-bar,
.dashboard-card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
}

.card {
    padding: 24px;
}

.panel-pad {
    padding: 24px;
}

.stack > * + * {
    margin-top: 20px;
}

/* ─── Tables ──────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink-3);
    white-space: nowrap;
    background: var(--surface-sunk);
    border-bottom: 1px solid var(--rule);
}

tbody td {
    padding: 12px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--rule);
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover td {
    background: var(--carbon-wash);
}

/* document numbers read as if stamped */
tbody td strong,
.activity-table tbody td:first-child a {
    font-family: var(--font-doc);
    font-size: 1.0313rem;
    font-weight: 600;
    color: var(--carbon);
    letter-spacing: 0.005em;
}

tbody td a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

tbody td a.btn:hover {
    text-decoration: none;
}

tfoot td {
    padding: 12px 16px;
    font-weight: 600;
    background: var(--surface-sunk);
    border-top: 1px solid var(--rule-strong);
}

td.cell-actions,
td.nowrap,
.table-container tbody td:first-child {
    white-space: nowrap;
}

.table-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--rule);
}

.table-head strong {
    font-family: var(--font-doc);
    font-size: 1.0625rem;
    font-weight: 600;
}

.table-head span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8438rem;
    color: var(--ink-3);
}

.toolbar-end {
    display: flex;
    justify-content: flex-end;
    margin: 0 0 12px;
}

/* ─── Forms ───────────────────────────────────────────── */
.form-container {
    padding: 28px;
}

.form-group {
    flex: 1;
    min-width: 0;
    margin-bottom: 18px;
}

.form-group label,
.form-group > .radio-group + label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8438rem;
    font-weight: 500;
    color: var(--ink-2);
}

.form-control {
    display: block;
    width: 100%;
    min-height: var(--control-h);
    padding: 9px 12px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.4;
    color: var(--ink);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select.form-control {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%237A8394' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1.5 1.5 6 6l4.5-4.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
}

textarea.form-control {
    min-height: 76px;
    resize: vertical;
}

input[type="file"].form-control {
    padding: 8px;
    font-size: 0.875rem;
}

.form-control:hover {
    border-color: var(--ink-3);
}

.form-control:focus {
    outline: 0;
    border-color: var(--carbon);
    box-shadow: 0 0 0 3px rgba(44, 55, 130, 0.14);
}

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

.form-control[readonly],
.form-control:disabled {
    background: var(--surface-sunk);
    color: var(--ink-2);
    border-color: var(--rule);
    box-shadow: none;
}

/* read-only value shown in a form layout */
.form-static,
div.form-control {
    min-height: 0;
    padding: 0 0 10px;
    border: 0;
    border-bottom: 1px solid var(--rule);
    border-radius: 0;
    background: transparent;
    font-size: 1rem;
    font-weight: 500;
}

.form-static:hover,
div.form-control:hover {
    border-color: var(--rule);
}

.form-static strong {
    font-family: var(--font-doc);
    font-size: 1.1875rem;
    font-weight: 600;
}

.form-row {
    display: flex;
    gap: 20px;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
    padding-top: 24px;
    border-top: 1px solid var(--rule);
}

/* Radio cards */
.radio-group {
    display: flex;
    gap: 10px;
}

.radio-group .radio-companion {
    flex: 1;
    margin: 0;
}

.radio-option {
    flex: 1;
    position: relative;
    margin: 0 !important;
    cursor: pointer;
}

.radio-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.radio-custom {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--control-h);
    padding: 8px 14px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.radio-custom i {
    font-size: 0.875rem;
    color: var(--ink-3);
}

.radio-label {
    font-size: 0.9063rem;
    font-weight: 500;
    color: var(--ink);
}

.radio-option:hover .radio-custom {
    border-color: var(--ink-3);
}

.radio-option input[type="radio"]:checked + .radio-custom {
    border-color: var(--carbon);
    background: var(--carbon-tint);
    box-shadow: inset 0 0 0 1px var(--carbon);
}

.radio-option input[type="radio"]:checked + .radio-custom i,
.radio-option input[type="radio"]:checked + .radio-custom .radio-label {
    color: var(--carbon);
}

.radio-option input[type="radio"]:focus-visible + .radio-custom {
    outline: 2px solid var(--carbon);
    outline-offset: 2px;
}

/* Repeating line (RR products) */
.item-row {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    margin-bottom: 10px;
    padding: 14px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    background: var(--surface-sunk);
}

.item-row .form-group {
    margin-bottom: 0;
}

.item-row > .btn {
    flex: none;
    width: var(--control-h);
    min-height: var(--control-h);
    padding: 0;
    background: transparent;
    border-color: var(--rule-strong);
    color: var(--ink-2);
}

.item-row > .btn:hover {
    background: var(--stop-tint);
    border-color: var(--stop);
    color: var(--stop);
}

/* Line-item tables inside forms */
.form-container .table-container {
    margin-bottom: 12px;
}

.form-container .table-container td {
    padding: 10px 12px;
}

.form-container .table-container tbody tr:hover td {
    background: transparent;
}

.form-container .table-container tbody td:last-child .btn {
    width: 38px;
    min-height: 38px;
}

.form-container .table-container + .btn {
    margin-bottom: 24px;
}

#productsContainer + .btn {
    margin: 2px 0 24px;
}

/* ─── Filters bar ─────────────────────────────────────── */
.filters-bar {
    margin-bottom: 20px;
    padding: 18px 20px;
}

.filter-form {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 16px;
    width: 100%;
}

.filter-form .form-group {
    flex: 0 1 200px;
    margin-bottom: 0;
}

.filter-form .form-group.wide {
    flex-basis: 300px;
}

/* ─── Modals ──────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    overflow-y: auto;
    padding: 5vh 16px;
    background: rgba(26, 33, 48, 0.45);
    animation: fadeIn 0.18s ease;
}

.modal-content {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sheet);
    animation: sheetIn 0.26s var(--ease-out);
}

.modal-large { max-width: 860px; }
.modal-small { max-width: 420px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--rule);
}

.modal-header h2 {
    font-family: var(--font-doc);
    font-size: 1.4375rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.modal-body {
    padding: 24px;
}

.close {
    width: 36px;
    height: 36px;
    flex: none;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--ink-3);
    cursor: pointer;
}

.close:hover {
    background: var(--surface-sunk);
    color: var(--ink);
}

.modal-confirm {
    max-width: 400px;
    margin-top: 12vh;
    text-align: center;
}

.modal-confirm .modal-header {
    flex-direction: column;
    gap: 14px;
    padding: 28px 24px 0;
    border-bottom: 0;
}

.confirm-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--stop-tint);
    color: var(--stop);
    font-size: 1.125rem;
}

.confirm-message {
    margin-bottom: 24px;
    color: var(--ink-2);
}

.modal-confirm .form-actions {
    margin-top: 0;
}

.modal-confirm .form-actions .btn {
    flex: 1;
}

@keyframes fadeIn {
    from { opacity: 0; }
}

@keyframes sheetIn {
    from { opacity: 0; transform: translateY(12px); }
}

/* ─── Sign in ─────────────────────────────────────────── */
.login-page {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--surface);
}

.login-visual {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 48px;
    padding: 48px 56px;
    background: var(--carbon);
    color: #fff;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-doc);
    font-size: 1.375rem;
    font-weight: 500;
}

.login-brand .brand-icon {
    background: #fff;
    color: var(--carbon);
}

.login-visual h1 {
    max-width: 14ch;
    font-family: var(--font-doc);
    font-size: clamp(2.25rem, 3.6vw, 3.25rem);
    font-weight: 400;
    line-height: 1.08;
    letter-spacing: -0.02em;
    color: #fff;
}

.login-route {
    list-style: none;
    display: grid;
    gap: 0;
}

.login-route li {
    position: relative;
    padding: 0 0 22px 28px;
    font-size: 0.9375rem;
    color: rgba(255, 255, 255, 0.82);
}

.login-route li:last-child {
    padding-bottom: 0;
}

.login-route li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    width: 9px;
    height: 9px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--carbon);
    z-index: 1;
}

.login-route li::after {
    content: '';
    position: absolute;
    left: 5.5px;
    top: 12px;
    bottom: -6px;
    width: 2px;
    background: rgba(255, 255, 255, 0.35);
}

.login-route li:last-child::after {
    display: none;
}

.login-route li:last-child::before {
    background: #fff;
}

.login-form-side {
    display: grid;
    place-items: center;
    padding: 48px 24px;
}

.login-container {
    width: 100%;
    max-width: 380px;
}

.login-container h2 {
    font-family: var(--font-doc);
    font-size: 2rem;
    font-weight: 500;
    letter-spacing: -0.015em;
}

.login-container > p {
    margin: 6px 0 28px;
    color: var(--ink-2);
}

.login-container .btn {
    width: 100%;
    min-height: 46px;
    margin-top: 6px;
}

/* ─── Flash messages ──────────────────────────────────── */
.flash-messages {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: grid;
    gap: 8px;
    width: min(400px, calc(100vw - 32px));
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 16px;
    border: 1px solid var(--rule);
    border-left-width: 3px;
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
    font-size: 0.9063rem;
    font-weight: 500;
    cursor: pointer;
    animation: toastIn 0.3s var(--ease-out);
}

.message i {
    margin-top: 3px;
}

.message-success {
    border-left-color: var(--go);
}

.message-success i {
    color: var(--go);
}

.message-error {
    border-left-color: var(--stop);
}

.message-error i {
    color: var(--stop);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-8px); }
}

@keyframes toastOut {
    to { opacity: 0; transform: translateY(-8px); }
}

/* ─── Dashboard: the route line ───────────────────────── */
.route {
    margin-bottom: 28px;
    padding: 28px 28px 24px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
}

.route-line {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.route-stop {
    position: relative;
    padding: 30px 20px 0 0;
}

/* the track */
.route-stop::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--rule-strong);
}

.route-stop:last-child::before {
    right: auto;
    width: 14px;
}

/* the station */
.route-stop::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 14px;
    height: 14px;
    border: 3px solid var(--carbon);
    border-radius: 50%;
    background: var(--surface);
}

.route-stop:last-child::after {
    background: var(--carbon);
}

.route-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ink);
}

.route-count {
    margin-top: 6px;
    font-family: var(--font-doc);
    font-size: 2.75rem;
    font-weight: 400;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--ink);
}

.route-label {
    margin-top: 4px;
    font-size: 0.8125rem;
    color: var(--ink-3);
}

.route-split {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    margin-top: 10px;
    font-size: 0.8125rem;
    color: var(--ink-2);
}

.route-split span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.signal {
    width: 8px;
    height: 8px;
    flex: none;
    border-radius: 50%;
    background: var(--ink-3);
}

.signal-go { background: var(--go); }
.signal-caution { background: var(--caution-dot); }

.route-action {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 36px;
    margin-top: 14px;
    padding: 0 12px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-md);
    font-size: 0.8438rem;
    font-weight: 600;
    color: var(--carbon);
}

.route-action i {
    font-size: 0.6875rem;
}

.route-action:hover {
    border-color: var(--carbon);
    background: var(--carbon-tint);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.dashboard-card {
    min-width: 0;
    overflow-x: auto;
}

.dashboard-card h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px 14px;
    font-family: var(--font-doc);
    font-size: 1.25rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.dashboard-card h3 .signal {
    width: 9px;
    height: 9px;
}

.activity-table thead th {
    background: transparent;
    padding: 8px 20px;
}

.activity-table tbody td {
    padding: 10px 20px;
    font-size: 0.875rem;
}

/* ─── Badges ──────────────────────────────────────────── */
.status-badge,
.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 8px;
    border-radius: 999px;
    font-size: 0.7813rem;
    font-weight: 600;
    white-space: nowrap;
    background: var(--surface-sunk);
    color: var(--ink-2);
}

.status-badge::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.status-badge.active {
    background: var(--go-tint);
    color: var(--go);
}

.status-badge.dispatch,
.status-badge.inward {
    background: var(--caution-tint);
    color: var(--caution);
}

.status-badge.dispatch::before,
.status-badge.inward::before {
    background: var(--caution-dot);
}

.status-badge.inactive,
.status-badge.cancelled {
    background: var(--stop-tint);
    color: var(--stop);
}

.role-badge {
    padding: 3px 10px;
    text-transform: capitalize;
}

.role-badge.admin {
    background: var(--carbon-tint);
    color: var(--carbon);
}

/* ─── Document lists (LR, GP): compact rows with an expandable detail strip ── */
.doc-table thead th,
.doc-table tbody td {
    padding: 10px 14px;
}

.doc-table .doc-row {
    cursor: pointer;
}

.doc-table .doc-id {
    white-space: nowrap;
}

.doc-table .doc-id-inner {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.doc-table .doc-id-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.doc-table .doc-id-text strong {
    line-height: 1.2;
}

.doc-table .doc-id .status-badge {
    padding: 2px 8px 2px 7px;
    font-family: var(--font-ui);
    font-size: 0.7188rem;
}

.doc-expander {
    flex: none;
    width: 24px;
    height: 24px;
    margin: -1px 0 0 -6px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-3);
    font-size: 0.6875rem;
    cursor: pointer;
}

.doc-expander:hover {
    background: var(--carbon-tint);
    color: var(--carbon);
}

.doc-expander:focus-visible {
    outline: 2px solid var(--carbon);
    outline-offset: 1px;
}

.doc-expander i {
    display: inline-block;
    transition: transform 0.15s ease;
}

.doc-row.is-open .doc-expander i {
    transform: rotate(90deg);
}

.doc-row.is-open td {
    border-bottom-color: transparent;
}

/* RR numbers stack, one per line, digits aligned */
.rr-list {
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.8438rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.5;
    white-space: nowrap;
}

.doc-type {
    display: inline-block;
    min-width: 36px;
    padding: 1px 6px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-align: center;
    color: var(--ink-2);
}

.doc-type-ex {
    border-color: var(--caution-dot);
    color: var(--caution);
}

/* The detail strip reads as a sunk ledger panel under its row */
.doc-table .doc-detail > td {
    padding: 0 14px 14px 44px;
    background: var(--surface-sunk);
    box-shadow: inset 0 1px 0 var(--rule);
}

.doc-table .doc-detail:hover > td {
    background: var(--surface-sunk);
}

.doc-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px 20px;
    margin: 0;
    padding-top: 12px;
}

.doc-detail-grid dt {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--ink-3);
}

.doc-detail-grid dd {
    margin: 2px 0 0;
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.doc-detail-grid dd small {
    display: block;
    font-size: 0.7813rem;
    color: var(--ink-2);
}

.muted {
    color: var(--ink-3);
}

@media (prefers-reduced-motion: reduce) {
    .doc-expander i { transition: none; }
}

/* ─── Searchable selects (Tom Select skin) ─────────────── */
.ts-wrapper.form-control {
    padding: 0;
    border: 0;
    min-height: 0;
    background: transparent;
    box-shadow: none;
}

.ts-wrapper.single .ts-control,
.ts-wrapper .ts-control {
    min-height: var(--control-h);
    padding: 9px 36px 9px 12px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.4;
    color: var(--ink);
    box-shadow: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ts-wrapper.single .ts-control {
    background-image: none;
}

.ts-wrapper.single .ts-control::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 14px;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--ink-3);
    border-bottom: 1.5px solid var(--ink-3);
    transform: translateY(-65%) rotate(45deg);
}

.ts-wrapper.focus .ts-control {
    border-color: var(--carbon);
    box-shadow: 0 0 0 3px rgba(44, 55, 130, 0.14);
}

.ts-wrapper.single.input-active .ts-control {
    background: var(--surface);
}

.ts-wrapper .ts-control input::placeholder,
.ts-wrapper .ts-control .item:empty::before {
    color: var(--ink-3);
}

.ts-wrapper .ts-control > input {
    font-family: inherit;
    font-size: inherit;
    color: var(--ink);
}

.ts-dropdown {
    margin-top: 4px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    font-family: inherit;
    font-size: 0.9063rem;
    color: var(--ink);
    z-index: 60;
}

.ts-dropdown .option {
    padding: 8px 12px;
}

.ts-dropdown .active {
    background: var(--carbon-tint);
    color: var(--carbon);
}

.ts-dropdown .no-results {
    padding: 8px 12px;
    color: var(--ink-3);
}

.ts-dropdown .option[data-value=""] {
    color: var(--ink-3);
}

.radio-group .ts-wrapper.radio-companion {
    flex: 1;
    margin: 0;
}

#items-table .ts-wrapper .ts-control,
.item-row .ts-wrapper .ts-control {
    min-height: 38px;
    padding-top: 7px;
    padding-bottom: 7px;
}

/* ─── Duplicate guard list ────────────────────────────── */
.dup-list {
    max-height: 220px;
    margin: 0 0 18px;
    padding: 0;
    list-style: none;
    overflow-y: auto;
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    text-align: left;
}

.dup-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--rule);
    font-size: 0.875rem;
}

.dup-list li:last-child {
    border-bottom: 0;
}

.dup-list li span {
    color: var(--ink-3);
    white-space: nowrap;
}

/* ─── Recent LRs ledger under the LR form ─────────────── */
.ledger {
    margin-top: 28px;
}

.ledger-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-bottom: 12px;
}

.ledger-head h2 {
    font-family: var(--font-doc);
    font-size: 1.3125rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.ledger-head h2 small {
    margin-left: 8px;
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--ink-3);
}

.ledger-search {
    position: relative;
    flex: 0 1 320px;
}

.ledger-search i {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    font-size: 0.8125rem;
    color: var(--ink-3);
}

.ledger-search .form-control {
    padding-left: 34px;
}

.ledger-body {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.ledger-row {
    display: grid;
    grid-template-columns: minmax(170px, 1.2fr) minmax(200px, 1.6fr) minmax(160px, 1.2fr) auto;
    align-items: center;
    gap: 8px 20px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--rule);
}

.ledger-row:last-child {
    border-bottom: 0;
}

.ledger-row:hover {
    background: var(--carbon-wash);
}

.ledger-id strong {
    display: block;
    font-family: var(--font-doc);
    font-size: 1.0313rem;
    font-weight: 600;
    color: var(--carbon);
    line-height: 1.2;
}

.ledger-id .meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-top: 3px;
    font-size: 0.7813rem;
    color: var(--ink-3);
}

.ledger-id .meta > * {
    white-space: nowrap;
}

.ledger-id .status-badge {
    padding: 1px 7px 1px 6px;
    font-size: 0.6875rem;
}

.ledger-route {
    font-size: 0.875rem;
    line-height: 1.35;
}

.ledger-route .arrow {
    margin: 0 6px;
    color: var(--ink-3);
}

.ledger-route small {
    display: block;
    color: var(--ink-2);
}

.ledger-figures {
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.35;
}

.ledger-figures small {
    display: block;
    color: var(--ink-2);
}

.ledger-actions {
    display: flex;
    gap: 2px;
    white-space: nowrap;
}

.ledger-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 16px;
    background: var(--surface-sunk);
    border-top: 1px solid var(--rule);
    font-size: 0.8125rem;
    color: var(--ink-2);
}

.ledger-foot .btn {
    min-height: 30px;
}

.ledger-empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--ink-3);
}

/* ─── Empty state ─────────────────────────────────────── */
.empty-state,
td.empty-state {
    padding: 40px 20px;
    text-align: center;
    font-size: 0.9375rem;
    color: var(--ink-3);
}

/* ─── Invoice sheet ───────────────────────────────────── */
#invoice-sheet {
    max-width: 960px;
}

#invoice-sheet h2 {
    font-family: var(--font-doc);
    font-weight: 600;
}

/* ─── Responsive: tablet ──────────────────────────────── */
@media (max-width: 1100px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        width: min(300px, 86vw);
        box-shadow: none;
    }

    .sidebar.open {
        transform: none;
        box-shadow: var(--shadow-sheet);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-toggle {
        display: grid;
        place-items: center;
    }

    .topbar {
        padding: 0 16px 0 8px;
    }

    .container {
        padding: 24px 20px 56px;
    }

    .nav-item {
        min-height: 44px;
    }

    .nav-dropdown-menu .nav-item {
        min-height: 42px;
    }
}

/* ─── Responsive: phone ───────────────────────────────── */
@media (max-width: 680px) {
    body {
        font-size: 16px;
    }

    .container {
        padding: 20px 16px calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 32px);
    }

    .topbar {
        padding: 0 12px 0 4px;
    }

    .branch-selector {
        max-width: 38vw;
        padding: 0 10px;
    }

    .dropdown-menu {
        position: fixed;
        top: calc(var(--header-height) + 4px);
        left: 12px;
        right: 12px;
    }

    .sidebar-footer .dropdown-menu {
        position: absolute;
    }

    /* Tab bar */
    .tabbar {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 150;
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        height: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--rule);
    }

    .tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        border: 0;
        background: transparent;
        font-family: inherit;
        font-size: 0.6875rem;
        font-weight: 500;
        color: var(--ink-3);
        cursor: pointer;
    }

    .tab i {
        font-size: 1.0625rem;
    }

    .tab.active {
        color: var(--carbon);
        font-weight: 600;
    }

    /* Page header */
    .page-header {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
        margin-bottom: 18px;
    }

    .page-header h1 {
        font-size: 1.75rem;
    }

    .page-actions,
    .inline-filters {
        width: 100%;
    }

    .page-actions > .btn {
        flex: 1;
    }

    .inline-filters .form-control {
        flex: 1;
        min-width: 0 !important;
    }

    /* Forms */
    .form-container {
        padding: 20px 16px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-control {
        font-size: 1rem; /* stops iOS zooming into fields */
        min-height: 46px;
    }

    .radio-group {
        flex-wrap: wrap;
    }

    .radio-option {
        flex: 1 1 140px;
    }

    .radio-custom {
        min-height: 46px;
    }

    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .btn {
        width: 100%;
        min-height: 46px;
    }

    .modal-confirm .form-actions {
        flex-direction: row;
    }

    .item-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        padding: 12px;
    }

    .item-row .form-group:first-child {
        grid-column: 1 / -1;
    }

    .item-row > .btn {
        grid-column: 1 / -1;
        width: 100%;
        margin: 0 !important;
    }

    .filters-bar {
        padding: 16px;
    }

    .filter-form {
        gap: 12px;
    }

    .filter-form .form-group,
    .filter-form .form-group.wide {
        flex: 1 1 140px;
        min-width: 0 !important;
    }

    .filter-form > .btn {
        width: 100%;
        min-height: 46px;
    }

    .toolbar-end .btn,
    .toolbar-end form {
        width: 100%;
    }

    /* Modals become full-height sheets */
    .modal {
        padding: 0;
    }

    .modal-content,
    .modal-large,
    .modal-small {
        max-width: none;
        min-height: 100%;
        border-radius: 0;
    }

    .modal-header {
        position: sticky;
        top: 0;
        z-index: 1;
        padding: 14px 16px;
        background: var(--surface);
    }

    .modal-body {
        padding: 20px 16px 32px;
    }

    .modal-content.modal-confirm {
        width: auto;
        min-height: 0;
        margin: 22vh 16px 0;
        border-radius: var(--radius-lg);
    }

    .modal-confirm .modal-header {
        position: static;
        padding: 28px 24px 0;
    }

    .modal-confirm .modal-body {
        padding: 20px 20px 24px;
    }

    /* Tables restack as labelled cards (labels set by common.js) */
    table.stackable thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    table.stackable,
    table.stackable tbody,
    table.stackable tfoot {
        display: block;
    }

    table.stackable tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px 16px;
        padding: 16px;
        border-bottom: 1px solid var(--rule);
    }

    table.stackable tbody tr:last-child {
        border-bottom: 0;
    }

    table.stackable td {
        display: block;
        min-width: 0;
        padding: 0;
        border: 0;
        background: transparent !important;
        overflow-wrap: anywhere;
    }

    table.stackable td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 1px;
        font-size: 0.75rem;
        font-weight: 500;
        color: var(--ink-3);
    }

    table.stackable tbody td:first-child:not(.empty-state) {
        grid-column: 1 / -1;
        font-family: var(--font-doc);
        font-size: 1.1875rem;
        font-weight: 600;
        color: var(--carbon);
    }

    table.stackable tbody td:first-child strong,
    table.stackable tbody td:first-child a {
        font-size: inherit;
    }

    table.stackable td[colspan],
    table.stackable td.cell-actions {
        grid-column: 1 / -1;
    }

    table.stackable td:empty {
        display: none;
    }

    table.stackable td.cell-actions {
        display: flex;
        gap: 8px;
        padding-top: 12px;
        border-top: 1px dashed var(--rule-strong);
    }

    table.stackable td.cell-actions::before {
        display: none;
    }

    table.stackable td.cell-actions:empty {
        display: none;
    }

    table.stackable tr.doc-detail[hidden] {
        display: none;
    }

    table.stackable tr.doc-detail {
        padding: 0;
        margin-top: -1px;
    }

    table.stackable .doc-table .doc-detail > td,
    .doc-table.stackable .doc-detail > td {
        padding: 0 16px 16px;
    }

    .ledger-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .ledger-actions {
        padding-top: 6px;
    }

    /* Document lists: chevron sits with the number; detail strip keeps UI type */
    table.doc-table.stackable tbody td.doc-id::before {
        display: none;
    }

    table.doc-table.stackable tbody td.doc-id .doc-expander {
        margin-top: 2px;
    }

    table.doc-table.stackable tbody tr.doc-detail > td {
        font-family: var(--font-ui);
        font-size: inherit;
        font-weight: inherit;
        color: inherit;
        background: var(--surface-sunk) !important;
    }

    table.doc-table.stackable tbody tr.doc-detail > td::before {
        display: none;
    }

    table.stackable td.cell-actions .btn {
        flex: 1;
        width: auto;
        min-height: 42px;
        border-color: var(--rule-strong);
        background: var(--surface);
    }

    table.stackable tfoot tr {
        background: var(--surface-sunk);
        border-top: 1px solid var(--rule-strong);
        border-bottom: 0;
    }

    table.stackable tfoot td {
        background: transparent;
    }

    table.stackable tfoot td[colspan] {
        text-align: left !important;
        font-family: var(--font-doc);
        font-size: 1.0625rem;
    }

    /* line-item editors: inputs keep full width */
    .form-container table.stackable tr {
        margin-bottom: 10px;
        padding: 12px;
        border: 1px solid var(--rule);
        border-radius: var(--radius-md);
        background: var(--surface-sunk);
    }

    .form-container table.stackable tbody td:nth-child(-n+2) {
        grid-column: 1 / -1;
        font-family: inherit;
        font-size: inherit;
        font-weight: inherit;
        color: inherit;
    }

    .form-container table.stackable tbody td:last-child {
        grid-column: 1 / -1;
    }

    .form-container table.stackable td {
        padding: 0;
    }

    .form-container table.stackable td.cell-actions {
        padding-top: 0;
        border-top: 0;
    }

    .form-container table.stackable tbody td:last-child .btn::after {
        content: 'Remove';
    }

    .form-container table.stackable tfoot td:first-child::before {
        display: none;
    }

    .form-container table.stackable tbody td:last-child .btn {
        width: 100%;
        border-color: var(--rule-strong);
        background: var(--surface);
        color: var(--ink-2);
    }

    .form-container .table-container {
        border: 0;
        border-radius: 0;
        overflow: visible;
    }

    .form-container table.stackable tfoot tr {
        border: 0;
        border-top: 1px solid var(--rule-strong);
        border-radius: 0;
        background: transparent;
        padding: 12px 0 0;
    }

    .form-container table.stackable tfoot td:first-child {
        grid-column: 1 / -1;
        text-align: left !important;
    }

    /* Dashboard */
    .route {
        padding: 22px 18px 6px;
    }

    .route-line {
        grid-template-columns: 1fr;
    }

    .route-stop {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 0 12px;
        padding: 0 0 26px 30px;
    }

    .route-stop::before {
        top: 8px;
        bottom: -8px;
        left: 6px;
        right: auto;
        width: 2px;
        height: auto;
    }

    .route-stop:last-child::before {
        display: none;
    }

    .route-stop::after {
        top: 3px;
    }

    .route-name,
    .route-label,
    .route-split {
        grid-column: 1;
    }

    .route-count {
        grid-column: 2;
        grid-row: 1 / span 2;
        margin-top: 0;
        font-size: 2.25rem;
        text-align: right;
    }

    .route-action {
        grid-column: 1 / -1;
        justify-self: start;
        margin-top: 12px;
        min-height: 40px;
    }

    .dashboard-card h3 {
        padding: 16px 16px 8px;
    }

    /* Sign in */
    .login-page {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .login-visual {
        gap: 20px;
        padding: 28px 24px 32px;
    }

    .login-visual h1 {
        max-width: none;
        font-size: 1.875rem;
    }

    .login-route {
        display: none;
    }

    .login-form-side {
        place-items: start center;
        padding: 32px 24px 48px;
    }

    .flash-messages {
        top: 8px;
        right: 16px;
    }
}

@media (min-width: 681px) and (max-width: 900px) {
    .login-page {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .login-visual {
        gap: 24px;
        padding: 36px 40px;
    }

    .login-route {
        display: none;
    }
}

/* ─── Reduced motion ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ─── Print ───────────────────────────────────────────── */
@media print {
    .sidebar,
    .sidebar-overlay,
    .topbar,
    .tabbar,
    .page-actions,
    .flash-messages,
    .filters-bar,
    .toolbar-end,
    .modal {
        display: none !important;
    }

    body {
        background: #fff;
        font-size: 12px;
    }

    .main-content {
        margin: 0;
    }

    .container {
        max-width: none;
        padding: 0;
    }

    .table-container,
    .form-container {
        border: 0;
        border-radius: 0;
        overflow: visible;
    }

    thead th,
    tfoot td {
        background: transparent;
    }
}
