/* =====================================================================
   Design tokens
   Self-hosted Inter (400/600/700, assets/fonts/) is the one web font in
   use; the system stack after it is the real fallback if it fails to
   load (no internet access required to use this app once deployed).
   ===================================================================== */

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/inter-400.woff2") format("woff2");
}

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/inter-600.woff2") format("woff2");
}

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/inter-700.woff2") format("woff2");
}

:root {
    /* Brand */
    --color-primary: #175e91;
    --color-primary-dark: #0f4a75;
    --color-primary-soft: #e7f0f7;
    --color-accent: #8a5a34;
    --color-accent-soft: #f4ece3;

    /* Neutrals */
    --color-bg: #f3f4f7;
    --color-surface: #ffffff;
    --color-surface-alt: #f7f8fa;
    --color-border: #e1e4ea;
    --color-border-strong: #c7cdd9;
    --color-text: #1a1d24;
    --color-text-secondary: #454b58;
    --color-muted: #676e7c;

    /* Semantic */
    --color-success-bg: #e5f5ea;
    --color-success-text: #17743d;
    --color-danger: #c0291f;
    --color-danger-dark: #9c2018;
    --color-danger-bg: #fbeae8;
    --color-danger-text: #b3261e;
    --color-warning-bg: #fdf0da;
    --color-warning-text: #8a5a06;
    --color-info-bg: #e6f0fa;
    --color-info-text: #145d92;
    --color-neutral-bg: #eceef2;
    --color-neutral-text: #454b58;
    --color-purple-bg: #f0eaff;
    --color-purple-text: #5b3aa8;

    /* Type */
    --font: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-system: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.9375rem;
    --text-md: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.375rem;
    --text-2xl: 1.75rem;
    --weight-normal: 400;
    --weight-semibold: 600;
    --weight-bold: 700;
    --line-height: 1.5;

    /* Spacing scale (4px base) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;

    /* Shape */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-full: 999px;
    --shadow-sm: 0 1px 2px rgba(20, 24, 33, 0.06);
    --shadow-md: 0 6px 20px rgba(20, 24, 33, 0.08);

    /* Touch */
    --tap: 44px;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--text-base);
    line-height: var(--line-height);
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
}

h1 {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    letter-spacing: -0.01em;
    margin: 0 0 var(--space-4);
    color: var(--color-text);
}

h2 {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    margin: 0 0 var(--space-3);
}

p {
    margin: 0 0 var(--space-3);
}

a {
    color: var(--color-primary);
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.auth-logo {
    display: block;
    height: 64px;
    width: auto;
    margin: 0 0 var(--space-5);
}

.topbar-logo {
    display: block;
    height: 32px;
    width: auto;
    border-radius: var(--radius-sm);
}

/* --- Auth page --- */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-5);
    background:
        radial-gradient(circle at 15% 0%, var(--color-accent-soft) 0%, transparent 45%),
        radial-gradient(circle at 100% 100%, var(--color-primary-soft) 0%, transparent 50%),
        var(--color-bg);
}

.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6) var(--space-5);
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-md);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.auth-form label {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
    margin-top: var(--space-3);
}

.auth-form input {
    min-height: var(--tap);
    padding: 0.65rem var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    font-size: var(--text-md);
}

.auth-form input:focus-visible {
    border-color: var(--color-primary);
}

/* --- Buttons --- */

button {
    font-family: inherit;
    cursor: pointer;
}

button:disabled {
    cursor: wait;
    opacity: 0.7;
}

.btn-primary,
.btn-secondary,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--tap);
    padding: 0.6rem var(--space-4);
    border-radius: var(--radius);
    text-decoration: none;
    text-align: center;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    line-height: 1.2;
    transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn-primary {
    border: 1px solid var(--color-primary);
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

.btn-secondary {
    border: 1.5px solid var(--color-border-strong);
    background: var(--color-surface);
    color: var(--color-text);
}

.btn-secondary:hover {
    background: var(--color-surface-alt);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* Destructive / irreversible actions - solid, saturated red so they are
   never mistaken for a neutral secondary action at a glance. */
.btn-danger {
    border: 1px solid var(--color-danger);
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--color-danger-dark);
    border-color: var(--color-danger-dark);
}

.auth-form .btn-primary {
    margin-top: var(--space-4);
    width: 100%;
}

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

@keyframes feedback-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    margin: 0 0 var(--space-4);
    animation: feedback-in 0.18s ease-out;
}

.alert-error {
    background: var(--color-danger-bg);
    color: var(--color-danger-text);
    border-color: rgba(179, 38, 30, 0.25);
    list-style: none;
}

