/* ==========================================================================
   BillBase Design System  ·  v2.0
   --------------------------------------------------------------------------
   The single authoritative stylesheet for the BillBase application.
   Replaces the previous stack of six mutually-overriding files
   (modern-ui / components / responsive-modern / bugfixes / app-theme / polish).

   Organisation
     01  Tokens
     02  Base & reset
     03  Typography
     04  Application shell
     05  Page header
     06  Surfaces — card, panel, section
     07  Buttons
     08  Forms
     09  Tables & data grid
     10  Status, badges & pills
     11  Metrics
     12  Empty / loading / error states
     13  Alerts & banners
     14  Toasts
     15  Modal, dialog & drawer
     16  Menu, dropdown & popover
     17  Tooltip
     18  Tabs & segmented control
     19  Pagination
     20  Avatar
     21  Command palette
     22  Money & numerics
     23  Timeline & activity
     24  Document workspace
     25  Utilities
     26  Responsive
     27  Print
     28  Accessibility & motion

   Conventions
     · Every colour, space, radius and shadow comes from a token.
     · Borders carry structure; shadows are used sparingly for elevation only.
     · Money is always tabular-figures and right-aligned.
     · Base element rules are written as `body h1` etc. so they defeat the
       Tailwind CDN preflight that gets injected after this file.
   ========================================================================== */


/* ==========================================================================
   01 · TOKENS
   ========================================================================== */

:root {
    /* ---- Neutral ramp (cool slate) ---- */
    --bb-n-0:    #ffffff;
    --bb-n-25:   #fcfcfd;
    --bb-n-50:   #f7f8fa;
    --bb-n-75:   #f2f4f7;
    --bb-n-100:  #eceff3;
    --bb-n-150:  #e7e9ee;
    --bb-n-200:  #dfe3e9;
    --bb-n-300:  #c8cdd7;
    --bb-n-400:  #9aa2b1;
    --bb-n-500:  #6f7787;
    --bb-n-600:  #545b6b;
    --bb-n-700:  #3d4351;
    --bb-n-800:  #272c38;
    --bb-n-900:  #171a21;
    --bb-n-950:  #0d0f14;

    /* ---- Brand · indigo (carried forward from the BillBase mark) ---- */
    --bb-brand-50:   #eef1ff;
    --bb-brand-100:  #e0e5ff;
    --bb-brand-200:  #c7cfff;
    --bb-brand-300:  #a5b0fc;
    --bb-brand-400:  #8189f7;
    --bb-brand-500:  #6366f1;
    --bb-brand-600:  #4f46e5;
    --bb-brand-700:  #4338ca;
    --bb-brand-800:  #3730a3;
    --bb-brand-900:  #292573;

    /* ---- Semantic ---- */
    --bb-success-50:  #ecfdf3;
    --bb-success-100: #d1fadf;
    --bb-success-200: #a6f4c5;
    --bb-success-500: #12b76a;
    --bb-success-600: #059669;
    --bb-success-700: #047857;

    --bb-warn-50:     #fffaeb;
    --bb-warn-100:    #fef0c7;
    --bb-warn-200:    #fedf89;
    --bb-warn-500:    #f79009;
    --bb-warn-600:    #dc6803;
    --bb-warn-700:    #b45309;

    --bb-danger-50:   #fef3f2;
    --bb-danger-100:  #fee4e2;
    --bb-danger-200:  #fecdca;
    --bb-danger-500:  #f04438;
    --bb-danger-600:  #dc2626;
    --bb-danger-700:  #b42318;

    --bb-info-50:     #ecfdff;
    --bb-info-100:    #cff9fe;
    --bb-info-200:    #a5f0fc;
    --bb-info-500:    #06aed4;
    --bb-info-600:    #0891b2;
    --bb-info-700:    #0e7090;

    --bb-violet-50:   #f5f3ff;
    --bb-violet-100:  #ede9fe;
    --bb-violet-600:  #7c3aed;
    --bb-violet-700:  #6d28d9;

    /* ---- Surfaces ---- */
    --bb-canvas:        var(--bb-n-50);
    --bb-surface:       var(--bb-n-0);
    --bb-surface-sunk:  var(--bb-n-50);
    --bb-surface-raised:var(--bb-n-0);
    --bb-surface-hover: var(--bb-n-75);
    --bb-surface-active:var(--bb-n-100);
    --bb-surface-head:  var(--bb-n-50);
    --bb-surface-inset: var(--bb-n-25);

    /* ---- Borders ---- */
    --bb-border:        var(--bb-n-150);
    --bb-border-soft:   var(--bb-n-100);
    --bb-border-strong: var(--bb-n-200);
    --bb-border-focus:  var(--bb-brand-500);

    /* ---- Text ---- */
    --bb-text:          var(--bb-n-900);
    --bb-text-secondary:var(--bb-n-600);
    /* WCAG AA (4.5:1) on every app surface (#fff, #f7f8fa, #f2f4f7), measured by the
    --bb-text-subtle:   #676f7e;
    --bb-text-invert:   var(--bb-n-0);
    --bb-text-link:     var(--bb-brand-700);

    /* ---- Navigation shell (deep, calm) ---- */
    --bb-nav-bg:        #14161d;
    --bb-nav-bg-soft:   #1b1e27;
    --bb-nav-border:    #262a35;
    --bb-nav-text:      #a8aebd;
    --bb-nav-text-dim:  #7b8292;   /* was #6f7789: 4.0:1 on the rail; now 4.7:1 */
    --bb-nav-text-on:   #ffffff;
    --bb-nav-active-bg: rgba(99, 102, 241, .16);
    --bb-nav-active-bar:var(--bb-brand-500);

    /* ---- Type ---- */
    --bb-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
    --bb-font-mono: "SFMono-Regular", ui-monospace, "JetBrains Mono", Menlo,
                    Consolas, "Liberation Mono", monospace;

    --bb-fs-2xs:  10.5px;
    --bb-fs-xs:   11.5px;
    --bb-fs-sm:   12.5px;
    --bb-fs-base: 13.5px;
    --bb-fs-md:   14px;
    --bb-fs-lg:   16px;
    --bb-fs-xl:   18px;
    --bb-fs-2xl:  21px;
    --bb-fs-3xl:  26px;
    --bb-fs-4xl:  32px;

    --bb-lh-tight:  1.25;
    --bb-lh-snug:   1.4;
    --bb-lh-normal: 1.55;

    --bb-fw-normal:   400;
    --bb-fw-medium:   500;
    --bb-fw-semibold: 600;
    --bb-fw-bold:     700;

    --bb-tracking-tight: -0.011em;
    --bb-tracking-wide:  0.04em;
    --bb-tracking-caps:  0.06em;

    /* ---- Space (4px base) ---- */
    --bb-s-0:  0;
    --bb-s-1:  2px;
    --bb-s-2:  4px;
    --bb-s-3:  6px;
    --bb-s-4:  8px;
    --bb-s-5:  10px;
    --bb-s-6:  12px;
    --bb-s-7:  14px;
    --bb-s-8:  16px;
    --bb-s-9:  20px;
    --bb-s-10: 24px;
    --bb-s-11: 28px;
    --bb-s-12: 32px;
    --bb-s-14: 40px;
    --bb-s-16: 48px;
    --bb-s-20: 64px;

    /* ---- Radius ---- */
    --bb-r-xs:   3px;
    --bb-r-sm:   5px;
    --bb-r:      7px;
    --bb-r-md:   9px;
    --bb-r-lg:   12px;
    --bb-r-xl:   16px;
    --bb-r-2xl:  22px;
    --bb-r-full: 9999px;

    /* ---- Elevation ---- */
    --bb-shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
    --bb-shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
    --bb-shadow:    0 2px 4px -1px rgba(16, 24, 40, .06), 0 4px 10px -2px rgba(16, 24, 40, .06);
    --bb-shadow-md: 0 4px 8px -2px rgba(16, 24, 40, .08), 0 12px 20px -6px rgba(16, 24, 40, .08);
    --bb-shadow-lg: 0 8px 16px -4px rgba(16, 24, 40, .08), 0 24px 40px -12px rgba(16, 24, 40, .12);
    --bb-shadow-xl: 0 24px 48px -12px rgba(16, 24, 40, .18);
    --bb-ring:      0 0 0 3px rgba(99, 102, 241, .22);
    --bb-ring-danger: 0 0 0 3px rgba(240, 68, 56, .18);

    /* ---- Motion ---- */
    --bb-ease:      cubic-bezier(.2, .6, .3, 1);
    --bb-ease-out:  cubic-bezier(.16, 1, .3, 1);
    --bb-t-fast:    120ms;
    --bb-t:         160ms;
    --bb-t-slow:    240ms;

    /* ---- Shell metrics ---- */
    --bb-sidebar-w:          252px;
    --bb-sidebar-w-collapsed: 64px;
    --bb-topbar-h:           56px;
    --bb-page-max:           1560px;
    --bb-page-pad:           var(--bb-s-10);

    /* ---- Z-index scale ---- */
    --bb-z-sticky:  20;
    --bb-z-sidebar: 60;
    --bb-z-topbar:  50;
    --bb-z-dropdown:400;
    --bb-z-overlay: 800;
    --bb-z-modal:   900;
    --bb-z-palette: 950;
    --bb-z-toast:   1000;
    --bb-z-tooltip: 1100;

    /* ---- Legacy aliases (older views reference these) ---- */
    --primary: var(--bb-brand-600);
    --primary-dark: var(--bb-brand-700);
    --primary-light: var(--bb-brand-500);
    --color-primary: var(--bb-brand-600);
    --color-success: var(--bb-success-600);
    --color-warning: var(--bb-warn-600);
    --color-error:   var(--bb-danger-600);
    --color-danger:  var(--bb-danger-600);
    --color-info:    var(--bb-info-600);
    --gray-50: var(--bb-n-50);   --gray-100: var(--bb-n-100);
    --gray-200: var(--bb-n-200); --gray-300: var(--bb-n-300);
    --gray-400: var(--bb-n-400); --gray-500: var(--bb-n-500);
    --gray-600: var(--bb-n-600); --gray-700: var(--bb-n-700);
    --gray-800: var(--bb-n-800); --gray-900: var(--bb-n-900);
    --border-color: var(--bb-border);
    --text-primary: var(--bb-text);
    --text-secondary: var(--bb-text-secondary);
    --radius: var(--bb-r);
    --radius-lg: var(--bb-r-lg);
    --shadow-sm: var(--bb-shadow-sm);
    --shadow-md: var(--bb-shadow);
    --shadow-lg: var(--bb-shadow-lg);
}


/* ==========================================================================
   02 · BASE & RESET
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--bb-font);
    font-size: var(--bb-fs-base);
    line-height: var(--bb-lh-normal);
    color: var(--bb-text);
    background: var(--bb-canvas);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
    text-rendering: optimizeLegibility;
}

body img,
body svg,
body video,
body canvas { max-width: 100%; }

body hr {
    border: 0;
    border-top: 1px solid var(--bb-border);
    margin: var(--bb-s-9) 0;
}

body ::selection { background: var(--bb-brand-100); color: var(--bb-brand-900); }

/* Scrollbars — thin and unobtrusive */
* { scrollbar-width: thin; scrollbar-color: var(--bb-n-300) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: var(--bb-n-300);
    border-radius: var(--bb-r-full);
    border: 3px solid transparent;
    background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--bb-n-400); background-clip: content-box; }


/* ==========================================================================
   03 · TYPOGRAPHY
   ========================================================================== */

body h1, body h2, body h3, body h4, body h5, body h6 {
    margin: 0;
    font-weight: var(--bb-fw-semibold);
    line-height: var(--bb-lh-tight);
    letter-spacing: var(--bb-tracking-tight);
    color: var(--bb-text);
}
body h1 { font-size: var(--bb-fs-2xl); }
body h2 { font-size: var(--bb-fs-xl); }
body h3 { font-size: var(--bb-fs-lg); }
body h4 { font-size: var(--bb-fs-md); }
body h5 { font-size: var(--bb-fs-base); }
body h6 { font-size: var(--bb-fs-sm); }

body p { margin: 0 0 var(--bb-s-6); }
body p:last-child { margin-bottom: 0; }

body a {
    color: var(--bb-text-link);
    text-decoration: none;
    transition: color var(--bb-t-fast) var(--bb-ease);
}
body a:hover { color: var(--bb-brand-800); }

body small { font-size: var(--bb-fs-sm); }

body code, body kbd, body pre, body samp {
    font-family: var(--bb-font-mono);
    font-size: 0.92em;
}
body code {
    background: var(--bb-n-75);
    border: 1px solid var(--bb-border-soft);
    border-radius: var(--bb-r-xs);
    padding: 1px 5px;
    color: var(--bb-n-700);
}

kbd, .kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    font-family: var(--bb-font);
    font-size: var(--bb-fs-2xs);
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-n-600);
    background: var(--bb-n-0);
    border: 1px solid var(--bb-border-strong);
    border-bottom-width: 2px;
    border-radius: var(--bb-r-xs);
    line-height: 1;
}

.eyebrow,
.section-eyebrow {
    font-size: var(--bb-fs-2xs);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-caps);
    text-transform: uppercase;
    color: var(--bb-text-muted);
}


/* ==========================================================================
   04 · APPLICATION SHELL
   ========================================================================== */

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--bb-sidebar-w);
    display: flex;
    flex-direction: column;
    background: var(--bb-nav-bg);
    border-right: 1px solid var(--bb-nav-border);
    z-index: var(--bb-z-sidebar);
    transition: width var(--bb-t) var(--bb-ease), transform var(--bb-t-slow) var(--bb-ease);
}

/* Brand lockup.
   The rail is dark, so it carries the REVERSED lockups from images/brand/
   (built by scripts/build_brand_assets.php) — never images/logo.png, which is
   dark navy ink and disappears against this background. The open rail shows
   the wordmark at its true 4.9:1 proportion; the collapsed rail swaps to the
   square "B" mark, because a wordmark cannot survive a 26px column. */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--bb-s-5);
    height: var(--bb-topbar-h);
    flex: 0 0 var(--bb-topbar-h);
    padding: 0 var(--bb-s-7);
    border-bottom: 1px solid var(--bb-nav-border);
    text-decoration: none;
    min-width: 0;
    border-radius: 0;
    transition: background var(--bb-t) var(--bb-ease);
}
.sidebar-brand:hover  { background: rgba(255,255,255,.05); }
.sidebar-brand:focus-visible {
    outline: 2px solid var(--bb-brand-500);
    outline-offset: -2px;
}
.sidebar-brand-wordmark {
    height: 21px;
    width: auto;
    max-width: 100%;
    display: block;
    flex: 0 1 auto;
    min-width: 0;
    object-fit: contain;
    object-position: left center;
}
.sidebar-brand-mark {
    display: none;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    object-fit: contain;
}

.plan-badge {
    font-size: 9px;
    font-weight: var(--bb-fw-bold);
    letter-spacing: var(--bb-tracking-caps);
    padding: 2.5px 6px;
    border-radius: var(--bb-r-xs);
    line-height: 1;
    text-transform: uppercase;
}
.plan-badge.pro        { background: rgba(99,102,241,.2);  color: #b3b8ff; }
.plan-badge.enterprise { background: rgba(124,58,237,.22); color: #d3c4ff; }
.plan-badge.basic      { background: rgba(255,255,255,.09);color: var(--bb-nav-text-dim); }

/* Nav scroll region */
.sidebar-nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--bb-s-6) var(--bb-s-5) var(--bb-s-8);
}
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); background-clip: content-box; }
.sidebar-nav:hover::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); background-clip: content-box; }

.nav-section-title {
    padding: var(--bb-s-8) var(--bb-s-4) var(--bb-s-3);
    font-size: var(--bb-fs-2xs);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-caps);
    text-transform: uppercase;
    color: var(--bb-nav-text-dim);
    white-space: nowrap;
}
.nav-section-title:first-child { padding-top: var(--bb-s-2); }

.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--bb-s-6);
    padding: 7px var(--bb-s-4);
    margin-bottom: 1px;
    border-radius: var(--bb-r-sm);
    font-size: var(--bb-fs-base);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-nav-text);
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--bb-t-fast) var(--bb-ease),
                color var(--bb-t-fast) var(--bb-ease);
}
.nav-link i,
.nav-link .nav-ico {
    width: 17px;
    flex: 0 0 17px;
    text-align: center;
    font-size: 13px;
    color: var(--bb-nav-text-dim);
    transition: color var(--bb-t-fast) var(--bb-ease);
}
.nav-link span { overflow: hidden; text-overflow: ellipsis; }
.nav-link:hover {
    background: rgba(255,255,255,.05);
    color: var(--bb-nav-text-on);
}
.nav-link:hover i { color: var(--bb-nav-text); }
.nav-link.active {
    background: var(--bb-nav-active-bg);
    color: var(--bb-nav-text-on);
    font-weight: var(--bb-fw-semibold);
}
.nav-link.active i { color: var(--bb-brand-400); }
.nav-link.active::before {
    content: "";
    position: absolute;
    left: -5px; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 16px;
    border-radius: 0 2px 2px 0;
    background: var(--bb-nav-active-bar);
}
.nav-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bb-nav-bg), 0 0 0 4px var(--bb-brand-500);
}
.nav-link .nav-count {
    margin-left: auto;
    font-size: var(--bb-fs-2xs);
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-nav-text-dim);
    background: rgba(255,255,255,.07);
    padding: 1px 6px;
    border-radius: var(--bb-r-full);
}

/* Sidebar footer / user */
.sidebar-footer {
    flex: 0 0 auto;
    padding: var(--bb-s-5);
    border-top: 1px solid var(--bb-nav-border);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--bb-s-4);
    padding: var(--bb-s-4);
    border-radius: var(--bb-r-md);
    transition: background var(--bb-t-fast) var(--bb-ease);
}
.sidebar-user:hover { background: rgba(255,255,255,.05); }
.sidebar-user-link { min-width: 0; }
.sidebar-user-avatar,
.sidebar-user-avatar-img {
    width: 30px; height: 30px;
    flex: 0 0 30px;
    border-radius: var(--bb-r-md);
    display: flex; align-items: center; justify-content: center;
    font-size: var(--bb-fs-sm);
    font-weight: var(--bb-fw-semibold);
    color: #fff;
    background: linear-gradient(135deg, var(--bb-brand-500), var(--bb-brand-700));
    object-fit: cover;
}
.sidebar-user-info { min-width: 0; }
.sidebar-user-name {
    font-size: var(--bb-fs-base);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-nav-text-on);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: var(--bb-fs-xs);
    color: var(--bb-nav-text-dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-logout {
    flex: 0 0 auto;
    width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--bb-r-sm);
    color: var(--bb-nav-text-dim);
    font-size: 13px;
    transition: background var(--bb-t-fast) var(--bb-ease), color var(--bb-t-fast) var(--bb-ease);
}
.sidebar-logout:hover { background: rgba(240,68,56,.16); color: #ff8b81; }

/* Collapsed rail */
.sidebar.is-collapsed { width: var(--bb-sidebar-w-collapsed); }
.sidebar.is-collapsed .sidebar-brand-wordmark,
.sidebar.is-collapsed .plan-badge,
.sidebar.is-collapsed .nav-link span,
.sidebar.is-collapsed .nav-link .nav-count,
.sidebar.is-collapsed .sidebar-user-info,
.sidebar.is-collapsed .sidebar-logout,
.sidebar.is-collapsed .nav-section-title { display: none; }
.sidebar.is-collapsed .sidebar-brand { justify-content: center; padding: 0; }
.sidebar.is-collapsed .sidebar-brand-mark { display: block; }
.sidebar.is-collapsed .sidebar-nav { padding-left: var(--bb-s-4); padding-right: var(--bb-s-4); }
.sidebar.is-collapsed .nav-link { justify-content: center; padding: 9px 0; }
.sidebar.is-collapsed .nav-link i { font-size: 15px; }
.sidebar.is-collapsed .sidebar-user { justify-content: center; padding: var(--bb-s-2); }
.sidebar.is-collapsed + .main-content,
body.sidebar-collapsed .main-content { margin-left: var(--bb-sidebar-w-collapsed); }
/* Rail tooltips */
.sidebar.is-collapsed .nav-link::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) scale(.96);
    padding: 5px 9px;
    background: var(--bb-n-900);
    color: #fff;
    font-size: var(--bb-fs-sm);
    font-weight: var(--bb-fw-medium);
    border-radius: var(--bb-r-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: var(--bb-shadow-md);
    transition: opacity var(--bb-t-fast) var(--bb-ease), transform var(--bb-t-fast) var(--bb-ease);
    z-index: var(--bb-z-tooltip);
}
.sidebar.is-collapsed .nav-link:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }

.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--bb-s-4);
    width: 100%;
    padding: 7px;
    margin-top: var(--bb-s-2);
    background: transparent;
    border: 0;
    border-radius: var(--bb-r-sm);
    color: var(--bb-nav-text-dim);
    font-family: inherit;
    font-size: var(--bb-fs-xs);
    cursor: pointer;
    transition: background var(--bb-t-fast) var(--bb-ease), color var(--bb-t-fast) var(--bb-ease);
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,.05); color: var(--bb-nav-text); }

