/* =============================================================================
   F7 BUSINESS SUITE — DESIGN SYSTEM
   IBM Plex Sans / IBM Plex Mono · F7 Orange · Dark Chrome · Warm Neutrals
   ============================================================================= */

/* ---------- CSS CUSTOM PROPERTIES (LIGHT — DEFAULT) ---------- */
:root {
    /* Brand */
    --f7-orange:       #ff6a00;
    --f7-orange-hover: #ff7d22;
    --f7-orange-muted: rgba(255,106,0,.16);
    --f7-orange-focus: rgba(255,106,0,.13);
    /* Brand palette (logo tokens) */
    --f7-ink:          #16171c;
    --f7-disc:         #e9e6df;
    --f7-paper:        #ffffff;

    /* Chrome (sidebar, header, dark panels) */
    --chrome:          #16171c;
    --chrome-light:    #1b1c22;
    --chrome-border:   #25272e;
    --chrome-hover:    rgba(255,255,255,.05);
    --chrome-text:     #cfd1d6;
    --chrome-muted:    #a6a8b0;
    --chrome-dim:      #92949c;
    --chrome-input:    #22242a;
    --chrome-input-bd: #34363d;

    /* Content surface (warm neutrals) */
    --bg:              #eceae5;
    --bg-alt:          #f4f2ee;
    --panel:           #fff;
    --panel2:          #f6f5f2;
    --panel3:          #faf9f7;

    /* Borders */
    --line:            #d8d5ce;
    --line-light:      #e7e4dd;
    --line-lighter:    #efece5;

    /* Ink */
    --ink:             #181715;
    --ink2:            #6c685f;
    --ink3:            #9a978f;
    --ink4:            #3a3833;

    /* Semantic */
    --green:           #1f8a52;
    --green-bg:        rgba(31,138,82,.10);
    --red:             #c0392b;
    --red-bg:          rgba(192,57,43,.12);
    --amber:           #a98700;
    --amber-bg:        rgba(202,166,0,.14);
    --blue:            #5b6ef5;
    --blue-bg:         rgba(91,110,245,.12);
    /* Aliases used by inline stock hints etc. — follow the theme automatically */
    --danger:          var(--red);
    --warning:         var(--amber);
    --success:         var(--green);

    /* Autocomplete dropdown outline (strong, visible edge in both themes) */
    --ac-outline:      #8f8c84;

    /* Generic surface aliases — several views (e.g. the email Details modals) style
       against --surface/--surface2/--muted. They are aliases of the theme panels/ink
       so those views follow light/dark automatically. */
    --surface:         var(--panel);
    --surface2:        var(--panel2);
    --muted:           var(--ink3);

    /* Layout */
    --sidebar-w:       236px;
    --topbar-h:        56px;
    --radius:          8px;
    --radius-lg:       11px;
    --radius-xl:       12px;

    /* Typography */
    --font-sans:       'IBM Plex Sans', system-ui, -apple-system, sans-serif;
    --font-mono:       'IBM Plex Mono', ui-monospace, 'Cascadia Code', monospace;

    color-scheme: light;
}

/* ---------- DARK THEME ---------- */
/* The chrome (sidebar/topbar) is dark in both modes. Dark mode flips the
   content surface, panels, borders, and ink so the work area goes dark too. */
[data-theme="dark"] {
    /* Content surface */
    --bg:              #121319;
    --bg-alt:          #16171c;
    --panel:           #1b1c22;
    --panel2:          #23252c;
    --panel3:          #1f2127;

    /* Borders */
    --line:            #2c2e35;
    --line-light:      #34363d;
    --line-lighter:    #26282f;

    /* Ink */
    --ink:             #e9e7e2;
    --ink2:            #b2b4bb;
    --ink3:            #979aa2;
    --ink4:            #cfd1d6;

    /* Semantic — slightly stronger backgrounds for contrast on dark */
    --green-bg:        rgba(31,138,82,.18);
    --red-bg:          rgba(192,57,43,.20);
    --amber-bg:        rgba(202,166,0,.20);
    --blue-bg:         rgba(91,110,245,.20);

    /* Brighter semantic foregrounds so they read on dark surfaces */
    --green:           #35b87a;
    --red:             #e15a4c;
    --amber:           #d6b53e;
    --blue:            #8093ff;

    /* Autocomplete dropdown outline — bright enough to read on dark panels */
    --ac-outline:      #5f6370;

    /* Generic surface aliases (see :root) — restated with the dark panel/ink values */
    --surface:         var(--panel);
    --surface2:        var(--panel2);
    --muted:           var(--ink3);

    color-scheme: dark;
}

[data-theme="dark"] body { background: var(--bg); }

/* Scrollbars in dark */
[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: #34363d;
    border: 3px solid transparent;
    background-clip: content-box;
}

/* Dark-mode tweaks for elements that assumed a white surface */
[data-theme="dark"] .f7-table thead th { background: var(--panel3); }
[data-theme="dark"] .f7-filter-tab.active { box-shadow: 0 1px 3px rgba(0,0,0,.4); }
[data-theme="dark"] .monogram-dark { background: #2c2e35; color: #fff; }
[data-theme="dark"] .dropdown-menu { background: var(--panel); }
[data-theme="dark"] .dropdown-item { color: var(--ink); }
[data-theme="dark"] .dropdown-item:hover { background: var(--panel2); color: var(--ink); }
[data-theme="dark"] .shadow,
[data-theme="dark"] .shadow-sm,
[data-theme="dark"] .shadow-lg { box-shadow: 0 10px 34px rgba(0,0,0,.45) !important; }

/* Theme toggle button */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink2);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.theme-toggle:hover { background: var(--panel2); color: var(--ink); }
.theme-toggle .material-icons { font-size: 18px; }
.theme-toggle .icon-dark { display: none; }
[data-theme="dark"] .theme-toggle .icon-light { display: none; }
[data-theme="dark"] .theme-toggle .icon-dark { display: inline; }

