/* ==========================================================================
   VnS Inventory – UI system
   Mobile-first. Loaded AFTER bootstrap + template css, so it wins.
   Sections: 1 tokens · 2 base · 3 shell/nav · 4 page · 5 buttons · 6 forms
             7 cards · 8 tables (auto-stack on mobile) · 9 badges/alerts
             10 pagination · 11 components · 12 desktop · 13 print
   ========================================================================== */

/* 1 ── TOKENS ─────────────────────────────────────────────────────────── */
:root {
    --brand-900: #2e2814;
    --brand-800: #3d3519;
    --brand-700: #54491f;
    --brand-accent: #e0c92c;     /* gold – used on dark backgrounds only */
    --brand-ink: #7a6a05;        /* gold, dark enough for text on white (5.3:1) */

    --bg: #f5f4ef;
    --surface: #ffffff;
    --surface-2: #faf9f5;
    --line: #e2dfd3;
    --line-strong: #c9c5b3;

    --text: #1d1b12;             /* 16:1 on white */
    --text-2: #4a4638;           /* 9:1 */
    --text-3: #6b6757;           /* 5.4:1 – lowest allowed for body text */

    --ok: #05603a;   --ok-bg: #e3f5ea;
    --warn: #8a4b00; --warn-bg: #fff1d6;
    --bad: #b42318;  --bad-bg: #fde8e6;
    --info: #1a4e8a; --info-bg: #e4eefb;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(29, 27, 18, .06), 0 2px 8px rgba(29, 27, 18, .05);
    --shadow-lg: 0 8px 28px rgba(29, 27, 18, .16);

    --tap: 48px;                 /* minimum touch target */
    --topbar-h: 56px;
    --tabbar-h: 64px;
    --sidebar-w: 260px;
    --safe-b: env(safe-area-inset-bottom, 0px);

    /* type scale – body never below 16px so iOS doesn't zoom inputs */
    --fs-xs: .8125rem;   /* 13 */
    --fs-sm: .9375rem;   /* 15 */
    --fs-base: 1rem;     /* 16 */
    --fs-lg: 1.125rem;   /* 18 */
    --fs-xl: 1.375rem;   /* 22 */
    --fs-2xl: 1.75rem;   /* 28 */
    --fs-num: 1.875rem;  /* 30 – big KPI numbers */

    /* Bootstrap variable bridge */
    --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --bs-body-font-size: 1rem;
    --bs-body-color: var(--text);
    --bs-body-bg: var(--bg);
    --bs-border-color: var(--line);
    --bs-link-color: var(--brand-ink);
    --bs-link-hover-color: var(--brand-900);
}