/* Mobile overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 15, 20, .5);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    z-index: calc(var(--bb-z-sidebar) - 1);
    transition: opacity var(--bb-t) var(--bb-ease), visibility var(--bb-t) var(--bb-ease);
}
.sidebar-overlay.open { opacity: 1; visibility: visible; }

/* ---- Main column ---- */
.main-content {
    margin-left: var(--bb-sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bb-canvas);
    transition: margin-left var(--bb-t) var(--bb-ease);
    /* A flex/grid child defaults to min-width:auto, which lets an overlong
       string (a 15-char GSTIN, a long customer name, a wide table) push the
       whole shell wider than the viewport and produce a horizontal page
       scrollbar. Pinning it to 0 makes the content area shrink instead, so
       overflow is handled locally — inside .table-wrapper, or by wrapping. */
    min-width: 0;
    max-width: 100%;

    /* A hidden dropdown must not widen the page.
       Menus are absolutely positioned and closed with visibility:hidden (not
       display:none, so they can animate open), so they still take part in
       layout — one anchored near the right edge extended the document a few
       pixels and gave three detail pages a horizontal scrollbar at 1440px.
       The width cap further down fixed the phone case but not the position.

       `clip` rather than `hidden`: clip does not create a scroll container,
       so `position: sticky` inside still works. Menus are right-anchored and
       open leftward, so nothing the user needs is on the clipped side. */
    overflow-x: clip;
}

/* ---- Topbar ---- */
.header {
    position: sticky;
    top: 0;
    z-index: var(--bb-z-topbar);

    /* The layout carries viewport-fit=cover so that env(safe-area-inset-*)
       reports real values (without it iOS returns 0 and every inset rule in
       this file is dead). The cost is that the page now starts at the
       PHYSICAL top of the screen, so this bar has to grow by the status-bar
       / notch inset or its buttons sit underneath the clock.

       In an ordinary browser tab the inset is 0 and this is exactly the old
       56px bar — the extra height only appears in an installed PWA and in the
       native shells. */
    height: calc(var(--bb-topbar-h) + env(safe-area-inset-top, 0px));
    flex: 0 0 calc(var(--bb-topbar-h) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: rgba(255,255,255,.86);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--bb-border);
}
.header-content {
    height: 100%;
    max-width: var(--bb-page-max);
    margin: 0 auto;
    /* Landscape on a notched phone puts the cutout down one side, so the
       horizontal padding takes whichever is larger: the design padding, or
       whatever the hardware needs. max() rather than addition, so the normal
       portrait case is unchanged. */
    padding: 0 max(var(--bb-page-pad), env(safe-area-inset-right, 0px))
             0 max(var(--bb-page-pad), env(safe-area-inset-left, 0px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--bb-s-8);
}
.header-left  { display: flex; align-items: center; gap: var(--bb-s-6); min-width: 0; }
.header-right { display: flex; align-items: center; gap: var(--bb-s-4); flex-shrink: 0; }

.header-title {
    font-size: var(--bb-fs-md);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-tight);
    color: var(--bb-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin: 0;
}

.mobile-toggle {
    display: none;
    width: 32px; height: 32px;
    align-items: center; justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--bb-r-sm);
    color: var(--bb-text-secondary);
    font-size: 15px;
    cursor: pointer;
    transition: background var(--bb-t-fast) var(--bb-ease);
}
.mobile-toggle:hover { background: var(--bb-surface-hover); }

.header-btn {
    position: relative;
    width: 32px; height: 32px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--bb-r-sm);
    color: var(--bb-text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: background var(--bb-t-fast) var(--bb-ease), color var(--bb-t-fast) var(--bb-ease);
}
.header-btn:hover { background: var(--bb-surface-hover); color: var(--bb-text); }
.header-btn .badge {
    position: absolute;
    top: 3px; right: 3px;
    min-width: 15px; height: 15px;
    padding: 0 3px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bb-danger-600);
    color: #fff;
    font-size: 9px;
    font-weight: var(--bb-fw-bold);
    border-radius: var(--bb-r-full);
    border: 1.5px solid var(--bb-surface);
    line-height: 1;
}

/* Topbar search trigger — opens the command palette */
.header-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--bb-s-5);
    width: 260px;
    height: 32px;
    padding: 0 var(--bb-s-5);
    background: var(--bb-n-75);
    border: 1px solid transparent;
    border-radius: var(--bb-r-md);
    color: var(--bb-text-muted);
    font-size: var(--bb-fs-base);
    cursor: pointer;
    transition: background var(--bb-t-fast) var(--bb-ease),
                border-color var(--bb-t-fast) var(--bb-ease);
}
.header-search:hover { background: var(--bb-n-100); }
.header-search:focus-within {
    background: var(--bb-surface);
    border-color: var(--bb-border-focus);
    box-shadow: var(--bb-ring);
}
.header-search > i { font-size: 12px; color: var(--bb-text-subtle); flex-shrink: 0; }
.header-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    font: inherit;
    color: var(--bb-text);
    outline: none;
    padding: 0;
}
.header-search input::placeholder { color: var(--bb-text-subtle); }
.header-search .kbd { margin-left: auto; flex-shrink: 0; }

/* ---- Page canvas ---- */
.page-content {
    flex: 1;
    width: 100%;
    max-width: var(--bb-page-max);
    margin: 0 auto;
    padding: var(--bb-s-9) var(--bb-page-pad) var(--bb-s-16);
    min-width: 0;
}

/* ---- Overflow safety net -------------------------------------------------
   Long real-world values must never break the layout: a 15-character GSTIN,
   a 60-character company name, a pasted note with no spaces. Content wraps or
   scrolls within its own container; the page itself never scrolls sideways. */

.page-content > * { min-width: 0; max-width: 100%; }

/* Anything that can carry free text or an identifier breaks rather than pushes. */
.card-title, .page-title, .page-subtitle,
.detail-field dd, .metric-label, .metric-sub,
.timeline-title, .timeline-meta,
.alert-body, .empty-state-text {
    overflow-wrap: anywhere;
}

/* Long words inside a table cell break; the row does not stretch the table. */
.table td, .table th { overflow-wrap: break-word; }

/* Preformatted/code content scrolls on its own rather than widening the page. */
pre, code { max-width: 100%; overflow-x: auto; }
/* Full-bleed workspaces (POS, document editors) */
body.pos-mode .page-content { max-width: none; padding: 0; }

/* Demo banner */
.demo-mode-banner {
    display: flex; align-items: center; justify-content: center;
    gap: var(--bb-s-5); flex-wrap: wrap;
    padding: var(--bb-s-4) var(--bb-s-8);
    background: var(--bb-brand-700);
    color: #fff;
    font-size: var(--bb-fs-sm);
    font-weight: var(--bb-fw-medium);
    text-align: center;
}
.demo-mode-banner a { color: #fff; text-decoration: underline; font-weight: var(--bb-fw-semibold); white-space: nowrap; }
.demo-mode-banner a:hover { color: #fff; opacity: .85; }


/* ==========================================================================
   05 · PAGE HEADER
   ========================================================================== */

.page-header { margin-bottom: var(--bb-s-9); }
.page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--bb-s-8);
    flex-wrap: wrap;
}
.page-title {
    display: flex;
    align-items: center;
    gap: var(--bb-s-5);
    margin: 0;
    font-size: var(--bb-fs-2xl);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: -0.018em;
    color: var(--bb-text);
    line-height: 1.2;
}
/* Decorative leading icons in page titles are muted, never loud */
.page-title > i {
    font-size: 0.72em;
    color: var(--bb-text-subtle);
    flex-shrink: 0;
}
.page-subtitle {
    margin: var(--bb-s-3) 0 0;
    font-size: var(--bb-fs-base);
    color: var(--bb-text-muted);
    max-width: 68ch;
}
.page-actions {
    display: flex;
    align-items: center;
    gap: var(--bb-s-4);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.breadcrumb {
    display: flex; align-items: center; gap: var(--bb-s-3);
    margin-bottom: var(--bb-s-4);
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    flex-wrap: wrap;
}
.breadcrumb a { color: var(--bb-text-muted); }
.breadcrumb a:hover { color: var(--bb-text); }
.breadcrumb .sep { color: var(--bb-n-300); }

/* Section header inside a page */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--bb-s-6);
    margin: var(--bb-s-12) 0 var(--bb-s-6);
    flex-wrap: wrap;
}
.section-header:first-child { margin-top: 0; }
.section-title {
    margin: 0;
    font-size: var(--bb-fs-md);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-tight);
}
.section-desc {
    margin: 2px 0 0;
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
}


/* ==========================================================================
   06 · SURFACES — CARD, PANEL, SECTION
   ========================================================================== */

.card,
.panel {
    background: var(--bb-surface);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-lg);
    box-shadow: var(--bb-shadow-xs);
    margin-bottom: var(--bb-s-8);
    overflow: hidden;
}
.card:last-child, .panel:last-child { margin-bottom: 0; }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--bb-s-6);
    padding: var(--bb-s-6) var(--bb-s-8);
    border-bottom: 1px solid var(--bb-border-soft);
    background: var(--bb-surface);
    flex-wrap: wrap;
    min-height: 46px;
}
.card-title {
    display: flex;
    align-items: center;
    gap: var(--bb-s-4);
    margin: 0;
    font-size: var(--bb-fs-md);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-tight);
    color: var(--bb-text);
}
.card-title > i { font-size: 0.85em; color: var(--bb-text-subtle); }
.card-subtitle {
    margin: 2px 0 0;
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    font-weight: var(--bb-fw-normal);
}
.card-body { padding: var(--bb-s-8); }
.card-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--bb-s-4);
    padding: var(--bb-s-6) var(--bb-s-8);
    border-top: 1px solid var(--bb-border-soft);
    background: var(--bb-surface-inset);
    flex-wrap: wrap;
}

/* A card that only wraps a table needs no body padding */
.card-body > .table-wrapper:only-child { margin: calc(-1 * var(--bb-s-8)); }
/* The bleed above cancels the card-body's own padding. 67 views instead set
   style="padding: 0" on the card-body, so the same negative margin pulled
   the table 12-16px OUTSIDE the card: row text sat on (or under) the left
   border on a phone. No padding to cancel, no bleed. */
.card-body[style*="padding: 0"] > .table-wrapper:only-child,
.card-body[style*="padding:0"] > .table-wrapper:only-child { margin: 0 !important; }

/* Quiet / flat variants — reduces the "card in a card" problem */
.card.is-flat  { box-shadow: none; }
.card.is-quiet { background: transparent; border-color: transparent; box-shadow: none; }
.card.is-inset { background: var(--bb-surface-inset); }
.card.is-plain > .card-header { background: transparent; border-bottom-color: transparent; padding-bottom: 0; }

/* Accent rails for attention states */
.card.accent-warning { border-left: 3px solid var(--bb-warn-500); }
.card.accent-danger  { border-left: 3px solid var(--bb-danger-500); }
.card.accent-success { border-left: 3px solid var(--bb-success-500); }
.card.accent-brand   { border-left: 3px solid var(--bb-brand-500); }

/* Nested cards flatten automatically */
.card .card { box-shadow: none; }

/* Sunken well */
.well {
    background: var(--bb-surface-sunk);
    border: 1px solid var(--bb-border-soft);
    border-radius: var(--bb-r-md);
    padding: var(--bb-s-8);
}


/* ==========================================================================
   07 · BUTTONS
   ========================================================================== */

.btn {
    --btn-h: 34px;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--bb-s-4);
    height: var(--btn-h);
    padding: 0 var(--bb-s-7);
    font-family: var(--bb-font);
    font-size: var(--bb-fs-base);
    font-weight: var(--bb-fw-medium);
    line-height: 1;
    letter-spacing: -0.005em;
    white-space: nowrap;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: var(--bb-r);
    cursor: pointer;
    user-select: none;
    transition: background var(--bb-t-fast) var(--bb-ease),
                border-color var(--bb-t-fast) var(--bb-ease),
                color var(--bb-t-fast) var(--bb-ease),
                box-shadow var(--bb-t-fast) var(--bb-ease),
                transform var(--bb-t-fast) var(--bb-ease);
}
.btn > i { font-size: 0.92em; flex-shrink: 0; }
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { outline: none; box-shadow: var(--bb-ring); }
.btn:disabled, .btn.is-disabled, .btn[aria-disabled="true"] {
    opacity: .5;
    pointer-events: none;
    cursor: not-allowed;
}

/* Primary — one per view */
.btn-primary {
    background: var(--bb-brand-600);
    border-color: var(--bb-brand-600);
    color: #fff;
    box-shadow: var(--bb-shadow-xs);
}
.btn-primary:hover { background: var(--bb-brand-700); border-color: var(--bb-brand-700); color: #fff; }
.btn-primary:active { background: var(--bb-brand-800); }

/* Secondary — the default workhorse */
.btn-secondary,
.btn-default,
.btn-outline {
    background: var(--bb-surface);
    border-color: var(--bb-border-strong);
    color: var(--bb-text);
    box-shadow: var(--bb-shadow-xs);
}
.btn-secondary:hover,
.btn-default:hover,
.btn-outline:hover {
    background: var(--bb-surface-hover);
    border-color: var(--bb-n-300);
    color: var(--bb-text);
}

/* Ghost / subtle */
.btn-ghost, .btn-link, .btn-text-only {
    background: transparent;
    border-color: transparent;
    color: var(--bb-text-secondary);
    box-shadow: none;
}
.btn-ghost:hover, .btn-link:hover, .btn-text-only:hover {
    background: var(--bb-surface-hover);
    color: var(--bb-text);
}

.btn-subtle {
    background: var(--bb-n-75);
    border-color: transparent;
    color: var(--bb-text);
}
.btn-subtle:hover { background: var(--bb-n-100); }

/* Semantic */
.btn-success { background: var(--bb-success-600); border-color: var(--bb-success-600); color: #fff; box-shadow: var(--bb-shadow-xs); }
.btn-success:hover { background: var(--bb-success-700); border-color: var(--bb-success-700); color: #fff; }

.btn-danger  { background: var(--bb-danger-600); border-color: var(--bb-danger-600); color: #fff; box-shadow: var(--bb-shadow-xs); }
.btn-danger:hover { background: var(--bb-danger-700); border-color: var(--bb-danger-700); color: #fff; }
.btn-danger:focus-visible { box-shadow: var(--bb-ring-danger); }

.btn-warning { background: var(--bb-warn-600); border-color: var(--bb-warn-600); color: #fff; box-shadow: var(--bb-shadow-xs); }
.btn-warning:hover { background: var(--bb-warn-700); border-color: var(--bb-warn-700); color: #fff; }

.btn-info    { background: var(--bb-info-600); border-color: var(--bb-info-600); color: #fff; }
.btn-info:hover { background: var(--bb-info-700); border-color: var(--bb-info-700); color: #fff; }

/* Destructive but quiet — for row actions */
.btn-ghost.is-danger { color: var(--bb-danger-600); }
.btn-ghost.is-danger:hover { background: var(--bb-danger-50); color: var(--bb-danger-700); }

/* Sizes */
.btn-xs { --btn-h: 24px; padding: 0 var(--bb-s-4); font-size: var(--bb-fs-xs); gap: var(--bb-s-2); border-radius: var(--bb-r-sm); }
.btn-sm { --btn-h: 28px; padding: 0 var(--bb-s-5); font-size: var(--bb-fs-sm); gap: var(--bb-s-3); border-radius: var(--bb-r-sm); }
.btn-lg { --btn-h: 40px; padding: 0 var(--bb-s-9); font-size: var(--bb-fs-md); border-radius: var(--bb-r-md); }
.btn-xl { --btn-h: 46px; padding: 0 var(--bb-s-10); font-size: var(--bb-fs-lg); border-radius: var(--bb-r-md); }

/* Icon-only */
.btn-icon { width: var(--btn-h); padding: 0; }
.btn-icon > i { font-size: 1em; }

.btn-block, .btn-full { width: 100%; }

/* Button group — seamless segmented row */
.btn-group {
    display: inline-flex;
    align-items: center;
    gap: var(--bb-s-2);
}
.btn-group.is-attached { gap: 0; }
.btn-group.is-attached .btn { border-radius: 0; margin-left: -1px; }
.btn-group.is-attached .btn:first-child { border-radius: var(--bb-r) 0 0 var(--bb-r); margin-left: 0; }
.btn-group.is-attached .btn:last-child  { border-radius: 0 var(--bb-r) var(--bb-r) 0; }
.btn-group.is-attached .btn:hover { z-index: 1; }

/* Loading */
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
    content: "";
    position: absolute;
    width: 14px; height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    color: #fff;
    animation: bb-spin .6s linear infinite;
}
.btn-secondary.is-loading::after, .btn-ghost.is-loading::after { color: var(--bb-n-600); }

@keyframes bb-spin { to { transform: rotate(360deg); } }


/* ==========================================================================
   08 · FORMS
   ========================================================================== */

.form-group { margin-bottom: var(--bb-s-8); }
.form-group:last-child { margin-bottom: 0; }

.form-label {
    display: block;
    margin-bottom: var(--bb-s-3);
    font-size: var(--bb-fs-sm);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-text-secondary);
    letter-spacing: -0.003em;
}
.form-label.required::after,
.form-label .required::after {
    content: "*";
    color: var(--bb-danger-600);
    margin-left: 3px;
    font-weight: var(--bb-fw-bold);
}

.form-input,
.form-select,
.form-control,
.form-textarea,
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], input[type="url"],
input[type="date"], input[type="datetime-local"], input[type="time"],
input[type="search"], input[type="month"], select, textarea {
    width: 100%;
    min-height: 34px;
    padding: 7px var(--bb-s-6);
    font-family: var(--bb-font);
    font-size: var(--bb-fs-base);
    line-height: 1.4;
    color: var(--bb-text);
    background: var(--bb-surface);
    border: 1px solid var(--bb-border-strong);
    border-radius: var(--bb-r);
    box-shadow: var(--bb-shadow-xs);
    transition: border-color var(--bb-t-fast) var(--bb-ease),
                box-shadow var(--bb-t-fast) var(--bb-ease),
                background var(--bb-t-fast) var(--bb-ease);
    appearance: none;
    -webkit-appearance: none;
}
textarea, .form-textarea { min-height: 76px; resize: vertical; line-height: var(--bb-lh-snug); }

.form-input:hover, .form-select:hover, .form-control:hover,
input:hover:not([type="checkbox"]):not([type="radio"]):not([disabled]),
select:hover:not([disabled]), textarea:hover:not([disabled]) {
    border-color: var(--bb-n-300);
}

.form-input:focus, .form-select:focus, .form-control:focus, .form-textarea:focus,
input:focus:not([type="checkbox"]):not([type="radio"]), select:focus, textarea:focus {
    outline: none;
    border-color: var(--bb-border-focus);
    box-shadow: var(--bb-ring);
    background: var(--bb-surface);
}

.form-input::placeholder, textarea::placeholder, input::placeholder { color: var(--bb-text-subtle); }

.form-input:disabled, .form-select:disabled, input:disabled, select:disabled, textarea:disabled,
.form-input[readonly], input[readonly] {
    background: var(--bb-n-75);
    color: var(--bb-text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

/* Native select chevron */
select, .form-select {
    padding-right: var(--bb-s-12);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236f7787' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--bb-s-6) center;
    background-size: 12px;
}
select[multiple] { background-image: none; padding-right: var(--bb-s-6); }

/* Sizes */
.form-input.is-sm, .form-select.is-sm, .input-sm { min-height: 28px; padding: 4px var(--bb-s-5); font-size: var(--bb-fs-sm); }
.form-input.is-lg, .form-select.is-lg, .input-lg { min-height: 40px; padding: 9px var(--bb-s-7); font-size: var(--bb-fs-md); }

/* Validation */
.form-input.is-invalid, .form-select.is-invalid, .is-invalid,
.form-input[aria-invalid="true"], input[aria-invalid="true"] {
    border-color: var(--bb-danger-500);
}
.form-input.is-invalid:focus, .is-invalid:focus, input[aria-invalid="true"]:focus {
    box-shadow: var(--bb-ring-danger);
    border-color: var(--bb-danger-500);
}
.form-error, .invalid-feedback, .field-error {
    display: flex;
    align-items: center;
    gap: var(--bb-s-3);
    margin-top: var(--bb-s-3);
    font-size: var(--bb-fs-sm);
    color: var(--bb-danger-700);
}
.form-hint, .form-help, .form-text, .help-text {
    display: block;
    margin-top: var(--bb-s-3);
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    line-height: var(--bb-lh-snug);
}

/* Input adornments */
.input-group { display: flex; align-items: stretch; }
.input-group > .form-input,
.input-group > input,
.input-group > select { border-radius: 0; margin-left: -1px; flex: 1; min-width: 0; }
.input-group > :first-child { border-radius: var(--bb-r) 0 0 var(--bb-r); margin-left: 0; }
.input-group > :last-child  { border-radius: 0 var(--bb-r) var(--bb-r) 0; }
.input-group > .form-input:focus, .input-group > input:focus { z-index: 2; }
.input-addon {
    display: inline-flex;
    align-items: center;
    padding: 0 var(--bb-s-6);
    background: var(--bb-n-75);
    border: 1px solid var(--bb-border-strong);
    color: var(--bb-text-muted);
    font-size: var(--bb-fs-base);
    white-space: nowrap;
}

/* Field with a leading icon */
.field-icon { position: relative; }
.field-icon > i {
    position: absolute;
    left: var(--bb-s-6);
    top: 50%;
    transform: translateY(-50%);
    color: var(--bb-text-subtle);
    font-size: 12px;
    pointer-events: none;
}
.field-icon > .form-input, .field-icon > input { padding-left: var(--bb-s-12); }

/* Currency input — rupee prefix, tabular figures */
.currency-input { position: relative; }
.currency-input::before {
    content: "₹";
    position: absolute;
    left: var(--bb-s-6);
    top: 50%;
    transform: translateY(-50%);
    color: var(--bb-text-muted);
    font-size: var(--bb-fs-base);
    pointer-events: none;
    z-index: 1;
}
.currency-input > input, .currency-input > .form-input {
    padding-left: 26px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

/* Numeric inputs are always tabular + right aligned */
input[type="number"], .input-numeric, .qty-input, .rate-input, .amount-input {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    text-align: right;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

/* Checkbox & radio */
input[type="checkbox"], input[type="radio"] {
    width: 15px; height: 15px;
    margin: 0;
    flex-shrink: 0;
    appearance: none;
    -webkit-appearance: none;
    background: var(--bb-surface);
    border: 1.5px solid var(--bb-n-300);
    border-radius: var(--bb-r-xs);
    cursor: pointer;
    display: inline-grid;
    place-content: center;
    transition: background var(--bb-t-fast) var(--bb-ease), border-color var(--bb-t-fast) var(--bb-ease);
    vertical-align: -2px;
}
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]::before {
    content: "";
    width: 9px; height: 9px;
    transform: scale(0);
    transition: transform var(--bb-t-fast) var(--bb-ease-out);
    background: #fff;
    clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 22%, 84% 6%, 38% 68%);
}
input[type="radio"]::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #fff;
    transform: scale(0);
    transition: transform var(--bb-t-fast) var(--bb-ease-out);
}
input[type="checkbox"]:checked, input[type="radio"]:checked {
    background: var(--bb-brand-600);
    border-color: var(--bb-brand-600);
}
input[type="checkbox"]:checked::before, input[type="radio"]:checked::before { transform: scale(1); }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: none; box-shadow: var(--bb-ring); }
input[type="checkbox"]:disabled, input[type="radio"]:disabled { background: var(--bb-n-100); border-color: var(--bb-n-200); cursor: not-allowed; }

.check-row, .form-check {
    display: flex;
    align-items: center;
    gap: var(--bb-s-5);
    font-size: var(--bb-fs-base);
    color: var(--bb-text);
    cursor: pointer;
}
.check-row input, .form-check input { cursor: pointer; }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
    width: 34px; height: 20px;
    background: var(--bb-n-300);
    border-radius: var(--bb-r-full);
    transition: background var(--bb-t) var(--bb-ease);
    flex-shrink: 0;
}
.switch-track::after {
    content: "";
    display: block;
    width: 16px; height: 16px;
    margin: 2px;
    background: #fff;
    border-radius: 50%;
    box-shadow: var(--bb-shadow-sm);
    transition: transform var(--bb-t) var(--bb-ease-out);
}
.switch input:checked + .switch-track { background: var(--bb-brand-600); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--bb-ring); }

/* Form layout helpers */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--bb-s-8);
}
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--bb-s-8); }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--bb-s-8); }
.form-grid  { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--bb-s-8); }
/* The grid's last .form-group loses its margin (:last-child), so whatever came
   after a grid sat flush against it -- on a phone, where the grid is one
   column, "Vendor/Supplier" touched the Category box above it. */