/* ---------- TOP-NAV MODE (desktop only; ≤991px always uses the sidebar/hamburger) ---------- */
@media (min-width: 992px) {
    [data-nav="top"] .app-wrapper { flex-direction: column; }

    /* Sidebar becomes a full-width horizontal bar (grows if the triggers wrap).
       position:relative + z-index put the whole bar (and therefore its dropdown
       panels) in a stacking context above the topbar, cards and sticky page bits. */
    [data-nav="top"] .app-sidebar {
        position: relative;
        z-index: 250;
        width: 100%;
        height: auto;
        min-height: var(--topbar-h);
        flex-direction: row;
        align-items: stretch;
        overflow: visible;
        transform: none;
        flex: none;
    }
    [data-nav="top"] .sidebar-header {
        border-bottom: none;
        border-right: 1px solid var(--chrome-border);
        flex: none;
    }
    /* The nav container goes horizontal and WRAPS so it never runs off the page.
       overflow MUST stay visible: any overflow trap on this ancestor clips the
       absolutely-positioned dropdown panels to the height of the bar (the old
       inline overflow-y:auto on this very div was exactly that bug — it beat the
       stylesheet override, so the panels were cut off and looked broken). */
    [data-nav="top"] .sidebar-scroll {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: stretch;
        padding: 0;
        overflow: visible;
        flex: 1;
    }

    /* Pinned HOME links (Dashboard, Time Clock) render as plain top-level bar items */
    [data-nav="top"] .nav-pinned { display: flex; align-items: stretch; }
    [data-nav="top"] .nav-pinned > .sidebar-section { display: none; }
    [data-nav="top"] .nav-pinned > .sidebar-nav {
        display: flex; flex-direction: row; align-items: stretch;
        max-height: none; overflow: visible;
    }
    [data-nav="top"] .nav-pinned li { display: flex; }
    [data-nav="top"] .nav-pinned .sidebar-link { align-items: center; padding: 0 15px; white-space: nowrap; }
    [data-nav="top"] .nav-pinned .sidebar-link.active::before {
        left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 2px; transform: none; border-radius: 0;
    }

    /* Each section becomes a top-level dropdown group */
    [data-nav="top"] .nav-group { position: relative; display: flex; align-items: stretch; }

    /* The section header (a real <button>) is the dropdown trigger. Panels open on
       hover AND on click/Enter/Space (site.js toggles .open) so touch and keyboard
       work too. The panel sits at top:100% of the group box with NO vertical gap,
       so the pointer never leaves the hover area travelling from trigger to panel. */
    [data-nav="top"] .nav-group > .sidebar-section {
        display: flex; align-items: center; gap: 5px;
        width: auto;
        min-height: var(--topbar-h); padding: 0 15px; margin: 0;
        border-left: 1px solid var(--chrome-border);
        white-space: nowrap; cursor: pointer;
    }
    [data-nav="top"] .nav-group:first-child > .sidebar-section { border-left: none; }
    /* The tree chevron is a left-nav affordance; top mode has its own ::after caret */
    [data-nav="top"] .nav-chevron { display: none; }
    [data-nav="top"] .nav-group > .sidebar-section::after {
        content: "expand_more"; font-family: "Material Icons"; font-size: 17px; letter-spacing: 0; opacity: .55;
    }
    [data-nav="top"] .nav-group:hover > .sidebar-section,
    [data-nav="top"] .nav-group.open > .sidebar-section { color: #fff; background: #1f2128; }

    /* The list drops down under its trigger. html-prefixed so it outranks the
       left-mode tree collapse (max-height/overflow) at any rule order. */
    html[data-nav="top"] .nav-group > .sidebar-nav {
        position: absolute; top: 100%; left: 0; z-index: 300;
        display: none; flex-direction: column;
        min-width: 236px; padding: 6px;
        max-height: none; overflow: visible; transition: none;
        background: var(--chrome); border: 1px solid var(--chrome-border);
        border-top: 2px solid var(--f7-orange);
        border-radius: 0 0 10px 10px; box-shadow: 0 16px 44px rgba(0,0,0,.45);
    }
    [data-nav="top"] .nav-group:hover > .sidebar-nav,
    [data-nav="top"] .nav-group.open > .sidebar-nav { display: flex; }
    /* After a click-close, site.js adds .hover-suppress until mouseleave so the panel
       actually disappears while the pointer is still parked on the trigger. */
    [data-nav="top"] .nav-group.hover-suppress:not(.open):hover > .sidebar-nav { display: none; }
    /* Right-align the last groups' dropdowns so they don't spill past the viewport edge */
    [data-nav="top"] .nav-group:nth-last-child(-n+2) > .sidebar-nav { left: auto; right: 0; }
    [data-nav="top"] .nav-group > .sidebar-nav .sidebar-link {
        height: auto; padding: 9px 12px; border-radius: 7px; white-space: nowrap; gap: 10px;
    }
    [data-nav="top"] .nav-group > .sidebar-nav .sidebar-link.active::before {
        left: 0; top: 6px; bottom: 6px; right: auto; width: 2px; height: auto; transform: none;
        border-radius: 0 2px 2px 0;
    }

    /* Hide the sidebar footers (tenant selector + user) in top mode — topbar has the user menu */
    [data-nav="top"] .sidebar-tenant,
    [data-nav="top"] .sidebar-user { display: none; }

    /* Content reclaims the full width */
    [data-nav="top"] .app-main { margin-left: 0; }

    /* Location switching in top mode: .sidebar-tenant (the only SetCurrentLocation form in
       left mode) is hidden above, so the topbar's read-only chip is swapped for a real
       <select> form that posts the same route. !important beats the chip's inline flex. */
    [data-nav="top"] .topbar-location-chip { display: none !important; }
    [data-nav="top"] .topbar-location-switcher {
        display: flex; align-items: center; gap: 7px; margin: 0;
        background: var(--panel2); border: 1px solid var(--line);
        border-radius: 7px; padding: 0 4px 0 11px;
    }
    [data-nav="top"] .topbar-location-switcher select {
        background: transparent; border: none; outline: none;
        font: 600 10px var(--font-mono); letter-spacing: .5px;
        color: var(--ink2); text-transform: uppercase; cursor: pointer;
        max-width: 200px; padding: 8px 4px;
    }
    [data-nav="top"] .topbar-location-switcher select:hover,
    [data-nav="top"] .topbar-location-switcher select:focus { color: var(--ink); }
    /* Native option list renders outside the chip — give it readable panel colors */
    [data-nav="top"] .topbar-location-switcher option {
        text-transform: none; background: var(--panel); color: var(--ink);
    }
}

/* Topbar location switcher exists only in desktop top-nav mode; hidden everywhere else
   (left mode and ≤991px, where the sidebar form owns switching). */
.topbar-location-switcher { display: none; }

/* Nav-mode toggle button — hidden on mobile (mobile always uses the hamburger sidebar) */
.nav-toggle { display: inline-flex; }
@media (max-width: 991.98px) { .nav-toggle { display: none; } }

/* ---------- RESET & BASE ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
}

a { color: var(--f7-orange); text-decoration: none; }
a:hover { color: var(--f7-orange-hover); }

::selection {
    background: var(--f7-orange);
    color: #fff;
}

/* Scrollbars (Webkit) */
::-webkit-scrollbar { width: 11px; }
::-webkit-scrollbar-thumb {
    background: #cfccc4;
    border-radius: 8px;
    border: 3px solid transparent;
    background-clip: content-box;
}
::-webkit-scrollbar-track { background: transparent; }

/* ---------- TYPOGRAPHY ---------- */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -.3px;
    line-height: 1.2;
    margin: 0 0 .5rem;
}
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }
h5 { font-size: 13px; font-weight: 600; }
h6 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--ink3); }

.mono { font-family: var(--font-mono); }

.section-label {
    font: 600 9px var(--font-mono);
    color: var(--ink3);
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 0;
    margin: 0 0 8px;
}

.page-title {
    font: 600 18px var(--font-sans);
    color: var(--ink);
    letter-spacing: -.3px;
}
.page-subtitle {
    font: 500 10px var(--font-mono);
    color: var(--ink2);
    letter-spacing: .4px;
    margin-top: 2px;
}

/* ---------- F7 LOGO ---------- */
.f7-logo {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: var(--f7-orange);
    display: flex;
    align-items: center;
    justify-content: center;
    font: 700 14px var(--font-mono);
    color: var(--chrome);
    flex: none;
}
.f7-logo-sm {
    width: 24px; height: 24px;
    border-radius: 5px;
    font-size: 11px;
}
.f7-logo-lg {
    width: 34px; height: 34px;
    border-radius: 7px;
    font-size: 15px;
}

/* ---------- SIDEBAR (DARK CHROME) ---------- */
.app-sidebar {
    width: var(--sidebar-w);
    flex: none;
    background: var(--chrome);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform .3s ease;
}
.app-sidebar::-webkit-scrollbar { width: 0; }