/* 2 ── BASE ───────────────────────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; height: auto; }
body {
    font-family: var(--bs-body-font-family);
    font-size: var(--fs-base);
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    height: auto;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    font-variant-numeric: tabular-nums;     /* numbers line up in columns */
}
h1, h2, h3, h4, h5, h6 { color: var(--text); font-weight: 700; line-height: 1.25; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3, h4 { font-size: var(--fs-lg); }
h5, h6 { font-size: var(--fs-base); }
a { color: var(--brand-ink); text-underline-offset: 2px; }
a:hover { color: var(--brand-900); }
.text-muted, .text-secondary { color: var(--text-3) !important; }
.small, small { font-size: var(--fs-sm); }
:focus-visible { outline: 3px solid var(--brand-accent); outline-offset: 2px; }
img { max-width: 100%; }

/* 3 ── APP SHELL ──────────────────────────────────────────────────────── */
/* Layout works like the original template: sidebar + page sit side by side and the sidebar
   slides in/out by changing its margin (0.35s). On phones it starts hidden and the toggle
   slides it in; on desktop it starts open and the toggle slides it away. */
:root { --brand-gradient: linear-gradient(135deg, rgba(196, 178, 5, .15) 0%, rgba(31, 26, 22, .8) 100%); }

.app { min-height: 100vh; display: flex; overflow-x: hidden; background: var(--brand-900); }
.app-body {
    flex: 0 0 100%; min-width: 0; min-height: 100vh; display: flex; flex-direction: column;
    background: var(--bg);
    transition: margin-left .35s ease-in-out;
}

/* top bar: dark olive with the gold-tinted gradient, on every screen size */
.app-topbar {
    position: sticky; top: 0; z-index: 1030;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: .75rem;
    padding: 0 1rem;
    background-color: var(--brand-900);
    background-image: var(--brand-gradient);
    color: #fff;
    box-shadow: 0 1px 0 rgba(255,255,255,.08), 0 2px 10px rgba(0,0,0,.2);
}
.app-topbar__brand {
    display: flex; align-items: center; gap: .6rem;
    color: #fff; font-weight: 700; font-size: var(--fs-lg);
    text-decoration: none; margin-right: auto;
}
.app-topbar__brand:hover { color: #fff; }
.app-topbar__brand img { height: 32px; width: auto; border-radius: 6px; background:#fff; padding:2px; }
.app-topbar__user { color: #fff; font-size: var(--fs-sm); display: none; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: var(--tap); height: var(--tap); border: 0; border-radius: 50%;
    background: transparent; color: #fff; font-size: 1.4rem; cursor: pointer;
}
.icon-btn:hover, .icon-btn:focus-visible { background: rgba(255,255,255,.14); color: #fff; }

/* sidebar: phones start hidden (margin pulls it off-screen); ".collapsed" is the toggled state,
   exactly as in the original template, so on phones collapsed = shown and on desktop collapsed = hidden. */
.app-sidebar {
    flex: 0 0 var(--sidebar-w); width: var(--sidebar-w);
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    margin-left: calc(-1 * var(--sidebar-w));
    padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 1rem);
    background-color: var(--brand-900);
    background-image: var(--brand-gradient);
    color: #fff;
    border-right: 1px solid rgba(255,255,255,.08);
    transition: margin-left .35s ease-in-out;
    z-index: 1020;
}
.app-sidebar.collapsed { margin-left: 0; }
.sidebar-brand {
    display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem;
    color: #fff; font-size: var(--fs-lg); font-weight: 700; text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-brand:hover { color: #fff; }
@media (prefers-reduced-motion: reduce) { .app-sidebar, .app-body { transition: none; } }
.nav-group {
    font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: #cfc79a; padding: 1.1rem 1rem .35rem;
}
.nav-link-ui {
    display: flex; align-items: center; gap: .85rem;
    min-height: var(--tap); padding: .5rem 1rem; margin: 2px .5rem;
    color: #f4f1de; font-size: var(--fs-base); font-weight: 500;
    border-radius: var(--radius-sm); text-decoration: none;
}
.nav-link-ui i { font-size: 1.2rem; width: 1.4rem; text-align: center; color: var(--brand-accent); }
.nav-link-ui:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link-ui.active { background: var(--brand-accent); color: #1d1b12; font-weight: 700; }
.nav-link-ui.active i { color: #1d1b12; }
.nav-link-ui .count {
    margin-left: auto; min-width: 1.6rem; padding: 0 .45rem; text-align: center;
    background: var(--bad); color: #fff; font-size: var(--fs-xs); font-weight: 700; border-radius: 999px;
}

/* bottom tab bar (mobile) */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
    height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: var(--surface); border-top: 1px solid var(--line);
    box-shadow: 0 -2px 12px rgba(29,27,18,.08);
}
.tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    background: none; border: 0; padding: 0; position: relative;
    color: var(--text-3); font-size: .75rem; font-weight: 600; text-decoration: none;
}
.tabbar i { font-size: 1.45rem; line-height: 1; }
.tabbar .active { color: var(--brand-900); }
.tabbar .active i { color: var(--brand-ink); }
.tabbar .active::before {
    content: ''; position: absolute; top: 0; left: 28%; right: 28%; height: 3px;
    background: var(--brand-accent); border-radius: 0 0 3px 3px;
}
.tabbar .dot {
    position: absolute; top: 6px; left: calc(50% + 6px);
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* content */
.app-main { flex: 1; min-width: 0; }
.app-content {
    width: 100%; max-width: 1280px; margin: 0 auto;
    padding: 1rem 1rem calc(var(--tabbar-h) + var(--safe-b) + 1.5rem);
}
.app-footer { display: none; }

/* 4 ── PAGE HEADER / HELPERS ──────────────────────────────────────────── */
.page-header {
    display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
    gap: .75rem 1rem; margin-bottom: 1rem;
}
.page-header__left { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.page-title { font-size: var(--fs-xl); font-weight: 800; margin: 0; }
.page-subtitle, .page-title__sub { color: var(--text-3); font-size: var(--fs-sm); }
.page-header__actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.back-link {
    display: inline-flex; align-items: center; gap: .35rem; min-height: 32px;
    font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); text-decoration: none;
}
.back-link:hover { color: var(--brand-900); }
.section-title, .section-header { font-size: var(--fs-lg); font-weight: 700; margin: 1.25rem 0 .6rem; }
.empty-state {
    background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius);
    color: var(--text-3); padding: 2rem 1rem; text-align: center; font-size: var(--fs-base);
}
.stack { display: flex; flex-direction: column; gap: 1rem; }
.num { font-variant-numeric: tabular-nums; font-weight: 700; }

/* 5 ── BUTTONS ────────────────────────────────────────────────────────── */
.btn {
    --bs-btn-font-size: var(--fs-base);
    --bs-btn-border-radius: var(--radius-sm);
    min-height: var(--tap); padding: .55rem 1.1rem;
    font-weight: 600; line-height: 1.2;
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    border-radius: var(--radius-sm);
}
.btn-sm { min-height: 40px; padding: .35rem .85rem; font-size: var(--fs-sm); --bs-btn-font-size: var(--fs-sm); }
.btn-lg { min-height: 56px; font-size: var(--fs-lg); }

.btn-primary, .btn-tertiary {
    background: var(--brand-900); border: 2px solid var(--brand-900); color: #fff;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active,
.btn-tertiary:hover, .btn-tertiary:focus, .btn-tertiary:active {
    background: var(--brand-700) !important; border-color: var(--brand-700) !important; color: #fff;
}
.btn-secondary {
    background: var(--surface); border: 2px solid var(--line-strong); color: var(--text);
}
.btn-secondary:hover, .btn-secondary:focus, .btn-secondary:active {
    background: var(--surface-2) !important; border-color: var(--brand-900) !important; color: var(--text);
}
.btn-ghost { background: transparent; border: 2px solid transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(29,27,18,.06); color: var(--text); }
.btn-outline-secondary, .btn-outline-primary {
    background: var(--surface); border: 2px solid var(--line-strong); color: var(--text);
}
.btn-outline-secondary:hover, .btn-outline-primary:hover { background: var(--brand-900); border-color: var(--brand-900); color: #fff; }
.btn-outline-warning { background: var(--surface); border: 2px solid #b97600; color: #7a4a00; }
.btn-outline-warning:hover { background: #b97600; color: #fff; }
.btn-success { background: var(--ok); border: 2px solid var(--ok); color: #fff; }
.btn-success:hover { background: #044a2d; border-color: #044a2d; color:#fff; }
.btn-danger, .btn-outline-danger { border: 2px solid var(--bad); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { background: #8f1c12; border-color: #8f1c12; color: #fff; }
.btn-outline-danger { background: var(--surface); color: var(--bad); }
.btn-outline-danger:hover { background: var(--bad); color: #fff; }
.btn-link { color: var(--brand-ink); font-weight: 600; text-decoration: underline; }
.btn:disabled, .btn.disabled { opacity: .5; }

.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn-row > form { margin: 0; display: contents; }
.btn-row--full > .btn, .btn-row--full > form > .btn { flex: 1 1 0; }
.btn-icon { font-size: 1.1rem; line-height: 1; }

/* 6 ── FORMS ──────────────────────────────────────────────────────────── */
.form-label, label { font-weight: 600; font-size: var(--fs-sm); color: var(--text); margin-bottom: .35rem; }
.form-control, .form-select {
    min-height: var(--tap); font-size: 1rem;            /* 16px: no iOS zoom */
    color: var(--text); background-color: var(--surface);
    border: 2px solid var(--line-strong); border-radius: var(--radius-sm);
    padding: .6rem .85rem;
}
textarea.form-control { min-height: 110px; }
.form-control::placeholder { color: #8b8672; }
.form-control:focus, .form-select:focus {
    border-color: var(--brand-900); box-shadow: 0 0 0 4px rgba(224,201,44,.35);
}
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--bad); background-image: none; padding-right: .85rem; }
.invalid-feedback { color: var(--bad); font-size: var(--fs-sm); font-weight: 600; }
.form-text { color: var(--text-3); font-size: var(--fs-sm); }
.form-check { min-height: var(--tap); display: flex; align-items: center; gap: .6rem; padding-left: 0; }
.form-check-input {
    float: none; margin: 0; width: 1.6rem; height: 1.6rem; flex: 0 0 auto;
    border: 2px solid var(--line-strong);
}
.form-check-input:checked { background-color: var(--brand-900); border-color: var(--brand-900); }
.form-check-label { font-size: var(--fs-base); font-weight: 500; }
.required { color: var(--bad); }
.input-group > .form-control, .input-group > .btn { min-height: var(--tap); }

.form-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1rem; max-width: 880px;
}
.form-section { padding-bottom: 1.25rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.form-section:last-of-type { border-bottom: 0; margin-bottom: 0; }
.form-section__title { font-size: var(--fs-lg); font-weight: 700; margin-bottom: .25rem; }
.form-section__hint { color: var(--text-3); font-size: var(--fs-sm); margin-bottom: .85rem; }
.form-row { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-bottom: 1rem; }
.form-group { min-width: 0; }
.form-actions {
    display: flex; flex-direction: column-reverse; gap: .6rem;
    margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line);
}
.form-actions .btn { width: 100%; }

.checkbox-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.checkbox-card {
    position: relative; display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    min-height: var(--tap); padding: .6rem .85rem; margin: 0; cursor: pointer;
    background: var(--surface); border: 2px solid var(--line-strong); border-radius: var(--radius-sm);
}
.checkbox-card .checkbox-input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.checkbox-card__label { font-weight: 600; }
.checkbox-card__hint { display: block; color: var(--text-3); font-size: var(--fs-xs); font-weight: 400; }
.checkbox-card__check {
    width: 1.5rem; height: 1.5rem; border-radius: 50%; display: grid; place-items: center;
    border: 2px solid var(--line-strong); color: transparent; flex: 0 0 auto;
}
.checkbox-card:has(.checkbox-input:checked), .checkbox-card.checked {
    border-color: var(--brand-900); background: #fbf7d8;
}
.checkbox-card:has(.checkbox-input:checked) .checkbox-card__check,
.checkbox-card.checked .checkbox-card__check { background: var(--brand-900); border-color: var(--brand-900); color: #fff; }

.search-bar { display: flex; gap: .5rem; }
.search-input-wrap { position: relative; flex: 1; min-width: 0; }
.search-input {
    width: 100%; min-height: var(--tap); font-size: 1rem; padding: .6rem 2.6rem .6rem .95rem;
    border: 2px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.search-input:focus { outline: 0; border-color: var(--brand-900); box-shadow: 0 0 0 4px rgba(224,201,44,.35); }
.search-clear {
    position: absolute; right: .35rem; top: 50%; transform: translateY(-50%);
    width: 40px; height: 40px; display: grid; place-items: center;
    color: var(--text-2); text-decoration: none; font-size: 1.1rem; border-radius: 50%;
}

/* 7 ── CARDS ──────────────────────────────────────────────────────────── */
.card, .item-card, .category-card {
    background: var(--surface); color: var(--text);
    border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); backdrop-filter: none;
}
.card-header { background: var(--surface-2) !important; border-bottom: 1px solid var(--line); font-weight: 700; padding: .85rem 1rem; }
.card-body { padding: 1rem; }
.category-card:hover { transform: none; }
.hover-shadow { transition: box-shadow .15s ease, transform .15s ease; }
.hover-shadow:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }

.meta-cards, .summary-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
.meta-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow); }
.meta-card__label { color: var(--text-3); font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.meta-card__value { font-size: var(--fs-lg); font-weight: 700; word-break: break-word; }

/* KPI tiles (dashboard) */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.kpi {
    display: flex; flex-direction: column; justify-content: space-between; gap: .35rem; min-height: 112px;
    padding: 1rem; border-radius: var(--radius); background: var(--surface);
    border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text); text-decoration: none;
}
.kpi:hover { color: var(--text); box-shadow: var(--shadow-lg); }
.kpi__top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.kpi__label { color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; }
.kpi__icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; font-size: 1.15rem; background: #f1eecf; color: var(--brand-ink); }
.kpi__value { font-size: var(--fs-num); font-weight: 800; line-height: 1.05; letter-spacing: -.02em; }
.kpi__hint { color: var(--text-3); font-size: var(--fs-xs); }
.kpi--alert { border-color: #f0b8b2; background: var(--bad-bg); }
.kpi--alert .kpi__icon { background: var(--bad); color: #fff; }
.kpi--alert .kpi__value { color: var(--bad); }
.kpi--ok .kpi__icon { background: var(--ok-bg); color: var(--ok); }
.kpi--wide { grid-column: 1 / -1; }

/* quick actions */
.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.quick-actions .btn { min-height: 56px; font-size: var(--fs-base); }

/* 8 ── TABLES ─────────────────────────────────────────────────────────── */
.table {
    --bs-table-bg: transparent; --bs-table-color: var(--text);
    --bs-table-striped-bg: var(--surface-2);
    --bs-table-hover-bg: #fbf9e6;
    margin-bottom: 0; font-size: var(--fs-sm);
}
.table > thead > tr > th {
    background: var(--surface-2); color: var(--text-2); border-bottom: 2px solid var(--line-strong);
    font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    white-space: nowrap; padding: .75rem 1rem;
}
.table > tbody > tr > td { padding: .85rem 1rem; vertical-align: middle; border-color: var(--line); }
.table-light, .table-light > th, .table-light > td { --bs-table-bg: var(--surface-2); }
.table tbody tr:hover { background: var(--bs-table-hover-bg); }
.table-wrap, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.th-actions, .td-actions { width: 1%; white-space: nowrap; }
.table .btn { min-height: 40px; }

/* AUTO-STACK: below 768px every <table class="table"> becomes a list of cards.
   JS (ui.js) copies each <th> label to its cells as data-label.
   Opt out with class "table-keep" (e.g. very wide report grids → horizontal scroll). */
@media (max-width: 767.98px) {
    .table:not(.table-keep) thead { display: none; }
    .table:not(.table-keep),
    .table:not(.table-keep) tbody,
    .table:not(.table-keep) tr,
    .table:not(.table-keep) td { display: block; width: 100%; }
    .table:not(.table-keep) tbody { display: grid; gap: .75rem; padding: .75rem; }
    .table:not(.table-keep) tbody tr {
        background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
        box-shadow: var(--shadow); padding: .35rem 0; overflow: hidden;
    }
    .table:not(.table-keep) tbody tr:hover { background: var(--surface); }
    .table:not(.table-keep) td {
        display: flex; justify-content: space-between; align-items: center; gap: 1rem;
        padding: .6rem 1rem; border: 0; border-bottom: 1px solid var(--line); text-align: right;
        font-size: var(--fs-base); word-break: break-word;
    }
    .table:not(.table-keep) td:last-child { border-bottom: 0; }
    .table:not(.table-keep) td::before {
        content: attr(data-label); flex: 0 0 38%; max-width: 38%; text-align: left;
        color: var(--text-3); font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    }
    .table:not(.table-keep) td[data-label=""]::before,
    .table:not(.table-keep) td:not([data-label])::before { display: none; }
    .table:not(.table-keep) td.td-actions, .table:not(.table-keep) td:has(> .btn),
    .table:not(.table-keep) td:has(> .btn-row), .table:not(.table-keep) td:has(> form) {
        justify-content: stretch; width: 100%; white-space: normal;
    }
    .table:not(.table-keep) td[colspan] { display: block; text-align: center; }
    .table:not(.table-keep) td[colspan]::before { display: none; }
    .table:not(.table-keep) td .d-flex { width: 100%; }
    .table:not(.table-keep) td .d-flex > *, .table:not(.table-keep) td .d-flex form { flex: 1 1 0; }
    .table:not(.table-keep) td .btn { width: 100%; min-height: var(--tap); white-space: nowrap; padding-left: .5rem; padding-right: .5rem; }
    .card:has(> .table:not(.table-keep)), .card > .table-responsive, .card > .table-wrap {
        background: transparent; border: 0; box-shadow: none;
    }
    .table-responsive:has(> .table:not(.table-keep)), .table-wrap:has(> .table:not(.table-keep)) { overflow: visible; }
    tfoot { display: none; }
}

/* 9 ── BADGES / ALERTS ────────────────────────────────────────────────── */
.badge {
    font-size: var(--fs-xs); font-weight: 700; padding: .4em .7em; border-radius: 999px;
    background: #ece9d6; color: var(--text) !important; letter-spacing: 0;
}
.badge.bg-success, .badge-success, .bg-success { background: var(--ok-bg) !important; color: var(--ok) !important; }
.badge.bg-danger, .badge-danger { background: var(--bad-bg) !important; color: var(--bad) !important; }
.badge.bg-warning, .badge-warning { background: var(--warn-bg) !important; color: var(--warn) !important; }
.badge.bg-info, .badge-info { background: var(--info-bg) !important; color: var(--info) !important; }
.badge.bg-light { background: #ece9d6 !important; color: var(--text) !important; }
.badge-unit, .badge-category { background: #f1eecf; color: var(--brand-700) !important; }
.dim-tag {
    display: inline-block; padding: .2rem .6rem; margin: 0 .25rem .25rem 0; font-size: var(--fs-xs); font-weight: 600;
    border-radius: 999px; background: #ece9d6; color: var(--text);
}
.text-success { color: var(--ok) !important; }
.text-danger { color: var(--bad) !important; }
.text-warning { color: var(--warn) !important; }
.alert { border-radius: var(--radius-sm); border-width: 2px; font-size: var(--fs-base); font-weight: 500; padding: .85rem 1rem; }
.alert-success { background: var(--ok-bg); border-color: #8fd1ad; color: var(--ok); }
.alert-danger  { background: var(--bad-bg); border-color: #f0a8a0; color: var(--bad); }
.alert-warning { background: var(--warn-bg); border-color: #efc27a; color: var(--warn); }
.alert-info    { background: var(--info-bg); border-color: #a9c6ee; color: var(--info); }

/* 10 ── PAGINATION (see resources/views/vendor/pagination/ui.blade.php) ─ */
.pager { margin-top: 1.25rem; display: flex; flex-direction: column; align-items: center; gap: .6rem; }
.pager__info { color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; text-align: center; }
.pager__mobile { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .6rem; width: 100%; }
.pager__page { font-weight: 700; font-size: var(--fs-base); text-align: center; white-space: nowrap; }
.pager__btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-height: var(--tap); padding: .5rem 1rem; border-radius: var(--radius-sm);
    background: var(--brand-900); color: #fff; border: 2px solid var(--brand-900);
    font-weight: 700; text-decoration: none;
}
.pager__btn:hover { background: var(--brand-700); color: #fff; }
.pager__btn.is-disabled { background: #e7e4d4; border-color: #e7e4d4; color: #8b8672; pointer-events: none; }
.pager__numbers { display: none; }

/* 11 ── COMPONENTS ─────────────────────────────────────────────────────── */
.stock-badge { font-weight: 800; font-size: var(--fs-lg); }
.measure-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.list-card { padding: 1rem; margin-bottom: .75rem; }
.auth-center { min-height: 100vh; padding: 1.5rem 1rem; }
.modal-content { border-radius: var(--radius); border: 0; box-shadow: var(--shadow-lg); }
.modal-header, .modal-footer { border-color: var(--line); }
.dropdown-menu { border-radius: var(--radius-sm); border: 1px solid var(--line); box-shadow: var(--shadow-lg); padding: .35rem; }
.dropdown-item { min-height: 44px; display: flex; align-items: center; border-radius: 6px; font-size: var(--fs-base); }
.dimension-field { margin-bottom: 1rem; }

/* flash toast container */
.flash { margin-bottom: 1rem; }

/* 12 ── DESKTOP ≥ 768 / ≥ 992 ──────────────────────────────────────────── */
@media (min-width: 768px) {
    .app-content { padding: 1.5rem 1.5rem 2rem; }
    .page-title { font-size: var(--fs-2xl); }
    h1 { font-size: var(--fs-2xl); }
    .form-card { padding: 1.5rem; }
    .form-row { grid-template-columns: repeat(2, 1fr); }
    .form-actions { flex-direction: row; justify-content: flex-end; }
    .form-actions .btn { width: auto; min-width: 140px; }
    .checkbox-grid { grid-template-columns: repeat(3, 1fr); }
    .meta-cards, .summary-cards { grid-template-columns: repeat(4, 1fr); }
    .kpi-grid { grid-template-columns: repeat(3, 1fr); gap: 1rem; }
    .quick-actions { grid-template-columns: repeat(4, 1fr); }
    .card:has(> .table), .card:has(> .table-responsive), .card:has(> .table-wrap) { overflow: hidden; }

    .pager { flex-direction: row; justify-content: space-between; }
    .pager__mobile { display: none; }
    .pager__numbers { display: flex; gap: .35rem; flex-wrap: wrap; }
    .pager__num {
        min-width: var(--tap); height: var(--tap); padding: 0 .5rem; display: inline-flex; align-items: center; justify-content: center;
        border: 2px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface);
        color: var(--text); font-weight: 700; text-decoration: none;
    }
    .pager__num:hover { border-color: var(--brand-900); color: var(--brand-900); }
    .pager__num.is-current { background: var(--brand-900); border-color: var(--brand-900); color: #fff; }
    .pager__num.is-gap { border-color: transparent; background: transparent; }
}

@media (min-width: 992px) {
    .tabbar { display: none; }
    /* desktop: sidebar starts open; the toggle slides it away */
    .app-sidebar { margin-left: 0; padding-bottom: 1rem; }
    .app-sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
    .app-body { flex: 1 1 0; }
    /* the brand lives in the sidebar, so only show it in the top bar while the sidebar is away */
    .app:not(.sidebar-closed) .app-topbar__brand { display: none; }
    .app-topbar__user { display: inline; }
    .app-content { padding: 1.75rem 2rem 2rem; }
    .app-footer { display: block; text-align: center; color: var(--text-3); font-size: var(--fs-sm); padding: 1rem; }
    .kpi-grid { grid-template-columns: repeat(4, 1fr); }
    .btn-row--full > .btn, .btn-row--full > form > .btn { flex: 0 0 auto; }
}

@media (min-width: 1200px) {
    .pager__info { font-size: var(--fs-base); }
}

/* 13 ── PRINT ──────────────────────────────────────────────────────────── */
@media print {
    .app-topbar, .app-sidebar, .tabbar, .app-footer, .btn, .pager { display: none !important; }
    .app-content { padding: 0; }
    body { background: #fff; }
}

/* 14 ── LEGACY COMPAT ──────────────────────────────────────────────────────
   Older views wrap content in container-fluid with their own padding and use
   a few Bootstrap variants we have not restyled. Normalise them here so those
   pages match the new shell without being edited one by one.               */
.app-content .container-fluid { padding-left: 0 !important; padding-right: 0 !important; padding-top: 0 !important; max-width: none; }
.app-content .container { max-width: none; padding-left: 0; padding-right: 0; }
.app-content .py-4 { padding-top: 0 !important; }
.btn-outline-info { background: var(--surface); border: 2px solid var(--info); color: var(--info); }
.btn-outline-info:hover { background: var(--info); color: #fff; }
.btn-info { background: var(--info); border: 2px solid var(--info); color: #fff; }
.btn-warning { background: #f6c445; border: 2px solid #f6c445; color: #1d1b12; }
.btn-warning:hover { background: #e5b030; border-color: #e5b030; color: #1d1b12; }
.btn-light { background: var(--surface); border: 2px solid var(--line-strong); color: var(--text); }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: var(--bs-table-hover-bg); }
.card.border-0 { border: 1px solid var(--line) !important; }
.card-header.bg-white { background: var(--surface-2) !important; }
.bg-light { background: var(--surface-2) !important; }
.text-dark { color: var(--text) !important; }
.list-group-item { border-color: var(--line); padding: .85rem 1rem; }
.nav-tabs .nav-link, .nav-pills .nav-link { min-height: var(--tap); display: inline-flex; align-items: center; font-weight: 600; color: var(--text-2); }
.nav-tabs .nav-link.active { color: var(--brand-900); border-bottom: 3px solid var(--brand-accent); }
.nav-pills .nav-link.active { background: var(--brand-900); color: #fff; }
@media (max-width: 575.98px) {
    .row > [class*="col-sm-"], .row > [class*="col-md-"] { margin-bottom: .25rem; }
    .d-flex.gap-2 > .btn:only-child { flex: 1; }
}

/* Filter pills (All / In / Out …) – scroll sideways rather than wrap on tiny screens */
.filter-pills { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.filter-pills a {
    flex: 0 0 auto; display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; padding: 0 1rem;
    border: 2px solid var(--line-strong); border-radius: 999px; background: var(--surface);
    color: var(--text); font-weight: 600; text-decoration: none; white-space: nowrap;
}
.filter-pills a.is-active { background: var(--brand-900); border-color: var(--brand-900); color: #fff; }
.filter-pills a.is-active.is-in { background: var(--ok); border-color: var(--ok); }
.filter-pills a.is-active.is-out { background: var(--bad); border-color: var(--bad); }

/* Measurement rows in variant / stock forms */
.measure-row {
    display: grid; grid-template-columns: 1fr; gap: .6rem;
    padding: .85rem; margin-bottom: .75rem;
    background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.measure-row .form-label { margin-bottom: .2rem; font-size: var(--fs-xs); color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
@media (min-width: 576px) {
    .measure-row { grid-template-columns: 1fr 1fr auto; align-items: end; }
    .measure-row__remove { width: var(--tap); padding: 0; }
}

/* Feather icons (older pages) */
.feather { width: 18px; height: 18px; stroke-width: 2; vertical-align: -3px; }
.feather-lg { width: 40px; height: 40px; }
.btn .feather { width: 18px; height: 18px; vertical-align: middle; }

/* Button groups inside stacked table cards: spread evenly, full width */
@media (max-width: 767.98px) {
    .table:not(.table-keep) td:has(> .btn-group),
    .table:not(.table-keep) td:has(> .d-flex) { display: block; }
    .table:not(.table-keep) td:has(> .btn-group)::before,
    .table:not(.table-keep) td:has(> .d-flex)::before { display: none; }
    .table:not(.table-keep) .btn-group { display: flex; width: 100%; gap: .5rem; }
    .table:not(.table-keep) .btn-group > .btn, .table:not(.table-keep) .btn-group > form { flex: 1 1 0; border-radius: var(--radius-sm) !important; }
    .table:not(.table-keep) .btn-group > form .btn { width: 100%; }
}

/* KPI numbers never break mid-figure */
.kpi__value { overflow-wrap: anywhere; }
@media (min-width: 768px) { .kpi--wide { grid-column: auto; } .kpi-grid > .kpi--wide:first-child { grid-column: span 2; } }

/* Desktop: row action buttons stay on one line */
@media (min-width: 768px) {
    .td-actions .btn-row { flex-wrap: nowrap; }
    .td-actions .btn { white-space: nowrap; }
}

/* Wide tables scroll inside their card instead of being clipped; no double divider above form buttons */
@media (min-width: 768px) {
    .card:has(> .table), .card:has(> .table-responsive), .card:has(> .table-wrap) { overflow-x: auto; }
}
.form-section:has(+ .form-actions) { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }

/* ── Logo: always on a white tile (the PNG is transparent) ───────────────── */
.brand-logo, .app-topbar__brand .brand-logo {
    width: 40px; height: 40px; object-fit: contain; flex: 0 0 auto;
    background: #0a0a0a; padding: 4px; border-radius: 10px;
    box-shadow: 0 0 0 1px rgba(255,255,255,.22);   /* thin ring so the black tile stands out on the dark bar */
}
.brand-logo--lg, .auth-center .brand-logo--lg { width: 88px; height: 88px; padding: 8px; border-radius: 20px; }

/* ── Top bar: toggle on the left, brand next, user/logout on the right ───── */
.app-topbar { gap: .5rem; padding-left: .5rem; }
.app-topbar__user { margin-left: auto; }
.app-topbar__brand { margin-right: auto; }
.app-topbar__user + form { margin-left: 0; }


/* ── Accessibility helpers ───────────────────────────────────────────────── */
.skip-link {
    position: absolute; left: .5rem; top: -100px; z-index: 2000;
    background: var(--brand-accent); color: #1d1b12; font-weight: 700;
    padding: .75rem 1rem; border-radius: var(--radius-sm); text-decoration: none;
}
.skip-link:focus { top: .5rem; }
.tabbar a:focus-visible, .tabbar button:focus-visible { outline-offset: -4px; }

.goto-grid { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media (min-width: 576px) { .goto-grid { grid-template-columns: repeat(2, 1fr); } }
.goto {
    display: flex; align-items: center; gap: 1rem; min-height: 72px; padding: .85rem 1rem;
    background: var(--surface); border: 2px solid var(--line-strong); border-radius: var(--radius);
    color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.goto:hover { border-color: var(--brand-900); color: var(--text); }
.goto__icon { width: 44px; height: 44px; display: grid; place-items: center; font-size: 1.4rem; border-radius: 12px; background: var(--brand-900); color: var(--brand-accent); flex: 0 0 auto; }
.goto__title { display: block; font-weight: 700; font-size: var(--fs-base); }
.goto__desc { display: block; color: var(--text-2); font-size: var(--fs-sm); }
.goto > .bi-chevron-right { margin-left: auto; color: var(--text-3); }
@media (min-width: 768px) { .kpi-grid > .kpi--span2-md { grid-column: span 2; } }

/* Low-stock rule picker */
.rule-grid { display: grid; grid-template-columns: 1fr; gap: .6rem; }
@media (min-width: 768px) { .rule-grid { grid-template-columns: repeat(3, 1fr); } }
.rule-card {
    position: relative; display: flex; align-items: center; gap: .85rem; margin: 0; cursor: pointer;
    min-height: 72px; padding: .75rem 1rem; background: var(--surface);
    border: 2px solid var(--line-strong); border-radius: var(--radius);
}
.rule-card input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.rule-card__icon { width: 42px; height: 42px; display: grid; place-items: center; font-size: 1.3rem; border-radius: 12px; background: #f1eecf; color: var(--brand-ink); flex: 0 0 auto; }
.rule-card__title { display: block; font-weight: 700; }
.rule-card__desc { display: block; color: var(--text-2); font-size: var(--fs-sm); font-weight: 400; }
.rule-card:has(input:checked) { border-color: var(--brand-900); background: #fbf7d8; box-shadow: 0 0 0 3px rgba(224,201,44,.45); }
.rule-card:has(input:checked) .rule-card__icon { background: var(--brand-900); color: var(--brand-accent); }
.rule-card:has(input:focus-visible) { outline: 3px solid var(--brand-accent); outline-offset: 2px; }

/* "Get alerts on this device" card */
.push-card {
    display: flex; gap: 1rem; align-items: flex-start; margin-bottom: 1rem; padding: 1rem;
    background: var(--surface); border: 2px solid var(--brand-accent); border-radius: var(--radius); box-shadow: var(--shadow);
}
.push-card.d-none { display: none !important; }
.push-card__icon { width: 44px; height: 44px; display: grid; place-items: center; flex: 0 0 auto; font-size: 1.4rem; border-radius: 12px; background: var(--brand-900); color: var(--brand-accent); }
.push-card__body { min-width: 0; flex: 1; }
.push-card__title { font-size: var(--fs-base); font-weight: 700; margin: 0 0 .25rem; }
.push-card__text { color: var(--text-2); margin-bottom: .75rem; }
.push-card__feedback { margin: .5rem 0 0; color: var(--text-2); font-size: var(--fs-sm); min-height: 1.2em; }