.form-grid { margin-bottom: var(--bb-s-8); }
.form-grid:last-child { margin-bottom: 0; }

.form-section { padding: var(--bb-s-9) 0; border-bottom: 1px solid var(--bb-border-soft); }
.form-section:first-child { padding-top: 0; }
.form-section:last-child  { border-bottom: 0; padding-bottom: 0; }
.form-section-title {
    margin: 0 0 var(--bb-s-6);
    font-size: var(--bb-fs-md);
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
}

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-size: var(--bb-fs-md); font-weight: var(--bb-fw-semibold); }

/* --------------------------------------------------------------------------
   Single-column record forms (edit payment, edit expense, settings panels).
   -------------------------------------------------------------------------- */

.form-narrow {
    max-width: 760px;
    display: flex;
    flex-direction: column;
    gap: var(--bb-s-8);
}

/* Two fields side by side, stacking on narrow viewports. */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--bb-s-5) var(--bb-s-7);
}
.form-row > .form-group { min-width: 0; }

.form-actions {
    display: flex;
    gap: var(--bb-s-5);
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* A computed value shown where an input would sit. */
.form-static {
    display: flex;
    align-items: center;
    min-height: var(--input-h, 38px);
    padding: 0 var(--bb-s-2);
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
}

/* Currency/unit prefix inside an input. */
.input-affix { position: relative; display: block; }
.input-prefix {
    position: absolute;
    left: var(--bb-s-5);
    top: 50%;
    transform: translateY(-50%);
    color: var(--bb-text-muted);
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}
.form-input.has-prefix { padding-left: calc(var(--bb-s-5) + 14px); }

/* Context the form shows but does not let you change. */
.readonly-panel {
    background: var(--bb-surface-sunk);
    border: 1px solid var(--bb-border-soft);
    border-radius: var(--bb-r-lg);
    padding: var(--bb-s-7);
    margin-bottom: var(--bb-s-8);
}
.readonly-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--bb-s-7);
}
.readonly-grid > div { min-width: 0; }
.readonly-label {
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    margin-bottom: var(--bb-s-3);
}
.readonly-value {
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
    text-decoration: none;
    display: block;
    overflow-wrap: anywhere;
}
a.readonly-value { color: var(--bb-text-link); }
a.readonly-value:hover { text-decoration: underline; }
.readonly-sub {
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    margin-top: 2px;
    overflow-wrap: anywhere;
}


/* ==========================================================================
   09 · TABLES & DATA GRID
   ========================================================================== */

.table-wrapper,
/*
 * .table-responsive is Bootstrap's name for this, and three views were written
 * with it (GST HSN summary, item import preview, staff activity log). BillBase
 * does not load Bootstrap, so the class resolved to nothing and those tables
 * pushed the whole page sideways on a phone -- the HSN summary table alone
 * measured 691px past a 390px viewport. Aliasing it here fixes all three at
 * once and makes the next person who reaches for the Bootstrap name right by
 * default, rather than silently wrong.
 */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrapper table,
.table-responsive table,
table.data-table,
.card-body > table,
.card > table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--bb-fs-base);
}

.table-wrapper thead th,
table.data-table thead th,
.card table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: var(--bb-s-5) var(--bb-s-8);
    text-align: left;
    font-size: var(--bb-fs-xs);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-wide);
    text-transform: uppercase;
    color: var(--bb-text-muted);
    background: var(--bb-surface-head);
    border-bottom: 1px solid var(--bb-border);
    white-space: nowrap;
}
.table-wrapper tbody td,
table.data-table tbody td,
.card table tbody td {
    padding: var(--bb-s-6) var(--bb-s-8);
    border-bottom: 1px solid var(--bb-border-soft);
    color: var(--bb-text);
    vertical-align: middle;
}
.table-wrapper tbody tr:last-child td,
.card table tbody tr:last-child td { border-bottom: 0; }

.table-wrapper tbody tr,
.card table tbody tr { transition: background var(--bb-t-fast) var(--bb-ease); }
.table-wrapper tbody tr:hover,
.card table tbody tr:hover { background: var(--bb-surface-hover); }

/* Rows that link somewhere */
tr.is-clickable { cursor: pointer; }

/* Numeric columns: tabular + right */
.table-wrapper td.text-right, .table-wrapper th.text-right,
td.num, th.num, .text-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}
.table-wrapper td.text-center, .table-wrapper th.text-center { text-align: center; }

/* Row actions column — reveal on hover, always visible on touch */
td.row-actions, .table-actions { white-space: nowrap; text-align: right; }
td.row-actions .btn, .table-actions .btn { opacity: .55; transition: opacity var(--bb-t-fast) var(--bb-ease); }
tr:hover td.row-actions .btn, tr:focus-within td.row-actions .btn,
tr:hover .table-actions .btn { opacity: 1; }
@media (hover: none) {
    td.row-actions .btn, .table-actions .btn { opacity: 1; }
}

/* Sortable headers */
th.sortable { cursor: pointer; user-select: none; position: sticky; }
th.sortable::after {
    content: "\f0dc";
    font-family: "Font Awesome 6 Free", "Font Awesome 5 Free";
    font-weight: 900;
    margin-left: var(--bb-s-4);
    font-size: 9px;
    opacity: .3;
    transition: opacity var(--bb-t-fast) var(--bb-ease);
}
th.sortable:hover { color: var(--bb-text); }
th.sortable:hover::after { opacity: .6; }
th.sortable.sort-asc::after  { content: "\f0de"; opacity: 1; color: var(--bb-brand-600); }
th.sortable.sort-desc::after { content: "\f0dd"; opacity: 1; color: var(--bb-brand-600); }

/* Compact & striped modifiers */
.table-compact tbody td, .table-compact thead th { padding: var(--bb-s-4) var(--bb-s-6); }
.table-striped tbody tr:nth-child(even) { background: var(--bb-surface-inset); }
.table-striped tbody tr:nth-child(even):hover { background: var(--bb-surface-hover); }

/* Bordered cells (used by print/summary tables) */
.table-bordered td, .table-bordered th { border: 1px solid var(--bb-border); }

/* Table toolbar / filter bar */
.filter-bar, .table-toolbar {
    display: flex;
    align-items: center;
    gap: var(--bb-s-5);
    flex-wrap: wrap;
    padding: var(--bb-s-6) var(--bb-s-8);
    border-bottom: 1px solid var(--bb-border-soft);
    background: var(--bb-surface);
}
.filter-bar .form-input,
.filter-bar .form-select,
.table-toolbar .form-select { width: auto; min-width: 140px; }
.filter-bar .spacer, .table-toolbar .spacer { margin-left: auto; }

/* Search field used inside card headers */
.header-search.is-inline {
    width: 220px;
    height: 30px;
    cursor: text;
    background: var(--bb-surface);
    border: 1px solid var(--bb-border-strong);
}
.header-search.is-inline:hover { background: var(--bb-surface); border-color: var(--bb-n-300); }

/* Table footer summary row */
tfoot td {
    padding: var(--bb-s-6) var(--bb-s-8);
    background: var(--bb-surface-inset);
    border-top: 1px solid var(--bb-border);
    font-weight: var(--bb-fw-semibold);
}

/* Selection column */
td.select-col, th.select-col { width: 36px; padding-right: 0; }

/* Result count / meta line */
.table-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--bb-s-6);
    padding: var(--bb-s-5) var(--bb-s-8);
    border-top: 1px solid var(--bb-border-soft);
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    flex-wrap: wrap;
}


/* ==========================================================================
   10 · STATUS, BADGES & PILLS
   ========================================================================== */

.status-badge, .badge, .pill, .tag {
    display: inline-flex;
    align-items: center;
    gap: var(--bb-s-3);
    padding: 2.5px var(--bb-s-5);
    font-size: var(--bb-fs-xs);
    font-weight: var(--bb-fw-medium);
    line-height: 1.45;
    border-radius: var(--bb-r-sm);
    white-space: nowrap;
    border: 1px solid transparent;
    background: var(--bb-n-75);
    color: var(--bb-n-700);
}

/* Dot marker for status semantics */
.status-badge::before {
    content: "";
    width: 5px; height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
    opacity: .8;
}
.status-badge.no-dot::before { display: none; }

/* Financial semantics — used consistently across every document module */
.status-paid, .status-completed, .status-active, .status-success,
.status-received, .status-delivered, .status-converted, .status-issued,
.badge-success, .bg-success {
    background: var(--bb-success-50);
    color: var(--bb-success-700);
    border-color: var(--bb-success-100);
}

/* Tones addressed by name (stock movement types, payment methods, and any
   status slug that maps to a semantic colour rather than a workflow state). */
.status-warning {
    background: var(--bb-warn-50);
    color: var(--bb-warn-700);
    border-color: var(--bb-warn-100);
}
.status-violet {
    background: var(--bb-violet-50);
    color: var(--bb-violet-700);
    border-color: var(--bb-violet-100);
}
.status-neutral, .status-unknown {
    background: var(--bb-surface-sunk);
    color: var(--bb-text-secondary);
    border-color: var(--bb-border);
}
.status-pending, .status-unpaid, .status-partial, .status-sent,
.status-in_transit, .status-confirmed, .status-processing,
.badge-warning, .bg-warning {
    background: var(--bb-warn-50);
    color: var(--bb-warn-700);
    border-color: var(--bb-warn-100);
}
.status-overdue, .status-failed, .status-rejected, .status-danger,
.badge-danger, .bg-danger {
    background: var(--bb-danger-50);
    color: var(--bb-danger-700);
    border-color: var(--bb-danger-100);
}
.status-draft, .status-cancelled, .status-inactive, .status-expired,
.status-declined, .status-void, .badge-secondary, .badge-neutral {
    background: var(--bb-n-75);
    color: var(--bb-n-600);
    border-color: var(--bb-n-150);
}
.status-info, .status-new, .badge-info, .bg-info {
    background: var(--bb-info-50);
    color: var(--bb-info-700);
    border-color: var(--bb-info-100);
}
.status-primary, .badge-primary, .badge-brand {
    background: var(--bb-brand-50);
    color: var(--bb-brand-700);
    border-color: var(--bb-brand-100);
}

/* Cancelled reads as struck-through, not merely grey */
.status-cancelled, .status-void { text-decoration: line-through; text-decoration-thickness: 1px; }

.badge-lg { padding: 4px var(--bb-s-6); font-size: var(--bb-fs-sm); }
.badge-dot { width: 7px; height: 7px; padding: 0; border-radius: 50%; }

/* Soft attention chips (stock alerts etc.) */
.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--bb-s-3);
    padding: 3px var(--bb-s-5);
    font-size: var(--bb-fs-sm);
    border-radius: var(--bb-r-full);
    background: var(--bb-n-75);
    color: var(--bb-n-700);
    border: 1px solid var(--bb-border-soft);
}
.chip.is-danger  { background: var(--bb-danger-50);  color: var(--bb-danger-700);  border-color: var(--bb-danger-100); }
.chip.is-warning { background: var(--bb-warn-50);    color: var(--bb-warn-700);    border-color: var(--bb-warn-100); }
.chip.is-success { background: var(--bb-success-50); color: var(--bb-success-700); border-color: var(--bb-success-100); }


/* ==========================================================================
   11 · METRICS
   ========================================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
    gap: var(--bb-s-6);
    margin-bottom: var(--bb-s-8);
}

.stat-card {
    position: relative;
    background: var(--bb-surface);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-lg);
    padding: var(--bb-s-8);
    box-shadow: var(--bb-shadow-xs);
    transition: border-color var(--bb-t-fast) var(--bb-ease),
                box-shadow var(--bb-t-fast) var(--bb-ease);
    min-width: 0;
}
a.stat-card:hover, .stat-card.is-clickable:hover {
    border-color: var(--bb-n-300);
    box-shadow: var(--bb-shadow-sm);
}

.stat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--bb-s-5);
    margin-bottom: var(--bb-s-6);
}

/* The icon is a quiet marker, not a decoration */
.stat-icon {
    width: 30px; height: 30px;
    flex: 0 0 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--bb-r-md);
    font-size: 13px;
    background: var(--bb-n-75);
    color: var(--bb-n-600);
}
.stat-icon.primary   { background: var(--bb-brand-50);   color: var(--bb-brand-600); }
.stat-icon.success   { background: var(--bb-success-50); color: var(--bb-success-600); }
.stat-icon.warning   { background: var(--bb-warn-50);    color: var(--bb-warn-600); }
.stat-icon.danger    { background: var(--bb-danger-50);  color: var(--bb-danger-600); }
.stat-icon.info      { background: var(--bb-info-50);    color: var(--bb-info-600); }
.stat-icon.secondary { background: var(--bb-violet-50);  color: var(--bb-violet-600); }

.stat-value {
    font-size: var(--bb-fs-3xl);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: -0.028em;
    line-height: 1.1;
    color: var(--bb-text);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    word-break: break-word;
}
.stat-label {
    margin-top: var(--bb-s-3);
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    font-weight: var(--bb-fw-normal);
}
.stat-change {
    display: inline-flex;
    align-items: center;
    gap: var(--bb-s-3);
    margin-top: var(--bb-s-5);
    font-size: var(--bb-fs-xs);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-text-muted);
}
.stat-change.up   { color: var(--bb-success-700); }
.stat-change.down { color: var(--bb-danger-700); }
.stat-change.flat { color: var(--bb-text-muted); }
.stat-change i { font-size: 9px; }

/* Metric strip — dense, borderless row of KPIs for the dashboard hero */
.metric-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    background: var(--bb-surface);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-lg);
    box-shadow: var(--bb-shadow-xs);
    overflow: hidden;
}
.metric {
    padding: var(--bb-s-9) var(--bb-s-9);
    border-right: 1px solid var(--bb-border-soft);
    min-width: 0;
}
.metric:last-child { border-right: 0; }
.metric-label {
    display: flex;
    align-items: center;
    gap: var(--bb-s-3);
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    margin-bottom: var(--bb-s-4);
}
.metric-value {
    font-size: var(--bb-fs-3xl);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: -0.03em;
    line-height: 1.05;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    color: var(--bb-text);
}
.metric-value.is-danger  { color: var(--bb-danger-700); }
.metric-value.is-success { color: var(--bb-success-700); }
/* The summed cell in a strip of parts — carries the total, so it reads first. */
.metric-emphasis { background: var(--bb-surface-sunk); }
.metric-emphasis .metric-label { color: var(--bb-text-secondary); font-weight: var(--bb-fw-medium); }
.metric-sub {
    margin-top: var(--bb-s-4);
    font-size: var(--bb-fs-xs);
    color: var(--bb-text-muted);
    display: flex; align-items: center; gap: var(--bb-s-3);
}

/* Progress meter */
.meter {
    height: 5px;
    background: var(--bb-n-100);
    border-radius: var(--bb-r-full);
    overflow: hidden;
    margin-top: var(--bb-s-5);
}
.meter-fill {
    height: 100%;
    background: var(--bb-brand-500);
    border-radius: var(--bb-r-full);
    transition: width var(--bb-t-slow) var(--bb-ease-out);
}
.meter-fill.is-success { background: var(--bb-success-500); }
.meter-fill.is-warning { background: var(--bb-warn-500); }
.meter-fill.is-danger  { background: var(--bb-danger-500); }


/* ==========================================================================
   12 · EMPTY / LOADING / ERROR STATES
   ========================================================================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--bb-s-16) var(--bb-s-9);
    max-width: 420px;
    margin: 0 auto;
}
.empty-state-icon {
    width: 46px; height: 46px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: var(--bb-s-7);
    border-radius: var(--bb-r-lg);
    background: var(--bb-n-75);
    color: var(--bb-n-400);
    font-size: 18px;
}
.empty-state-title {
    margin: 0 0 var(--bb-s-4);
    font-size: var(--bb-fs-md);
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
}
.empty-state-text {
    margin: 0 0 var(--bb-s-9);
    font-size: var(--bb-fs-base);
    color: var(--bb-text-muted);
    line-height: var(--bb-lh-snug);
}
.empty-state-text:last-child { margin-bottom: 0; }
.empty-state .btn + .btn { margin-left: var(--bb-s-4); }

/* Compact inline empty (inside a small panel) */
.empty-inline {
    padding: var(--bb-s-12) var(--bb-s-8);
    text-align: center;
    color: var(--bb-text-muted);
    font-size: var(--bb-fs-base);
}

/* Error state */
.error-state { }
.error-state .empty-state-icon { background: var(--bb-danger-50); color: var(--bb-danger-600); }

/* Skeleton */
.skeleton {
    background: linear-gradient(90deg, var(--bb-n-100) 25%, var(--bb-n-75) 37%, var(--bb-n-100) 63%);
    background-size: 400% 100%;
    animation: bb-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--bb-r-sm);
}
@keyframes bb-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.skeleton-text  { height: 11px; margin-bottom: var(--bb-s-4); }
.skeleton-text:last-child { margin-bottom: 0; width: 60%; }
.skeleton-title { height: 18px; width: 40%; margin-bottom: var(--bb-s-6); }
.skeleton-block { height: 84px; border-radius: var(--bb-r-md); }
.skeleton-avatar{ width: 30px; height: 30px; border-radius: var(--bb-r-md); }
.skeleton-row {
    display: flex; align-items: center; gap: var(--bb-s-6);
    padding: var(--bb-s-6) var(--bb-s-8);
    border-bottom: 1px solid var(--bb-border-soft);
}
.skeleton-row > .skeleton { flex: 1; height: 11px; }