.alert-success {
    background: var(--color-success-bg);
    color: var(--color-success-text);
    border-color: rgba(23, 116, 61, 0.25);
}

.alert-success a {
    color: inherit;
    font-weight: var(--weight-bold);
}

/* Neither an error nor a success - a heads-up that something real is
   being hidden by the current filter (see the reports "excluded by
   status" note), not that anything went wrong. */
.alert-notice {
    background: var(--color-warning-bg);
    color: var(--color-warning-text);
    border-color: rgba(138, 90, 6, 0.25);
}

.delivery-preview {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    font-size: var(--text-base);
    margin: 0 0 var(--space-4);
    background: var(--color-primary-soft);
    border: 1px solid rgba(23, 94, 145, 0.2);
    color: var(--color-primary-dark);
}

.delivery-preview strong {
    color: var(--color-text);
}

/* --- Empty states --- */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-3);
    padding: var(--space-6) var(--space-4);
    color: var(--color-muted);
}

.empty-state svg {
    width: 40px;
    height: 40px;
    color: var(--color-border-strong);
}

.empty-state p {
    margin: 0;
    font-size: var(--text-base);
    max-width: 32em;
}

.empty-state .btn-primary,
.empty-state .btn-secondary {
    margin-top: var(--space-1);
}

/* --- App shell --- */

.topbar {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    border-top: 3px solid var(--color-accent);
    flex-wrap: wrap;
}

.topbar-nav {
    display: flex;
    gap: var(--space-4);
    flex: 1;
    flex-wrap: wrap;
}

.topbar-nav a {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

.topbar-nav a:hover {
    color: var(--color-primary);
}

.logout-form {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.user-name {
    font-size: var(--text-sm);
    color: var(--color-muted);
}

.link-button {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    cursor: pointer;
    padding: 0;
}

.link-button:hover {
    text-decoration: underline;
}

.page {
    max-width: 960px;
    margin: 0 auto;
    padding: var(--space-5) var(--space-4) var(--space-7);
}

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

/* --- Panels / cards --- */

.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
    margin: 0 0 var(--space-5);
}

.panel h2 {
    font-size: var(--text-lg);
    margin: 0 0 var(--space-4);
}

/* --- Per-section product search (new-request screen) ---
   One search box per catalog block (Roastery/Central Kitchen/Central
   Store), scoped to that section only - replaces the single shared
   search box that used to sit above all four blocks. Not sticky: it
   lives inside its own block now, not the page header. */

.section-search {
    position: relative;
    margin: 0 0 var(--space-4);
}

.section-search label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
    margin: 0 0 var(--space-2);
}

.section-search-input {
    width: 100%;
    min-height: var(--tap);
    padding: 0.6rem var(--space-4);
    border: 1.5px solid var(--color-border-strong);
    border-radius: var(--radius);
    font-size: var(--text-md);
    font-family: inherit;
    box-sizing: border-box;
}

.section-search-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* The tappable results list, right below its own search box, capped at
   8 entries by the script - every row is at least --tap (44px) tall,
   this is the control used most, on a phone, one-handed, during a rush. */
.section-search-results {
    position: relative;
    z-index: 5;
    list-style: none;
    margin: var(--space-2) 0 0;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.section-search-result,
.section-search-no-match {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: var(--tap);
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--text-md);
}

.section-search-result:last-child,
.section-search-no-match:last-child {
    border-bottom: none;
}

.section-search-result {
    cursor: pointer;
}

.section-search-result:active {
    background: var(--color-neutral-bg);
}

/* Already on this request - shown, not hidden, but not tappable. */
.section-search-result-added {
    cursor: default;
    color: var(--color-text-secondary);
}

.section-search-added-tag {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.section-search-no-match {
    color: var(--color-text-secondary);
    cursor: default;
}

/* --- Grid tables (admin lists, request lists, queues) --- */

.grid-table {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    margin: 0 0 var(--space-4);
}

.grid-header,
.grid-row {
    display: grid;
    gap: var(--space-2);
    align-items: center;
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border);
}

.grid-row {
    border: none;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    border-radius: 0;
}

.grid-table > :last-child {
    border-bottom: none;
}

