:root {
    --border: #e1e0d9;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --surface-1: #f1efe8;
    --surface-2: #ffffff;
    --accent: #2a78d6;
    /* Form fields: kept separate from card colours so a field always
       stands out from the card it sits on. */
    --field-bg: #ffffff;
    --field-border: #cfccc2;
    --field-border-hover: #a9a69c;
    --field-placeholder: #898781;
    --field-disabled-bg: #f1efe8;
    --focus-ring: rgba(42, 120, 214, 0.28);
    --button-border: var(--border);
    color-scheme: light;
}

/* Dark mode - same token names, dark-appropriate values. Applied via a
   data-theme attribute on <html>, set by the inline script in
   templates/header.php before first paint (avoids a flash of the wrong
   theme), and toggled by the switch in the sidebar. Defaults to the
   OS's prefers-color-scheme on a person's first visit; once they use
   the toggle, their explicit choice (in localStorage) always wins after
   that, regardless of OS setting. */
html[data-theme="dark"] {
    --border: #35342f;
    --text-primary: #f2f1ec;
    --text-secondary: #b8b6af;
    --text-muted: #837f77;
    --surface-1: #131211;
    --surface-2: #1e1d1b;
    --accent: #5b9be0;
    --field-bg: #0e0d0c;
    --field-border: #78746b;
    --field-border-hover: #9a968d;
    --field-placeholder: #8e8a82;
    --field-disabled-bg: #262522;
    --focus-ring: rgba(91, 155, 224, 0.6);
    --button-border: #4a4842;
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    background: var(--surface-1);
}