/* Spinner */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid var(--bb-n-200);
    border-top-color: var(--bb-brand-600);
    border-radius: 50%;
    animation: bb-spin .6s linear infinite;
}
.spinner-lg { width: 26px; height: 26px; border-width: 2.5px; }

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--bb-s-6);
    padding: var(--bb-s-16);
    color: var(--bb-text-muted);
    font-size: var(--bb-fs-base);
}

/* Indeterminate top progress bar */
.route-progress {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 2px;
    z-index: var(--bb-z-toast);
    background: transparent;
    overflow: hidden;
    pointer-events: none;
}
.route-progress::after {
    content: "";
    position: absolute;
    inset: 0;
    width: 40%;
    background: linear-gradient(90deg, transparent, var(--bb-brand-500), transparent);
    animation: bb-indeterminate 1.1s var(--bb-ease) infinite;
}
@keyframes bb-indeterminate {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}


/* ==========================================================================
   13 · ALERTS & BANNERS
   ========================================================================== */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--bb-s-5);
    padding: var(--bb-s-6) var(--bb-s-8);
    margin-bottom: var(--bb-s-8);
    border: 1px solid transparent;
    border-radius: var(--bb-r-md);
    font-size: var(--bb-fs-base);
    line-height: var(--bb-lh-snug);
}
.alert > i, .alert > .alert-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.alert-title { font-weight: var(--bb-fw-semibold); margin-bottom: 2px; }
.alert-body { min-width: 0; flex: 1; }
.alert .alert-close {
    margin-left: auto;
    background: transparent;
    border: 0;
    color: inherit;
    opacity: .5;
    cursor: pointer;
    padding: 0 2px;
    font-size: 13px;
    transition: opacity var(--bb-t-fast) var(--bb-ease);
}
.alert .alert-close:hover { opacity: 1; }

.alert-success, .alert-green {
    background: var(--bb-success-50);
    border-color: var(--bb-success-100);
    color: var(--bb-success-700);
}
.alert-warning, .alert-yellow {
    background: var(--bb-warn-50);
    border-color: var(--bb-warn-100);
    color: var(--bb-warn-700);
}
.alert-danger, .alert-error, .alert-red {
    background: var(--bb-danger-50);
    border-color: var(--bb-danger-100);
    color: var(--bb-danger-700);
}
.alert-info, .alert-blue {
    background: var(--bb-info-50);
    border-color: var(--bb-info-100);
    color: var(--bb-info-700);
}
/* "Save this walk-in customer" opt-in — shared by the invoice and sale-order forms. */
.save-customer-option { margin-top: var(--bb-s-6); }
.save-customer-label {
    display: flex; align-items: center; gap: var(--bb-s-4);
    cursor: pointer; margin: 0; font-size: var(--bb-fs-sm);
    font-weight: var(--bb-fw-normal); color: inherit;
}
.save-customer-label input[type="checkbox"] { width: 16px; height: 16px; margin: 0; }

/* Summed row at the foot of a report table. */
.table-total-row td {
    background: var(--bb-surface-sunk);
    border-top: 2px solid var(--bb-border);
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
}

/* Generated-commentary callout — the emoji reads as the icon slot. */
.insight-callout { margin-bottom: var(--bb-s-8); }
.insight-mark { font-size: 24px; line-height: 1; flex-shrink: 0; }
.insight-text { margin: var(--bb-s-2) 0 0; line-height: 1.6; }

/* "Nothing matched" row inside a search dropdown. */
.dropdown-empty {
    padding: var(--bb-s-6);
    text-align: center;
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    border-bottom: 1px solid var(--bb-border);
}

/* A "create new …" affordance at the foot of a search dropdown. */
.dropdown-item-create {
    background: var(--bb-success-50);
    border-top: 1px solid var(--bb-success-200);
}
.dropdown-item-create:hover { background: var(--bb-success-100); }
.dropdown-item-create .name { color: var(--bb-success-700); }
.dropdown-item-create .details { color: var(--bb-success-600); }

.alert-neutral {
    background: var(--bb-n-50);
    border-color: var(--bb-border);
    color: var(--bb-text-secondary);
}

/* Inline notice — quieter than an alert */
.notice {
    display: flex; align-items: center; gap: var(--bb-s-5);
    padding: var(--bb-s-5) var(--bb-s-7);
    background: var(--bb-surface-inset);
    border: 1px solid var(--bb-border-soft);
    border-radius: var(--bb-r-md);
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-secondary);
}


/* ==========================================================================
   14 · TOASTS
   ========================================================================== */

.toast-stack {
    position: fixed;
    bottom: var(--bb-s-9);
    right: var(--bb-s-9);
    z-index: var(--bb-z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--bb-s-4);
    max-width: 380px;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--bb-s-5);
    padding: var(--bb-s-6) var(--bb-s-7);
    background: var(--bb-n-900);
    color: #fff;
    border-radius: var(--bb-r-md);
    box-shadow: var(--bb-shadow-lg);
    font-size: var(--bb-fs-base);
    line-height: var(--bb-lh-snug);
    pointer-events: auto;
    animation: bb-toast-in var(--bb-t-slow) var(--bb-ease-out);
}
.toast.is-leaving { animation: bb-toast-out var(--bb-t) var(--bb-ease) forwards; }
.toast > i { flex-shrink: 0; margin-top: 1px; font-size: 13px; }
.toast.is-success > i { color: var(--bb-success-200); }
.toast.is-error   > i { color: var(--bb-danger-200); }
.toast.is-warning > i { color: var(--bb-warn-200); }
.toast.is-info    > i { color: var(--bb-info-200); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: var(--bb-fw-semibold); }
.toast-msg { color: rgba(255,255,255,.72); margin-top: 1px; }
.toast-close {
    background: transparent; border: 0; color: rgba(255,255,255,.5);
    cursor: pointer; padding: 0 2px; font-size: 12px;
    transition: color var(--bb-t-fast) var(--bb-ease);
}
.toast-close:hover { color: #fff; }

@keyframes bb-toast-in  { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes bb-toast-out { to { opacity: 0; transform: translateY(4px) scale(.98); } }

/* Document export progress (public/js/document-share.js).
   Rasterising a long invoice takes a second or two, and a share sheet that
   appears with no warning reads as a bug. Positioned above the toast stack so
   the two never collide, and bottom-anchored on phones where the top-right
   corner is under the browser UI. */
.bb-doc-progress {
    position: fixed;
    top: var(--bb-s-8);
    right: var(--bb-s-8);
    z-index: calc(var(--bb-z-toast) + 1);
    display: flex;
    align-items: center;
    gap: var(--bb-s-5);
    max-width: min(320px, calc(100vw - 2 * var(--bb-s-8)));
    padding: var(--bb-s-6) var(--bb-s-7);
    border-radius: var(--bb-r-md);
    background: var(--bb-n-900);
    color: #fff;
    font-size: var(--bb-fs-base);
    font-weight: var(--bb-fw-medium);
    box-shadow: var(--bb-shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity var(--bb-t) var(--bb-ease),
                transform var(--bb-t) var(--bb-ease),
                visibility var(--bb-t) var(--bb-ease);
}
.bb-doc-progress.is-visible { opacity: 1; visibility: visible; transform: none; }
.bb-doc-progress-spinner {
    width: 14px; height: 14px;
    flex: 0 0 14px;
    border: 2px solid rgba(255,255,255,.28);
    border-top-color: #fff;
    border-radius: 50%;
    animation: bb-spin .7s linear infinite;
}
@keyframes bb-spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
    .bb-doc-progress {
        top: auto;
        bottom: calc(var(--bb-s-8) + env(safe-area-inset-bottom, 0px));
        left: var(--bb-s-8);
        right: var(--bb-s-8);
        max-width: none;
        justify-content: center;
    }
}


/* ==========================================================================
   15 · MODAL, DIALOG & DRAWER
   ========================================================================== */

.modal-overlay, .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(13, 15, 20, .44);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: var(--bb-z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--bb-s-9);
    overflow-y: auto;
    animation: bb-fade-in var(--bb-t) var(--bb-ease);
}
.modal, .modal-content, .modal-dialog {
    position: relative;
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - var(--bb-s-16));
    display: flex;
    flex-direction: column;
    background: var(--bb-surface);
    border-radius: var(--bb-r-xl);
    box-shadow: var(--bb-shadow-xl);
    overflow: hidden;
    animation: bb-modal-in var(--bb-t-slow) var(--bb-ease-out);
}
.modal-sm  { max-width: 400px; }
.modal-lg  { max-width: 720px; }
.modal-xl  { max-width: 960px; }
.modal-full{ max-width: 1200px; }

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--bb-s-6);
    padding: var(--bb-s-9) var(--bb-s-9) var(--bb-s-6);
    flex-shrink: 0;
}
.modal-title {
    margin: 0;
    font-size: var(--bb-fs-lg);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-tight);
}
.modal-subtitle { margin: var(--bb-s-3) 0 0; font-size: var(--bb-fs-base); color: var(--bb-text-muted); }
.modal-close {
    flex-shrink: 0;
    width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent;
    border: 0;
    border-radius: var(--bb-r-sm);
    color: var(--bb-text-muted);
    font-size: 14px;
    cursor: pointer;
    transition: background var(--bb-t-fast) var(--bb-ease), color var(--bb-t-fast) var(--bb-ease);
}
.modal-close:hover { background: var(--bb-surface-hover); color: var(--bb-text); }
.modal-body {
    padding: 0 var(--bb-s-9) var(--bb-s-9);
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--bb-s-4);
    padding: var(--bb-s-7) var(--bb-s-9);
    border-top: 1px solid var(--bb-border-soft);
    background: var(--bb-surface-inset);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.modal-footer .spacer { margin-right: auto; }

/* Drawer (side sheet) */
.drawer-overlay {
    position: fixed; inset: 0;
    background: rgba(13, 15, 20, .44);
    backdrop-filter: blur(3px);
    z-index: var(--bb-z-modal);
    animation: bb-fade-in var(--bb-t) var(--bb-ease);
}
.drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(480px, 100vw);
    display: flex;
    flex-direction: column;
    background: var(--bb-surface);
    border-left: 1px solid var(--bb-border);
    box-shadow: var(--bb-shadow-xl);
    z-index: calc(var(--bb-z-modal) + 1);
    animation: bb-drawer-in var(--bb-t-slow) var(--bb-ease-out);
}
.drawer-lg { width: min(680px, 100vw); }
.drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--bb-s-6);
    padding: var(--bb-s-8) var(--bb-s-9);
    border-bottom: 1px solid var(--bb-border-soft);
    flex-shrink: 0;
}
.drawer-body { flex: 1; overflow-y: auto; padding: var(--bb-s-9); }
.drawer-footer {
    display: flex; align-items: center; justify-content: flex-end; gap: var(--bb-s-4);
    padding: var(--bb-s-7) var(--bb-s-9);
    border-top: 1px solid var(--bb-border-soft);
    background: var(--bb-surface-inset);
    flex-shrink: 0;
}

@keyframes bb-fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes bb-modal-in { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes bb-drawer-in{ from { transform: translateX(100%); } to { transform: none; } }

body.modal-open { overflow: hidden; }


/* ==========================================================================
   16 · MENU, DROPDOWN & POPOVER
   ========================================================================== */

.dropdown { position: relative; display: inline-block; }

.menu, .dropdown-menu, .dropdown-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 190px;
    padding: var(--bb-s-3);
    background: var(--bb-surface);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-md);
    box-shadow: var(--bb-shadow-md);
    z-index: var(--bb-z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px) scale(.985);
    transform-origin: top right;
    transition: opacity var(--bb-t-fast) var(--bb-ease),
                transform var(--bb-t-fast) var(--bb-ease-out),
                visibility var(--bb-t-fast) var(--bb-ease);
}
.menu.open, .dropdown-menu.open, .dropdown-menu.show, .dropdown.open > .menu,
.dropdown-panel.open {
    opacity: 1;
    visibility: visible;
    transform: none;
}
.menu-left, .dropdown-menu.align-left { right: auto; left: 0; transform-origin: top left; }

/* A menu is absolutely positioned, so even while hidden it still occupies
   layout and can extend the page's scroll width — on a 360px screen the
   left-anchored Print menu on the invoice view pushed the document to 379px
   and gave every page a horizontal scrollbar. Capping the width to the
   viewport fixes the hidden case and the open case at once: the menu can
   never be wider than the screen it opens on. */
.menu, .dropdown-menu, .dropdown-panel {
    max-width: min(320px, calc(100vw - 2 * var(--bb-s-8)));
}

/* On phones a left-anchored menu near the right edge would still run off.
   Anchoring every menu to its trigger's right edge keeps it on-screen. */
@media (max-width: 560px) {
    .menu-left, .dropdown-menu.align-left {
        left: auto;
        right: 0;
        transform-origin: top right;
    }
}

.menu-item, .dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--bb-s-5);
    width: 100%;
    padding: 6px var(--bb-s-5);
    background: transparent;
    border: 0;
    border-radius: var(--bb-r-sm);
    font-family: var(--bb-font);
    font-size: var(--bb-fs-base);
    color: var(--bb-text);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--bb-t-fast) var(--bb-ease);
}
.menu-item > i, .dropdown-item > i {
    width: 15px; flex: 0 0 15px; text-align: center;
    font-size: 12px; color: var(--bb-text-subtle);
}
.menu-item:hover, .dropdown-item:hover,
.menu-item:focus-visible, .dropdown-item:focus-visible {
    background: var(--bb-surface-hover);
    color: var(--bb-text);
    outline: none;
}
.menu-item.is-danger, .dropdown-item.is-danger { color: var(--bb-danger-600); }
.menu-item.is-danger > i, .dropdown-item.is-danger > i { color: var(--bb-danger-500); }
.menu-item.is-danger:hover, .dropdown-item.is-danger:hover { background: var(--bb-danger-50); }
.menu-item .shortcut { margin-left: auto; color: var(--bb-text-subtle); font-size: var(--bb-fs-xs); }

.menu-divider, .dropdown-divider {
    height: 1px;
    margin: var(--bb-s-3) calc(-1 * var(--bb-s-3));
    background: var(--bb-border-soft);
}
.menu-label {
    padding: var(--bb-s-4) var(--bb-s-5) var(--bb-s-2);
    font-size: var(--bb-fs-2xs);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-caps);
    text-transform: uppercase;
    color: var(--bb-text-subtle);
}

/* Notifications panel (topbar) */
.notification-dropdown { position: relative; }
.notification-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 348px;
    max-height: 460px;
    display: flex;
    flex-direction: column;
    background: var(--bb-surface);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-lg);
    box-shadow: var(--bb-shadow-lg);
    z-index: var(--bb-z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px) scale(.99);
    transform-origin: top right;
    transition: opacity var(--bb-t-fast) var(--bb-ease),
                transform var(--bb-t-fast) var(--bb-ease-out),
                visibility var(--bb-t-fast) var(--bb-ease);
    overflow: hidden;
}
.notification-panel.open, .notification-panel.show { opacity: 1; visibility: visible; transform: none; }
.notification-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--bb-s-6) var(--bb-s-7);
    border-bottom: 1px solid var(--bb-border-soft);
    flex-shrink: 0;
}
.notification-header h4 { margin: 0; font-size: var(--bb-fs-md); font-weight: var(--bb-fw-semibold); }
.mark-all-read { font-size: var(--bb-fs-sm); color: var(--bb-text-link); }
.notification-list { flex: 1; overflow-y: auto; }
.notification-item {
    display: flex; align-items: center; gap: var(--bb-s-5);
    padding: var(--bb-s-6) var(--bb-s-7);
    border-bottom: 1px solid var(--bb-border-soft);
    transition: background var(--bb-t-fast) var(--bb-ease);
}
.notification-item:last-child { border-bottom: 0; }
.notification-item:hover { background: var(--bb-surface-hover); }
.notification-item.unread { background: var(--bb-brand-50); }
.notification-item.unread:hover { background: var(--bb-brand-100); }
.notification-icon {
    width: 30px; height: 30px; flex: 0 0 30px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--bb-r-md);
    font-size: 12px;
}
.notification-content { min-width: 0; flex: 1; }
.notification-title {
    font-size: var(--bb-fs-base);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-text);
    line-height: var(--bb-lh-snug);
}
.notification-time { font-size: var(--bb-fs-xs); color: var(--bb-text-muted); margin-top: 1px; }
.notification-delete { flex-shrink: 0; border-radius: var(--bb-r-sm); }
.notification-delete:hover { background: var(--bb-danger-50); opacity: 1 !important; }
.notification-empty {
    padding: var(--bb-s-14) var(--bb-s-8);
    text-align: center;
    color: var(--bb-text-muted);
}
.notification-empty i { font-size: 22px; color: var(--bb-n-300); display: block; margin-bottom: var(--bb-s-5); }
.notification-empty p { margin: 0; font-size: var(--bb-fs-base); }
.notification-footer {
    padding: var(--bb-s-5);
    border-top: 1px solid var(--bb-border-soft);
    background: var(--bb-surface-inset);
    text-align: center;
    flex-shrink: 0;
}
.notification-footer a { font-size: var(--bb-fs-sm); font-weight: var(--bb-fw-medium); }

/* Search results dropdown (customer / item pickers) */
.search-dropdown, .autocomplete-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    max-height: 280px;
    overflow-y: auto;
    background: var(--bb-surface);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-md);
    box-shadow: var(--bb-shadow-md);
    z-index: var(--bb-z-dropdown);
    display: none;
    padding: var(--bb-s-3);
}
.search-dropdown.show, .search-dropdown.open, .autocomplete-list.show { display: block; }
.search-dropdown .dropdown-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    padding: var(--bb-s-5);
    white-space: normal;
}
.search-dropdown .dropdown-item .name { font-weight: var(--bb-fw-medium); font-size: var(--bb-fs-base); }
.search-dropdown .dropdown-item .details { font-size: var(--bb-fs-sm); color: var(--bb-text-muted); }
.search-input-wrapper { position: relative; }
/* A card clips its children and later cards paint over it, so an open
   results list was cut off or covered. While one is open, let its card
   overflow and sit above its siblings. */
.card:has(.search-dropdown.show, .search-dropdown.open, .autocomplete-list.show) {
    overflow: visible;
    position: relative;
    z-index: 20;
}


/* ==========================================================================
   17 · TOOLTIP
   ========================================================================== */

[data-tip] { position: relative; }
[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 7px);
    left: 50%;
    transform: translateX(-50%) translateY(3px);
    padding: 5px var(--bb-s-5);
    background: var(--bb-n-900);
    color: #fff;
    font-size: var(--bb-fs-xs);
    font-weight: var(--bb-fw-medium);
    line-height: 1.4;
    border-radius: var(--bb-r-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: var(--bb-shadow-md);
    transition: opacity var(--bb-t-fast) var(--bb-ease), transform var(--bb-t-fast) var(--bb-ease-out);
    z-index: var(--bb-z-tooltip);
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
[data-tip-pos="bottom"]::after { bottom: auto; top: calc(100% + 7px); transform: translateX(-50%) translateY(-3px); }
[data-tip-pos="bottom"]:hover::after { transform: translateX(-50%) translateY(0); }


/* ==========================================================================
   18 · TABS & SEGMENTED CONTROL
   ========================================================================== */

.tabs {
    display: flex;
    align-items: center;
    gap: var(--bb-s-8);
    border-bottom: 1px solid var(--bb-border);
    margin-bottom: var(--bb-s-9);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    position: relative;
    padding: var(--bb-s-6) 0;
    background: none;
    border: 0;
    font-family: var(--bb-font);
    font-size: var(--bb-fs-base);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-text-muted);
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: color var(--bb-t-fast) var(--bb-ease);
}
.tab::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 2px;
    background: var(--bb-brand-600);
    border-radius: 2px 2px 0 0;
    transform: scaleX(0);
    transition: transform var(--bb-t) var(--bb-ease-out);
}
.tab:hover { color: var(--bb-text); }
.tab.active, .tab[aria-selected="true"] { color: var(--bb-text); font-weight: var(--bb-fw-semibold); }
.tab.active::after, .tab[aria-selected="true"]::after { transform: scaleX(1); }
.tab .count {
    margin-left: var(--bb-s-3);
    padding: 1px 5px;
    font-size: var(--bb-fs-2xs);
    background: var(--bb-n-100);
    color: var(--bb-text-muted);
    border-radius: var(--bb-r-full);
}
.tab.active .count { background: var(--bb-brand-100); color: var(--bb-brand-700); }

/* Segmented control */
.segmented {
    display: inline-flex;
    padding: 2px;
    background: var(--bb-n-75);
    border-radius: var(--bb-r-md);
    gap: 2px;
}
.segmented button, .segmented a {
    padding: 5px var(--bb-s-6);
    background: transparent;
    border: 0;
    border-radius: var(--bb-r-sm);
    font-family: var(--bb-font);
    font-size: var(--bb-fs-sm);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-text-muted);
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background var(--bb-t-fast) var(--bb-ease), color var(--bb-t-fast) var(--bb-ease);
}
.segmented button:hover, .segmented a:hover { color: var(--bb-text); }
.segmented button.active, .segmented a.active {
    background: var(--bb-surface);
    color: var(--bb-text);
    box-shadow: var(--bb-shadow-xs);
}