.sidebar-header {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 18px;
    border-bottom: 1px solid var(--chrome-border);
    flex: none;
}
.sidebar-brand {
    font: 600 14px var(--font-sans);
    color: #fff;
    letter-spacing: -.2px;
    line-height: 1;
}
.sidebar-brand-sub {
    font: 500 8.5px var(--font-mono);
    color: var(--chrome-dim);
    letter-spacing: 1.4px;
    margin-top: 3px;
}

/* Sidebar navigation */
/* .sidebar-section is a real <button> on collapsible groups (tree toggle in left mode,
   dropdown trigger in top mode) and a plain <div> on the pinned HOME label. */
.sidebar-section {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: none;
    border: 0;
    text-align: left;
    font: 600 10.5px var(--font-mono);
    color: #9fa1a9;
    letter-spacing: 1.4px;
    padding: 18px 18px 9px;
}
.sidebar-section:first-child { padding-top: 14px; }
button.sidebar-section { cursor: pointer; transition: color .15s; }
button.sidebar-section:hover { color: var(--chrome-muted); }
button.sidebar-section:focus-visible { outline: 2px solid var(--f7-orange); outline-offset: -2px; }

/* Tree chevron (left mode + mobile drawer): points right collapsed, rotates down expanded */
.nav-chevron {
    margin-left: auto;
    font-size: 15px;
    opacity: .55;
    transition: transform .2s ease;
}
.nav-group.expanded > .sidebar-section .nav-chevron { transform: rotate(90deg); }

.sidebar-nav { padding: 0; margin: 0; list-style: none; }

/* Collapsible tree (left mode + mobile drawer): groups are collapsed by default; .expanded
   is restored from localStorage (f7-nav-tree) by an inline script right after the sidebar
   markup — i.e. before first paint — or derived from the page being viewed. Top-nav desktop
   mode neutralizes the collapse (see the html[data-nav="top"] dropdown rules above). */
.nav-group > .sidebar-nav {
    max-height: 0;
    overflow: hidden;
    transition: max-height .28s ease;
}
.nav-group.expanded > .sidebar-nav { max-height: 1000px; }

/* Scrollable nav region between the brand header and the footer cards. Kept as a class
   (NOT an inline style) so top-nav mode can lift the overflow trap for its dropdowns. */
.sidebar-scroll {
    padding: 14px 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    font: 500 12.5px var(--font-sans);
    color: var(--chrome-text);
    text-decoration: none;
    border-radius: 0;
    transition: background .15s, color .15s;
    cursor: pointer;
}
.sidebar-link:hover {
    background: var(--chrome-hover);
    color: #fff;
}
.sidebar-link.active {
    color: #fff;
    background: rgba(255,106,0,.12);
}
.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--f7-orange);
    border-radius: 0 2px 2px 0;
}
.sidebar-link { position: relative; }

.sidebar-icon {
    width: 20px;
    height: 20px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    opacity: .7;
}
.sidebar-link.active .sidebar-icon { opacity: 1; }

.sidebar-badge {
    margin-left: auto;
    font: 600 9px var(--font-mono);
    color: var(--chrome-muted);
    background: rgba(255,255,255,.08);
    padding: 2px 7px;
    border-radius: 4px;
    letter-spacing: .3px;
}
.sidebar-badge.alert-badge {
    color: var(--f7-orange);
    background: var(--f7-orange-muted);
}