.grid-header {
    background: var(--color-surface-alt);
    font-size: var(--text-xs);
    color: var(--color-muted);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.grid-row.row-inactive {
    opacity: 0.55;
}

.grid-row input,
.grid-row select {
    width: 100%;
    min-height: var(--tap);
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-family: inherit;
}

.row-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.row-actions .btn-primary,
.row-actions .btn-danger {
    padding: 0.4rem var(--space-3);
    min-height: 36px;
    font-size: var(--text-sm);
}

.sections-table .grid-header,
.sections-table .grid-row {
    grid-template-columns: 2fr 110px 90px 210px;
}

.items-table .grid-header,
.items-table .grid-row {
    grid-template-columns: 1.8fr 1.3fr 90px 110px 90px 80px 210px;
}

@media (max-width: 800px) {
    .grid-header {
        display: none;
    }

    .grid-row {
        grid-template-columns: 1fr !important;
        gap: var(--space-2);
        padding: var(--space-4);
    }

    /* Status is excluded here - the colour + text pill is already
       self-explanatory, and .status-badge's own inline-flex layout
       would otherwise sit this label beside the badge text instead of
       above it. */
    .requests-table .grid-row > span[data-label]:not(.status-badge)::before,
    .lines-table .grid-row > span[data-label]:not(.status-badge)::before,
    .queue-table .grid-row > span[data-label]:not(.status-badge)::before,
    .all-requests-table .grid-row > span[data-label]:not(.status-badge)::before {
        content: attr(data-label);
        display: block;
        font-size: var(--text-xs);
        font-weight: var(--weight-semibold);
        color: var(--color-muted);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        margin-bottom: 0.15rem;
    }
}

.add-form {
    border-top: 1px solid var(--color-border);
    padding-top: var(--space-4);
}

.add-form summary {
    cursor: pointer;
    color: var(--color-primary);
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    min-height: var(--tap);
    display: flex;
    align-items: center;
}

.add-form form {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    align-items: flex-end;
    margin-top: var(--space-4);
}

.add-form label {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    font-weight: var(--weight-semibold);
}

.add-form input,
.add-form select {
    min-height: var(--tap);
    padding: 0.5rem var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
    font-family: inherit;
}

/* --- Request builder: one block per section, native selects only ---
   Every field is full-width and stacked, label above control, so this
   never depends on a custom widget to open correctly on a real phone. */

.product-row,
.external-row {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface-alt);
    padding: var(--space-4);
    margin: 0 0 var(--space-3);
}

.product-row label,
.external-row label {
    display: block;
    margin: 0 0 var(--space-3);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
}

.product-row label > select,
.product-row label > input,
.external-row label > input {
    display: block;
    width: 100%;
    min-height: var(--tap);
    margin-top: var(--space-1);
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    font-size: var(--text-md);
    font-weight: var(--weight-normal);
}

.product-row label > select:focus-visible,
.product-row label > input:focus-visible,
.external-row label > input:focus-visible {
    border-color: var(--color-primary);
}

/* Purchases' own item rows get slightly more breathing room than the
   catalog request builder's product rows - overridden separately (not
   folded into the shared rule above) so this never touches
   .product-row, which is already verified working well on a real phone. */
.external-row {
    margin-bottom: var(--space-4);
}

.external-row label {
    margin-bottom: var(--space-4);
}

.product-row select:disabled,
.product-row option:disabled {
    color: var(--color-muted);
}

.remove-row-btn-full {
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: 0.5rem;
    border: 1.5px solid var(--color-danger);
    border-radius: var(--radius);
    background: none;
    color: var(--color-danger);
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
}

.remove-row-btn-full:hover {
    background: var(--color-danger-bg);
}

.row-error {
    color: var(--color-danger-text);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    margin: -0.4rem 0 var(--space-3);
}

.add-row-btn {
    width: 100%;
    min-height: 48px;
}

/* --- Generic stacked labeled field, one per row, phone-first - the
   same block/full-width treatment .external-row label already gives an
   item row's own inputs, but usable standalone (e.g. a form's header
   section) where fields aren't wrapped in a repeating row. A bare
   <label>text<input></label> with no class renders inline by default
   and several in a row cram onto one line at mismatched widths - this
   is the fix for that, not a cosmetic extra. */

.field {
    display: block;
    margin: 0 0 var(--space-5);
}

.field:last-child {
    margin-bottom: 0;
}

.field > .field-label {
    display: block;
    margin: 0 0 var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
}

.field > .field-label > .optional-tag {
    font-weight: var(--weight-normal);
    color: var(--color-muted);
}

.field > input {
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    font-size: var(--text-md);
    font-weight: var(--weight-normal);
}

.field > input:focus-visible {
    border-color: var(--color-primary);
}

.note-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
    margin: var(--space-4) 0;
}

.note-field textarea {
    font-family: inherit;
    font-size: var(--text-md);
    font-weight: var(--weight-normal);
    color: var(--color-text);
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    resize: vertical;
}

.note-field textarea:focus-visible {
    border-color: var(--color-primary);
}