/* ==========================================================================
   19 · PAGINATION
   ========================================================================== */

.pagination {
    display: flex;
    align-items: center;
    gap: var(--bb-s-2);
    flex-wrap: wrap;
}
.pagination a, .pagination span, .page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    padding: 0 var(--bb-s-4);
    font-size: var(--bb-fs-sm);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--bb-r-sm);
    text-decoration: none;
    transition: background var(--bb-t-fast) var(--bb-ease), color var(--bb-t-fast) var(--bb-ease);
}
.pagination a:hover, .page-link:hover { background: var(--bb-surface-hover); color: var(--bb-text); }
.pagination .active, .pagination a.active, .page-link.active {
    background: var(--bb-brand-600);
    border-color: var(--bb-brand-600);
    color: #fff;
}
.pagination .disabled, .pagination [aria-disabled="true"] { opacity: .4; pointer-events: none; }


/* ==========================================================================
   20 · AVATAR
   ========================================================================== */

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px; height: 30px;
    flex-shrink: 0;
    border-radius: var(--bb-r-md);
    background: var(--bb-n-100);
    color: var(--bb-n-600);
    font-size: var(--bb-fs-sm);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: .01em;
    text-transform: uppercase;
    overflow: hidden;
    user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-xs { width: 20px; height: 20px; font-size: var(--bb-fs-2xs); border-radius: var(--bb-r-sm); }
.avatar-sm { width: 26px; height: 26px; font-size: var(--bb-fs-xs); }
.avatar-lg { width: 40px; height: 40px; font-size: var(--bb-fs-md); border-radius: var(--bb-r-lg); }
.avatar-xl { width: 56px; height: 56px; font-size: var(--bb-fs-xl); border-radius: var(--bb-r-lg); }
.avatar-brand { background: var(--bb-brand-100); color: var(--bb-brand-700); }

/* Identity cell — avatar + name, the most common table pattern */
.identity { display: flex; align-items: center; gap: var(--bb-s-5); min-width: 0; }
.identity-body { min-width: 0; }
.identity-name {
    font-weight: var(--bb-fw-medium);
    color: var(--bb-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.identity-meta { font-size: var(--bb-fs-sm); color: var(--bb-text-muted); }

/* ---------------------------------------------------------------------------
   A long name must not widen the table it sits in.

   .identity-name already carries nowrap + ellipsis, but ellipsis only engages
   against a constrained width — and inside a `table-layout: auto` cell there
   is none, so the column simply grew to fit. One customer called
   "Ramachandran Textiles & Handloom Exports (Coimbatore Division) Private
   Limited" pushed the invoice table to 1688px inside a 1510px content area,
   which put the Total, Balance and Status columns behind a horizontal
   scrollbar on a 1920px monitor.

   A ch-based cap scales with the type size and truncates the name instead of
   the table. The full value stays available: the cell keeps its title
   attribute, and the row links to the record.
   --------------------------------------------------------------------------- */
.table-wrapper td .identity-name,
.table-wrapper td .truncate,
table.data-table td .identity-name { max-width: 26ch; }

@media (max-width: 1400px) {
    .table-wrapper td .identity-name,
    table.data-table td .identity-name { max-width: 20ch; }
}


/* ==========================================================================
   21 · COMMAND PALETTE
   ========================================================================== */

.cmdk-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 15, 20, .38);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: var(--bb-z-palette);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 12vh var(--bb-s-8) var(--bb-s-8);
}
.cmdk-overlay.open { display: flex; animation: bb-fade-in var(--bb-t-fast) var(--bb-ease); }

.cmdk {
    width: 100%;
    max-width: 600px;
    max-height: 62vh;
    display: flex;
    flex-direction: column;
    background: var(--bb-surface);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-xl);
    box-shadow: var(--bb-shadow-xl);
    overflow: hidden;
    animation: bb-modal-in var(--bb-t) var(--bb-ease-out);
}
.cmdk-input-wrap {
    display: flex;
    align-items: center;
    gap: var(--bb-s-6);
    padding: 0 var(--bb-s-8);
    height: 50px;
    border-bottom: 1px solid var(--bb-border-soft);
    flex-shrink: 0;
}
.cmdk-input-wrap > i { color: var(--bb-text-subtle); font-size: 14px; }
.cmdk-input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    font-family: var(--bb-font);
    font-size: var(--bb-fs-lg);
    color: var(--bb-text);
    outline: none;
    padding: 0;
    box-shadow: none;
}
.cmdk-input::placeholder { color: var(--bb-text-subtle); }
.cmdk-input:focus { box-shadow: none; border: 0; }

.cmdk-results { flex: 1; overflow-y: auto; padding: var(--bb-s-4); }
.cmdk-group-label {
    padding: var(--bb-s-5) var(--bb-s-5) var(--bb-s-3);
    font-size: var(--bb-fs-2xs);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-caps);
    text-transform: uppercase;
    color: var(--bb-text-subtle);
}
.cmdk-item {
    display: flex;
    align-items: center;
    gap: var(--bb-s-6);
    padding: var(--bb-s-5) var(--bb-s-5);
    border-radius: var(--bb-r-sm);
    color: var(--bb-text);
    text-decoration: none;
    cursor: pointer;
    scroll-margin: var(--bb-s-8);
}
.cmdk-item .cmdk-ico {
    width: 26px; height: 26px; flex: 0 0 26px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--bb-r-sm);
    background: var(--bb-n-75);
    color: var(--bb-n-500);
    font-size: 11px;
}
.cmdk-item .cmdk-body { min-width: 0; flex: 1; }
.cmdk-item .cmdk-title {
    font-size: var(--bb-fs-base);
    font-weight: var(--bb-fw-medium);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmdk-item .cmdk-meta {
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmdk-item .cmdk-hint { margin-left: auto; flex-shrink: 0; color: var(--bb-text-subtle); font-size: var(--bb-fs-xs); }
.cmdk-item.is-active, .cmdk-item:hover {
    background: var(--bb-brand-50);
}
.cmdk-item.is-active .cmdk-ico { background: var(--bb-brand-100); color: var(--bb-brand-600); }

.cmdk-empty {
    padding: var(--bb-s-14) var(--bb-s-8);
    text-align: center;
    color: var(--bb-text-muted);
    font-size: var(--bb-fs-base);
}
.cmdk-loading { display: flex; align-items: center; justify-content: center; gap: var(--bb-s-5); padding: var(--bb-s-12); color: var(--bb-text-muted); font-size: var(--bb-fs-sm); }

.cmdk-footer {
    display: flex;
    align-items: center;
    gap: var(--bb-s-7);
    padding: var(--bb-s-5) var(--bb-s-8);
    border-top: 1px solid var(--bb-border-soft);
    background: var(--bb-surface-inset);
    font-size: var(--bb-fs-xs);
    color: var(--bb-text-muted);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.cmdk-footer .hint { display: inline-flex; align-items: center; gap: var(--bb-s-3); }


/* ==========================================================================
   22 · MONEY & NUMERICS
   ========================================================================== */

.money, .amount, .currency, .stat-value, .metric-value,
.summary-row span:last-child, td.text-right, .total-row span {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

.money { white-space: nowrap; }
.money-lg { font-size: var(--bb-fs-xl); font-weight: var(--bb-fw-semibold); letter-spacing: -0.02em; }
.money-xl { font-size: var(--bb-fs-3xl); font-weight: var(--bb-fw-semibold); letter-spacing: -0.028em; }
.money-pos { color: var(--bb-success-700); }
.money-neg { color: var(--bb-danger-700); }
.money-zero { color: var(--bb-text-muted); }
.money-muted { color: var(--bb-text-muted); font-weight: var(--bb-fw-normal); }

/* Document summary rows */
.summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--bb-s-6);
    padding: var(--bb-s-5) 0;
    font-size: var(--bb-fs-base);
    color: var(--bb-text-secondary);
    border-bottom: 1px solid var(--bb-border-soft);
}
.summary-row:last-child { border-bottom: 0; }
.summary-row span:last-child { color: var(--bb-text); font-weight: var(--bb-fw-medium); }
.summary-row.total-row, .total-row {
    margin-top: var(--bb-s-3);
    padding-top: var(--bb-s-7);
    border-top: 1px solid var(--bb-border);
    border-bottom: 0;
    font-size: var(--bb-fs-lg);
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
}
.summary-row.total-row span:last-child,
.total-row span:last-child {
    font-size: var(--bb-fs-2xl);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: -0.022em;
    color: var(--bb-text);
}

/* Definition pairs (info-label / info-value) */
.info-label {
    display: block;
    font-size: var(--bb-fs-xs);
    font-weight: var(--bb-fw-medium);
    letter-spacing: var(--bb-tracking-wide);
    text-transform: uppercase;
    color: var(--bb-text-muted);
    margin-bottom: 2px;
}
.info-value {
    display: block;
    font-size: var(--bb-fs-base);
    color: var(--bb-text);
    font-weight: var(--bb-fw-medium);
    word-break: break-word;
}
.info-grid, .customer-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--bb-s-8);
}
.customer-info-box {
    padding: var(--bb-s-8);
    background: var(--bb-surface-inset);
    border: 1px solid var(--bb-border-soft);
    border-radius: var(--bb-r-md);
}

/* Definition list */
.dl { display: grid; grid-template-columns: auto 1fr; gap: var(--bb-s-4) var(--bb-s-9); font-size: var(--bb-fs-base); }
.dl dt { color: var(--bb-text-muted); }
.dl dd { margin: 0; color: var(--bb-text); font-weight: var(--bb-fw-medium); text-align: right; }


/* ==========================================================================
   23 · TIMELINE & ACTIVITY
   ========================================================================== */

.timeline { position: relative; padding-left: var(--bb-s-9); }
.timeline::before {
    content: "";
    position: absolute;
    left: 5px; top: 6px; bottom: 6px;
    width: 1px;
    background: var(--bb-border);
}
.timeline-item { position: relative; padding-bottom: var(--bb-s-9); }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
    content: "";
    position: absolute;
    left: calc(-1 * var(--bb-s-9) + 2px);
    top: 5px;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--bb-n-300);
    box-shadow: 0 0 0 3px var(--bb-surface);
}
.timeline-item.is-success::before { background: var(--bb-success-500); }
.timeline-item.is-danger::before  { background: var(--bb-danger-500); }
.timeline-item.is-current::before { background: var(--bb-brand-500); }
.timeline-title { font-size: var(--bb-fs-base); font-weight: var(--bb-fw-medium); color: var(--bb-text); }
.timeline-meta  { font-size: var(--bb-fs-sm); color: var(--bb-text-muted); margin-top: 1px; }

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: var(--bb-s-6);
    padding: var(--bb-s-6) 0;
    border-bottom: 1px solid var(--bb-border-soft);
}
.activity-item:last-child { border-bottom: 0; }
.activity-ico {
    width: 28px; height: 28px; flex: 0 0 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--bb-r-md);
    background: var(--bb-n-75);
    color: var(--bb-n-500);
    font-size: 11px;
}
.activity-body { min-width: 0; flex: 1; }
.activity-time { font-size: var(--bb-fs-xs); color: var(--bb-text-muted); white-space: nowrap; }


/* ==========================================================================
   24 · DOCUMENT WORKSPACE
   (invoice / estimate / sale-order / challan / proforma / bill editors)
   ========================================================================== */

.order-form-grid, .document-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 336px;
    gap: var(--bb-s-8);
    align-items: start;
}
.main-form-area { min-width: 0; }
.sidebar-form-area {
    position: sticky;
    top: calc(var(--bb-topbar-h) + var(--bb-s-8));
    display: flex;
    flex-direction: column;
    gap: var(--bb-s-8);
    min-width: 0;
}

/* Line items table inside document editors */
.line-items-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--bb-fs-base); }
.line-items-table thead th {
    padding: var(--bb-s-5) var(--bb-s-6);
    font-size: var(--bb-fs-xs);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-wide);
    text-transform: uppercase;
    color: var(--bb-text-muted);
    background: var(--bb-surface-head);
    border-bottom: 1px solid var(--bb-border);
    text-align: left;
    white-space: nowrap;
}
.line-items-table tbody td {
    padding: var(--bb-s-4) var(--bb-s-6);
    border-bottom: 1px solid var(--bb-border-soft);
    vertical-align: middle;
}
.line-items-table tbody tr:last-child td { border-bottom: 0; }
.line-items-table tbody tr:hover { background: var(--bb-surface-inset); }
.line-items-table .form-input,
.line-items-table input,
.line-items-table select {
    min-height: 30px;
    padding: 4px var(--bb-s-5);
    font-size: var(--bb-fs-base);
    box-shadow: none;
    border-color: transparent;
    background: transparent;
}
.line-items-table .form-input:hover,
.line-items-table input:hover,
.line-items-table select:hover { border-color: var(--bb-border); background: var(--bb-surface); }
.line-items-table .form-input:focus,
.line-items-table input:focus,
.line-items-table select:focus {
    border-color: var(--bb-border-focus);
    background: var(--bb-surface);
    box-shadow: var(--bb-ring);
}
.line-items-table .rate-input,
.line-items-table .qty-input,
.line-items-table input[type="number"] { text-align: right; }
.line-items-table .r-amt, .line-items-table .amount-cell {
    font-weight: var(--bb-fw-semibold);
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.items-card .card-body { padding: 0; }
.item-actions-btns { display: flex; align-items: center; gap: var(--bb-s-4); flex-wrap: wrap; }

/* Item search overlay inside document editors */
.item-search-modal {
    padding: var(--bb-s-7) var(--bb-s-8);
    background: var(--bb-surface-inset);
    border-bottom: 1px solid var(--bb-border-soft);
}

/* Walk-in customer capture block */
.walkin-fields {
    padding: var(--bb-s-8);
    background: var(--bb-surface-inset);
    border: 1px solid var(--bb-border-soft);
    border-radius: var(--bb-r-md);
}
.walkin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--bb-s-7); }

/* Compact empty state used between line items */
.empty-state-compact {
    padding: var(--bb-s-12) var(--bb-s-8);
    text-align: center;
    color: var(--bb-text-muted);
    font-size: var(--bb-fs-base);
}

/* Discount block */
.discount-section { padding: var(--bb-s-6) 0; border-bottom: 1px solid var(--bb-border-soft); }
.discount-header { display: flex; align-items: center; justify-content: space-between; gap: var(--bb-s-5); flex-wrap: wrap; }
.discount-label { font-size: var(--bb-fs-sm); font-weight: var(--bb-fw-medium); color: var(--bb-text-secondary); display: flex; align-items: center; gap: var(--bb-s-3); }
.discount-inputs { display: flex; align-items: center; gap: var(--bb-s-3); }
.discount-pct-input, .discount-amt-input { width: 74px; min-height: 28px; padding: 3px var(--bb-s-4); font-size: var(--bb-fs-sm); text-align: right; }
.discount-separator { font-size: var(--bb-fs-xs); color: var(--bb-text-muted); white-space: nowrap; }

/* Sticky action bar for long document forms */
.doc-actionbar {
    position: sticky;
    bottom: 0;
    z-index: var(--bb-z-sticky);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--bb-s-5);
    padding: var(--bb-s-6) var(--bb-s-8);
    margin: var(--bb-s-9) calc(-1 * var(--bb-page-pad)) calc(-1 * var(--bb-s-16));
    background: rgba(255,255,255,.9);
    backdrop-filter: saturate(180%) blur(10px);
    border-top: 1px solid var(--bb-border);
    flex-wrap: wrap;
}
.doc-actionbar .spacer { margin-right: auto; }

/* Document meta header (view screens) */
.doc-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--bb-s-9);
    flex-wrap: wrap;
    padding-bottom: var(--bb-s-8);
    margin-bottom: var(--bb-s-8);
    border-bottom: 1px solid var(--bb-border);
}
.doc-number {
    font-size: var(--bb-fs-2xl);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: -0.02em;
    display: flex; align-items: center; gap: var(--bb-s-5); flex-wrap: wrap;
}
.doc-amount {
    font-size: var(--bb-fs-4xl);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: -0.032em;
    font-variant-numeric: tabular-nums;
    line-height: 1.05;
}

/* --------------------------------------------------------------------------
   Record detail pages (payment, customer, vendor, item …).
   A main column of fact cards plus a narrower summary rail.
   -------------------------------------------------------------------------- */

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: var(--bb-s-8);
    align-items: start;
}
.detail-main, .detail-side {
    display: flex;
    flex-direction: column;
    gap: var(--bb-s-8);
    min-width: 0;                 /* lets long values wrap instead of stretching the grid */
}