/* Sidebar tenant selector (bottom) */
.sidebar-tenant {
    border-top: 1px solid var(--chrome-border);
    padding: 12px;
    flex: none;
}
.sidebar-tenant-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #1f2128;
    border: 1px solid #2d2f37;
    border-radius: 8px;
    padding: 9px 11px;
    cursor: pointer;
    transition: border-color .15s;
}
.sidebar-tenant-card:hover { border-color: #3d3f47; }
.sidebar-tenant-mono {
    width: 26px; height: 26px;
    border-radius: 5px;
    background: #2d2f37;
    display: flex;
    align-items: center;
    justify-content: center;
    font: 700 10px var(--font-mono);
    color: var(--f7-orange);
    flex: none;
}
.sidebar-tenant-name {
    font: 600 11.5px var(--font-sans);
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-tenant-sub {
    font: 500 8.5px var(--font-mono);
    color: var(--chrome-dim);
    letter-spacing: .6px;
}

/* Sidebar user profile (bottom) */
.sidebar-user {
    border-top: 1px solid var(--chrome-border);
    padding: 12px;
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-avatar {
    width: 32px; height: 32px;
    border-radius: 7px;
    background: var(--f7-orange);
    color: var(--chrome);
    display: flex;
    align-items: center;
    justify-content: center;
    font: 700 11px var(--font-mono);
    flex: none;
}
.sidebar-user-name {
    font: 600 11.5px var(--font-sans);
    color: #fff;
}
.sidebar-user-role {
    font: 500 10px var(--font-mono);
    color: #9fa1a9;
    letter-spacing: .4px;
}

/* ---------- TOPBAR ---------- */
.app-topbar {
    height: var(--topbar-h);
    flex: none;
    background: var(--panel3);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 18px;
}

/* ---------- MAIN CONTENT AREA ---------- */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}
.app-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.app-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

/* ---------- SEARCH BAR ---------- */
.search-bar {
    display: flex;
    align-items: center;
    background: var(--chrome-input);
    border: 1px solid var(--chrome-input-bd);
    border-radius: 6px;
    padding: 6px 10px;
    gap: 8px;
    width: 240px;
    cursor: text;
}
.search-bar-icon {
    width: 10px; height: 10px;
    border: 1.5px solid var(--chrome-muted);
    border-radius: 50%;
    flex: none;
}
.search-bar-text {
    font: 400 12px var(--font-sans);
    color: #9a9ca3;
    flex: 1;
}
.search-bar-shortcut {
    font: 500 10px var(--font-mono);
    color: var(--chrome-dim);
}

/* ---------- CARDS ---------- */
.f7-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.f7-card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--line-lighter);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.f7-card-title {
    font: 600 13px var(--font-sans);
    color: var(--ink);
}
.f7-card-body { padding: 16px 20px; }

/* ---------- KPI CARDS ---------- */
.kpi-strip {
    display: grid;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.kpi-cell {
    padding: 15px 16px;
    border-right: 1px solid var(--line-light);
}
.kpi-cell:last-child { border-right: none; }
.kpi-label {
    font: 500 9.5px var(--font-mono);
    color: var(--ink2);
    letter-spacing: .8px;
    text-transform: uppercase;
}
.kpi-value {
    font: 600 25px var(--font-mono);
    color: var(--ink);
    margin-top: 9px;
    letter-spacing: -.5px;
}
.kpi-delta {
    font: 500 11px var(--font-mono);
    margin-top: 5px;
}
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }
.kpi-delta.neutral { color: var(--ink3); }

/* ---------- STATUS BADGES ---------- */
.badge-status {
    font: 600 9px var(--font-mono);
    letter-spacing: .5px;
    padding: 4px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.badge-green  { color: var(--green); background: var(--green-bg); }
.badge-red    { color: var(--red);   background: var(--red-bg); }
.badge-amber  { color: var(--amber); background: var(--amber-bg); }
.badge-blue   { color: var(--blue);  background: var(--blue-bg); }
.badge-orange { color: var(--f7-orange); background: var(--f7-orange-muted); }
/* Neutral chips: --ink flips to near-white in dark mode, so these two must NOT
   use it as a fill — they get explicit per-theme values instead. */
.badge-muted  { color: #9a9ca3; background: #26282f; }
.badge-dark   { color: #fff; background: var(--chrome); }
[data-theme="dark"] .badge-muted { color: #a8aab2; background: #32343c; }
[data-theme="dark"] .badge-dark  { color: #e9e7e2; background: #3a3d45; }
/* Brighter orange text on dark so the tint chip stays readable */
[data-theme="dark"] .badge-orange { color: #ff8a3d; }

/* ---------- DATA TABLES ---------- */
.f7-table {
    width: 100%;
    border-collapse: collapse;
}
.f7-table thead th {
    font: 600 9.5px var(--font-mono);
    color: var(--ink3);
    letter-spacing: .6px;
    text-transform: uppercase;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line-light);
    background: var(--panel3);
    text-align: left;
}
.f7-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line-lighter);
    font: 400 12.5px var(--font-sans);
    color: var(--ink);
    vertical-align: middle;
}
.f7-table tbody tr { cursor: default; transition: background .1s; }
.f7-table tbody tr:hover { background: var(--panel2); }
.f7-table tbody tr:last-child td { border-bottom: none; }

.f7-table .col-mono {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 11.5px;
    color: var(--ink2);
}
.f7-table .col-amount {
    font: 600 12px var(--font-mono);
    color: var(--ink);
    text-align: right;
}
.f7-table .col-muted {
    font: 500 11px var(--font-mono);
    color: var(--ink3);
}

/* ---------- BUTTONS ---------- */
.btn-f7 {
    font: 600 12px var(--font-sans);
    padding: 9px 15px;
    border-radius: 7px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s, border-color .15s;
    text-decoration: none;
    line-height: 1;
}
.btn-f7-primary {
    background: var(--f7-orange);
    color: var(--chrome);
}
.btn-f7-primary:hover { background: var(--f7-orange-hover); color: var(--chrome); }

.btn-f7-secondary {
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
}
.btn-f7-secondary:hover { background: var(--panel2); color: var(--ink); }

.btn-f7-dark {
    background: var(--chrome-input);
    color: var(--chrome-text);
    border: 1px solid var(--chrome-input-bd);
}
.btn-f7-dark:hover { border-color: #5a5c63; color: #fff; }

.btn-f7-ghost {
    background: transparent;
    color: var(--ink2);
    border: 1px solid var(--line);
}
.btn-f7-ghost:hover { background: var(--panel2); color: var(--ink); }

.btn-f7-danger {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid transparent;
}
.btn-f7-danger:hover { background: rgba(192,57,43,.18); }

.btn-f7-sm {
    font-size: 11px;
    padding: 7px 11px;
    border-radius: 6px;
}

/* ---------- FORM CONTROLS ---------- */
.f7-input,
.f7-select,
.f7-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    font: 400 13px var(--font-sans);
    color: var(--ink);
    background: var(--panel);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.f7-input:focus,
.f7-select:focus,
.f7-textarea:focus {
    border-color: var(--f7-orange);
    box-shadow: 0 0 0 3px var(--f7-orange-focus);
}
.f7-input::placeholder { color: var(--ink3); }

.f7-label {
    font: 600 11.5px var(--font-sans);
    color: var(--ink4);
    display: block;
    margin-bottom: 6px;
}
.f7-label-mono {
    font: 600 9px var(--font-mono);
    color: var(--ink3);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 8px;
}

/* Inline editable table cells */
.f7-cell-input {
    font-family: var(--font-sans);
    border: 1px solid transparent;
    background: transparent;
    outline: none;
    width: 100%;
    border-radius: 6px;
    padding: 8px 9px;
    font-size: 13px;
    color: var(--ink);
}
.f7-cell-input:hover { background: var(--panel2); }
.f7-cell-input:focus {
    background: var(--panel);
    border-color: var(--f7-orange);
    box-shadow: 0 0 0 2px var(--f7-orange-focus);
}

/* ---------- FILTER TABS ---------- */
.f7-filters {
    display: flex;
    gap: 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 4px;
}
.f7-filter-tab {
    font: 500 12px var(--font-sans);
    color: var(--ink2);
    padding: 7px 14px;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    background: transparent;
    transition: background .15s, color .15s;
}
.f7-filter-tab:hover { color: var(--ink); background: var(--panel2); }
.f7-filter-tab.active {
    color: var(--ink);
    background: var(--panel);
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    font-weight: 600;
}

/* ---------- STATUS DOTS ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-green  { background: var(--green); }
.dot-red    { background: var(--red); }
.dot-amber  { background: var(--amber); }
.dot-blue   { background: var(--blue); }
.dot-orange { background: var(--f7-orange); }
.dot-muted  { background: var(--ink3); }

/* ---------- ACTIVITY TIMELINE ---------- */
.timeline-item {
    display: flex;
    gap: 13px;
}
.timeline-line {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.timeline-dot {
    width: 11px; height: 11px;
    border-radius: 50%;
    flex: none;
    border: 2px solid;
}
.timeline-connector {
    width: 2px;
    flex: 1;
    min-height: 14px;
}
.timeline-content { padding-bottom: 14px; }
.timeline-title { font: 600 12.5px var(--font-sans); }
.timeline-when {
    font: 500 11px var(--font-mono);
    color: var(--ink3);
    margin-top: 2px;
}

/* ---------- MONOGRAM AVATARS ---------- */
.monogram {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    font: 700 10px var(--font-mono);
    flex: none;
}
.monogram-sm { width: 26px; height: 26px; font-size: 9px; border-radius: 5px; }
.monogram-md { width: 32px; height: 32px; font-size: 11px; border-radius: 7px; }
.monogram-lg { width: 40px; height: 40px; font-size: 14px; border-radius: 9px; }
.monogram-xl { width: 60px; height: 60px; font-size: 22px; border-radius: 13px; }
.monogram-dark { background: var(--chrome); color: #fff; }
.monogram-orange { background: var(--f7-orange); color: var(--chrome); }
.monogram-blue { background: var(--blue); color: #fff; }

/* ---------- PROGRESS BARS ---------- */
.f7-progress {
    height: 7px;
    background: var(--panel2);
    border-radius: 4px;
    overflow: hidden;
}
.f7-progress-fill {
    height: 100%;
    background: var(--f7-orange);
    border-radius: 4px;
    transition: width .3s;
}

/* ---------- DARK BANNER ---------- */
.f7-dark-banner {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--chrome);
    border-radius: 12px;
    padding: 18px 22px;
}

/* ---------- DOCUMENT HEADER STRIPE ---------- */
.doc-stripe {
    height: 5px;
    background: var(--f7-orange);
}

/* ---------- PAGINATION ---------- */
.f7-pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
    justify-content: center;
}
.f7-page-btn {
    font: 500 12px var(--font-mono);
    color: var(--ink2);
    padding: 7px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    cursor: pointer;
    transition: background .15s;
}
.f7-page-btn:hover { background: var(--panel2); }
.f7-page-btn.active {
    background: var(--f7-orange);
    color: #fff;
    border-color: var(--f7-orange);
}
.f7-page-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}

/* ---------- EMPTY STATES ---------- */
.f7-empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--ink3);
}
.f7-empty-icon {
    font-size: 48px;
    opacity: .3;
    margin-bottom: 12px;
}
.f7-empty-title {
    font: 600 15px var(--font-sans);
    color: var(--ink2);
    margin-bottom: 6px;
}
.f7-empty-text {
    font: 400 13px var(--font-sans);
    color: var(--ink3);
}

/* ---------- MODALS ---------- */
.f7-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.f7-modal {
    background: var(--panel);
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 56px rgba(0,0,0,.22);
    max-width: 560px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
}
.f7-modal-header {
    padding: 20px 24px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.f7-modal-title { font: 600 16px var(--font-sans); color: var(--ink); }
.f7-modal-body { padding: 0 24px 24px; }
.f7-modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--line-lighter);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ---------- ALERTS / TOASTS ---------- */
.f7-alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font: 500 12.5px var(--font-sans);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}
.f7-alert-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(31,138,82,.2); }
.f7-alert-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid rgba(192,57,43,.2); }
.f7-alert-warning { background: var(--amber-bg); color: var(--amber); border: 1px solid rgba(202,166,0,.2); }
.f7-alert-info    { background: var(--blue-bg);  color: var(--blue);  border: 1px solid rgba(91,110,245,.2); }