.form-actions {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.form-actions .btn-primary,
.form-actions .btn-secondary,
.form-actions .btn-danger {
    flex: 1 1 auto;
}

@media (min-width: 480px) {
    .form-actions .btn-primary,
    .form-actions .btn-secondary,
    .form-actions .btn-danger {
        flex: 0 1 auto;
    }
}

/* --- Request lists / detail --- */

.status-filter {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin: 0 0 var(--space-5);
}

.status-filter a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

.status-filter a.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.requests-table .grid-header,
.requests-table .grid-row {
    grid-template-columns: 1fr 140px 180px 220px;
}

.dashboard-table .grid-header,
.dashboard-table .grid-row {
    grid-template-columns: 1fr 130px 170px;
}

.requests-row {
    text-decoration: none;
    color: inherit;
}

.requests-row:hover {
    background: var(--color-surface-alt);
}

.lines-table .grid-header,
.lines-table .grid-row {
    grid-template-columns: 2fr 100px 100px 130px;
}

/* --- Status badges: one distinct colour + label per status, reused
   identically everywhere a status appears (request list/detail, queue,
   print). Colour is never the only signal - the label text is always
   present alongside it. --- */

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.status-draft { background: var(--color-neutral-bg); color: var(--color-neutral-text); }
.status-submitted { background: var(--color-info-bg); color: var(--color-info-text); }
.status-ready_for_final { background: var(--color-warning-bg); color: var(--color-warning-text); }
.status-approved { background: var(--color-success-bg); color: var(--color-success-text); }
.status-rejected { background: var(--color-danger-bg); color: var(--color-danger-text); }
.status-completed { background: var(--color-purple-bg); color: var(--color-purple-text); }

/* Per-section approval status (request_section_approvals.status) -
   pending/not_used reuse the request-level submitted/draft colours,
   approved/rejected are shared with .status-line-* below. */
.status-pending { background: var(--color-info-bg); color: var(--color-info-text); }
.status-not_used { background: var(--color-neutral-bg); color: var(--color-neutral-text); }

.status-line-pending { background: var(--color-neutral-bg); color: var(--color-neutral-text); }
.status-line-approved { background: var(--color-success-bg); color: var(--color-success-text); }
.status-line-edited { background: var(--color-warning-bg); color: var(--color-warning-text); }
.status-line-unavailable { background: var(--color-danger-bg); color: var(--color-danger-text); }
.status-line-rejected { background: var(--color-danger-bg); color: var(--color-danger-text); }

.timeline {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: var(--text-base);
}

.timeline li {
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
}

.timeline li:last-child {
    border-bottom: none;
}

/* --- Logistics queue / review --- */

.status-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0 0 var(--space-4);
}

.status-tab {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    gap: var(--space-2);
    padding: 0 var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

.status-tab.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.tab-count {
    display: inline-block;
    min-width: 1.4rem;
    padding: 0.05rem 0.45rem;
    border-radius: var(--radius-full);
    background: rgba(20, 24, 33, 0.1);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    text-align: center;
}

.status-tab.active .tab-count {
    background: rgba(255, 255, 255, 0.25);
}

.quick-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0 0 var(--space-3);
}

.quick-filter {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

.quick-filter.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.quick-filter-clear {
    color: var(--color-muted);
    font-weight: var(--weight-normal);
}

.delivery-group {
    margin: 0 0 var(--space-6);
}

.delivery-group-heading {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
    margin: 0 0 var(--space-2);
    border-left: 3px solid var(--color-primary);
    padding-left: var(--space-2);
}

.queue-table .grid-header,
.queue-table .grid-row {
    grid-template-columns: 1fr 1fr 110px 180px;
}

.review-table .grid-header,
.review-table .grid-row {
    grid-template-columns: 1.8fr 90px 110px 90px 1.4fr;
}

.review-table input[type="number"] {
    min-height: 40px;
}

.review-table input[type="checkbox"] {
    width: 24px;
    height: 24px;
}

/* External Purchase lines with an amount paid: logistics' and the
   manager's editable review table (Item/Requested/Approved qty/
   Unavailable/Amount paid/Note), and the read-only post-decision
   variant of .lines-table with one amount column appended. */
.priced-review-table .grid-header,
.priced-review-table .grid-row {
    grid-template-columns: 1.4fr 90px 110px 90px 130px 1.2fr;
}

.priced-review-table input[type="number"] {
    min-height: 40px;
}

.priced-review-table input[type="checkbox"] {
    width: 24px;
    height: 24px;
}

.lines-table-priced .grid-header,
.lines-table-priced .grid-row {
    grid-template-columns: 1.6fr 90px 90px 120px 130px;
}

.field-error {
    display: block;
    color: var(--color-danger-text);
    font-size: var(--text-sm);
    margin-top: var(--space-1);
}

/* --- Reports --- */

.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    align-items: flex-end;
}