/* Breadcrumb above the page title. */
.page-eyebrow {
    display: flex;
    align-items: center;
    gap: var(--bb-s-3);
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    margin-bottom: var(--bb-s-3);
    min-width: 0;
}
.page-eyebrow a { color: var(--bb-text-muted); text-decoration: none; }
.page-eyebrow a:hover { color: var(--bb-text-link); text-decoration: underline; }
.page-eyebrow i { font-size: 9px; opacity: .6; }
.page-eyebrow > span {
    color: var(--bb-text-secondary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.page-header-titles { min-width: 0; }

/* Label/value pairs. */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: var(--bb-s-8) var(--bb-s-9);
    margin: 0;
}
.detail-field { min-width: 0; }
.detail-field dt {
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    margin-bottom: var(--bb-s-3);
}
.detail-field dd {
    margin: 0;
    color: var(--bb-text);
    font-weight: var(--bb-fw-medium);
    /* Long GSTINs, emails and reference numbers must wrap, not overflow. */
    overflow-wrap: anywhere;
}
.detail-amount {
    font-size: var(--bb-fs-2xl);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: -0.02em;
}

.detail-block { margin-top: var(--bb-s-9); }
.detail-block-label {
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    margin-bottom: var(--bb-s-4);
}
.detail-note {
    background: var(--bb-surface-sunk);
    border: 1px solid var(--bb-border-soft);
    border-radius: var(--bb-r-md);
    padding: var(--bb-s-6);
    color: var(--bb-text-secondary);
    line-height: 1.6;
    overflow-wrap: anywhere;
}
.detail-foot {
    margin-top: var(--bb-s-9);
    padding-top: var(--bb-s-6);
    border-top: 1px solid var(--bb-border-soft);
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    display: flex; align-items: center; gap: var(--bb-s-3);
}

.ref-code {
    display: inline-block;
    background: var(--bb-surface-sunk);
    border: 1px solid var(--bb-border-soft);
    border-radius: var(--bb-r-sm);
    padding: 2px var(--bb-s-4);
    font-family: var(--bb-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: var(--bb-fs-sm);
    overflow-wrap: anywhere;
}

/* A link out to a related document. */
.linked-doc {
    display: flex;
    align-items: center;
    gap: var(--bb-s-6);
    padding: var(--bb-s-6);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-lg);
    text-decoration: none;
    color: inherit;
    transition: border-color .12s ease, background .12s ease;
    min-width: 0;
}
.linked-doc:hover { border-color: var(--bb-brand-300); background: var(--bb-surface-hover); }
.linked-doc-icon {
    width: 38px; height: 38px; flex-shrink: 0;
    display: grid; place-items: center;
    border-radius: var(--bb-r-md);
    background: var(--bb-brand-50);
    color: var(--bb-brand-600);
}
.linked-doc-body { min-width: 0; flex: 1; }
.linked-doc-title {
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.linked-doc-meta {
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.linked-doc-go { color: var(--bb-text-subtle); flex-shrink: 0; }

/* Stacked figures in a summary rail. */
.summary-rows { display: flex; flex-direction: column; gap: var(--bb-s-5); }
.summary-rows .summary-row {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: var(--bb-s-5);
    font-size: var(--bb-fs-base);
    color: var(--bb-text-secondary);
}
.summary-rows .summary-row-total {
    margin-top: var(--bb-s-3);
    padding-top: var(--bb-s-5);
    border-top: 1px solid var(--bb-border);
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
}
.summary-status {
    margin-top: var(--bb-s-8);
    padding-top: var(--bb-s-6);
    border-top: 1px solid var(--bb-border-soft);
    display: flex; align-items: center; justify-content: space-between; gap: var(--bb-s-5);
}
.summary-status-label { font-size: var(--bb-fs-sm); color: var(--bb-text-muted); }

.action-stack { display: flex; flex-direction: column; gap: var(--bb-s-4); }
.action-stack .btn { justify-content: center; }

@media (max-width: 1024px) {
    .detail-layout { grid-template-columns: minmax(0, 1fr); }
}

/* Single-column variant, for a detail grid inside a narrow rail. */
.detail-grid-1 { grid-template-columns: minmax(0, 1fr); gap: var(--bb-s-6); }

/* A card nested inside another surface — flat, so cards don't stack shadows. */
.card-inset { box-shadow: none; background: var(--bb-surface-sunk); }

/* Identity block: avatar + name + contact chips. */
.identity { display: flex; align-items: center; gap: var(--bb-s-7); min-width: 0; }
.identity-body { min-width: 0; }
.identity-meta {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: var(--bb-s-4) var(--bb-s-7);
    margin-top: var(--bb-s-3);
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    min-width: 0;
}
.identity-meta > * {
    display: inline-flex; align-items: center; gap: var(--bb-s-3);
    min-width: 0; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.identity-meta a { color: var(--bb-text-muted); text-decoration: none; }
.identity-meta a:hover { color: var(--bb-text-link); text-decoration: underline; }
.identity-meta i { flex-shrink: 0; opacity: .75; }
/* GSTINs are 15 chars and must never be truncated — they are identifiers. */
.identity-meta .gstin {
    font-variant-numeric: tabular-nums;
    letter-spacing: .01em;
    white-space: nowrap; overflow: visible; text-overflow: clip;
}

.section-title {
    font-size: var(--bb-fs-md);
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
    margin: 0 0 var(--bb-s-6);
}

/* Tabs: count pill, and the panels they switch between. */
.tab-count {
    display: inline-block;
    margin-left: var(--bb-s-3);
    padding: 0 6px;
    min-width: 18px;
    border-radius: 9px;
    background: var(--bb-surface-sunk);
    border: 1px solid var(--bb-border-soft);
    font-size: var(--bb-fs-xs);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-text-muted);
    font-variant-numeric: tabular-nums;
}
.tab.active .tab-count, .tab[aria-selected="true"] .tab-count {
    background: var(--bb-brand-50); border-color: var(--bb-brand-200); color: var(--bb-brand-700);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Table cells: numeric alignment, a strong first cell, and an actions column. */
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-strong { font-weight: var(--bb-fw-semibold); color: var(--bb-text); text-decoration: none; }
a.cell-strong:hover { color: var(--bb-text-link); text-decoration: underline; }

/* A table cell that links somewhere without shouting about it. */
.cell-link { color: var(--bb-text); text-decoration: none; }
.cell-link:hover { color: var(--bb-text-link); text-decoration: underline; }

/* Long free text in a table cell — a 90-character customer name, a pasted
   note, a supplier reference. Clamps to two lines and ellipsises rather than
   stretching the column until the whole table needs a horizontal scrollbar.
   Never shrink the type to make text fit; clamp it and keep it readable. */
.cell-clamp {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    max-width: 32ch;
}

/* Secondary line under a cell's primary value. */
.cell-sub {
    display: flex;
    align-items: center;
    gap: var(--bb-s-3);
    margin-top: 2px;
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
}
.cell-sub i { font-size: 10px; opacity: .75; }

/* Compact form controls, for a filter bar inside a card header. */
.form-input-sm, .form-select-sm {
    min-height: 30px;
    padding: 3px var(--bb-s-5);
    font-size: var(--bb-fs-sm);
}

/* A deliberately quiet status: cancelled, closed, not applicable. */
.status-muted {
    background: var(--bb-surface-sunk);
    color: var(--bb-text-muted);
}

/* Supporting points under an empty state — what the feature actually does,
   shown while the user has no data to look at yet. */
.empty-hints {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--bb-s-8);
    margin-top: var(--bb-s-9);
    padding-top: var(--bb-s-9);
    border-top: 1px solid var(--bb-border-soft);
    text-align: left;
}
.empty-hint { display: flex; gap: var(--bb-s-6); align-items: flex-start; }
.empty-hint > i {
    flex: 0 0 28px;
    width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--bb-r-sm);
    background: var(--bb-brand-50);
    color: var(--bb-brand-600);
    font-size: 12px;
}
.empty-hint strong { display: block; font-size: var(--bb-fs-base); color: var(--bb-text); }
.empty-hint p {
    margin: 2px 0 0;
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    line-height: var(--bb-lh-normal);
}

/* On a phone the clamp's width cap fights the stacked card layout — the row
   is already narrow, so let the text use it. */
@media (max-width: 900px) {
    .cell-clamp { max-width: none; -webkit-line-clamp: 3; }
}

.table th.col-actions, .table td.col-actions { text-align: right; white-space: nowrap; width: 1%; }

/* --------------------------------------------------------------------------
   Payment allocation (receive payment against several open invoices).
   -------------------------------------------------------------------------- */

.form-row-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.allocation-list {
    display: flex; flex-direction: column; gap: var(--bb-s-4);
    margin-bottom: var(--bb-s-8);
}
.pending-invoice-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto 150px;
    align-items: center;
    gap: var(--bb-s-6);
    padding: var(--bb-s-6);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-lg);
    background: var(--bb-surface);
    transition: border-color .12s ease, background .12s ease;
}
.pending-invoice-item:hover { border-color: var(--bb-border-strong, var(--bb-border)); }
.pending-invoice-item.selected {
    border-color: var(--bb-brand-300);
    background: var(--bb-brand-50);
}
.pending-invoice-checkbox { width: 16px; height: 16px; margin: 0; flex-shrink: 0; }

.allocation-doc { min-width: 0; cursor: pointer; margin: 0; display: block; }
.allocation-doc-no {
    display: block;
    font-weight: var(--bb-fw-semibold);
    color: var(--bb-text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.allocation-doc-meta {
    display: block;
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.allocation-due { text-align: right; white-space: nowrap; }
.allocation-due-label {
    display: block;
    font-size: var(--bb-fs-xs);
    color: var(--bb-text-muted);
    margin-bottom: 2px;
}
.allocation-field { min-width: 0; }
.allocation-input { text-align: right; font-variant-numeric: tabular-nums; }

.allocation-summary {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: var(--bb-s-6);
    padding: var(--bb-s-7);
    background: var(--bb-surface-sunk);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-r-lg);
}
.allocation-summary-total {
    display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--bb-s-4);
    min-width: 0;
}
.allocation-status { font-size: var(--bb-fs-sm); color: var(--bb-text-muted); }
.allocation-status.is-danger  { color: var(--bb-danger-700); }
.allocation-status.is-warning { color: var(--bb-warn-700); }
.allocation-status.is-success { color: var(--bb-success-700); }

@media (max-width: 720px) {
    /* Stack the allocation row so nothing is squeezed on a phone. */
    .pending-invoice-item {
        grid-template-columns: auto minmax(0, 1fr);
        row-gap: var(--bb-s-5);
    }
    .allocation-due, .allocation-field { grid-column: 2; text-align: left; }
    .allocation-due { display: flex; align-items: baseline; gap: var(--bb-s-4); }
    .allocation-due .allocation-due-label { margin-bottom: 0; }
}


/* ==========================================================================
   24b · LEGACY PATTERN NORMALISATION
   --------------------------------------------------------------------------
   A number of older views hand-roll their overlays with inline styles
   (`<div id="...Modal" style="position:fixed; background:rgba(0,0,0,.5)">`).
   Rewriting all sixteen call sites would touch a dozen files for no
   behavioural gain, so the pattern is adopted into the design system here
   instead. Inline declarations can only be beaten with !important — that is
   the whole reason this block exists, and it is deliberately the only place
   in the stylesheet that uses it.

   The `display` property is intentionally NOT touched: those modals are
   opened and closed by setting `style.display` from JavaScript, and that
   contract must keep working.
   ========================================================================== */

div[id$="Modal"][style*="position: fixed"],
div[id$="modal"][style*="position: fixed"] {
    background: rgba(13, 15, 20, .44) !important;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    align-items: center !important;
    justify-content: center !important;
    padding: var(--bb-s-9) !important;
    overflow-y: auto;
    z-index: var(--bb-z-modal) !important;
}

/* The white panel inside a hand-rolled overlay */
div[id$="Modal"][style*="position: fixed"] > div,
div[id$="modal"][style*="position: fixed"] > div {
    background: var(--bb-surface) !important;
    border-radius: var(--bb-r-xl) !important;
    box-shadow: var(--bb-shadow-xl) !important;
    max-height: calc(100vh - var(--bb-s-16));
    overflow-y: auto;
    animation: bb-modal-in var(--bb-t-slow) var(--bb-ease-out);
}

/* Headings inside those panels pick up the modal title treatment */
div[id$="Modal"][style*="position: fixed"] > div > h3:first-child {
    font-size: var(--bb-fs-lg);
    font-weight: var(--bb-fw-semibold);
    letter-spacing: var(--bb-tracking-tight);
}

@media (max-width: 768px) {
    div[id$="Modal"][style*="position: fixed"],
    div[id$="modal"][style*="position: fixed"] {
        align-items: flex-end !important;
        padding: var(--bb-s-5) !important;
    }
    div[id$="Modal"][style*="position: fixed"] > div {
        width: 100% !important;
        max-width: none !important;
        max-height: 90vh;
    }
}



/* --------------------------------------------------------------------------
   Recurring billing
   -------------------------------------------------------------------------- */

/* Radio-backed segmented control. The existing .segmented styles buttons and
   links; this variant wraps a real <input type="radio"> so the choice posts
   with the form and stays keyboard- and screen-reader-navigable. */
.segmented-option {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--bb-s-4);
    padding: 7px var(--bb-s-7);
    border-radius: var(--bb-r-sm);
    font-size: var(--bb-fs-base);
    font-weight: var(--bb-fw-medium);
    color: var(--bb-text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--bb-t-fast) var(--bb-ease), color var(--bb-t-fast) var(--bb-ease);
}
.segmented-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.segmented-option i { font-size: 12px; opacity: .8; }
.segmented-option:hover { color: var(--bb-text); }
.segmented-option.is-active {
    background: var(--bb-surface);
    color: var(--bb-text);
    box-shadow: var(--bb-shadow-xs);
}
.segmented-option:focus-within {
    outline: 2px solid var(--bb-brand-500);
    outline-offset: 1px;
}

/* Number input with a trailing unit ("30 days to pay", "every 2 months").
   The unit is a label, not a placeholder, so it stays visible while typing. */
.input-suffix {
    display: flex;
    align-items: center;
    gap: var(--bb-s-5);
}
.input-suffix .form-input { max-width: 110px; }
.input-suffix > span {
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    white-space: nowrap;
}

/* "Here are the next four billing dates" — makes an abstract schedule
   concrete before the user commits to it. */
.schedule-preview {
    margin-top: var(--bb-s-7);
    padding: var(--bb-s-6) var(--bb-s-7);
    border: 1px dashed var(--bb-border);
    border-radius: var(--bb-r-md);
    background: var(--bb-surface-inset);
}
.schedule-preview:empty { display: none; }
.schedule-preview-label {
    font-size: var(--bb-fs-xs);
    font-weight: var(--bb-fw-medium);
    letter-spacing: var(--bb-tracking-wide);
    text-transform: uppercase;
    color: var(--bb-text-muted);
    margin-bottom: var(--bb-s-4);
}
.schedule-preview-row {
    display: flex;
    justify-content: space-between;
    gap: var(--bb-s-6);
    padding: 3px 0;
    font-size: var(--bb-fs-sm);
    font-variant-numeric: tabular-nums;
}
.schedule-preview-row > span:first-child { color: var(--bb-text-muted); }
.schedule-preview-row > span:last-child  { color: var(--bb-text); font-weight: var(--bb-fw-medium); }

/* Line-item editor rows keep their columns rather than collapsing to cards:
   a spreadsheet-shaped editor is easier to scan side by side, and the wrapper
   scrolls horizontally on a phone (see .table-keep). */
#lineTable .form-input-sm,
#lineTable .form-select-sm { width: 100%; }
#lineTable td { vertical-align: top; }

/* Run history */
.run-list { display: flex; flex-direction: column; }
.run-row {
    display: flex;
    align-items: center;
    gap: var(--bb-s-6);
    padding: var(--bb-s-6) 0;
    border-bottom: 1px solid var(--bb-border-soft);
    font-size: var(--bb-fs-base);
}
.run-row:last-child { border-bottom: 0; }
.run-icon {
    flex: 0 0 26px;
    width: 26px; height: 26px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 11px;
}
.run-icon.is-success { background: var(--bb-success-50); color: var(--bb-success-700); }
.run-icon.is-failed  { background: var(--bb-danger-50);  color: var(--bb-danger-700); }
.run-icon.is-skipped { background: var(--bb-n-75);       color: var(--bb-text-muted); }
.run-icon.is-running { background: var(--bb-info-50);   color: var(--bb-info-700); }
.run-icon.is-running i { animation: bb-spin 1s linear infinite; }
.run-body { flex: 1; min-width: 0; }
.run-title { font-weight: var(--bb-fw-medium); }
.run-meta  { font-size: var(--bb-fs-sm); color: var(--bb-text-muted); overflow-wrap: anywhere; }

@media (max-width: 560px) {
    .segmented { display: flex; width: 100%; }
    .segmented-option { flex: 1; justify-content: center; padding: 9px var(--bb-s-5); }
}

/* ==========================================================================
   25 · UTILITIES
   ========================================================================== */

/* Display / flex / grid */
.d-flex, .flex { display: flex; }
.d-inline-flex, .inline-flex { display: inline-flex; }
.d-block, .block { display: block; }
.d-inline-block, .inline-block { display: inline-block; }
.d-none, .hidden { display: none; }
.d-grid, .grid { display: grid; }

.flex-col, .flex-column { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-nowrap { flex-wrap: nowrap; }
.flex-1 { flex: 1; min-width: 0; }
.flex-shrink-0 { flex-shrink: 0; }

.items-center, .align-items-center { align-items: center; }
.items-start,  .align-items-start  { align-items: flex-start; }
.items-end,    .align-items-end    { align-items: flex-end; }
.items-baseline { align-items: baseline; }
.items-stretch { align-items: stretch; }

.justify-between, .justify-content-between { justify-content: space-between; }
.justify-center,  .justify-content-center  { justify-content: center; }
.justify-end,     .justify-content-end     { justify-content: flex-end; }
.justify-start,   .justify-content-start   { justify-content: flex-start; }

.gap-1 { gap: var(--bb-s-2); }
.gap-2 { gap: var(--bb-s-4); }
.gap-3 { gap: var(--bb-s-6); }
.gap-4 { gap: var(--bb-s-8); }
.gap-5 { gap: var(--bb-s-10); }
.gap-6 { gap: var(--bb-s-12); }

/* Bootstrap-compatible grid (several legacy views reference it) */
.row {
    display: flex;
    flex-wrap: wrap;
    margin-left: calc(-1 * var(--bb-s-5));
    margin-right: calc(-1 * var(--bb-s-5));
}
.row > [class*="col-"] { padding-left: var(--bb-s-5); padding-right: var(--bb-s-5); min-width: 0; }
.col     { flex: 1 0 0%; }
.col-12  { flex: 0 0 100%;      max-width: 100%; }
.col-6   { flex: 0 0 50%;       max-width: 50%; }
.col-4   { flex: 0 0 33.3333%;  max-width: 33.3333%; }
.col-3   { flex: 0 0 25%;       max-width: 25%; }
.col-8   { flex: 0 0 66.6667%;  max-width: 66.6667%; }
.col-9   { flex: 0 0 75%;       max-width: 75%; }
@media (min-width: 768px) {
    .col-md-12 { flex: 0 0 100%;     max-width: 100%; }
    .col-md-8  { flex: 0 0 66.6667%; max-width: 66.6667%; }
    .col-md-6  { flex: 0 0 50%;      max-width: 50%; }
    .col-md-4  { flex: 0 0 33.3333%; max-width: 33.3333%; }
    .col-md-3  { flex: 0 0 25%;      max-width: 25%; }
}
@media (max-width: 767.98px) {
    .row > [class*="col-md-"] { flex: 0 0 100%; max-width: 100%; }
}

/* Spacing (Bootstrap + Tailwind-compatible names) */
.m-0  { margin: 0; }
.mt-0 { margin-top: 0; }      .mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: var(--bb-s-2); }  .mb-1 { margin-bottom: var(--bb-s-2); }
.mt-2 { margin-top: var(--bb-s-4); }  .mb-2 { margin-bottom: var(--bb-s-4); }
.mt-3 { margin-top: var(--bb-s-6); }  .mb-3 { margin-bottom: var(--bb-s-6); }
.mt-4 { margin-top: var(--bb-s-8); }  .mb-4 { margin-bottom: var(--bb-s-8); }
.mt-5 { margin-top: var(--bb-s-10); } .mb-5 { margin-bottom: var(--bb-s-10); }
.mt-6 { margin-top: var(--bb-s-12); } .mb-6 { margin-bottom: var(--bb-s-12); }
.ms-auto, .ml-auto { margin-left: auto; }
.me-auto, .mr-auto { margin-right: auto; }
.me-1, .mr-1 { margin-right: var(--bb-s-2); }
.me-2, .mr-2 { margin-right: var(--bb-s-4); }
.me-3, .mr-3 { margin-right: var(--bb-s-6); }
.ms-1, .ml-1 { margin-left: var(--bb-s-2); }
.ms-2, .ml-2 { margin-left: var(--bb-s-4); }
.ms-3, .ml-3 { margin-left: var(--bb-s-6); }
.p-0 { padding: 0; }
.p-2 { padding: var(--bb-s-4); }
.p-3 { padding: var(--bb-s-6); }
.p-4 { padding: var(--bb-s-8); }

/* Text */
.text-left   { text-align: left; }
.text-center { text-align: center; }
.text-xs   { font-size: var(--bb-fs-xs); }
.text-sm   { font-size: var(--bb-fs-sm); }
.text-base { font-size: var(--bb-fs-base); }
.text-md   { font-size: var(--bb-fs-md); }
.text-lg   { font-size: var(--bb-fs-lg); }
.text-xl   { font-size: var(--bb-fs-xl); }
.text-2xl  { font-size: var(--bb-fs-2xl); }

.fw-400, .fw-normal, .font-normal { font-weight: var(--bb-fw-normal); }
.fw-500, .fw-medium, .font-medium { font-weight: var(--bb-fw-medium); }
.fw-600, .fw-semibold, .font-semibold { font-weight: var(--bb-fw-semibold); }
.fw-700, .fw-bold, .font-bold { font-weight: var(--bb-fw-bold); }

.text-muted, .text-secondary { color: var(--bb-text-muted); }
.text-subtle { color: var(--bb-text-subtle); }
.text-body { color: var(--bb-text); }
.text-primary  { color: var(--bb-text-link); }
.text-success  { color: var(--bb-success-700); }
.text-danger, .text-error { color: var(--bb-danger-700); }
.text-warning  { color: var(--bb-warn-700); }
.text-info     { color: var(--bb-info-700); }
.text-white    { color: #fff; }

.truncate, .text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.text-nowrap { white-space: nowrap; }
.text-break  { word-break: break-word; overflow-wrap: anywhere; }
.uppercase   { text-transform: uppercase; letter-spacing: var(--bb-tracking-wide); }
.tabular     { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.nowrap      { white-space: nowrap; }
.text-right  { text-align: right; }
/* The label half of a label/value pair — the single most repeated inline
   style in this codebase, previously written out longhand in ~30 places. */
.field-label {
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
    margin-bottom: var(--bb-s-4);
}
.field-value { font-weight: var(--bb-fw-semibold); color: var(--bb-text); overflow-wrap: anywhere; }
/* A table cell whose text may be long: let it wrap, and break unbroken runs. */
.cell-wrap   { white-space: normal; overflow-wrap: anywhere; min-width: 160px; }
.mono        { font-family: var(--bb-font-mono); font-size: 0.94em; }

/* Backgrounds & borders */
.bg-white   { background: var(--bb-surface); }
.bg-subtle  { background: var(--bb-surface-inset); }
.bg-sunk    { background: var(--bb-surface-sunk); }
.border     { border: 1px solid var(--bb-border); }
.border-0   { border: 0; }
.border-t   { border-top: 1px solid var(--bb-border); }
.border-b   { border-bottom: 1px solid var(--bb-border); }
.rounded    { border-radius: var(--bb-r); }
.rounded-md { border-radius: var(--bb-r-md); }
.rounded-lg { border-radius: var(--bb-r-lg); }
.rounded-full { border-radius: var(--bb-r-full); }
.shadow-none{ box-shadow: none; }
.shadow-sm  { box-shadow: var(--bb-shadow-sm); }
.shadow     { box-shadow: var(--bb-shadow); }

.w-full { width: 100%; }
.h-full { height: 100%; }
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.pointer { cursor: pointer; }
.relative { position: relative; }
.absolute { position: absolute; }
.sticky { position: sticky; }

/* Layout blocks */
.stack   { display: flex; flex-direction: column; gap: var(--bb-s-8); }
.stack-sm{ display: flex; flex-direction: column; gap: var(--bb-s-5); }
.cluster { display: flex; align-items: center; gap: var(--bb-s-5); flex-wrap: wrap; }

/* Inline filter bar for a card header. .form-select/.form-input are
   width:100% by default (they are built for stacked form rows), so dropping
   them into a flex cluster makes each one claim a full line and the header
   grows into a column. These give them an intrinsic width again. */
.filter-bar { display: flex; align-items: center; gap: var(--bb-s-4); flex-wrap: wrap; }
.filter-bar .form-input,
.filter-bar .form-select { width: auto; min-width: 130px; max-width: 200px; }
.filter-bar .form-input[type="search"] { min-width: 160px; }
@media (max-width: 560px) {
    .filter-bar { width: 100%; }
    .filter-bar .form-input,
    .filter-bar .form-select { flex: 1 1 130px; max-width: none; }
}

.split   { display: flex; align-items: center; justify-content: space-between; gap: var(--bb-s-6); }
.grid-2  { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--bb-s-8); }
.grid-3  { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--bb-s-8); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--bb-s-8); }