/* ---------- SIDEBAR TOGGLE (MOBILE) ---------- */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1050;
    background: var(--chrome);
    color: #fff;
    border: 1px solid var(--chrome-border);
    border-radius: 7px;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    cursor: pointer;
    font-size: 20px;
}

/* Sidebar backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 199;
}
.sidebar-backdrop.show { display: block; }

/* ---------- MOBILE BOTTOM NAV ---------- */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--chrome);
    border-top: 1px solid var(--chrome-border);
    z-index: 1040;
    padding: 6px 0;
    padding-bottom: env(safe-area-inset-bottom, 6px);
}
.mobile-bottom-nav .nav {
    display: flex;
    justify-content: space-around;
}
.mobile-bottom-nav .nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    font: 500 9px var(--font-sans);
    color: var(--chrome-muted);
    padding: 4px 8px;
    gap: 2px;
    text-decoration: none;
}
.mobile-bottom-nav .nav-link .material-icons { font-size: 20px; }
.mobile-bottom-nav .nav-link.active,
.mobile-bottom-nav .nav-link:hover { color: var(--f7-orange); }

/* ---------- LINE ITEMS TABLE (HORIZONTAL SCROLL) ---------- */
.line-items-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.line-items-wrapper table { min-width: 700px; }

/* ---------- AUTOCOMPLETE ---------- */
.autocomplete-dropdown {
    position: absolute;
    z-index: 1050;
    background: var(--panel);
    border: 1.5px solid var(--ac-outline);
    border-radius: var(--radius);
    max-height: 250px;
    overflow-y: auto;
    width: 100%;
    display: none;
    box-shadow: 0 10px 34px rgba(0,0,0,.16), 0 2px 8px rgba(0,0,0,.09);
}
[data-theme="dark"] .autocomplete-dropdown {
    box-shadow: 0 12px 38px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.35);
}
.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--line-lighter);
    font: 400 12.5px var(--font-sans);
    color: var(--ink);
    transition: background .1s;
}
.autocomplete-item:last-child { border-bottom: none; }
/* Hover = subtle surface lighten; keyboard/active = accent tint. Both tokenized. */
.autocomplete-item:hover { background: var(--panel2); }
.autocomplete-item.active { background: var(--f7-orange-muted); }
/* Clear (×) button injected by autocomplete.js */
.autocomplete-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--ink3);
    font-size: 18px;
    display: none;
    z-index: 1051;
}
.autocomplete-clear:hover { color: var(--ink); }
.autocomplete-no-results {
    padding: 10px 14px;
    color: var(--ink3);
    font-style: italic;
    font-size: 12px;
}
.autocomplete-loading {
    padding: 10px 14px;
    color: var(--ink3);
    text-align: center;
    font-size: 12px;
}

/* ---------- MULTI-COLUMN AUTOCOMPLETE GRID ---------- */
.autocomplete-dropdown.autocomplete-grid { max-height: 320px; }
.autocomplete-grid .ac-grid-header,
.autocomplete-grid .ac-grid-row {
    display: grid;
    align-items: center;
    column-gap: 12px;
    padding: 0 14px;
}
/* Column-label row: dark chrome header (like the app sidebar/topbar) in BOTH
   themes — dark background, light uppercase labels. */
.autocomplete-grid .ac-grid-header {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--chrome);
    border-bottom: 1px solid var(--chrome-border);
    padding-top: 7px;
    padding-bottom: 7px;
    font: 600 10px var(--font-mono);
    letter-spacing: .6px;
    text-transform: uppercase;
    color: var(--chrome-text);
}
.autocomplete-grid .autocomplete-item.ac-grid-row {
    padding-top: 8px;
    padding-bottom: 8px;
    font: 400 12px var(--font-sans);
}
.autocomplete-grid .ac-grid-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    color: var(--ink);
}
.autocomplete-grid .ac-grid-cell.ac-right { text-align: right; }
.autocomplete-grid .ac-grid-cell.ac-mono { font-family: var(--font-mono); font-size: 11.5px; }
.autocomplete-grid .ac-grid-cell.ac-muted { color: var(--ink2); }
.autocomplete-grid .ac-grid-header .ac-grid-cell { color: var(--chrome-text); }

.autocomplete-loading::after {
    content: '';
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid var(--line);
    border-top-color: var(--f7-orange);
    border-radius: 50%;
    animation: f7-spin .6s linear infinite;
    margin-left: 6px;
    vertical-align: middle;
}
@keyframes f7-spin { to { transform: rotate(360deg); } }

/* ---------- BOOTSTRAP OVERRIDES ---------- */
/* Keep Bootstrap for grid/utility but override visuals */

.btn-primary {
    background-color: var(--f7-orange) !important;
    border-color: var(--f7-orange) !important;
    color: var(--chrome) !important;
    font-family: var(--font-sans);
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    border-radius: 7px;
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--f7-orange-hover) !important;
    border-color: var(--f7-orange-hover) !important;
}

.btn-outline-primary {
    color: var(--f7-orange) !important;
    border-color: var(--f7-orange) !important;
}
.btn-outline-primary:hover {
    background-color: var(--f7-orange) !important;
    color: #fff !important;
}

.btn-outline-danger {
    color: var(--red) !important;
    border-color: var(--red) !important;
}

.btn {
    font-family: var(--font-sans);
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    font-size: 12px;
    border-radius: 7px;
    padding: 8px 13px;
}

.bg-primary { background-color: var(--chrome) !important; }

.form-control, .form-select {
    font-family: var(--font-sans);
    border-color: var(--line);
    border-radius: 7px;
    font-size: 13px;
    color: var(--ink);
}
.form-control:focus, .form-select:focus {
    border-color: var(--f7-orange);
    box-shadow: 0 0 0 3px var(--f7-orange-focus);
}

.form-label {
    font: 600 11.5px var(--font-sans);
    color: var(--ink4);
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
}
.card-header {
    background: var(--panel);
    border-bottom: 1px solid var(--line-lighter);
    font: 600 13px var(--font-sans);
    color: var(--ink);
    padding: 14px 20px;
}
.card-body { padding: 16px 20px; }

.table { font-family: var(--font-sans); }
.table th {
    font: 600 9.5px var(--font-mono);
    color: var(--ink3);
    letter-spacing: .6px;
    text-transform: uppercase;
    border-bottom-color: var(--line-light);
    padding: 10px 16px;
}
.table td {
    padding: 12px 16px;
    border-bottom-color: var(--line-lighter);
    color: var(--ink);
    font-size: 12.5px;
    vertical-align: middle;
}
.table-hover tbody tr:hover { background-color: var(--panel2); }