h1 { font-size: 22px; font-weight: 600; line-height: 1.25; margin: 0 0 1rem; }
/* Section headings inside a page: one size everywhere. */
h2, h3 { font-size: 15px; font-weight: 600; line-height: 1.3; }
h2 { margin: 28px 0 8px; }
h3 { margin: 1.5rem 0 8px; }
:is(.card, .form-card, .list, details) > :is(h2, h3):first-child { margin-top: 0; }
.muted { color: var(--text-secondary); }
/* Secondary / helper text, used all over (page intros, captions, hints). */
.sub { color: var(--text-secondary); font-size: 0.9em; }
.text-warning { color: #93630a; }
html[data-theme="dark"] .text-warning { color: #eab362; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

input, select, textarea, button {
    font-family: inherit;
    font-size: 14px;
    padding: 8px 10px;
    border: 0.5px solid var(--button-border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text-primary);
}
/* Text boxes, dropdowns and text areas: their own background and a
   full 1px border so they're easy to spot, especially in dark mode. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="submit"]):not([type="button"]),
select,
textarea {
    background-color: var(--field-bg);
    border: 1px solid var(--field-border);
    transition: border-color .12s, box-shadow .12s;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):hover,
select:hover,
textarea:hover { border-color: var(--field-border-hover); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
input:disabled, select:disabled, textarea:disabled,
input[readonly], textarea[readonly] {
    background-color: var(--field-disabled-bg);
    color: var(--text-secondary);
}
input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }
::placeholder {
    color: var(--field-placeholder);
    opacity: 1;
}

button {
    cursor: pointer;
}
button:hover {
    background: var(--surface-1);
}

.card {
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.25rem;
}

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

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--surface-2);
    border-right: 0.5px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 50;
    transition: transform 0.2s ease;
}
.sidebar-brand {
    padding: 18px 16px;
    font-weight: 500;
    font-size: 15px;
    border-bottom: 0.5px solid var(--border);
}
.sidebar-nav { flex: 1; padding: 14px 0; }
.nav-section { margin-bottom: 20px; border-left: 3px solid transparent; }
.nav-section--reporting { border-left-color: #2a78d6; }
.nav-section--warehouse { border-left-color: #1e9c6b; }
.nav-section--drivers { border-left-color: #c98a1f; }
.nav-section--settings { border-left-color: #8a5ac9; }
.nav-section--danger { border-left-color: #a32d2d; }
/* Salesman menu groups (match the phone's bottom tabs). */
.nav-section--customers { border-left-color: #2a78d6; }
.nav-section--van { border-left-color: #1e9c6b; }
.nav-section--trip { border-left-color: #8a5ac9; }
.nav-section--customers a i { color: #2a78d6; }
.nav-section--van a i { color: #1e9c6b; }
.nav-section--trip a i { color: #8a5ac9; }
.nav-section--reporting .sidebar-nav a i, .nav-section--reporting a i { color: #2a78d6; }
.nav-section--warehouse .sidebar-nav a i, .nav-section--warehouse a i { color: #1e9c6b; }
.nav-section--drivers .sidebar-nav a i, .nav-section--drivers a i { color: #c98a1f; }
.nav-section--settings .sidebar-nav a i, .nav-section--settings a i { color: #8a5ac9; }
.nav-section--danger .sidebar-nav a, .nav-section--danger a { color: #a32d2d; }
.nav-section--danger .sidebar-nav a i, .nav-section--danger a i { color: #a32d2d; }
.nav-collapsible { margin-bottom: 8px; }
.nav-collapsible > summary { cursor: pointer; list-style: none; padding: 6px 16px; margin: 0; display: flex; justify-content: space-between; align-items: center; }
.nav-collapsible > summary::-webkit-details-marker { display: none; }
.nav-collapsible > summary::after { content: '+'; font-size: 13px; color: var(--text-muted); }
.nav-collapsible[open] > summary::after { content: '\2212'; }
.nav-collapsible[open] > summary { margin-bottom: 4px; }
.nav-section--sales { border-left-color: #c2410c; }
.nav-section--sales a i { color: #c2410c; }
.nav-section--reports { border-left-color: #2a78d6; }
.nav-section--reports a i { color: #2a78d6; }
.nav-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 16px;
    margin: 0 0 6px;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: 0 20px 20px 0;
    margin-right: 12px;
}
.sidebar-nav a:hover { background: var(--surface-1); text-decoration: none; }
.sidebar-nav a.active { color: var(--text-primary); font-weight: 500; background: var(--surface-1); }
.sidebar-nav a i { font-size: 15px; width: 16px; text-align: center; flex-shrink: 0; }
.sidebar-user {
    padding: 14px 16px;
    border-top: 0.5px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.theme-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    padding: 0;
    font-size: 12px;
    color: var(--accent);
    cursor: pointer;
    width: fit-content;
}
.theme-toggle-btn i { font-size: 14px; }

.sidebar-toggle-btn .inbox-dot {
    position: absolute; top: 6px; right: 6px;
    width: 10px; height: 10px; border-radius: 50%;
    background: #a32d2d; border: 2px solid var(--surface-2);
}
.sidebar-toggle-btn {
    display: none;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 60;
    width: 42px; height: 42px;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    border-radius: 8px;
    font-size: 18px;
}
/* Hidden while the menu is open - it was sitting on top of the sidebar
   and, being fixed-position, stayed in the way while scrolling any page
   behind an open menu. The JS already toggles aria-expanded, so this
   needs no script changes. */
.sidebar-toggle-btn[aria-expanded="true"] {
    display: none !important;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 40;
}

.page {
    margin-left: 220px;
    padding: 24px;
    max-width: 1000px;
    width: 100%;
}

/* Mobile bottom tab bar - Salesman role only, their 4 most-used pages,
   a more native-app-like alternative to the hamburger sidebar for
   whoever lives on this screen all day. Sidebar still works alongside
   it for anything else (Customers, Payments). Hidden above the same
   860px breakpoint the sidebar itself collapses at (see that media
   query below, which turns this to display:flex on mobile - this rule
   must come first in the file so that later, more specific rule wins). */
.bottom-tabs {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface-2);
    border-top: 0.5px solid var(--border);
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-tabs a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 4px 6px;
    font-size: 11px;
    color: var(--text-secondary);
    text-decoration: none;
}
.bottom-tabs a i { font-size: 20px; }
.bottom-tabs a.active { color: var(--accent); font-weight: 500; }

@media (max-width: 860px) {
    .sidebar {
        transform: translateX(-100%);
        width: 250px;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle-btn { display: flex; }
    .sidebar-backdrop.open { display: block; }
    .page {
        margin-left: 0;
        padding: 64px 16px 24px;
    }
    .page.has-bottom-tabs { padding-bottom: 84px; }
    .bottom-tabs { display: flex; }
}

/* Login page */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
}
.login-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 320px;
    padding: 2rem;
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    border-radius: 12px;
}
.login-card label { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.login-card button { margin-top: 12px; background: var(--accent); color: #fff; border: none; }
.form-error { color: #a32d2d; font-size: 13px; margin: 0; }
html[data-theme="dark"] .form-error { color: #e58a8a; }

/* Page layout helpers */

/* Every page opens with the same header:
     <div class="page-header">
         <div class="page-title"><h1>Title</h1><p class="page-desc">One or two lines.</p></div>
         ...optional actions (buttons, links, a back link)...
     </div>
   Same title size, description size and spacing on every page and role. */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 16px;
    margin: 0 0 20px;
}
.page-header:has(.page-desc) { align-items: flex-start; }
.page-title { flex: 1 1 320px; min-width: 0; }
.page-header h1 { margin: 0; }
.page-header h1 .badge { vertical-align: middle; font-size: 12px; font-weight: 500; }
.page-desc {
    margin: 6px 0 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary);
    max-width: 80ch;
}
.page-desc + .page-desc { margin-top: 4px; }
/* Actions sit to the right of the title and wrap onto more lines on narrow screens, never wider than the page. */
.page-header > :not(.page-title) { flex: 0 1 auto; min-width: 0; max-width: 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.page-header > form { display: block; }
.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.filters input[type="text"] { flex: 1; min-width: 180px; }

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
}
.btn-primary:hover { filter: brightness(0.85); }

/* Flash messages */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 1rem;
}
.alert-success { background: #e6f4ea; color: #1e6b3c; }
.alert-error { background: #fbe9e9; color: #a32d2d; }
.alert-warning { background: #fdf1da; color: #93630a; }
html[data-theme="dark"] .alert-success { background: #1c3324; color: #7cd9a3; }
html[data-theme="dark"] .alert-error { background: #3a1f1f; color: #e58a8a; }
html[data-theme="dark"] .alert-warning { background: #3a2f15; color: #eab362; }

/* Row-based list (mirrors the mockups) */
.list {
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1.5rem;
    overflow-x: auto;
}
.list-head, .list-row {
    display: grid;
    gap: 8px;
    align-items: center;
    padding: 10px 14px;
    min-width: 480px;
}
.list-head {
    font-size: 11px;
    color: var(--text-muted);
    border-bottom: 0.5px solid var(--border);
}
.list-row { border-bottom: 0.5px solid var(--border); font-size: 13px; }
.list-row:last-child { border-bottom: none; }
.list-row .sub { font-size: 11px; color: var(--text-muted); }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px 16px; text-align: center; width: 100%; }
.empty-state p { margin: 0; }
.list-actions { display: flex; justify-content: flex-end; gap: 4px; }

/* Narrow lists (e.g. display-order.php's reorder columns: name + two
   small buttons) don't need the wide min-width meant for multi-column
   data tables elsewhere - forcing it here just pushes the buttons off
   to the right, requiring horizontal scroll to even see them. */
.list--compact { overflow-x: visible; }
.list--compact .list-row, .list--compact .list-head { min-width: 0; }
.icon-btn {
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-1);
    border: 0.5px solid var(--border);
    border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-2); }

.badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    white-space: nowrap;
}
.badge-success { background: #e6f4ea; color: #1e6b3c; }
.badge-warning { background: #fdf1da; color: #93630a; }
.badge-info { background: #e6f0fb; color: #1d4f8f; }
.badge-danger { background: #fbe9e9; color: #a32d2d; }
.badge-muted { background: var(--surface-1); color: var(--text-muted); }
html[data-theme="dark"] .badge-success { background: #1c3324; color: #7cd9a3; }
html[data-theme="dark"] .badge-warning { background: #3a2f15; color: #eab362; }
html[data-theme="dark"] .badge-danger { background: #3a1f1f; color: #e58a8a; }
html[data-theme="dark"] .badge-info { background: #1a2b40; color: #8fbdf0; }

/* Expandable invoice history cards - visit.php's "Previous invoices"
   section and customer-view.php's history list (see renderInvoiceHistoryCards()). */
.history-card > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    font-size: 13px;
}
.history-card > summary::-webkit-details-marker { display: none; }
.history-card > summary::before {
    content: "\203A"; /* chevron, rotates open */
    display: inline-block;
    margin-right: 8px;
    transition: transform 0.15s ease;
    color: var(--text-muted);
}
.history-card[open] > summary::before { transform: rotate(90deg); }

/* Route sheet stop cards - visit.php landing screen */
.route-stop {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 14px;
    text-decoration: none;
    color: inherit;
}
.route-stop:hover { background: var(--surface-1); }
.route-stop-name { font-size: 15px; font-weight: 500; }
.route-stop-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.route-stop-balance { font-size: 15px; font-weight: 500; text-align: right; white-space: nowrap; }

/* Balance banner + Sell/Payment-only mode toggle - visit.php (section 4) */
.balance-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.balance-banner-amount { font-size: 28px; font-weight: 600; }
.mode-toggle {
    display: flex;
    background: var(--surface-1);
    border: 0.5px solid var(--border);
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
}
.mode-btn {
    border: none;
    background: transparent;
    padding: 8px 14px;
    font-size: 13px;
    border-radius: 8px;
    color: var(--text-secondary);
}
.mode-btn.active { background: var(--accent); color: #fff; }

/* "What's on the van" product grid - visit.php (section 5) */
.grid-search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.grid-search-row input { flex: 1; min-width: 0; }
.grid-search-row button { white-space: nowrap; flex: none; }

/* Supplier sections on Visit: open = bought before or new, others folded */
.supplier-block { border-bottom: 0.5px solid var(--border); }
.supplier-block:first-child { border-top: 0.5px solid var(--border); }
.supplier-head {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 52px;
    padding: 6px 2px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.supplier-head::-webkit-details-marker { display: none; }
.supplier-chevron { font-size: 18px; color: var(--text-muted); transition: transform .15s; flex: none; }
.supplier-block[open] > .supplier-head .supplier-chevron { transform: rotate(90deg); }
.supplier-head-name { font-weight: 600; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.supplier-head-code { color: var(--text-muted); font-weight: 600; }
.supplier-head-count { margin-left: auto; flex: none; font-size: 12px; }
.supplier-head-ordered {
    flex: none;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    padding: 2px 9px;
}
.supplier-new { flex: none; }
.supplier-block > .grid-group:last-child { padding-bottom: 14px; }
.supplier-block > .grid-group:first-of-type .grid-group-title { margin-top: 4px; }
.grid-group-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    margin: 16px 0 8px;
}
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.grid-cell {
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.grid-cell.has-qty { border-color: var(--accent); }
.grid-cell-name { font-size: 13px; font-weight: 500; line-height: 1.3; }
.grid-cell-stock { font-size: 11px; margin: 0; }
.unit-toggle { display: flex; gap: 4px; }
.unit-btn {
    flex: 1;
    border: 0.5px solid var(--border);
    background: transparent;
    border-radius: 6px;
    padding: 5px 4px;
    font-size: 11px;
    color: var(--text-secondary);
}
.unit-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.grid-stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 2px;
}
.stepper-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 0.5px solid var(--border);
    background: var(--surface-1);
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.grid-qty {
    font-size: 16px;
    font-weight: 500;
    min-width: 32px;
    text-align: center;
    cursor: pointer;
}

/* Cart line rows - the compact "Your order" list under the grid */
.cart-list {
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}
.cart-line {
    display: grid;
    grid-template-columns: minmax(0,1fr) 60px 70px 60px 32px;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 0.5px solid var(--border);
}
.cart-line:last-child { border-bottom: none; }
.cart-list--scroll { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.cart-line-main { min-width: 0; }
.cart-line .sale-name { display: block; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-line .sale-van-stock { display: block; }
.cart-line .sale-qty, .cart-line .sale-price { width: 100%; padding: 6px; font-size: 13px; }
.cart-line .sale-line-total { font-size: 13px; text-align: right; white-space: nowrap; }

@media (max-width: 480px) {
    .cart-line { grid-template-columns: minmax(0,1fr) 50px 60px 50px 28px; }
}

/* Simpler cart line for request-stock.php - just name, qty, remove;
   no price/total columns since this is a request, not a sale. */
.request-cart-line { grid-template-columns: minmax(0,1fr) 70px 32px; }
.request-cart-line .sale-qty { width: 100%; padding: 6px; font-size: 13px; }

/* Forms */
.form-card {
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
}
.form-card h3 { margin: 0 0 1rem; }
.form-grid {
    display: grid;
    gap: 12px;
    margin-bottom: 14px;
}
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-field label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.form-field input, .form-field select, .form-field textarea { width: 100%; }
.form-field + .form-field { margin-top: 10px; }
/* Side-by-side fields in a grid share a top line - the stacking gap above is only for fields one under another. */
.form-grid > .form-field + .form-field { margin-top: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.checkbox-field { display: flex; align-items: center; gap: 6px; font-size: 13px; }

/* Driver-facing screens (Drivers nav section) get larger tap targets and
   text unconditionally - not just below the mobile breakpoint - since
   these are used one-handed, standing up, often in poor light. See the
   driver-flow notes, section 9. The exclusions below leave the compact
   grid/cart controls (sized deliberately for those tight layouts) alone. */
/* Scoped to .page so the sidebar (Dark mode, Inbox, links) is the same
   size on every page. */
body.driver-page .page input:not(.sale-qty):not(.sale-price):not(.sale-product-id):not(.sale-sold-as),
body.driver-page .page select,
body.driver-page .page textarea {
    font-size: 16px;
    padding: 12px 14px;
}
body.driver-page .page button:not(.icon-btn):not(.stepper-btn):not(.unit-btn):not(.mode-btn):not(.cart-remove):not(.seg-btn):not(.grid-cell-photo) {
    font-size: 15px;
    padding: 12px 16px;
    min-height: 44px;
}
body.driver-page .page .icon-btn { width: 40px; height: 40px; }
body.driver-page .stepper-btn { width: 44px; height: 44px; font-size: 20px; }
body.driver-page .checkbox-field { gap: 10px; padding: 4px 0; }
body.driver-page .checkbox-field input[type="checkbox"] { width: 20px; height: 20px; }

@media (max-width: 600px) {
    .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr; }
    .icon-btn { width: 36px; height: 36px; }
    input, select, textarea, .page button { font-size: 16px; } /* fields at 16px prevent iOS auto-zoom on focus */
    h1 { font-size: 20px; }
}

/* ---------------------------------------------------------------------
   Invoice forms: totals, payment lines, Check & sign (invoice-form.js)
   --------------------------------------------------------------------- */
.field-caption { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.invoice-totals { display: flex; flex-direction: column; gap: 4px; }
.totals-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; color: var(--text-secondary); }
.totals-line > span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.totals-sub { font-size: 12px; padding-left: 10px; }
.totals-strong { color: var(--text-primary); font-weight: 500; font-size: 14px; padding-top: 6px; margin-top: 4px; border-top: 0.5px solid var(--border); }
.totals-grand { color: var(--text-primary); font-weight: 600; font-size: 16px; padding-top: 6px; margin-top: 4px; border-top: 0.5px solid var(--border); }
.totals-line-charge { color: #a32d2d; }
html[data-theme="dark"] .totals-line-charge { color: #e58a8a; }
.totals-input { width: 100px !important; text-align: right; padding: 4px 6px !important; font-size: 13px !important; }

.pay-card { margin-bottom: 16px; }
.pay-card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pay-line { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 150px) 40px; gap: 8px; align-items: center; margin-bottom: 8px; }
.pay-line .pay-amount { font-size: 18px !important; font-weight: 500; }
.pay-summary { margin-top: 12px; padding-top: 10px; border-top: 0.5px solid var(--border); }
.towards-box { margin-top: 12px; font-size: 13px; }
.towards-box > summary { cursor: pointer; padding: 6px 0; }
.towards-list { display: flex; flex-direction: column; gap: 4px; padding: 6px 0 0 4px; }

.sign-step { margin-bottom: 16px; }
.sign-step-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.sign-step-title { font-size: 15px; font-weight: 600; margin: 0; }
.sign-step.is-signed { border-color: #1e9c6b; }
.sign-step.is-skipped { border-color: #c98a1f; }
.sign-summary { background: var(--surface-1); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.sign-heading { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 6px 0 4px; }
.sign-heading:first-child { margin-top: 0; }
.sign-line { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 15px; border-bottom: 0.5px dashed var(--border); }
.sign-line:last-of-type { border-bottom: none; }
.sign-line-qty { font-weight: 600; white-space: nowrap; }
.sign-total { margin: 8px 0 0; font-weight: 600; font-size: 15px; }
.signature-pad { width: 100%; height: 170px; border: 1px dashed var(--border); border-radius: 10px; touch-action: none; background: #fff; display: block; }
.sign-pad-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.sign-skip-toggle { margin-top: 12px; }

/* "Hand to customer": the sign step fills the screen, big and simple. */
.sign-step.sign-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 200;
    margin: 0;
    border-radius: 0;
    overflow-y: auto;
    padding: 24px max(24px, env(safe-area-inset-left));
}
.sign-step.sign-fullscreen .sign-line { font-size: 20px; padding: 10px 0; }
.sign-step.sign-fullscreen .sign-total { font-size: 20px; }
.sign-step.sign-fullscreen .signature-pad { height: 260px; }
body.sign-fullscreen-open { overflow: hidden; }
/* The sticky side panel makes its own stacking layer, so while the
   customer is signing, flatten it and hide the menu button + tabs. */
body.sign-fullscreen-open .visit-side { position: static; overflow: visible; max-height: none; }
body.sign-fullscreen-open .sidebar-toggle-btn,
body.sign-fullscreen-open .bottom-tabs { display: none !important; }

.btn-block-lg { width: 100%; padding: 16px !important; font-size: 16px !important; }
.invoice-actions { display: flex; gap: 8px; margin-bottom: 1.5rem; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------------
   Visit screen layout. Phone: one narrow column. 10" tablet portrait:
   one wide column, more products per row. Tablet landscape / desktop:
   products on the left, the order + totals + sign + pay panel on the
   right, always in view while tapping items.
   --------------------------------------------------------------------- */
.visit-page { max-width: 480px; margin: 0 auto; }
.visit-layout.payment-only #sell-section,
.visit-layout.payment-only #order-section,
.visit-layout.payment-only #sign-step,
.visit-layout.payment-only #invoice-totals .totals-line:not(.totals-grand):not(:has(#balance-forward)),
.visit-layout.payment-only #auto-discount-note { display: none !important; }

@media (min-width: 700px) {
    .visit-page { max-width: 760px; }
    .visit-page--form { max-width: none; }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
    .grid-cell { padding: 12px; }
    .grid-cell-name { font-size: 14px; }
    .cart-line { grid-template-columns: minmax(0,1fr) 70px 84px 70px 40px; }
}
@media (min-width: 1000px) {
    .visit-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(360px, 1fr); gap: 20px; align-items: start; }
    .visit-side {
        position: sticky;
        top: 12px;
        max-height: calc(100vh - 24px);
        overflow-y: auto;
        padding-right: 4px;
        overscroll-behavior: contain;
    }
    .visit-layout.payment-only { grid-template-columns: minmax(0, 560px); justify-content: center; }
}

/* Driver pages on a touch tablet in landscape: the full sidebar would eat
   a fifth of the screen, so they get the same hamburger + bottom tabs as
   portrait. Laptops (mouse/trackpad) keep the normal sidebar. */
@media (min-width: 861px) and (max-width: 1400px) and (pointer: coarse) {
    body.driver-page .sidebar { transform: translateX(-100%); width: 250px; }
    body.driver-page .sidebar.open { transform: translateX(0); }
    body.driver-page .sidebar-toggle-btn { display: flex; }
    body.driver-page .sidebar-backdrop.open { display: block; }
    body.driver-page .page { margin-left: 0; padding: 64px 20px 24px; max-width: none; }
    body.driver-page .page.has-bottom-tabs { padding-bottom: 84px; }
    body.driver-page .bottom-tabs { display: flex; }
}
body.driver-page .page { max-width: 1280px; }

/* Vehicle return counts: one column on a phone, two on a tablet. */
/* Vehicle return (vehicle-return.php). Phone: one column. Tablet and
   wider: full page width, count cards in as many columns as fit (3 on a
   10" tablet in landscape), vehicle picker and progress side by side,
   notes and Submit in a row at the bottom. */
.return-page { max-width: 480px; margin: 0 auto; }
.return-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; margin-bottom: 16px; }
.return-vehicle { flex: 1 1 320px; max-width: 520px; }
.return-vehicle select { width: 100%; font-size: 15px; padding: 10px; }
.return-progress { flex: 0 1 260px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-secondary); padding-bottom: 4px; }
.return-progress strong { color: var(--text-primary); font-size: 16px; }
.return-progress-bar { display: block; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.return-progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.return-progress.is-complete .return-progress-bar span { background: #2e9e5b; }
.count-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 20px; }
.count-grid-heading { grid-column: 1 / -1; font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-secondary); margin: 10px 0 0; }
.count-grid-heading:first-child { margin-top: 0; }
.count-card { padding: 12px 14px; display: flex; flex-direction: column; transition: border-color .15s; }
.count-card-head { margin-bottom: 10px; align-items: flex-start; }
.count-card-name { font-size: 14px; font-weight: 500; flex: 1; min-width: 0; }
.count-card-tick { font-size: 20px; color: #2e9e5b; visibility: hidden; flex: none; }
.count-card.is-counted { border-color: #2e9e5b; }
.count-card.is-counted .count-card-tick { visibility: visible; }
.count-card input[type="number"] { width: 100%; font-size: 16px; padding: 10px; }
.count-fields { display: flex; gap: 8px; margin-top: auto; }
.count-fields > div { flex: 1; min-width: 0; }
.count-empty { margin-bottom: 18px; }
.return-footer { display: flex; flex-direction: column; gap: 16px; }
.return-notes textarea { width: 100%; font-size: 14px; }
.return-submit { width: 100%; padding: 14px; font-size: 15px; }
@media (min-width: 700px) {
    .return-page { max-width: none; }
    .count-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
    .return-footer { flex-direction: row; align-items: flex-end; }
    .return-notes { flex: 1; margin: 0; }
    .return-submit { width: auto; min-width: 240px; flex: none; }
}

/* Settings hub */
.hub-heading { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); margin: 1.5rem 0 8px; }
.hub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.hub-card { display: flex; gap: 12px; align-items: flex-start; padding: 14px; background: var(--surface-2); border: 0.5px solid var(--border); border-radius: 12px; color: var(--text-primary); text-decoration: none; }
.hub-card:hover { border-color: var(--accent); text-decoration: none; }
.hub-card i { font-size: 20px; color: #8a5ac9; margin-top: 1px; }
.hub-card strong { display: block; font-weight: 500; font-size: 14px; }
.hub-card .sub { display: block; font-size: 12px; margin-top: 2px; }
.hub-card--danger i, .hub-card--danger strong { color: #a32d2d; }

/* Data tables that would otherwise force sideways scrolling on a phone. */
@media (max-width: 600px) {
    .table-scroll .list-head, .table-scroll .list-row { min-width: 0; font-size: 12px; }
    .table-scroll .list-row .sub { display: none; }
    .pay-line { grid-template-columns: minmax(0, 1fr) 120px 40px; }
}

/* ---------------------------------------------------------------------
   Print - currently used by invoice-view.php ("Print invoice" button).
   Any element with class "no-print" is hidden on any page when printed;
   the invoice-specific card widening only applies within invoice-view.php.
   --------------------------------------------------------------------- */
@media print {
    .sidebar, .sidebar-toggle-btn, .sidebar-backdrop, .no-print { display: none !important; }
    .page { margin-left: 0; padding: 0; max-width: none; }
    body { background: #fff; }

    .invoice-info-card, .invoice-totals-card {
        max-width: none !important;
        width: 100%;
        border: none;
        box-shadow: none;
        padding: 0;
    }
    .invoice-totals-card > div { font-size: 14px !important; }
    .invoice-totals-card .invoice-total-row, .invoice-totals-card .totals-grand { font-size: 16px !important; }

    .list { border: 0.5px solid #000; }
    .list-row, .list-head { border-bottom: 0.5px solid #000; }
    .badge { border: 0.5px solid #000; background: none !important; color: #000 !important; }
}

/* ---- End trip / cash-up ------------------------------------------- */
.link-btn { background: none; border: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
.link-btn.danger { color: #a32d2d; }
.trip-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.checklist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.check-step { display: flex; gap: 12px; align-items: flex-start; background: var(--surface-2); border: 0.5px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.check-step-icon { flex: 0 0 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border); display: inline-flex; align-items: center; justify-content: center; }
.check-step-icon.done { background: #1e6b3c; border-color: #1e6b3c; color: #fff; }
.check-step-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.check-step-title { font-weight: 600; }
.check-step.is-done .check-step-title { color: var(--text-secondary); }
.check-link { display: block; padding: 4px 0; }
.check-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.check-actions form { margin: 0; }
.check-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 0.5px solid var(--border); background: var(--surface-2); color: var(--text-primary); text-decoration: none; cursor: pointer; font-size: 15px; }
.check-btn.btn-primary { background: var(--accent); color: #fff; border-color: transparent; }
.expense-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.expense-row { border-bottom: 0.5px solid var(--border); padding-bottom: 10px; display: flex; flex-direction: column; gap: 2px; }
.expense-row.is-rejected { opacity: 0.55; }
.expense-main { display: flex; justify-content: space-between; gap: 8px; }
.expense-amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.expense-actions { display: flex; gap: 14px; align-items: center; margin-top: 4px; }
.expense-actions form { margin: 0; }
.expense-form { margin-top: 12px; }
.expense-form > summary { list-style: none; width: fit-content; }
.expense-form > summary::-webkit-details-marker { display: none; }
.expense-form[open] > summary { margin-bottom: 12px; }
.radio-stack { display: flex; flex-direction: column; gap: 8px; }
.cashup-group-title { font-weight: 600; margin: 14px 0 6px; }
.cashup-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px minmax(0, 1fr); gap: 10px; align-items: center; padding: 5px 0; }
.cashup-row label { font-size: 15px; }
.cashup-row input { width: 100%; font-size: 18px; text-align: center; padding: 10px 6px; font-variant-numeric: tabular-nums; }
.cashup-line-value { text-align: right; color: var(--text-secondary); font-variant-numeric: tabular-nums; font-size: 14px; }
.cashup-totals { margin-top: 14px; padding-top: 10px; border-top: 0.5px solid var(--border); position: sticky; bottom: 0; background: var(--surface-2); }
@media (max-width: 860px) { .page.has-bottom-tabs .cashup-totals { bottom: 56px; } }
.cu-diff { font-weight: 600; padding: 2px 10px; border-radius: 6px; }
.cu-diff.is-green { background: #e6f4ea; color: #1e6b3c; }
.cu-diff.is-amber { background: #fdf1da; color: #93630a; }
.cu-diff.is-red { background: #fbe9e9; color: #a32d2d; }
html[data-theme="dark"] .cu-diff.is-green { background: #1c3324; color: #7cd9a3; }
html[data-theme="dark"] .cu-diff.is-amber { background: #3a2f15; color: #eab362; }
html[data-theme="dark"] .cu-diff.is-red { background: #3a1f1f; color: #e58a8a; }
.cashup-tick { padding: 6px 0; }
.cashup-list-row { padding: 6px 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
form[inert] { opacity: 0.55; }
@media (max-width: 420px) {
    .cashup-row { grid-template-columns: minmax(0, 1fr) 76px; }
    .cashup-line-value { grid-column: 1 / -1; text-align: left; margin-top: -4px; font-size: 13px; }
}
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
.data-table th { text-align: left; font-size: 11px; font-weight: 500; color: var(--text-muted); padding: 6px 8px; border-bottom: 0.5px solid var(--border); }
.data-table td { padding: 8px; border-bottom: 0.5px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .sub { font-size: 11px; color: var(--text-muted); }
a.check-btn, summary.check-btn { text-decoration: none !important; }

/* ---- Collections ---------------------------------------------------- */
.text-danger { color: #a32d2d; }
html[data-theme="dark"] .text-danger { color: #e58a8a; }
.coll-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.coll-switch a { padding: 8px 16px; font-size: 14px; border-radius: 8px; color: var(--text-secondary); text-decoration: none; }
.coll-switch a.active { background: var(--accent); color: #fff; }
.coll-period { font-size: 15px; padding: 0 4px; }
.coll-date { margin: 0 0 0 auto; }
.coll-date input { min-height: 44px; }
.coll-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.coll-tiles .card { margin: 0; }
.coll-tiles .sub { margin: 0; }
.coll-big { margin: 4px 0; font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; }
.table-card { padding: 0; margin-bottom: 16px; overflow: hidden; }
.table-card .table-wrap { padding: 4px 8px; }
.coll-table { min-width: 760px; }
.coll-table tfoot td { border-top: 1px solid var(--border); border-bottom: none; }
@media (max-width: 860px) { .coll-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) {
    .coll-tiles { grid-template-columns: minmax(0, 1fr); }
    .coll-date { margin-left: 0; width: 100%; }
    .coll-date input { width: 100%; }
}
.coll-nav .check-btn[aria-label] { font-size: 22px; line-height: 1; padding: 6px 14px; }

/* ---- Overpayment warning ------------------------------------------- */
.overpay-box { margin: 12px 0; padding: 12px 14px; border-radius: 10px; background: #fdf1da; border: 1px solid #eda100; color: #5c3d00; }
.overpay-box.is-blocked { background: #fbe9e9; border-color: #a32d2d; color: #6b1d1d; }
.overpay-box[hidden] { display: none; }
.overpay-box label { display: block; font-size: 13px; margin: 8px 0 4px; }
.overpay-box input { width: 100%; }
.overpay-title { margin: 0; font-weight: 600; }
.overpay-over-limit { margin: 6px 0 0; font-weight: 600; }
.overpay-box .sub { color: inherit; opacity: 0.85; }
html[data-theme="dark"] .overpay-box { background: #3a2f15; color: #eab362; }
html[data-theme="dark"] .overpay-box.is-blocked { background: #3a1f1f; color: #e58a8a; }
.overpay-note { margin: 8px 0 0; font-size: 13px; }

/* ---------------------------------------------------------------------
   Product photos and the three display modes (Names / Photos + names /
   Photos only). The grid wrapper's pgrid--* class picks what shows.
   --------------------------------------------------------------------- */
.display-switch { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.display-switch-label { font-size: 12px; color: var(--text-secondary); }
.segmented { display: inline-flex; border: 0.5px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.seg-btn { background: transparent; border: 0; border-right: 0.5px solid var(--border); border-radius: 0; padding: 9px 12px; font-size: 13px; color: var(--text-secondary); min-height: 40px; cursor: pointer; }
.seg-btn:last-child { border-right: 0; }
.seg-btn.active { background: var(--accent); color: #fff; }

.grid-cell-photo { position: relative; display: block; width: 100%; aspect-ratio: 1 / 1; padding: 0; margin: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--surface-1); cursor: pointer; }
.grid-photo { display: block; width: 100%; height: 100%; object-fit: cover; }
.grid-cell-photo .photo-placeholder { width: 100%; height: 100%; font-size: 26px; }
.photo-placeholder { display: inline-flex; align-items: center; justify-content: center; width: var(--ph, 40px); height: var(--ph, 40px); background: var(--surface-1); color: var(--text-muted); font-weight: 600; letter-spacing: 0.04em; border-radius: 6px; flex-shrink: 0; }
.photo-badge { position: absolute; top: 6px; right: 6px; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 13px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.photo-badge[hidden] { display: none; }
.photo-nostock { position: absolute; left: 0; right: 0; bottom: 0; background: #b42318; color: #fff; font-size: 11px; font-weight: 600; text-align: center; padding: 3px 0; }
.grid-cell-short { font-size: 12px; font-weight: 500; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.unit-short { display: none; }

/* Names: today's layout, no photos. */
.pgrid--names .grid-cell-photo,
.pgrid--names .grid-cell-short { display: none; }

/* Photos + names: photo, full name (no SKU), stock, unit switch, stepper. */
.pgrid--photos_names .grid-cell-short,
.pgrid--photos_names .grid-cell-sku { display: none; }

/* Photos only: three across on a phone, bigger photo, short label, compact controls. */
.pgrid--photos .grid-cell-name,
.pgrid--photos .grid-cell-sku,
.pgrid--photos .grid-qty { display: none; }
.pgrid--photos .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pgrid--photos .grid-cell { padding: 6px; gap: 5px; }
.pgrid--photos .grid-cell-stock { font-size: 10.5px; }
.pgrid--photos .unit-btn { padding: 4px 2px; font-size: 11px; }
.pgrid--photos .unit-long { display: none; }
.pgrid--photos .unit-short { display: inline; }
.pgrid--photos .grid-stepper { gap: 4px; }
.pgrid--photos .stepper-btn { flex: 1; width: auto !important; min-width: 0; height: 40px !important; }

/* Photo modes: chosen tiles get a clear blue border; none on the van fades. */
.pgrid--photos_names .grid-cell.has-qty,
.pgrid--photos .grid-cell.has-qty { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }
.pgrid--photos_names .grid-cell.no-stock,
.pgrid--photos .grid-cell.no-stock { opacity: 0.55; }
.pgrid--names .photo-nostock { display: none; }

@media (min-width: 700px) {
    .pgrid--photos .product-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
    .pgrid--photos .grid-cell { padding: 8px; }
}

/* Thumbnails beside product names (products list, loading, vehicle return). */
.product-thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; flex-shrink: 0; background: var(--surface-1); font-size: 13px; }
.thumb-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.thumb-row > .thumb-text { min-width: 0; }
.product-photo-lg { width: 160px; height: 160px; border-radius: 10px; object-fit: cover; font-size: 40px; }

/* Display choice cards on My account. */
.display-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.display-card { position: relative; display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); cursor: pointer; }
.display-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }
.display-card-title { display: flex; align-items: center; gap: 8px; }
.display-card input { margin: 0; width: 18px; height: 18px; accent-color: var(--accent); }
.display-card strong { font-size: 14px; }
.display-card .sub { font-size: 12px; line-height: 1.35; }
.mode-sketch { display: grid; gap: 4px; height: 58px; }
.mode-sketch span { background: var(--surface-1); border-radius: 3px; }
.mode-sketch--names { grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; }
.mode-sketch--names span { background: none; border: 1px solid var(--border); }
.mode-sketch--photos_names { grid-template-columns: 1fr 1fr; }
.mode-sketch--photos_names span { background: linear-gradient(var(--text-muted) 0 0) bottom / 70% 3px no-repeat, var(--surface-1); opacity: 0.8; }
.mode-sketch--photos { grid-template-columns: 1fr 1fr 1fr; }

/* Bulk photo upload review */
.photo-review { display: grid; grid-template-columns: 28px 64px minmax(0,1fr); gap: 10px; align-items: center; padding: 8px 0; border-bottom: 0.5px solid var(--border); }
.photo-review img { width: 64px; height: 64px; border-radius: 6px; object-fit: cover; }
.photo-review .pair { display: flex; gap: 6px; align-items: center; }
.photo-review .pair img { width: 48px; height: 48px; }
.file-btn { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; padding: 8px 12px; border: 0.5px solid var(--border); border-radius: 6px; background: var(--surface-2); color: var(--text-primary); cursor: pointer; font-weight: 400; }
.file-btn:hover { background: var(--surface-1); }

/* System settings > Email: test email row */
.test-email-row { margin-top: 16px; padding-top: 14px; border-top: 0.5px solid var(--border); }
.test-email-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.test-email-controls input { flex: 1 1 240px; max-width: 360px; }

/* Invoice view: Email invoice panel and sent history */
.email-history { margin: -8px 0 14px; }
.email-history p { margin: 3px 0; line-height: 1.4; }
.email-history i { vertical-align: -1px; }
.email-panel { margin-bottom: 1.5rem; max-width: 640px; }
.email-panel h3 { margin-top: 0; }
.email-panel .form-field { margin-bottom: 12px; }
.email-panel textarea { width: 100%; }
.email-save { margin: -4px 0 12px; }
.email-save[hidden], .email-panel[hidden] { display: none; }
.form-field .checkbox-field input[type="checkbox"] { width: auto; flex: none; }

/* Customer registered name (v1.10.0) */
.field-hint { margin: 4px 0 0; font-size: 12px; line-height: 1.4; color: var(--text-muted, #6b6860); }
.form-field[hidden] { display: none; }
.filters .filter-check { white-space: nowrap; }
.registered-name { font-size: 12px; }
.page-title .registered-name { margin: 2px 0 0; font-size: 14px; }
.select-filter { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.select-filter input[type="search"] { flex: 1; min-width: 0; }
.select-filter-count { white-space: nowrap; font-size: 12px; }
/* "Patel Retail Ltd t/a Corner Shop": when it can't fit on one line it breaks before "t/a" */
.billing-ta { display: inline-block; max-width: 100%; }

/* Admin van stock overview (v1.11.1) */
.van-stock-row { grid-template-columns: minmax(0,1.1fr) minmax(0,1.4fr) minmax(0,1.3fr) 110px; align-items: center; }
@media (max-width: 640px) {
    .van-stock-row { grid-template-columns: 1fr 1fr; row-gap: 6px; }
    .van-stock-row.list-head { display: none; }
}

/* Stock moves between vans (v1.12.0) */
.list-group-head { background: var(--surface-1); }
.van-move-row { grid-template-columns: minmax(0,1fr) auto; align-items: center; }
.van-move-lines { margin: 2px 0; }
.van-move-row.is-undone .van-move-lines { text-decoration: line-through; color: var(--text-muted, #6b6860); }
.move-grid-row { grid-template-columns: minmax(0,1fr) 120px 230px; align-items: center; }
.van-move-row > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.move-grid-row .move-qty { display: flex; gap: 6px; }
.move-grid-row .move-qty input { width: 80px; }
@media (max-width: 640px) {
    .move-grid-row { grid-template-columns: 1fr auto; row-gap: 6px; }
    .move-grid-row .move-on-van { text-align: right; }
    .move-grid-row .move-qty { grid-column: 1 / -1; }
    .move-grid-row.list-head { display: none; }
}
.load-move-van[hidden] { display: none; }

/* Delete load (v1.12.4) */
.btn-danger { background: #a32d2d; border-color: #a32d2d; color: #fff; }
.btn-danger:hover { background: #8a2424; border-color: #8a2424; }
.danger-zone summary { cursor: pointer; }

/* System settings -> Overrides: one row per override, roles beside it. */
.override-setting{display:grid;grid-template-columns:minmax(0,1fr) 230px;gap:8px 16px;padding:12px 0;border-top:1px solid var(--border, #e5e5e5)}
.override-setting:first-of-type{border-top:0;padding-top:0}
.override-roles{display:flex;flex-direction:column;gap:6px}
@media (max-width:640px){.override-setting{grid-template-columns:1fr}.override-roles{flex-direction:row;flex-wrap:wrap;gap:6px 14px}}

/* Vehicle return: "Skip the count" (only when switched on in Overrides). */
.skip-count-card{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:1rem}
.skip-count-card form{flex-shrink:0}
@media (max-width:640px){.skip-count-card{flex-direction:column;align-items:stretch}}

/* A form card that opens and closes (customers.php "Add customer"). */
.collapsible-form > summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.collapsible-form > summary::-webkit-details-marker { display: none; }
.collapsible-form > summary h3 { margin: 0; }
.collapsible-form > summary::after { content: '+'; font-size: 20px; color: var(--text-muted); line-height: 1; }
.collapsible-form[open] > summary::after { content: '\2212'; }
.collapsible-form[open] > summary { margin-bottom: 14px; }

/* Customer page invoices (customer-view.php): list on the left, the
   picked invoice on the right. Two columns once the page area is 640px
   wide (a 10" tablet either way round, or a desktop); narrower than that
   the details open under the row that was tapped. */
.ci-split { container-type: inline-size; }
.ci-list { padding: 0; overflow: hidden; }
.ci-pane { display: none; }
.ci-item + .ci-item { border-top: 0.5px solid var(--border); }
.ci-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 12px 14px; color: inherit; text-decoration: none; }
.ci-row:hover { background: var(--surface-1); text-decoration: none; }
.ci-item.is-selected > .ci-row { background: rgba(42, 120, 214, 0.10); box-shadow: inset 3px 0 0 var(--accent); }
.ci-row-main { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; }
.ci-row-meta { flex-basis: 100%; font-size: 12px; overflow-wrap: anywhere; }
.ci-row-money { text-align: right; white-space: nowrap; display: flex; flex-direction: column; align-items: flex-end; }
.ci-row-money .sub { font-size: 12px; }
.ci-owed { color: #a32d2d !important; }
html[data-theme="dark"] .ci-owed { color: #e58a8a !important; }
.ci-inline { margin: 0 10px 12px; padding: 12px 14px; }
.ci-inline.is-loading, .ci-pane.is-loading { opacity: 0.55; }
.ci-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.ci-head .sub { font-size: 13px; margin-top: 2px; }
.ci-number { font-size: 16px; }
.ci-head button { font-size: 13px; padding: 7px 12px; }
.ci-label { font-size: 12px; color: var(--text-secondary); margin: 14px 0 4px; }
.ci-line { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 4px 0; }
.ci-line > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.ci-line > span:last-child { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ci-none { font-size: 13px; margin: 0; }
.ci-totals { margin-top: 14px; padding-top: 10px; border-top: 0.5px dashed var(--border); }
@container (min-width: 640px) {
    .ci-grid { display: grid; grid-template-columns: minmax(250px, 2fr) minmax(0, 3fr); gap: 14px; align-items: start; }
    .ci-inline { display: none !important; }
    .ci-pane { display: block; position: sticky; top: 72px; padding: 16px 18px; max-height: calc(100vh - 90px); overflow-y: auto; }
}
@container (min-width: 1000px) {
    .ci-grid { grid-template-columns: minmax(300px, 2fr) minmax(0, 3fr); }
}

/* Van count differences (renderCountDifferencesHtml): one product per row,
   expected / counted underneath, Short / Over badge on the right. */
.count-diff-title { margin: 0 0 8px; font-weight: 500; font-size: 14px; }
.count-diff-title .sub { font-weight: 400; }
.list-row.count-diff-row { grid-template-columns: minmax(0, 1fr) auto; }
.count-diff-figures { display: block; margin-top: 1px; font-size: 12px !important; }
.count-diff-badge { white-space: nowrap; font-size: 12px; }
.count-diff-details { margin-top: 8px; }
.count-diff-details > summary { cursor: pointer; font-size: 13px; color: #a32d2d; font-weight: 500; }
html[data-theme="dark"] .count-diff-details > summary { color: #e58a8a; }
.count-diff-details[open] > summary { margin-bottom: 8px; }
.count-diff-details .count-diff-title { display: none; }

/* Visit: one stop list per route on an overnight with a second route. */
.stop-list-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 15px; margin: 4px 0 8px; }
.stop-list-count { font-size: 12px; font-weight: 400; margin-left: auto; }

/* Night 1 of an overnight trip (vehicle-return.php, end-trip.php). */
.overnight-wait { border-left: 4px solid #8a5ac9; border-radius: 0 12px 12px 0; margin-bottom: 1rem; }
.overnight-wait .ti-moon { color: #8a5ac9; }

/* Add extra stock (load-view.php): "Where from?" - warehouse or supplier pick-up. */
.add-stock-source .segmented label { display: inline-flex; align-items: center; margin: 0; padding: 9px 14px; font-size: 13px; font-weight: 400; color: var(--text-secondary); min-height: 40px; cursor: pointer; border-right: 0.5px solid var(--border); }
.add-stock-source .segmented label:last-child { border-right: 0; }
.add-stock-source .segmented input { position: absolute; opacity: 0; pointer-events: none; width: auto; }
.add-stock-source .segmented label:has(input:checked) { background: var(--accent); color: #fff; }
.add-stock-source .segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.list-row.pickup-row { grid-template-columns: minmax(0, 1fr) auto; }
.pickup-meta { display: block; font-size: 12px !important; margin-top: 2px; }

/* Invoice page: once confirmed, Print to EPOS is the clear next step. */
.epos-print-btn.epos-main { font-size: 15px; padding: 11px 18px; box-shadow: 0 0 0 3px rgba(42, 120, 214, 0.25); }
.epos-print-btn.epos-main .ti { font-size: 18px; vertical-align: -3px; }
.epos-backup { margin: -6px 0 12px; font-size: 13px; }
@media (max-width: 600px) {
    .epos-print-btn.epos-main { width: 100%; justify-content: center; order: -1; }
}

/* Invoice page: Create PDF stands out next to Print to EPOS without competing with it. */
.btn-pdf { border: 1.5px solid #c0392b !important; color: #a32d2d !important; background: #fdf0ee !important; font-weight: 500; }
.btn-pdf:hover { background: #fbe3df !important; }
.btn-pdf .ti { font-size: 16px; vertical-align: -2px; }
html[data-theme="dark"] .btn-pdf { background: #3a1f1f !important; color: #f0a39a !important; border-color: #e07a6e !important; }

/* Keep one route (keep-route.php): what's kept / removed side by side. */
.keep-route-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-bottom: 20px; }
.keep-route-keep { border-left: 4px solid #1e9c6b; border-radius: 0 12px 12px 0; }
.keep-route-remove { border-left: 4px solid #a32d2d; border-radius: 0 12px 12px 0; }
.keep-route-list { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.7; }

/* Add extra stock (load-view.php): several product rows. */
.add-stock-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px 90px 40px; gap: 8px; align-items: end; margin-bottom: 8px; }
.add-stock-row .form-field { margin: 0; }
.add-stock-row + .add-stock-row .form-field > label { display: none; }
.add-stock-row .as-remove { height: 40px; width: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: #a32d2d; font-size: 22px; line-height: 1; }
.add-stock-row .as-remove[hidden] { display: inline-flex !important; visibility: hidden; }
@media (max-width: 600px) {
    .add-stock-row { grid-template-columns: minmax(0, 1fr) 90px 40px; padding-bottom: 8px; border-bottom: 0.5px solid var(--border); }
    .add-stock-row .add-stock-product { grid-column: 1 / -1; }
    .add-stock-row + .add-stock-row .form-field > label { display: block; }
}

/* Visit order lines: "Out of stock" switch and the van-is-short offer. */
.oos-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.cart-line .oos-actions button { font-size: 11.5px !important; padding: 3px 8px !important; min-height: 0 !important; height: auto !important; line-height: 1.3; border-radius: 6px; white-space: nowrap; width: auto; }
.oos-offer { background: #fdf1da; color: #93630a; border: 0.5px solid #e9c46a; font-weight: 500; }
.oos-toggle[aria-pressed="true"] { background: #fbe9e9; color: #a32d2d; border-color: #e7a5a5; font-weight: 500; }
.cart-line.is-oos { background: repeating-linear-gradient(135deg, transparent 0 8px, rgba(163, 45, 45, 0.04) 8px 16px); }
.cart-line.is-oos .sale-name { text-decoration: line-through; text-decoration-color: rgba(163, 45, 45, 0.6); }
.cart-line.is-oos .sale-price { opacity: 0.45; }
.cart-line.is-oos .sale-line-total { color: #a32d2d; font-size: 11.5px; white-space: normal; line-height: 1.2; }
html[data-theme="dark"] .oos-offer { background: #3a2f15; color: #eab362; border-color: #6b5520; }
html[data-theme="dark"] .oos-toggle[aria-pressed="true"] { background: #3a1f1f; color: #e58a8a; border-color: #6b3434; }

/* Missed sales report (missed-sales.php). */
.missed-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 1rem 0; }
.missed-stats .stat-card { background: var(--surface-2); border: 0.5px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.missed-stats .stat-card .sub { display: block; font-size: 12px; }
.missed-stats .stat-card strong { font-size: 22px; font-weight: 600; }
.list-head.missed-row, .list-row.missed-row { grid-template-columns: minmax(0, 1fr) 70px 110px 80px; }
.missed-meta { display: block; font-size: 12px !important; margin-top: 2px; }
.missed-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 16px; }
@media (max-width: 600px) {
    .list-head.missed-row, .list-row.missed-row { grid-template-columns: minmax(0, 1fr) 44px 80px 64px; font-size: 13px; }
}

/* Check & sign: "Not supplied (out of stock)" heading. */
.sign-heading--oos { color: #a32d2d; }
html[data-theme="dark"] .sign-heading--oos { color: #e58a8a; }
.oos-confirm-check { margin-bottom: 10px; }
.cart-line .oos-actions .oos-offer { white-space: normal !important; text-align: left; max-width: 100%; }
.list-head.missed-sup-row, .list-row.missed-sup-row { grid-template-columns: minmax(0, 1fr) 90px 110px 80px; }
@media (max-width: 600px) {
    .list-head.missed-sup-row, .list-row.missed-sup-row { grid-template-columns: minmax(0, 1fr) 54px 70px 64px; font-size: 13px; }
}
.ci-customer { font-weight: 500; margin-top: 2px; }
.ci-times { font-size: 12px !important; }
.van-stock-details > summary { cursor: pointer; padding: 4px 0; list-style-position: inside; }
.van-stock-details > summary::marker { color: var(--text-secondary); }
/* Two short columns - fits a phone without scrolling sideways. */
#van-stock-list .list-row { min-width: 0; }
#van-stock-list .list-row > span:last-child { white-space: nowrap; }