/* Dashboard split grids used by existing views */
.dashboard-grid   { display: grid; grid-template-columns: 2fr 1fr; gap: var(--bb-s-8); align-items: start; }
.dashboard-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--bb-s-8); align-items: start; }


/* ==========================================================================
   26 · RESPONSIVE
   ========================================================================== */

/* Laptop */
@media (max-width: 1280px) {
    :root { --bb-sidebar-w: 232px; --bb-page-pad: var(--bb-s-9); }
    .order-form-grid, .document-grid { grid-template-columns: minmax(0, 1fr) 300px; }
}

/* Tablet landscape */
@media (max-width: 1080px) {
    .order-form-grid, .document-grid { grid-template-columns: 1fr; }
    .sidebar-form-area { position: static; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .metric-strip { grid-template-columns: repeat(2, 1fr); }
    .metric { border-bottom: 1px solid var(--bb-border-soft); }
    .metric:nth-child(2n) { border-right: 0; }
}

/* Tablet / mobile — sidebar becomes an off-canvas drawer */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--bb-shadow-xl);
        width: 268px;
    }
    .sidebar.open { transform: none; }
    .sidebar.is-collapsed { width: 268px; }
    /* The drawer is always full width, so a persisted "collapsed" rail state
       from a desktop session must not shrink it. `display: revert` is wrong
       for the wordmark — it would fall back to the UA's inline default and
       break the lockup — so the image is restored explicitly. */
    .sidebar.is-collapsed .nav-link span,
    .sidebar.is-collapsed .sidebar-user-info,
    .sidebar.is-collapsed .sidebar-logout,
    .sidebar.is-collapsed .nav-section-title { display: revert; }
    .sidebar.is-collapsed .sidebar-brand-wordmark { display: block; }
    .sidebar.is-collapsed .sidebar-brand-mark     { display: none; }
    .sidebar.is-collapsed .plan-badge             { display: inline-block; }
    .sidebar.is-collapsed .sidebar-brand {
        justify-content: flex-start;
        padding: 0 var(--bb-s-7);
    }
    .sidebar.is-collapsed .sidebar-user { justify-content: flex-start; padding: var(--bb-s-4); }
    .sidebar.is-collapsed .nav-link { justify-content: flex-start; padding: 7px var(--bb-s-4); }
    .sidebar.is-collapsed .nav-link::after { display: none; }
    .sidebar-collapse-btn { display: none; }

    .main-content,
    body.sidebar-collapsed .main-content { margin-left: 0; }
    .mobile-toggle { display: inline-flex; }
    .header-search { display: none; }
    .grid-2, .grid-3, .dashboard-grid-2, .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
}

/* Small tablet */
@media (max-width: 768px) {
    :root { --bb-page-pad: var(--bb-s-8); --bb-topbar-h: 52px; }
    .page-content { padding-top: var(--bb-s-8); padding-bottom: var(--bb-s-14); }
    .page-title { font-size: var(--bb-fs-xl); }
    .page-header-row { flex-direction: column; align-items: stretch; gap: var(--bb-s-6); }

    /* Page actions become a wrapping row, not a stack of full-width buttons.
       Stretching everything left icon-only controls (the "hide figures" eye,
       the overflow "…") sitting alone and centred on their own line, reading
       as an orphaned glyph rather than a button. Labelled buttons still grow
       to share the row; icon-only ones keep their square footprint. */
    .page-actions { width: 100%; flex-wrap: wrap; }
    .page-actions > .btn:not(.btn-icon),
    .page-actions > .dropdown > .btn:not(.btn-icon) { flex: 1 1 auto; justify-content: center; }
    .page-actions > .btn.btn-icon,
    .page-actions > .dropdown > .btn.btn-icon { flex: 0 0 auto; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--bb-s-5); }
    .stat-card { padding: var(--bb-s-7); }
    .stat-value { font-size: var(--bb-fs-2xl); }
    /* Two up, not one tile per row.
       Four full-width tiles consumed the entire first screen of every list
       page on a phone — you scrolled past a wall of numbers before reaching
       a single invoice. A 2×2 block carries the same four figures in a
       quarter of the height, so the list itself starts above the fold. */
    .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric { padding: var(--bb-s-6) var(--bb-s-7); }
    .metric:nth-child(2n) { border-right: 0; }
    .metric-value { font-size: var(--bb-fs-xl); }
    .metric-note  { font-size: var(--bb-fs-xs); }
    .card-header { padding: var(--bb-s-6); }
    .card-body { padding: var(--bb-s-6); }
    .card-body > .table-wrapper:only-child { margin: calc(-1 * var(--bb-s-6)); }
    .modal-overlay { padding: var(--bb-s-5); align-items: flex-end; }
    .modal, .modal-content { max-height: 90vh; border-radius: var(--bb-r-xl) var(--bb-r-xl) 0 0; }
    .toast-stack { left: var(--bb-s-5); right: var(--bb-s-5); bottom: var(--bb-s-5); max-width: none; }
    .drawer { width: 100vw; }
    .doc-actionbar { margin-left: calc(-1 * var(--bb-s-8)); margin-right: calc(-1 * var(--bb-s-8)); }
    .cmdk-overlay { padding-top: 6vh; }
}

/* Phone — tables become stacked records */
@media (max-width: 640px) {
    :root { --bb-page-pad: var(--bb-s-6); }

    /* Two up, compact. One per row put ~400px of tiles (four full-width
       cards, each an icon row plus a figure) ahead of the first record on
       every list: the estimates, purchase and stock screens opened on a
       wall of summary. A long rupee figure wraps instead of overflowing. */
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--bb-s-4); }
    .stats-grid .stat-card { padding: var(--bb-s-5) var(--bb-s-6); min-width: 0; }
    .stats-grid .stat-header { margin-bottom: var(--bb-s-3); }
    .stats-grid .stat-value { font-size: var(--bb-fs-lg); overflow-wrap: anywhere; }

    /* Page actions stay a WRAPPING ROW on a phone, not a column of
       full-width buttons.
       `flex-direction: column` + `width: 100%` gave every control its own
       line, which turned icon-only controls — the invoice list's show/hide
       figures eye, an overflow "…" — into a lone glyph floating on an
       otherwise empty row, reading as a rendering fault rather than a button.
       It also pushed the actual content three button-heights further down on
       the one screen size with the least room to spare.
       Labelled buttons share the row and grow to fill it; icon-only buttons
       keep their square footprint beside them. */
    .page-actions { flex-direction: row; flex-wrap: wrap; align-items: center; }
    .page-actions > .btn:not(.btn-icon),
    .page-actions > .dropdown { flex: 1 1 auto; }
    .page-actions > .dropdown > .btn:not(.btn-icon) { width: 100%; justify-content: center; }
    .page-actions > .btn.btn-icon,
    .page-actions > .dropdown:has(> .btn.btn-icon) { flex: 0 0 auto; }
    .page-actions > .dropdown > .btn.btn-icon { width: var(--btn-h); }

    .btn-text { display: none; }
    .page-actions .btn-text { display: inline; }

    /* Card-per-row table mode. Opt out with .table-keep on the wrapper. */
    .table-wrapper:not(.table-keep) table { display: block; }
    .table-wrapper:not(.table-keep) thead { display: none; }
    .table-wrapper:not(.table-keep) tbody { display: block; }
    .table-wrapper:not(.table-keep) tbody tr {
        display: block;
        padding: var(--bb-s-6) var(--bb-s-7);
        border-bottom: 1px solid var(--bb-border);
    }
    .table-wrapper:not(.table-keep) tbody tr:last-child { border-bottom: 0; }
    .table-wrapper:not(.table-keep) tbody td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--bb-s-6);
        padding: 3px 0;
        border: 0;
        text-align: right;
    }
    .table-wrapper:not(.table-keep) tbody td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-size: var(--bb-fs-xs);
        font-weight: var(--bb-fw-medium);
        letter-spacing: var(--bb-tracking-wide);
        text-transform: uppercase;
        color: var(--bb-text-muted);
        text-align: left;
    }
    /* Cells with no label render full-width (first cell, action cell) */
    .table-wrapper:not(.table-keep) tbody td:not([data-label]) { justify-content: flex-start; text-align: left; }

    /* ------------------------------------------------------------------
       Prioritised record cards.

       Only applies to tables whose <thead> declares data-m on at least one
       column (the stamper adds .has-mobile-cards). Everything else keeps the
       plain label/value stack above, so this cannot disturb a table nobody
       has reviewed.

       Two lines and a disclosure — the shape a list actually needs on a
       phone. Transposing all nine columns gave each invoice a screenful,
       which made the list useless precisely where a list matters most:

           B2B-0027                          ₹42,500  ⌄
           Zenith Exports                Outstanding

       Exactly one column may be `sub`. Two supporting columns would have to
       share a line, and the sibling-selector gymnastics that took collapsed
       the moment a cell was empty. Anything else that earns a place goes to
       `fold` and is one tap away.
       ------------------------------------------------------------------ */
    /* NOTE ON SPECIFICITY.
       The generic card rules above are written as
       `.table-wrapper:not(.table-keep) tbody tr`, which carries three classes
       of specificity. Written as `.has-mobile-cards tbody tr` these lost to
       it: `display: grid` never applied, so every explicit grid-column and
       grid-row below sat inert on a block-level cell and the card silently
       rendered as the old one-value-per-line stack. They are scoped through
       the wrapper to outrank it. Do not "simplify" these selectors. */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: var(--bb-s-5);
        row-gap: 3px;
    }

    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="lead"] {
        grid-column: 1; grid-row: 1;
        justify-content: flex-start;
        gap: var(--bb-s-3);
        font-size: var(--bb-fs-base);
        font-weight: var(--bb-fw-semibold);
        text-align: left;
        padding: 0;
        min-width: 0;
    }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="amt"] {
        grid-column: 2; grid-row: 1;
        justify-content: flex-end;
        font-size: var(--bb-fs-base);
        font-weight: var(--bb-fw-semibold);
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        padding: 0;
    }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="sub"] {
        grid-column: 1; grid-row: 2;
        justify-content: flex-start;
        font-size: var(--bb-fs-xs);
        color: var(--bb-text-muted);
        text-align: left;
        padding: 0;
        min-width: 0;
    }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="status"] {
        grid-column: 2; grid-row: 2;
        justify-content: flex-end;
        padding: 0;
    }

    /* Long names truncate rather than pushing the amount off the card. */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="lead"] > *,
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="sub"] > * { min-width: 0; }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="lead"],
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="sub"] { overflow: hidden; }
    /* The supporting line is ONE line.
       Clipping the <td> alone was not enough: these cells usually hold two or
       three child elements (an e-mail and a phone number, a company and a
       contact), and as flex children those wrapped onto lines of their own —
       so a "two-line card" quietly became four lines for any customer with
       both an e-mail and a phone. Making the cell a block and its children
       inline collapses them onto a single run of text that then ellipsises. */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="sub"] {
        display: block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.5;
    }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="sub"] > * {
        display: inline;
        vertical-align: baseline;
    }
    /* Separate the runs that are now inline so they do not read as one word. */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="sub"] > * + *::before {
        content: " · ";
        color: var(--bb-border);
    }

    /* These carry their own meaning; a label would be noise. */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="lead"]::before,
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="sub"]::before,
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="amt"]::before,
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="status"]::before { content: none; }

    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="hide"] { display: none !important; }

    /* Secondary detail: present, one tap away, never in the way. */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="fold"] { display: none; }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody tr.is-expanded td[data-m="fold"] {
        display: flex;
        grid-column: 1 / -1;
        padding: 2px 0;
    }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody tr.is-expanded td[data-m="fold"]:first-of-type {
        margin-top: var(--bb-s-4);
        padding-top: var(--bb-s-4);
        border-top: 1px solid var(--bb-border-soft);
    }

    /* The action cell spans the card and only appears with the detail: on a
       phone the whole row is already a link to the record, so a permanent
       "ACTIONS →  ⋯" strip under every card was a wasted line per record. */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td.row-actions,
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td:last-child:not([data-label]) {
        display: none;
        grid-column: 1 / -1;
    }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody tr.is-expanded td.row-actions,
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody tr.is-expanded td:last-child:not([data-label]) {
        display: flex;
        margin-top: var(--bb-s-4);
        padding-top: var(--bb-s-4);
        border-top: 1px solid var(--bb-border-soft);
    }

    /* ------------------------------------------------------------------
       The whole card is the tap target.

       The only thing a finger could hit on a record card was the identifier
       link itself — 67x20px on a 390px screen, well under a comfortable
       target, with the rest of the card inert. A stretched pseudo-element on
       that link makes the entire row activate it, which is the behaviour a
       list of records should have anyway.

       The disclosure is lifted above the overlay so it stays independently
       tappable; without the z-index it would sit underneath and every tap on
       the chevron would open the record instead of expanding it.
       ------------------------------------------------------------------ */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody tr { position: relative; }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="lead"] a::after {
        content: "";
        position: absolute;
        inset: 0;
    }
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="lead"] a {
        position: static;   /* so ::after resolves against the row, not the link */
    }

    .row-more {
        position: relative;
        z-index: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 28px; height: 28px;
        /* Sits beside the identifier, not pushed to the far edge of its
           column — at `margin-left:auto` it landed in the gutter between the
           invoice number and the amount and read as a control belonging to
           neither. */
        margin-left: 2px;
        flex-shrink: 0;
        border: 0;
        border-radius: var(--bb-r-sm);
        background: transparent;
        color: var(--bb-text-muted);
        font-size: 12px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: transform var(--bb-t-fast) var(--bb-ease);
    }
    .row-more:active { background: var(--bb-surface-inset); }
    .table-wrapper table.has-mobile-cards tr.is-expanded .row-more { transform: rotate(180deg); }
    .table-wrapper:not(.table-keep) tbody td:empty { display: none; }
    .table-wrapper:not(.table-keep) tbody td.row-actions,
    .table-wrapper:not(.table-keep) tbody td:last-child:not([data-label]) {
        justify-content: flex-start;
        gap: var(--bb-s-3);
        margin-top: var(--bb-s-5);
        padding-top: var(--bb-s-5);
        border-top: 1px solid var(--bb-border-soft);
    }

    .line-items-table { font-size: var(--bb-fs-sm); }
    .empty-state { padding: var(--bb-s-12) var(--bb-s-6); }
    .filter-bar, .table-toolbar { padding: var(--bb-s-5) var(--bb-s-6); }
    .filter-bar .form-input, .filter-bar .form-select, .header-search.is-inline { width: 100%; min-width: 0; }
}

/* ---------------------------------------------------------------------------
   The row disclosure belongs to the card layout only.

   The stamper in layout.php appends .row-more to every row when the DOM is
   ready — it has no business branching on viewport width there, since a
   window can be resized after load and re-running the whole pass on resize
   would be worse than a rule. So the button is created always and shown only
   where a card exists. Without this it appeared beside every invoice number
   on the desktop table, where the columns it would reveal are already on
   screen anyway.
   --------------------------------------------------------------------------- */
.row-more { display: none; }
@media (max-width: 640px) {
    .table-wrapper:not(.table-keep) table.has-mobile-cards .row-more { display: inline-flex; }
}

/* ---------------------------------------------------------------------------
   Laptop and tablet: shed the least useful column instead of scrolling.

   At 1024px the invoice table wants 1688px inside a 714px content area, so
   five of its nine columns sat off-screen behind a horizontal scrollbar.
   A column already marked `data-m="hide"` is one the card layout judged not
   worth its space; that judgement holds on a narrow laptop too, and dropping
   it beats hiding half the table behind a scroll.

   Only `hide` columns go. `fold` columns stay: a desktop table has no
   disclosure to reveal them again, so hiding those would lose data outright.
   --------------------------------------------------------------------------- */
@media (min-width: 641px) and (max-width: 1200px) {
    .table-wrapper:not(.table-keep) table th[data-m="hide"],
    .table-wrapper:not(.table-keep) table td[data-m="hide"] { display: none; }
}

/* ---------------------------------------------------------------------------
   Coarse pointers.

   A fingertip is about 9mm; the widely-used floor for a comfortable target is
   44px, and these were 38/32/28. The small sizes in particular — a 28px
   "btn-xs" delete on a table row — are the ones people miss and then hit the
   row link underneath instead, which on a list of invoices means opening the
   wrong record.

   The button's VISUAL height is not what grows. `--btn-h` sets the box, and
   inflating that would make every toolbar on a phone look like a stack of
   slabs. Instead the visual size is nudged and the remaining reach is added
   as an invisible touch area via a pseudo-element, so the control looks the
   same and is easier to hit. Targets that already sit inside a large padded
   row (nav items, sheet tiles) are excluded — they are big enough already.
   --------------------------------------------------------------------------- */
@media (pointer: coarse) {
    .btn { --btn-h: 40px; }
    .btn-sm { --btn-h: 36px; }
    .btn-xs { --btn-h: 32px; }
    .form-input:not([type=checkbox]):not([type=radio]), .form-select,
    input:not([type=checkbox]):not([type=radio]), select, textarea { min-height: 40px; }   /* a bare `input` here stretched every checkbox into a 17x40 slot */

    /* NOT DONE HERE: an invisible 44px halo via ::after.
       It is the usual trick for growing a hit area without growing the
       control, but this app puts icon buttons a few pixels apart in table
       rows and toolbars — two adjacent 28px buttons would end up with
       overlapping haloes, and a tap in the overlap would land on whichever
       won the stacking order rather than the one under the finger. Trading a
       small target for a wrong target is not an improvement. The sizes above
       grow honestly instead, and spacing does the rest. */
    .btn-icon + .btn-icon,
    .dropdown + .dropdown,
    .btn-icon + .dropdown { margin-left: var(--bb-s-3); }

    /* Anything that opens a menu or a record has room to be a full target. */
    a.nav-link, .bottom-nav-item, .mn-tile, .mn-list a { min-height: 44px; }

    /* Segmented filters (All / Unpaid / Partial / Overdue …) measured 29px
       tall on a phone — under the comfortable floor, and they sit in a row
       where a mis-tap silently changes what the list is showing. */
    .segmented > button,
    .segmented > a { min-height: 36px; }

    /* 44px floor, product-completion pass.
       The sizes above stopped at 40/36/32px, and the audit at a true 390px
       touch viewport found every screen WITHOUT its own mobile view (about
       ninety: estimates, purchases, stock, settings...) opening with seven
       controls under 44px -- the 32px hamburger and header icons, the 28px
       sign-out -- plus row actions at 32-36px. Real controls grow now; still
       no invisible halo, for the overlap reason given above. */
    .btn, .btn-sm, .btn-xs { --btn-h: 44px; }
    .btn-icon, .btn-sm.btn-icon, .btn-xs.btn-icon { min-width: 44px; }
    /* Checkboxes/radios excluded even when they carry .form-input (Settings'
       reverse-charge box does): min-height turned them into a tall empty slot. */
    .form-input:not([type=checkbox]):not([type=radio]), .form-select,
    input:not([type=checkbox]):not([type=radio]), select, textarea { min-height: 44px; }
    .mobile-toggle, .header-btn, .sidebar-logout { width: 44px; height: 44px; }
    /* Icon-only buttons (view / edit / delete in every row) were 44 tall but
       33-35 wide, and the card disclosure chevron 28x28. */
    /* Every button at least as wide as it is tall. (An icon-only :has() test
       missed buttons whose label span is merely HIDDEN on phones, like the
       header Create button at 33px.) */
    .btn { min-width: 44px; justify-content: center; }
    .desk-notice-dismiss { min-width: 44px; min-height: 44px; }
    /* Specific enough to beat the card lead cell's "> * { min-width: 0 }". */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td .row-more,
    .row-more { min-width: 44px; min-height: 44px; }
    /* The record number in a phone card is a text link 20px tall; grow its
       hit area without moving the layout. */
    .table-wrapper:not(.table-keep) table.has-mobile-cards tbody td[data-m="lead"] > a { display: inline-block; padding: 12px 0; margin: -12px 0; }
    input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
    .segmented > button,
    .segmented > a { min-height: 44px; }
}

/* Small phones. Anything still sitting in columns at this width is squeezed
   past readability, so the remaining multi-column primitives go single-file. */