.nav-link { font-family: var(--font-sans); }
.nav-link.active { color: var(--f7-orange) !important; }

.dropdown-menu {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 10px 34px rgba(0,0,0,.13);
    font-family: var(--font-sans);
}

.modal-content {
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 56px rgba(0,0,0,.22);
}

/* Bootstrap modals default to a white .modal-content; map their CSS variables
   to theme tokens so the modal follows the dark theme (same selector convention
   as the other dark overrides above). */
[data-theme="dark"] .modal-content {
    --bs-modal-bg: var(--panel);
    --bs-modal-color: var(--ink);
    --bs-modal-header-border-color: var(--line);
    --bs-modal-footer-border-color: var(--line);
    background: var(--panel);
    color: var(--ink);
    border-color: var(--line);
}
[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer { border-color: var(--line); color: var(--ink); }
[data-theme="dark"] .modal-title { color: var(--ink); }
[data-theme="dark"] .modal-content .btn-close { filter: invert(1) grayscale(100%) brightness(1.8); }

/* Auth cards (2FA / recovery-code) sit on --panel, which is a light card in the
   light theme, so they default to the ink-text f7-lockup.svg. On the dark card,
   swap to the white-text lockup so the wordmark stays legible. Scoped via
   .auth-lockup so the always-white login-brand lockup is untouched. */
[data-theme="dark"] .auth-lockup { content: url("/logo/svg/f7-lockup-white.svg"); }

.badge {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 9px;
    letter-spacing: .5px;
}

.alert {
    border-radius: var(--radius);
    font-family: var(--font-sans);
}

.text-primary { color: var(--f7-orange) !important; }
.text-muted { color: var(--ink3) !important; }
.border-primary { border-color: var(--f7-orange) !important; }

/* Shadow system matching F7 design */
.shadow-sm { box-shadow: 0 2px 10px rgba(0,0,0,.05) !important; }
.shadow { box-shadow: 0 10px 34px rgba(0,0,0,.13), 0 2px 8px rgba(0,0,0,.07) !important; }
.shadow-lg { box-shadow: 0 18px 50px rgba(0,0,0,.22) !important; }

/* ---------- RESPONSIVE — TABLET (≤992px) ---------- */
@media (max-width: 991.98px) {
    .sidebar-toggle { display: flex; }

    .app-sidebar {
        transform: translateX(-100%);
        z-index: 200 !important;
    }
    .app-sidebar.show { transform: translateX(0); }

    .app-main {
        margin-left: 0 !important;
        width: 100% !important;
    }
    .app-content {
        padding: 60px 14px 14px;
    }

    /* Clear the fixed hamburger (top-left) so the page title isn't hidden behind it */
    .app-topbar { padding-left: 60px; }

    .mobile-bottom-nav { display: block; }
    .app-content { padding-bottom: 70px; }

    .kpi-strip { grid-template-columns: repeat(2, 1fr) !important; }

    .card-header { flex-wrap: wrap !important; gap: 8px; }

    .modal-dialog { max-width: 95%; margin: 10px auto; }
    .modal-lg, .modal-xl { max-width: 95%; }

    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .nav-tabs .nav-item { flex-shrink: 0; }
}

/* ---------- RESPONSIVE — PHONE (≤576px) ---------- */
@media (max-width: 575.98px) {
    .kpi-strip { grid-template-columns: 1fr !important; }

    /* On phones, every multi-column inline grid collapses to a single column.
       Wide line-item rows stack rather than overflow the viewport. */
    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

    .app-content { padding: 56px 10px 80px; }

    /* Topbar wraps instead of overflowing once the title + controls don't fit */
    .app-topbar { flex-wrap: wrap; height: auto; padding: 8px 14px 8px 60px; gap: 8px; }

    /* Bigger tap targets on phones */
    .btn-f7-sm { min-height: 38px; }
    .f7-modal-header button { min-width: 40px; min-height: 40px; }
    .f7-select { max-width: 100%; }

    .form-control, .form-select { min-width: 0 !important; }

    .card-header.d-flex {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .table td, .table th {
        padding: .4rem .5rem;
        font-size: 11px;
    }

    .btn-sm {
        min-height: 36px;
        min-width: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    h1 { font-size: 20px; }
    h2 { font-size: 17px; }
    h3 { font-size: 15px; }

    .modal-dialog { max-width: 100%; margin: 0; min-height: 100vh; }
    .modal-content { border-radius: 0; min-height: 100vh; }
}

/* ---------- RESPONSIVE — COMMON MOBILE (≤768px) ---------- */
@media (max-width: 768px) {
    /* Any wide table scrolls horizontally instead of overflowing the page — regardless of how deeply
       it's nested inside a card body (.f7-card-body, .card-body) or used standalone (.f7-table). */
    .card-body table,
    .f7-card table,
    .f7-card-body table,
    .f7-table,
    .table-responsive {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .row > [class*="col-md-"],
    .row > [class*="col-lg-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Collapse the big document / detail 2-column page splits so the side rail
       stacks under the document instead of being crushed into a sliver. */
    [style*="grid-template-columns: 1.55fr"],
    [style*="grid-template-columns: 1.6fr"],
    [style*="grid-template-columns: 1.7fr"],
    [style*="grid-template-columns: 1.5fr"],
    [style*="grid-template-columns: 1.45fr"],
    [style*="grid-template-columns: 1.4fr"],
    [style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* The cylinder "on hire" banner is a 3-part flex — let it wrap on small screens. */
    .f7-dark-banner { flex-wrap: wrap; }

    .autocomplete-dropdown { max-height: 200px; }
    .autocomplete-item { padding: 12px; font-size: 14px; min-height: 44px; }

    .admin-sidebar {
        transform: translateX(-100%);
        transition: transform .3s ease;
        z-index: 200 !important;
    }
    .admin-sidebar.show { transform: translateX(0); }
    .admin-main {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 60px 12px 12px !important;
    }
}

/* ---------- PORTAL TOP NAV (responsive) ----------
   The portal top bar is a single fixed-height flex row with no hamburger. On phones the brand +
   up to 7 links + theme toggle + user menu overflow the viewport. Rather than push controls off
   the right edge, shrink the brand and turn the link row into a single horizontally-scrollable
   strip (the strip scrolls, the page does not), keeping the toggle and user menu on screen. */
@media (max-width: 768px) {
    .portal-nav-inner { gap: 12px !important; }
    .portal-brand-name { display: none; }               /* keep the F7 mark, drop the long company name */
    .portal-nav-links {
        margin-left: 8px !important;
        min-width: 0;                                   /* allow the flex row to shrink so it can scroll */
        flex: 1 1 auto;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;                          /* Firefox: hide scrollbar */
    }
    .portal-nav-links::-webkit-scrollbar { display: none; }   /* WebKit: hide scrollbar */
    .portal-nav-links > a { flex: 0 0 auto; padding: 0 12px !important; }
}

/* WorkOrders labor/parts grids use fixed-px columns that don't stack; on narrow screens scroll the
   whole block horizontally so the rows keep their column alignment instead of being crushed. */
@media (max-width: 767px) {
    .wo-lines-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .wo-lines-scroll > div,
    .wo-lines-scroll > form { min-width: 540px; }
}

/* ---------- PRINT ---------- */
@media print {
    .app-sidebar,
    .sidebar-toggle,
    .mobile-bottom-nav,
    .sidebar-backdrop,
    .app-topbar { display: none !important; }

    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0 !important; }

    body { background: #fff; color: #000; }
    .f7-card { border: 1px solid #ddd; box-shadow: none; }

    /* Paper always prints LIGHT: re-declare the core surface/ink/line tokens so a user printing
       from the dark theme doesn't get dark cards and light ink on paper. Selector includes the
       dark-theme root so it out-specifies the [data-theme="dark"] block. */
    :root, [data-theme="dark"] {
        --bg: #fff;
        --bg-alt: #fff;
        --panel: #fff;
        --panel2: #f6f5f2;
        --panel3: #faf9f7;
        --line: #d8d5ce;
        --line-light: #e7e4dd;
        --line-lighter: #efece5;
        --ink: #181715;
        --ink2: #6c685f;
        --ink3: #9a978f;
        --ink4: #3a3833;
        --green: #1f8a52;
        --red: #c0392b;
        --amber: #a98700;
        --blue: #5b6ef5;
    }
}

/* ---------- UTILITY HELPERS ---------- */
.gap-sm  { gap: 8px; }
.gap-md  { gap: 14px; }
.gap-lg  { gap: 18px; }
.gap-xl  { gap: 22px; }
.w-full  { width: 100%; }
.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.no-wrap { white-space: nowrap; }

/* ---------- BRAND MARKS (logo assets) ---------- */
/* Badge/lockup swapped in for the old .f7-logo text tile. Keep them from
   inheriting flex-shrink so spacing in nav/sidebar headers stays intact. */
.f7-brand-badge  { flex: none; display: block; }
.f7-brand-lockup { flex: none; display: block; width: auto; }

/* ---------- LOADING OVERLAY (f7-loader.svg) ---------- */
.f7-loading {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(22, 23, 28, .42);
    backdrop-filter: blur(1.5px);
}
.f7-loading.show { display: flex; }
.f7-loading img {
    width: 56px;
    height: 56px;
    filter: drop-shadow(0 4px 14px rgba(0,0,0,.25));
}

/* ---------- DASHBOARD CATEGORY GRID ----------
   Quick-access cards on the home screen. One card per business category, mirroring the
   navigation menus (same names, same member links, same permission gates). */
.dash-cat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.dash-cat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
}
.dash-cat-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.dash-cat-head .material-icons { font-size: 17px; color: var(--f7-orange); }
.dash-cat-title {
    font: 600 10px var(--font-mono);
    letter-spacing: 1px;
    color: var(--ink2);
    text-transform: uppercase;
}
.dash-cat-links { display: flex; flex-direction: column; }
.dash-cat-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    margin: 0 -6px;
    border-radius: 6px;
    font: 500 12.5px var(--font-sans);
    color: var(--ink);
}
.dash-cat-link:hover { background: var(--panel2); color: var(--f7-orange); }
.dash-cat-link .material-icons { font-size: 15px; color: var(--ink3); }
.dash-cat-link:hover .material-icons { color: var(--f7-orange); }

/* ---------- PRINTED DOCUMENT LETTERHEAD ---------- */
.doc-logo { height: 40px; width: auto; }
@media print {
    /* Ink letterhead must render as-is regardless of any inherited filters. */
    .doc-logo { filter: none; }
}

/* ---------- DOCUMENT FLOW STEPPER ---------- */
/* Vertical lifecycle rail rendered by Areas/Tenant/Views/Shared/_DocumentFlow.cshtml.
   Node states: done (filled ✓), current (accent ring, pulsing), pending (hollow muted),
   skipped (⊘, struck title). All colors ride the theme variables so dark mode just works. */
.docflow { display: flex; flex-direction: column; }
.docflow-step { display: flex; gap: 11px; min-height: 40px; }
.docflow-rail { display: flex; flex-direction: column; align-items: center; width: 18px; flex: none; }
.docflow-node {
    width: 18px; height: 18px; border-radius: 50%; flex: none; box-sizing: border-box;
    display: flex; align-items: center; justify-content: center;
    font: 700 10px/1 var(--font-mono);
    background: var(--panel2);
    border: 2px solid var(--line-lighter);
    color: var(--ink3);
}
.docflow-line { width: 2px; flex: 1; min-height: 12px; background: var(--line-lighter); margin: 2px 0; }
.docflow-line-done { background: var(--green); }
.docflow-body { flex: 1; min-width: 0; padding-bottom: 12px; }
.docflow-step:last-child .docflow-body { padding-bottom: 0; }
.docflow-title { font: 600 12.5px var(--font-sans); color: var(--ink); margin-top: 1px; }
.docflow-detail { font: 500 10.5px var(--font-mono); color: var(--ink3); margin-top: 2px; word-break: break-word; }
.docflow-link { display: inline-block; font: 600 11px var(--font-mono); color: var(--f7-orange); margin-top: 3px; }
.docflow-link:hover { color: var(--f7-orange); text-decoration: underline; }

/* Next-step action — the small "walk me through it" button on the step the document is
   waiting on (link or one-click POST, built server-side in BuildDocumentFlow). */
.docflow-action-form { margin: 0; }
.docflow-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 4px 10px;
    font: 600 11.5px var(--font-sans);
    color: var(--f7-orange);
    background: transparent;
    border: 1px solid var(--f7-orange);
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.docflow-action:hover { background: var(--f7-orange); color: #fff; }

.docflow-done .docflow-node { background: var(--green); border-color: var(--green); color: #fff; }
.docflow-current .docflow-node {
    background: var(--panel); border-color: var(--f7-orange); color: var(--f7-orange);
    animation: docflow-pulse 2s ease-in-out infinite;
}
.docflow-current .docflow-title { color: var(--f7-orange); }
.docflow-pending .docflow-node { background: transparent; }
.docflow-pending .docflow-title { color: var(--ink3); font-weight: 500; }
.docflow-skipped .docflow-node { background: transparent; border-style: dashed; }
.docflow-skipped .docflow-title { color: var(--ink3); font-weight: 500; text-decoration: line-through; }
@keyframes docflow-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(255, 106, 0, .20); }
    50%      { box-shadow: 0 0 0 7px rgba(255, 106, 0, .06); }
}
@media (prefers-reduced-motion: reduce) {
    .docflow-current .docflow-node { animation: none; box-shadow: 0 0 0 3px rgba(255, 106, 0, .20); }
}

/* ---- Quantity increment note (F7Qty.note) ----
   Standing "Multiples of X" hint rendered under a line's qty input when the item's
   MinQuantity isn't 1 — the buyer/seller sees the pack rule before typing. */
.f7-qty-note {
    font: 500 10px var(--font-mono);
    color: var(--amber);
    line-height: 1.3;
    margin-top: 2px;
    white-space: nowrap;
}

/* ═══════════════ F7 THEMED CONFIRM/ALERT MODALS (replaces native confirm/alert) ═══════════════
   Namespaced f7-confirm-* — deliberately NOT .f7-modal/.f7-modal-title/.f7-modal-body, which are
   already used by the app's static per-page modals (WorkOrders/Receiving/Shipments/etc.); reusing
   those class names collided the two systems' styles (sizing/transform bled across both). */
.f7-confirm-overlay {
    position: fixed; inset: 0; z-index: 4000;
    background: rgba(10, 11, 14, .45); backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center; padding: 20px;
    opacity: 0; transition: opacity .12s ease;
}
.f7-confirm-overlay.f7-confirm-open { opacity: 1; }
.f7-confirm-overlay.f7-confirm-closing { opacity: 0; }
.f7-confirm-modal {
    background: var(--surface, #fff); color: var(--ink, #16171c);
    border: 1px solid var(--line, #d9dbe0); border-radius: 10px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
    width: 100%; max-width: 420px; padding: 18px 20px 16px;
    transform: translateY(8px) scale(.98); transition: transform .12s ease;
}
.f7-confirm-overlay.f7-confirm-open .f7-confirm-modal { transform: translateY(0) scale(1); }
.f7-confirm-title {
    font: 600 14px var(--font-sans); color: var(--ink); letter-spacing: -.2px;
    margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line-lighter, #eceef1);
}
.f7-confirm-danger .f7-confirm-title { color: var(--red, #c92a2a); }
.f7-confirm-body { font: 400 13px/1.5 var(--font-sans); color: var(--ink2, #3f4147); white-space: pre-line; }
.f7-confirm-input { margin-top: 12px; width: 100%; }
.f7-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.f7-confirm-danger .f7-confirm-ok { background: var(--red, #c92a2a); border-color: var(--red, #c92a2a); }

/* ═══════════ In-app help drawer (tenant) ═══════════
   Content comes from wwwroot/help/help-content.json (built from the manual chapters).
   Theme-aware via the standard tokens; slides over the right edge above everything. */
.help-backdrop {
    position: fixed; inset: 0; background: rgba(10, 10, 14, .35);
    opacity: 0; pointer-events: none; transition: opacity .18s ease; z-index: 1090;
}
.help-backdrop.open { opacity: 1; pointer-events: auto; }

.help-drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 94vw;
    background: var(--panel); border-left: 1px solid var(--line);
    box-shadow: -8px 0 28px rgba(0, 0, 0, .18);
    transform: translateX(102%); transition: transform .2s ease;
    z-index: 1091; display: flex; flex-direction: column;
}
.help-drawer.open { transform: translateX(0); }

.help-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px 10px; border-bottom: 1px solid var(--line-light);
}
.help-head-title { display: flex; align-items: center; gap: 8px; font: 700 14px var(--font-sans); color: var(--ink); }
.help-close { background: none; border: none; color: var(--ink3); cursor: pointer; padding: 4px; border-radius: 6px; }
.help-close:hover { color: var(--ink); background: var(--panel2); }

.help-search {
    display: flex; align-items: center; gap: 8px; margin: 10px 14px 8px;
    background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
.help-search input {
    flex: 1; border: none; background: none; outline: none;
    font: 400 12.5px var(--font-sans); color: var(--ink);
}
.help-search input::placeholder { color: var(--ink3); }

.help-crumb {
    padding: 4px 16px 8px; font: 600 10px var(--font-mono); letter-spacing: .8px;
    text-transform: uppercase; color: var(--ink3);
    display: flex; align-items: center; gap: 10px;
}
.help-crumb a { color: var(--f7-orange); text-decoration: none; font: 600 10px var(--font-mono); letter-spacing: .8px; }
.help-crumb .help-crumb-chap { color: var(--ink3); }

.help-body { flex: 1; overflow-y: auto; padding: 2px 16px 14px; }
.help-empty { padding: 26px 6px; font: 400 12.5px var(--font-sans); color: var(--ink2); text-align: center; }
.help-empty a { color: var(--f7-orange); }

/* TOC */
.help-chap { border-bottom: 1px solid var(--line-lighter, var(--line-light)); }
.help-chap summary {
    cursor: pointer; list-style: none; padding: 9px 2px;
    font: 600 12.5px var(--font-sans); color: var(--ink); display: flex; align-items: center; gap: 8px;
}
.help-chap summary::-webkit-details-marker { display: none; }
.help-chap-no {
    min-width: 20px; text-align: center; font: 700 10px var(--font-mono);
    color: var(--f7-orange); background: var(--panel2); border: 1px solid var(--line);
    border-radius: 5px; padding: 2px 4px;
}
.help-chap-secs { padding: 0 2px 8px 28px; display: flex; flex-direction: column; }
.help-sec-link {
    padding: 4px 0; font: 400 12px var(--font-sans); color: var(--ink2); text-decoration: none;
}
.help-sec-link:hover { color: var(--f7-orange); }
.help-sec-no { font: 600 10.5px var(--font-mono); color: var(--f7-orange); margin-right: 4px; }

/* Search results */
.help-result {
    display: block; padding: 9px 10px; margin: 6px 0; border: 1px solid var(--line-light);
    border-radius: 8px; text-decoration: none; background: var(--panel);
}
.help-result:hover { border-color: var(--f7-orange); }
.help-result-title { font: 600 12.5px var(--font-sans); color: var(--ink); }
.help-result-chap { font: 600 9.5px var(--font-mono); letter-spacing: .6px; text-transform: uppercase; color: var(--ink3); margin-top: 2px; }
.help-result-snip { font: 400 11.5px/1.5 var(--font-sans); color: var(--ink2); margin-top: 4px; }
.help-result-snip mark { background: color-mix(in srgb, var(--f7-orange) 24%, transparent); color: var(--ink); border-radius: 2px; padding: 0 1px; }

/* Article view — mirrors the manual's typography at drawer scale */
.help-article { font: 400 12.5px/1.65 var(--font-sans); color: var(--ink2); }
.help-article h2 { font: 700 15px var(--font-sans); color: var(--ink); margin: 10px 0 8px; letter-spacing: -.2px; }
.help-article h3 { font: 600 13px var(--font-sans); color: var(--ink); margin: 14px 0 5px; }
.help-article h3 .no, .help-article h2 .no { color: var(--f7-orange); margin-right: 5px; }
.help-article p { margin: 6px 0; }
.help-article strong { color: var(--ink); }
.help-article ol, .help-article ul { margin: 6px 0 10px; padding-left: 20px; }
.help-article li { margin: 4px 0; }
.help-article table { border-collapse: collapse; width: 100%; margin: 8px 0 12px; font-size: 11px; display: block; overflow-x: auto; }
.help-article th { text-align: left; background: var(--panel2); border: 1px solid var(--line); padding: 4px 7px; font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink2); }
.help-article td { border: 1px solid var(--line-light); padding: 4px 7px; vertical-align: top; }
.help-article blockquote {
    margin: 10px 0; padding: 8px 12px; border-left: 3px solid var(--ink3);
    background: var(--panel2); border-radius: 0 6px 6px 0;
}
.help-article blockquote p { margin: 2px 0; }
.help-article blockquote.tip { border-left-color: var(--green, #1f8a52); }
.help-article blockquote.note { border-left-color: #5b6ef5; }
.help-article blockquote.warning { border-left-color: var(--red, #c0392b); }
.help-article a { color: var(--f7-orange); }

.help-foot {
    border-top: 1px solid var(--line-light); padding: 10px 16px;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.help-foot a {
    display: inline-flex; align-items: center; gap: 6px;
    font: 600 11.5px var(--font-sans); color: var(--f7-orange); text-decoration: none;
}
.help-foot a:hover { text-decoration: underline; }
.help-foot-hint { font: 400 10px var(--font-mono); color: var(--ink3); }

@media (max-width: 640px) {
    .help-drawer { width: 100vw; max-width: 100vw; }
    .help-foot-hint { display: none; }
}