.filter-form label {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
}

.filter-form input,
.filter-form select {
    min-height: var(--tap);
    padding: 0.5rem var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
    font-family: inherit;
}

.status-checks {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
    margin: 0;
}

.status-checks legend {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--color-muted);
    padding: 0 0.3rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--tap);
    font-size: var(--text-base);
    color: var(--color-text);
    flex-direction: row !important;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
}

.grand-total {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    color: var(--color-primary);
    margin: 0;
}

.cost-split {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-6);
}

.cost-split p {
    margin: 0;
}

.summary-table .grid-header,
.summary-table .grid-row {
    grid-template-columns: 1fr 100px 140px;
}

.branch-cost-table .grid-header,
.branch-cost-table .grid-row {
    grid-template-columns: 1.2fr 80px 130px 130px 140px;
}

.top-items-table .grid-header,
.top-items-table .grid-row {
    grid-template-columns: 2fr 120px 140px;
}

.detail-table .grid-header,
.detail-table .grid-row {
    grid-template-columns: 90px 1fr 120px 1fr 1fr 1.4fr 90px 120px 150px;
    font-size: var(--text-sm);
}

/* --- Branches / Users admin --- */

.branches-table .grid-header,
.branches-table .grid-row {
    grid-template-columns: 2fr 120px 90px 280px;
}

.users-table .grid-header,
.users-table .grid-row {
    grid-template-columns: 1.2fr 1.4fr 110px 1.2fr 1.2fr 80px 340px;
}

.users-table .row-actions {
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-3);
}

/* --- Manager: all requests --- */

.all-requests-table .grid-header,
.all-requests-table .grid-row {
    grid-template-columns: 1fr 1fr 130px 180px;
}

.manager-lines-table .grid-header,
.manager-lines-table .grid-row {
    grid-template-columns: 1.6fr 90px 110px 90px 100px 110px 1.2fr;
}

/* --- Manager dashboard stat tiles --- */

.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: var(--space-3);
    margin: 0 0 var(--space-5);
}

.stat-tile {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
    text-align: center;
    text-decoration: none;
    transition: border-color 0.12s ease, transform 0.12s ease;
}

.stat-tile:hover {
    border-color: var(--color-primary);
    transform: translateY(-1px);
}

.stat-value {
    display: block;
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    color: var(--color-primary);
}

.stat-label {
    display: block;
    font-size: var(--text-sm);
    color: var(--color-muted);
    margin-top: var(--space-1);
}

/* =====================================================================
   Print - deliberately plain and ink-efficient. No brand colour, no
   webfont dependency, no shadows or gradients: this is the one part of
   the app meant to be printed, not admired on screen.
   ===================================================================== */

.print-body {
    background: #7c828c;
    font-family: var(--font-system);
}

.print-toolbar {
    max-width: 210mm;
    margin: 0 auto;
    padding: var(--space-4) var(--space-4) 0;
}

.print-page {
    max-width: 210mm;
    margin: var(--space-4) auto;
    padding: 14mm;
    background: #fff;
    color: #111;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.print-header {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    border-bottom: 2px solid #111;
    padding-bottom: var(--space-3);
    margin-bottom: var(--space-4);
}

.print-logo {
    height: 48px;
    width: auto;
}

.print-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: #111;
}

.print-header p {
    margin: 0.15rem 0 0;
    font-size: 0.9rem;
}

.print-note {
    font-size: 0.9rem;
    margin: 0 0 var(--space-4);
}

.print-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 1.25rem;
    font-size: 0.85rem;
}

.print-table caption {
    text-align: left;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0.4rem 0;
    color: #111;
}

.print-table th,
.print-table td {
    border: 1px solid #999;
    padding: 0.4rem 0.5rem;
    text-align: left;
}

.print-table thead {
    background: #eee;
}

.print-table tfoot td {
    font-weight: 700;
    text-align: right;
}

.print-grand-total {
    text-align: right;
    font-size: 1.1rem;
    font-weight: 700;
}

@media print {
    .no-print {
        display: none !important;
    }

    .print-body {
        background: #fff;
    }

    .print-page {
        margin: 0;
        padding: 0;
        box-shadow: none;
        max-width: none;
    }

    @page {
        size: A4;
        margin: 14mm;
    }
}

/* Respect reduced-motion preferences for the small entrance animations
   used on feedback banners. */
@media (prefers-reduced-motion: reduce) {
    .alert {
        animation: none;
    }
}