@media (max-width: 480px) {
    :root { --bb-page-pad: var(--bb-s-5); }

    /* Still two up at 360–480px. A metric is a short label and a number,
       both of which sit comfortably in half of even the narrowest screen —
       collapsing to one per row buys no legibility and costs a screenful. */
    .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric { border-right: 0; border-bottom: 1px solid var(--bb-border-soft); padding: var(--bb-s-6); }
    .metric:nth-last-child(-n+2) { border-bottom: 0; }
    .metric-value { font-size: var(--bb-fs-lg); }

    .detail-grid, .readonly-grid, .form-row, .form-row-4 { grid-template-columns: minmax(0, 1fr); }

    .page-eyebrow { flex-wrap: wrap; }
    .identity { gap: var(--bb-s-5); }
    .identity-meta { gap: var(--bb-s-3) var(--bb-s-5); }
    /* A GSTIN is an identifier — let it wrap rather than shrink the type. */
    .identity-meta .gstin { white-space: normal; overflow-wrap: anywhere; }

    .allocation-summary { flex-direction: column; align-items: stretch; }
    .allocation-summary .btn { width: 100%; justify-content: center; }

    .tabs { gap: var(--bb-s-5); }
    .tab { padding-left: 0; padding-right: 0; }

    .detail-amount { font-size: var(--bb-fs-xl); }
    .metric-value  { font-size: var(--bb-fs-2xl); }
}



/* --------------------------------------------------------------------------
   Mobile bottom navigation

   Phones only. Above 900px the rail is permanently visible and a second
   navigation surface would just be clutter.

   Sized for thumbs, not for pixels saved: every target is at least 48px tall,
   which is the smallest reliably tappable size, and the bar sits above the
   home indicator via env(safe-area-inset-bottom) so iOS does not swallow the
   outer two items.
   -------------------------------------------------------------------------- */
.bottom-nav { display: none; }

@media (max-width: 900px) {
    .bottom-nav {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: var(--bb-z-sidebar);
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        gap: 2px;
        padding: 4px var(--bb-s-4) calc(4px + env(safe-area-inset-bottom, 0px));
        background: var(--bb-surface);
        border-top: 1px solid var(--bb-border);
        box-shadow: 0 -1px 3px rgba(15, 23, 42, .05);
    }

    .bottom-nav-item {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-height: 48px;
        padding: 6px 2px;
        border: 0;
        background: transparent;
        border-radius: var(--bb-r-sm);
        font-family: var(--bb-font);
        font-size: 10.5px;
        font-weight: var(--bb-fw-medium);
        line-height: 1;
        color: var(--bb-text-muted);
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color var(--bb-t-fast) var(--bb-ease);
    }
    .bottom-nav-item i { font-size: 16px; }
    /* Five tabs at 360px leaves ~68px each. The labels still have to read as
       words rather than truncate to "Custo…", so they lose a little size and
       letter-spacing rather than the bar losing a destination. */
    .bottom-nav-item { font-size: 10px; letter-spacing: -.01em; padding-left: 0; padding-right: 0; }
    .bottom-nav-item span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .bottom-nav-item:active { background: var(--bb-surface-inset); }
    .bottom-nav-item.active { color: var(--bb-brand-600); }
    .bottom-nav-item.active i { color: var(--bb-brand-600); }

    /* ------------------------------------------------------------------
       Create invoice: a floating action, NOT a tab.
       The bar now carries five journeys (Home, Invoices, Customers,
       Payments, More). Putting "new invoice" inside it would have meant
       dropping one of them — Payments, most likely, which is half the
       reason anyone opens this on a phone. Floating it keeps the app's
       single most-used action the biggest target on every screen without
       spending a tab slot.
       ------------------------------------------------------------------ */
    .mn-fab {
        position: fixed;
        right: var(--bb-s-7);
        bottom: calc(64px + env(safe-area-inset-bottom, 0px));
        z-index: calc(var(--bb-z-sidebar) + 1);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 52px; height: 52px;
        border-radius: 50%;
        background: var(--bb-brand-600);
        color: #fff;
        font-size: 19px;
        text-decoration: none;
        box-shadow: 0 6px 18px rgba(79, 70, 229, .40);
        -webkit-tap-highlight-color: transparent;
        transition: transform var(--bb-t-fast) var(--bb-ease),
                    background var(--bb-t-fast) var(--bb-ease);
    }
    .mn-fab:active { background: var(--bb-brand-700); transform: scale(.94); }

    /* On the create screen itself the button would only lead back to where
       you already are, and it covers the form's own controls. */
    body.page-invoices-create .mn-fab,
    body.is-form-screen .mn-fab,
    body.pos-mode .mn-fab { display: none; }

    /* ------------------------------------------------------------------
       "More" sheet
       ------------------------------------------------------------------ */
    .mn-sheet-overlay {
        position: fixed; inset: 0;
        z-index: calc(var(--bb-z-sidebar) + 3);
        background: rgba(15, 23, 42, .45);
        opacity: 0;
        transition: opacity 180ms var(--bb-ease);
    }
    .mn-sheet-overlay.is-open { opacity: 1; }

    .mn-sheet {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: calc(var(--bb-z-sidebar) + 4);
        max-height: 85vh;
        display: flex;
        flex-direction: column;
        background: var(--bb-surface);
        border-radius: var(--bb-r-xl) var(--bb-r-xl) 0 0;
        box-shadow: 0 -8px 30px rgba(15, 23, 42, .18);
        transform: translateY(100%);
        transition: transform 200ms var(--bb-ease);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .mn-sheet.is-open { transform: translateY(0); }

    .mn-sheet-grip {
        width: 36px; height: 4px;
        margin: 8px auto 0;
        border-radius: 999px;
        background: var(--bb-border);
        flex-shrink: 0;
    }
    .mn-sheet-head {
        display: flex; align-items: center; justify-content: space-between;
        padding: var(--bb-s-5) var(--bb-s-7) var(--bb-s-3);
        flex-shrink: 0;
    }
    .mn-sheet-head h2 {
        margin: 0;
        font-size: var(--bb-fs-lg);
        font-weight: var(--bb-fw-semibold);
    }
    .mn-sheet-close {
        width: 34px; height: 34px;
        display: inline-flex; align-items: center; justify-content: center;
        border: 0; border-radius: var(--bb-r-md);
        background: var(--bb-surface-inset);
        color: var(--bb-text-muted);
        cursor: pointer;
    }

    .mn-sheet-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0 var(--bb-s-7) var(--bb-s-8);
    }

    .mn-group-label {
        margin: var(--bb-s-6) 0 var(--bb-s-4);
        font-size: var(--bb-fs-xs);
        font-weight: var(--bb-fw-semibold);
        letter-spacing: var(--bb-tracking-wide);
        text-transform: uppercase;
        color: var(--bb-text-muted);
    }
    .mn-group-label span {
        display: block;
        margin-top: 3px;
        font-size: var(--bb-fs-xs);
        font-weight: var(--bb-fw-regular);
        letter-spacing: 0;
        text-transform: none;
        color: var(--bb-text-muted);
        line-height: 1.5;
    }

    /* Phone-friendly modules get big tap tiles. */
    .mn-grid {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: var(--bb-s-4);
    }
    .mn-tile {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-height: 74px;
        padding: var(--bb-s-4) 4px;
        border: 1px solid var(--bb-border);
        border-radius: var(--bb-r-lg);
        background: var(--bb-surface);
        color: var(--bb-text);
        text-decoration: none;
        text-align: center;
        -webkit-tap-highlight-color: transparent;
    }
    .mn-tile i { font-size: 17px; color: var(--bb-brand-600); }
    .mn-tile span {
        font-size: 11px;
        line-height: 1.25;
        font-weight: var(--bb-fw-medium);
    }
    .mn-tile:active { background: var(--bb-surface-inset); }

    /* Desktop-heavy modules get a plain list — reachable, but not dressed up
       as something the phone does well. */
    .mn-list { list-style: none; margin: 0; padding: 0; }
    .mn-list a {
        display: flex;
        align-items: center;
        gap: var(--bb-s-5);
        min-height: 48px;
        padding: var(--bb-s-4) 0;
        border-bottom: 1px solid var(--bb-border-soft);
        color: var(--bb-text);
        text-decoration: none;
        font-size: var(--bb-fs-sm);
    }
    .mn-list li:last-child a { border-bottom: 0; }
    .mn-list a > i:first-child {
        width: 20px;
        text-align: center;
        color: var(--bb-text-muted);
    }
    .mn-list a span { flex: 1; min-width: 0; }
    .mn-chev { font-size: 11px; color: var(--bb-text-subtle, var(--bb-text-muted)); }

    .mn-allsections,
    .mn-signout {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--bb-s-4);
        width: 100%;
        min-height: 44px;
        margin-top: var(--bb-s-6);
        padding: var(--bb-s-4);
        border: 1px solid var(--bb-border);
        border-radius: var(--bb-r-lg);
        background: var(--bb-surface);
        font-family: var(--bb-font);
        font-size: var(--bb-fs-sm);
        font-weight: var(--bb-fw-medium);
        color: var(--bb-text);
        text-decoration: none;
        cursor: pointer;
    }
    .mn-signout { color: var(--bb-danger-600); border-color: transparent; margin-top: var(--bb-s-4); }

    /* Reserve the bar's height so the last row of any list stays reachable
       and nothing important hides underneath it. */
    .page-content {
        padding-bottom: calc(var(--bb-s-14) + 56px + env(safe-area-inset-bottom, 0px));
    }

    /* Toasts and the export progress pill sit above the bar, not behind it. */
    .toast-stack { bottom: calc(var(--bb-s-5) + 60px + env(safe-area-inset-bottom, 0px)); }

    /* POS is its own full-screen surface with its own controls. */
    body.pos-mode .bottom-nav { display: none; }
    body.pos-mode .mn-sheet, body.pos-mode .mn-sheet-overlay { display: none; }
    body.pos-mode .page-content { padding-bottom: var(--bb-s-14); }
    /* Full-bleed is for the desktop till; on a phone the title and every
       card touched both screen edges. */
    body.pos-mode .page-content { padding-left: var(--bb-s-5); padding-right: var(--bb-s-5); }

    /* The drawer and its scrim must cover the bar while open. */
    .sidebar, .sidebar-overlay { z-index: calc(var(--bb-z-sidebar) + 2); }
}

@media (max-width: 560px) {
    .bb-doc-progress { bottom: calc(var(--bb-s-8) + 60px + env(safe-area-inset-bottom, 0px)); }
}

/* Printing must never include navigation chrome. */
@media print {
    .bottom-nav,
    .mn-fab,
    .mn-sheet,
    .mn-sheet-overlay { display: none !important; }
}



/* ==========================================================================
   "Better on a computer" notice
   Only ever rendered on the mobile shell; see
   resources/views/components/desktop_notice.php. It informs, it does not gate.
   ========================================================================== */
/* Hidden on anything wide enough to be the computer it recommends.
   Viewport width cannot be known server-side, so the markup ships and CSS
   decides — see the note in resources/views/components/desktop_notice.php. */
.desk-notice { display: none; }

@media (max-width: 900px) {
.desk-notice {
    display: flex;
    align-items: flex-start;
    gap: var(--bb-s-5);
    margin-bottom: var(--bb-s-7);
    padding: var(--bb-s-6);
    border: 1px solid var(--bb-border);
    border-left: 3px solid var(--bb-brand-600);
    border-radius: var(--bb-r-lg);
    background: var(--bb-surface);
}
.desk-notice-icon {
    flex-shrink: 0;
    margin-top: 2px;
    font-size: 15px;
    color: var(--bb-brand-600);
}
.desk-notice-text { flex: 1; min-width: 0; }
.desk-notice-text strong {
    display: block;
    font-size: var(--bb-fs-sm);
    font-weight: var(--bb-fw-semibold);
    margin-bottom: 2px;
}
.desk-notice-text p {
    margin: 0;
    font-size: var(--bb-fs-xs);
    line-height: 1.55;
    color: var(--bb-text-muted);
}
.desk-notice-dismiss {
    flex-shrink: 0;
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: var(--bb-r-md);
    background: transparent;
    color: var(--bb-text-muted);
    cursor: pointer;
}
.desk-notice-dismiss:active { background: var(--bb-surface-inset); }
}

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


/* ==========================================================================
   Mobile submit bar (create/edit invoice)
   The primary action stays on screen while the form scrolls. See the note in
   resources/views/invoices_create.php for why this exists rather than relying
   on the in-page button.
   ========================================================================== */
.create-actionbar { display: none; }

@media (max-width: 900px) {
    .create-actionbar {
        position: fixed;
        left: 0; right: 0;
        /* Sits directly above the tab bar, not over it. */
        bottom: calc(56px + env(safe-area-inset-bottom, 0px));
        z-index: calc(var(--bb-z-sidebar) + 1);
        display: flex;
        align-items: center;
        gap: var(--bb-s-5);
        padding: var(--bb-s-5) var(--bb-s-6);
        background: var(--bb-surface);
        border-top: 1px solid var(--bb-border);
        box-shadow: 0 -2px 10px rgba(15, 23, 42, .06);
    }
    .create-actionbar-total { flex: 1; min-width: 0; line-height: 1.2; }
    .create-actionbar-total span {
        display: block;
        font-size: var(--bb-fs-xs);
        color: var(--bb-text-muted);
    }
    .create-actionbar-total strong {
        font-size: var(--bb-fs-lg);
        font-weight: var(--bb-fw-semibold);
        font-variant-numeric: tabular-nums;
    }
    .create-actionbar .btn { flex: 0 0 auto; min-height: 42px; padding-inline: var(--bb-s-8); }

    /* Room for the bar plus the tab bar, so the last field is not trapped
       underneath both. */
    body.page-invoices-create .page-content,
    body.page-invoices-edit .page-content {
        padding-bottom: calc(var(--bb-s-14) + 120px + env(safe-area-inset-bottom, 0px));
    }

    /* The inline pair is redundant once the bar is on screen — but Cancel is
       not, so only the duplicate submit goes. */
    .create-actions-inline .btn-primary { display: none; }
}

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


/* ==========================================================================
   Offline banner
   Shown by public/js/connection.js when the browser reports no network. It
   states a fact and offers a retry; it does NOT imply anything works offline.
   ========================================================================== */
.net-banner {
    position: fixed;
    left: 0; right: 0;
    top: 0;
    z-index: calc(var(--bb-z-sidebar) + 10);
    display: flex;
    align-items: center;
    gap: var(--bb-s-5);
    padding: var(--bb-s-5) var(--bb-s-7);
    background: var(--bb-warn-100, #fef3c7);
    color: var(--bb-warn-800, #92400e);
    border-bottom: 1px solid var(--bb-warn-300, #fcd34d);
    font-size: var(--bb-fs-sm);
    transform: translateY(-100%);
    transition: transform 200ms var(--bb-ease);
}
.net-banner.is-in { transform: translateY(0); }
.net-banner i { flex-shrink: 0; }
.net-banner span { flex: 1; min-width: 0; line-height: 1.4; }
.net-banner-retry {
    flex-shrink: 0;
    min-height: 32px;
    padding: 0 var(--bb-s-6);
    border: 1px solid currentColor;
    border-radius: var(--bb-r-md);
    background: transparent;
    color: inherit;
    font-family: var(--bb-font);
    font-size: var(--bb-fs-xs);
    font-weight: var(--bb-fw-medium);
    cursor: pointer;
}

@media (max-width: 640px) {
    .net-banner { padding: var(--bb-s-4) var(--bb-s-5); font-size: var(--bb-fs-xs); }
}

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

/* ==========================================================================
   27 · PRINT
   ========================================================================== */

@media print {
    .sidebar, .sidebar-overlay, .header, .demo-mode-banner,
    .page-actions, .toast-stack, .cmdk-overlay, .doc-actionbar,
    .btn, .no-print, .mobile-toggle, .filter-bar, .table-meta,
    .notification-panel { display: none !important; }

    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; max-width: none !important; }

    body { background: #fff; font-size: 11px; color: #000; }
    .card, .panel {
        border: 1px solid #ddd !important;
        box-shadow: none !important;
        break-inside: avoid;
        margin-bottom: 12px;
    }
    .table-wrapper { overflow: visible !important; }
    table { break-inside: auto; }
    tr { break-inside: avoid; break-after: auto; }
    thead { display: table-header-group; }
    .table-wrapper thead th { position: static; background: #f4f4f4 !important; color: #000 !important; }
    a { color: #000 !important; text-decoration: none !important; }
    .status-badge, .badge { border: 1px solid #999 !important; color: #000 !important; background: #fff !important; }
    .print-only { display: revert !important; }
}
.print-only { display: none; }


/* ==========================================================================
   28 · ACCESSIBILITY & MOTION
   ========================================================================== */

/* Consistent, always-visible keyboard focus */
:focus-visible {
    outline: 2px solid var(--bb-brand-500);
    outline-offset: 2px;
    border-radius: var(--bb-r-xs);
}
/* Components that render their own ring suppress the default outline */
.btn:focus-visible, .form-input:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, .nav-link:focus-visible,
.cmdk-input:focus-visible { outline: none; }

.sr-only, .visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -60px;
    left: var(--bb-s-6);
    z-index: var(--bb-z-tooltip);
    padding: var(--bb-s-5) var(--bb-s-8);
    background: var(--bb-brand-600);
    color: #fff;
    font-weight: var(--bb-fw-medium);
    border-radius: 0 0 var(--bb-r) var(--bb-r);
    transition: top var(--bb-t) var(--bb-ease);
}
.skip-link:focus { top: 0; color: #fff; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

@media (prefers-contrast: more) {
    :root {
        --bb-border: var(--bb-n-300);
        --bb-border-soft: var(--bb-n-200);
        --bb-text-muted: var(--bb-n-600);
        --bb-text-subtle: var(--bb-n-500);
    }
}


/* ---------------------------------------------------------------------------
 * List pager (app/Support/list_pager.php). Lists show one page at a time.
 * ------------------------------------------------------------------------- */
.bb-pager {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--bb-s-4) var(--bb-s-8);
    width: 100%;
    font-size: var(--bb-fs-sm);
    color: var(--bb-text-muted);
}
.bb-pager-info { flex: 1 1 auto; min-width: 0; }
.bb-pager-pages { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.bb-pg {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 32px; height: 32px; padding: 0 8px;
    border: 1px solid var(--bb-border); border-radius: 8px;
    background: var(--bb-surface); color: var(--bb-text);
    font-weight: var(--bb-fw-semibold); text-decoration: none;
}
a.bb-pg:hover { border-color: var(--bb-n-300); background: var(--bb-surface-hover); }
.bb-pg.is-on { background: var(--bb-primary, #4f46e5); border-color: var(--bb-primary, #4f46e5); color: #fff; }
.bb-pg.is-off { opacity: .4; }
.bb-pg.is-gap { border: 0; background: none; min-width: 16px; padding: 0; }
.bb-pager-per { display: inline-flex; align-items: center; gap: 6px; }
.bb-pager-per select {
    height: 32px; padding: 0 6px; border: 1px solid var(--bb-border);
    border-radius: 8px; background: var(--bb-surface); color: var(--bb-text);
}
.bb-pager { padding: var(--bb-s-5) var(--bb-s-8); border-top: 1px solid var(--bb-border-soft); }
.table-meta > .bb-pager { padding: 0; border-top: 0; }

/* ---------------------------------------------------------------------------
 * List tables between phone and wide desktop (641–1439px: laptops, zoomed
 * browsers, a docked window). Nine columns at desktop padding overflowed the
 * card and pushed Balance/Status/actions off to the right. Tighter cells, and
 * below 1280px the columns a view marks low-priority (data-m="hide", e.g.
 * "Billed by") step aside, as they already do on a phone.
 * ------------------------------------------------------------------------- */
/* max-width is ignored by inline elements, and several lists render the name
   as an <a class="identity-name">: the 20ch cap never applied and one long
   customer name stretched the Customers table to 1,500px. */
.table-wrapper td .identity-name,
.table-wrapper td span.truncate { display: inline-block; vertical-align: top; }

@media (min-width: 641px) and (max-width: 1439px) {
    /* .card prefix: .card table tbody td (0,1,3) set the 16px padding. */
    .card .table-wrapper thead th,
    .card .table-wrapper tbody td,
    .table-wrapper thead th,
    .table-wrapper tbody td { padding-left: var(--bb-s-5); padding-right: var(--bb-s-5); }
    .card .table-wrapper thead th:first-child,
    .card .table-wrapper tbody td:first-child { padding-left: var(--bb-s-8); }
    .table-wrapper tbody td.text-right,
    .table-wrapper tbody td[data-m="amt"] { white-space: nowrap; }
}
@media (min-width: 641px) and (max-width: 1279px) {
    /* !important: several views set max-width:200px inline on .truncate. */
    .table-wrapper td .identity-name,
    .table-wrapper td .truncate { max-width: 15ch !important; }
    .table-wrapper td .identity-meta { max-width: 24ch; }
    .card .table-wrapper thead th,
    .card .table-wrapper tbody td { padding-left: var(--bb-s-4); padding-right: var(--bb-s-4); }
    .card .table-wrapper thead th:first-child,
    .card .table-wrapper tbody td:first-child { padding-left: var(--bb-s-7); }
    /* Secondary lines (marketplace order refs, notes) may break anywhere
       rather than set the column width. */
    .table-wrapper td .text-sm { overflow-wrap: anywhere; }
    .table-wrapper:not(.table-keep) th[data-m="hide"],
    .table-wrapper:not(.table-keep) td[data-m="hide"] { display: none; }
}
