/* ============================================================================
   Anirup Interiors — design system + internal application theme
   Brand: Anirup red (#E8161F) on warmed near-black / editorial ivory + neutrals.
   Type: Fraunces (editorial display) + Inter (UI/body) + Space Grotesk (labels).
   ========================================================================== */
:root {
    /* Brand */
    --anirup-red: #E8161F;
    --anirup-red-hover: #C11118;
    --anirup-red-soft: rgba(232, 22, 31, .10);
    --anirup-red-line: rgba(232, 22, 31, .24);

    /* Dark canvas — warmed so the black reads rich, not flat */
    --ink: #0B0A0C;
    --ink-2: #141115;        /* raisin-tinted layer for depth */
    --charcoal: #17151A;
    --surface: #FFFFFF;
    --surface-2: #F6F6F4;    /* app body — a hair warm */

    /* Editorial light neutrals (premium light surfaces) */
    --ivory: #FAF8F4;
    --sand: #F3EDE4;
    --bone: #EDE7DD;
    --line: #E6E7EA;
    --line-warm: #E4DBCE;

    /* Metallic hairline accent — used VERY sparingly (rules / eyebrows) */
    --champagne: #C9A86A;
    --champagne-soft: rgba(201, 168, 106, .18);

    /* Text */
    --text: #16171A;
    --muted: #6B7280;

    /* Layout */
    --sidebar-width: 272px;
    --sidebar-collapsed-width: 76px;
    --topbar-height: 72px;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-lg: 22px;

    /* Elevation ramp + brand glow */
    --shadow-sm: 0 1px 2px rgba(16, 16, 18, .04), 0 1px 3px rgba(16, 16, 18, .06);
    --shadow-md: 0 10px 28px rgba(16, 16, 18, .12);
    --shadow-lg: 0 30px 60px -28px rgba(16, 16, 18, .42);
    --glow-red: 0 16px 42px -14px rgba(232, 22, 31, .58);

    /* Gradients / atmosphere */
    --grad-ember: radial-gradient(120% 120% at 82% -10%, rgba(232, 22, 31, .22), transparent 52%);
    --grad-ink: linear-gradient(180deg, #141115 0%, #0B0A0C 58%, #060507 100%);

    /* Type families */
    --font-display: "Fraunces", Georgia, "Times New Roman", serif;
    --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-label: "Space Grotesk", system-ui, sans-serif;

    /* Legacy aliases — kept so older welcome/public rules still resolve. */
    --espresso: var(--ink);
    --brass: var(--anirup-red);
    --brass-bright: var(--anirup-red);
    --sage: #9AA0A6;
    --surface-muted: var(--surface-2);
    --border: var(--line);
    --text-muted: var(--muted);

    /* Bootstrap overrides */
    --bs-primary: #E8161F;
    --bs-primary-rgb: 232, 22, 31;
    --bs-body-color: #16171A;
    --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --bs-link-color: #C11118;
    --bs-link-hover-color: #8f0d13;
    --bs-border-color: #E6E7EA;
    --bs-focus-ring-color: rgba(232, 22, 31, .25);
}

/* Global rem scale — fluid with the viewport so every rem-based size (text, icons,
   spacing) tracks the device: ~14px on phones up to 16px on desktop
   (cap reached at ~1193px wide; large screens are unchanged). */
html { font-size: clamp(14px, 13.25px + 0.23vw, 16px); -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-ui);
    color: var(--text);
    background: var(--surface-2);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    font-optical-sizing: auto;
}

/* Editorial display (Fraunces) for the big moments; Space Grotesk for UI headings. */
h1, .display-font, .u-serif {
    font-family: var(--font-display);
    color: var(--text);
    font-weight: 600;
    letter-spacing: -.01em;
    font-optical-sizing: auto;
}
h2, h3, h4, h5 {
    font-family: var(--font-label);
    color: var(--text);
    letter-spacing: -.015em;
    font-weight: 600;
}

/* Shared eyebrow — small uppercase label used across welcome / auth / app. */
.eyebrow {
    display: inline-block;
    font-family: var(--font-label);
    text-transform: uppercase;
    letter-spacing: .2em;
    font-size: .8rem;
    font-weight: 600;
    color: var(--muted);
}
.eyebrow-rule { display: inline-flex; align-items: center; gap: .8rem; }
.eyebrow-rule::before { content: ""; width: 40px; height: 1px; background: var(--champagne); opacity: .9; }

a { color: var(--anirup-red-hover); }
:focus-visible { outline: 2px solid var(--anirup-red); outline-offset: 2px; }
.form-control:focus, .form-select:focus { border-color: var(--anirup-red); box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color); }

/* ---- Larger, simpler UI (accessibility for the primary user) ---- */
.btn { font-size: 1.02rem; }
.btn-sm { font-size: .92rem; }
.btn-lg { font-size: 1.15rem; padding: .7rem 1.4rem; }
.form-label { font-size: 1rem; font-weight: 600; margin-bottom: .35rem; }
/* Red asterisk auto-appended to required-field labels (see forms.js markRequired). */
.req-star { color: var(--anirup-red); font-weight: 700; margin-left: .15rem; }
.form-control, .form-select { font-size: 1.05rem; padding: .6rem .85rem; min-height: 48px; }
.form-text { font-size: .9rem; }
.table { font-size: 1rem; }
.table > tbody > tr > td { padding: .8rem .9rem; vertical-align: middle; }

/* ---- Brand / logo — Anirup Interiors mark (dark-surface variant, sits bare on the ink) ---- */
.brand { display: inline-flex; align-items: center; gap: .6rem; text-decoration: none; color: inherit; }
.brand-logo { display: block; height: 2.15rem; width: auto; filter: drop-shadow(0 6px 18px rgba(0, 0, 0, .35)); }
.brand-lg .brand-logo { height: clamp(3.6rem, 5.2vw, 5.2rem); }
/* Compact peak mark — hidden unless the sidebar is collapsed (see the desktop collapse block). */
.brand-mark-collapsed { display: none; }
.brand-mark-collapsed svg { display: block; width: 2.1rem; height: 2.1rem; }

/* Upload preview thumbnail (file-pick widgets — item images, company logo). */
.upload-thumb { height: 36px; width: 36px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #fff; flex: 0 0 auto; }
.upload-thumb-lg { height: 56px; width: 56px; }

/* Broken-image fallback (images.js swaps the src to a "No image" placeholder + adds this class). */
.img-fallback { object-fit: contain !important; background: #F3EEE6; }

/* Inline fallback lockup — rendered (in the real webfont) until the asset is dropped in. */
.brand-fallback { display: inline-flex; align-items: center; gap: .62rem; }
.brand-peak { flex: 0 0 auto; display: block; width: 2.3rem; height: 2.3rem; }
.brand-lg .brand-peak { width: 2.9rem; height: 2.9rem; }
.brand-lockup { display: flex; flex-direction: column; line-height: 1; }
.brand-word { font-family: var(--font-label); font-weight: 700; font-size: 1.34rem; letter-spacing: .005em; color: inherit; }
.brand-lg .brand-word { font-size: 1.85rem; }
.brand-sub { font-family: var(--font-label); font-weight: 600; font-size: .56rem; letter-spacing: .32em; text-transform: uppercase; color: inherit; opacity: .7; margin-top: .26rem; }
.brand-lg .brand-sub { font-size: .68rem; letter-spacing: .38em; }

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

.app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--grad-ink);
    color: rgba(255, 255, 255, .82);
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 1030;
    transition: transform .25s ease, width .2s ease;
    border-right: 1px solid rgba(255, 255, 255, .07);
}
.app-main { transition: margin-left .2s ease; }
/* faint ember at the top of the rail for depth */
.app-sidebar::before {
    content: ""; position: absolute; inset: 0 0 auto 0; height: 220px;
    background: radial-gradient(80% 100% at 20% 0%, rgba(232, 22, 31, .14), transparent 70%);
    pointer-events: none;
}

.app-sidebar .brand-header {
    position: relative;
    min-height: 84px;
    display: flex;
    align-items: center;
    padding: 1.1rem 1.5rem;
    margin-bottom: .2rem;
    text-decoration: none;
}
/* hairline with a soft brand fade under the logo zone */
.app-sidebar .brand-header::after {
    content: ""; position: absolute; left: 1.5rem; right: 1.5rem; bottom: 0; height: 1px;
    background: linear-gradient(90deg, var(--anirup-red-line), rgba(255, 255, 255, .1) 40%, transparent);
}
.app-sidebar .brand-logo { height: 2.85rem; }
.app-sidebar .brand-word, .app-sidebar .brand-sub { color: #fff; }

/* Custom scrollbar for the nav rail */
.app-nav { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.16) transparent; }
.app-nav::-webkit-scrollbar { width: 8px; }
.app-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 8px; }

.app-nav { padding: 1rem .8rem; overflow-y: auto; position: relative; }
.app-nav .nav-section {
    font-family: var(--font-label);
    font-size: .68rem; text-transform: uppercase; letter-spacing: .16em;
    color: rgba(255, 255, 255, .55); padding: 1.1rem .7rem .45rem; /* ≥4.5:1 on the dark rail (WCAG AA) */
}
.app-nav .nav-link {
    position: relative;
    display: flex; align-items: center; gap: .75rem;
    padding: .6rem .8rem; margin-bottom: .1rem;
    border-radius: 11px;
    color: rgba(255, 255, 255, .72);
    font-size: 1.05rem; font-weight: 500;
    transition: background .16s ease, color .16s ease;
}
.app-nav .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.app-nav .nav-link:hover i { color: rgba(255, 255, 255, .92); }
.app-nav .nav-link.active {
    background: linear-gradient(90deg, rgba(232, 22, 31, .18), rgba(232, 22, 31, .03));
    color: #fff;
}
/* glowing rail at the sidebar edge marks the active item */
.app-nav .nav-link.active::before {
    content: ""; position: absolute; left: -.8rem; top: 50%; transform: translateY(-50%);
    width: 3px; height: 22px; border-radius: 0 3px 3px 0;
    background: var(--anirup-red); box-shadow: 0 0 12px rgba(232, 22, 31, .85);
}
.app-nav .nav-link.active i { color: #ff5159; }
.app-nav .nav-link i { font-size: 1.2rem; width: 1.35rem; text-align: center; transition: color .16s ease; color: rgba(255, 255, 255, .5); }

/* ---- Sidebar: quick filter + collapsible groups (structured, fast access) ---- */
.nav-filter { position: relative; margin: .1rem .3rem .7rem; }
.nav-filter > .bi { position: absolute; left: .68rem; top: 50%; transform: translateY(-50%); font-size: .82rem; color: rgba(255, 255, 255, .42); pointer-events: none; }
.nav-filter input {
    width: 100%; padding: .46rem .7rem .46rem 1.95rem; font-size: .85rem;
    color: #fff; background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .1); border-radius: var(--radius-sm);
}
.nav-filter input::placeholder { color: rgba(255, 255, 255, .42); }
.nav-filter input:focus { outline: none; border-color: rgba(255, 255, 255, .26); background: rgba(255, 255, 255, .1); }

.app-nav .nav-section-toggle {
    width: 100%; display: flex; align-items: center; justify-content: space-between;
    background: none; border: 0; cursor: pointer; text-align: left;
}
.app-nav .nav-section-toggle:hover .nav-section-label { color: rgba(255, 255, 255, .65); }
.nav-section-chevron { font-size: .62rem; opacity: .5; transition: transform .2s ease; margin-right: .15rem; }
.nav-group.collapsed .nav-section-chevron { transform: rotate(-90deg); }
.nav-group.collapsed .nav-group-items { display: none; }
.nav-group-items { display: flex; flex-direction: column; }
/* live filter: hide non-matching links + groups with no matches */
.app-nav .nav-link.nav-hidden, .nav-group.nav-hidden { display: none; }

.app-main { margin-left: var(--sidebar-width); flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* ---- Desktop: collapsible icons-only sidebar with hover-to-peek ----
   Only on large screens; the mobile off-canvas drawer below is untouched. */
@media (min-width: 992px) {
    .app-shell.sidebar-collapsed .app-sidebar { width: var(--sidebar-collapsed-width); flex-basis: var(--sidebar-collapsed-width); }
    .app-shell.sidebar-collapsed .app-main { margin-left: var(--sidebar-collapsed-width); }
    /* Hover anywhere over the rail expands it (it floats over the content — fixed-position, so margins stay put). */
    .app-shell.sidebar-collapsed .app-sidebar:hover { width: var(--sidebar-width); box-shadow: var(--shadow-md); }

    /* Collapsed + not hovered: hide all text, leaving a clean column of centred icons. */
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .nav-link-text,
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .nav-section-label,
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .nav-section-chevron,
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .nav-filter,
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .brand-word,
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .brand-sub { display: none; }

    /* Swap the wide wordmark for the compact peak mark so it fits the slim rail. */
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .brand { display: none; }
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .brand-mark-collapsed { display: block; }

    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .nav-section-toggle { justify-content: center; padding: .6rem 0 .35rem; }
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .brand-header { justify-content: center; padding-left: 0; padding-right: 0; }
    /* Keep the active-item rail tucked against the collapsed edge. */
    .app-shell.sidebar-collapsed .app-sidebar:not(:hover) .nav-link.active::before { left: -.55rem; }
}

.app-topbar {
    height: var(--topbar-height);
    background: rgba(255, 255, 255, .82);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 24px -24px rgba(16, 16, 18, .5);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.5rem;
    position: sticky; top: 0; z-index: 1020;
}

.app-content { padding: 2rem 2.1rem; flex: 1 1 auto; }
.app-page-title { font-family: var(--font-label); font-size: 2.15rem; margin: 0; font-weight: 700; letter-spacing: -.01em; }

/* ---- Notification bell ---- */
.bell { position: relative; border: none; background: transparent; color: var(--text); width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; }
.bell:hover { background: var(--surface-2); }
.bell .badge-count {
    position: absolute; top: 5px; right: 5px; min-width: 17px; height: 17px; padding: 0 4px;
    font-size: .65rem; line-height: 17px; border-radius: 9px; background: var(--anirup-red); color: #fff; display: none;
}
.bell .badge-count.show { display: block; }
/* Dropdown stays inside the viewport on narrow phones; list height fits short screens. */
.notif-menu { width: min(320px, calc(100vw - 1rem)); }
.notif-list { max-height: min(320px, 55vh); overflow: auto; }

/* ---- Cards / surfaces ---- */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card .card-header { background: var(--surface); border-bottom: 1px solid var(--line); font-weight: 600; font-size: 1.1rem; }

.stat-card .stat-value { font-family: var(--font-display); font-size: 2rem; font-weight: 600; color: var(--text); }
.stat-card .stat-label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; }

/* ---- Buttons (class names preserved; restyled to brand) ---- */
.btn-anirup, .btn-brass {
    background: var(--anirup-red); border: 1px solid var(--anirup-red); color: #fff; font-weight: 600;
}
.btn-anirup:hover, .btn-brass:hover { background: var(--anirup-red-hover); border-color: var(--anirup-red-hover); color: #fff; }

.btn-outline-espresso, .btn-outline-anirup {
    border: 1px solid var(--line); color: var(--text); background: var(--surface); font-weight: 500;
}
.btn-outline-espresso:hover, .btn-outline-anirup:hover { border-color: var(--anirup-red); color: var(--anirup-red-hover); background: var(--surface); }

.badge.text-bg-success-subtle { background: #e9f7ef !important; color: #1c7a47 !important; }

/* ---- Tables ---- */
.table thead th {
    font-size: .8rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); border-bottom: 1px solid var(--line); font-weight: 600;
}
.table tbody tr { border-bottom: 1px solid var(--line); }
.table tbody tr:hover { background: var(--surface-2); }

/* ---- Toasts ---- */
.toast-container { z-index: 1090; }

/* SweetAlert2 toasts (app-alerts.js) carry dynamic text — customer email addresses, file names.
   The toast is a grid with `grid-template-columns: min-content auto min-content` and puts the
   message in the `auto` track. That track's floor is the item's min-content contribution, and the
   library's `overflow-wrap: break-word` does NOT reduce min-content contribution (only `anywhere`
   and `word-break: break-all` do). So one long unbroken token widens the toast past its 360px
   container, and because `.swal2-toast` sets `overflow-y: hidden` and `.swal2-container` sets
   `overflow-x: hidden`, the other axis on each computes to `auto` — giving a horizontal scrollbar
   on the toast plus a vertical one on the container.
   `min-width: 0` removes the automatic minimum so the track can shrink; `anywhere` then lets the
   token wrap inside it. SweetAlert2 injects its stylesheet at runtime, so these must win on
   specificity, never source order — `.swal2-popup.swal2-toast > *` (0,2,0) outranks the library's
   `.swal2-toast > *` (0,1,0). */
.swal2-popup.swal2-toast { max-width: 100%; overflow: hidden; }
.swal2-popup.swal2-toast > * { min-width: 0; max-width: 100%; }
.swal2-popup.swal2-toast .swal2-title,
.swal2-popup.swal2-toast .swal2-html-container {
    overflow-wrap: anywhere;
    word-break: normal;
    text-align: start;
}
/* Never sit flush against the viewport edge on a narrow phone. */
body.swal2-toast-shown .swal2-container { width: min(360px, calc(100vw - .75rem)); }

/* ---- Mobile sidebar backdrop ---- */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(14, 14, 16, .5); z-index: 1025; }

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); box-shadow: var(--shadow-md); }
    .app-sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .sidebar-backdrop.show { display: block; }

    /* Larger tap targets on touch screens */
    #sidebarToggle { min-width: 44px; min-height: 44px; }
    .app-nav .nav-link { padding: .8rem .75rem; }
    .app-topbar .btn, .app-topbar .bell { min-height: 42px; }
}

/* Lock background scroll while the drawer is open */
body.nav-open { overflow: hidden; }

/* Topbar stays on one row; the switcher truncates instead of overflowing */
.app-topbar { flex-wrap: nowrap; }
.topbar-username { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Company / branch switcher ---- */
.tenant-wrap { position: relative; }
.tenant-switcher {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .4rem .8rem; border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface-2); color: var(--text); font-size: .85rem; font-weight: 500;
    cursor: pointer; min-height: 40px; min-width: 0; max-width: 46vw;
}
.tenant-switcher:hover { border-color: var(--anirup-red); }
.tenant-switcher .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--anirup-red); flex: 0 0 auto; }
.tenant-current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tenant-panel {
    position: absolute; top: calc(100% + 8px); left: 0; z-index: 1050;
    width: 300px; max-width: 86vw; background: var(--surface); border: 1px solid var(--line);
    border-radius: 14px; box-shadow: var(--shadow-md); padding: .5rem; display: none;
}
.tenant-panel.open { display: block; }
.tenant-panel form { margin: 0; }
.tenant-panel-head { display: none; }
.tenant-group-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); padding: .6rem .6rem .3rem; }
.tenant-empty { color: var(--muted); padding: .4rem .6rem; font-size: .9rem; }
.tenant-option {
    display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left;
    border: 0; background: transparent; padding: .55rem .6rem; border-radius: 10px; color: var(--text); min-height: 44px;
}
.tenant-option:hover { background: var(--surface-2); }
.tenant-option.active { color: var(--anirup-red-hover); font-weight: 600; }
.tenant-option > i:first-child { color: var(--muted); }
.tenant-option.active > i { color: var(--anirup-red); }
.tenant-backdrop { display: none; position: fixed; inset: 0; background: rgba(14, 14, 16, .4); z-index: 1045; }

@media (max-width: 991.98px) {
    /* backdrop-filter establishes a containing block for position:fixed descendants — that would
       trap the switcher sheet + its backdrop INSIDE the topbar (why the panel floated mid-screen
       and the dim was missing). Drop it on mobile so they anchor to the viewport; the topbar stays
       clean with a near-opaque background instead of the blur. */
    .app-topbar { background: rgba(255, 255, 255, .96); backdrop-filter: none; -webkit-backdrop-filter: none; }

    .tenant-panel {
        position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; max-width: none;
        border-radius: 20px 20px 0 0; padding: .25rem .8rem calc(1.1rem + env(safe-area-inset-bottom));
        display: block; transform: translateY(110%); transition: transform .3s cubic-bezier(.2, .8, .2, 1);
        max-height: 82vh; overflow: auto; box-shadow: 0 -18px 44px -14px rgba(16, 16, 18, .4);
    }
    .tenant-panel.open { transform: translateY(0); }
    /* Grab handle — signals a dismissible bottom sheet. */
    .tenant-panel::before {
        content: ""; display: block; width: 42px; height: 4px; border-radius: 999px;
        background: var(--line); margin: .55rem auto .35rem;
    }
    .tenant-panel-head { display: block; text-align: center; font-weight: 600; font-size: 1.05rem; padding: .35rem .8rem .7rem; border-bottom: 1px solid var(--line); margin-bottom: .4rem; }
    .tenant-group-label { padding-top: .8rem; }
    .tenant-option { min-height: 52px; padding: .7rem; font-size: 1rem; }

    /* Full-screen dim that fades in (now anchored to the viewport). */
    .tenant-backdrop { display: block; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
    .tenant-backdrop.show { display: block; opacity: 1; pointer-events: auto; }

    .tenant-switcher { max-width: 42vw; }
}

/* Subtle content entrance (no Lenis in the app) */
@media (prefers-reduced-motion: no-preference) {
    .app-content { animation: appFade .35s ease both; }
}
@keyframes appFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- Responsive "stacked card" tables (mobile) ---- */
@media (max-width: 767.98px) {
    :root { --topbar-height: 60px; }
    .app-content { padding: 1rem; }
    .app-page-title { font-size: 1.6rem; }
    .topbar-username { display: none; }

    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack tr {
        border: 1px solid var(--line); border-radius: var(--radius-sm);
        margin-bottom: .75rem; padding: .35rem .25rem; background: var(--surface);
    }
    .table-stack tr:hover { background: var(--surface); }
    .table-stack td { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border: 0; padding: .45rem .85rem; text-align: right; min-height: 40px; }
    .table-stack td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; }
    .table-stack td.cell-actions { justify-content: flex-end; }
    .table-stack td.cell-actions::before { content: ""; }
    .table-stack td.cell-actions .btn { min-width: 40px; min-height: 40px; }
}

/* ============================================================================
   Premium polish — depth, hierarchy and motion (brand stays red / black / white).
   ========================================================================== */

/* Cards: rounded, hairline border, soft layered shadow, gentle lift on hover. */
.card {
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(16, 16, 18, .04), 0 8px 24px -16px rgba(16, 16, 18, .22);
    transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease;
}
.card .card-body { padding: 1.4rem 1.55rem; }
.card .card-header {
    padding: 1rem 1.55rem;
    background: transparent;
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    font-size: 1.05rem;
    letter-spacing: -.01em;
}

/* KPI / stat tiles (dashboard): red accent rail, big display number, hover lift. */
.stat-card { position: relative; overflow: hidden; }
.stat-card::before {
    content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
    background: linear-gradient(180deg, var(--anirup-red), var(--anirup-red-hover));
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 16px 34px -18px rgba(16, 16, 18, .3); }
.stat-card .card-body { padding-left: 1.7rem; }
.stat-card .stat-label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.stat-card .stat-value { font-family: var(--font-display); font-weight: 600; font-size: 2.5rem; line-height: 1.05; color: var(--ink); margin-top: .4rem; letter-spacing: -.01em; font-optical-sizing: auto; }

/* Buttons: consistent rounding, depth on the primary, crisp press. */
.btn { border-radius: 12px; font-weight: 600; transition: transform .12s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease, color .2s ease; }
.btn-anirup, .btn-brass { box-shadow: var(--glow-red); }
.btn-anirup:hover, .btn-brass:hover { transform: translateY(-1px); box-shadow: 0 20px 48px -14px rgba(232, 22, 31, .62); }
.btn-anirup:active, .btn-brass:active { transform: translateY(1px); box-shadow: 0 8px 18px -12px rgba(232, 22, 31, .6); }
.btn-outline-espresso:hover, .btn-outline-anirup:hover { box-shadow: 0 6px 16px -12px rgba(16, 16, 18, .4); }

/* Inputs: match the rounded language. */
.form-control, .form-select { border-radius: 12px; }

/* Tables in cards: clipped corners, shaded head, comfy rows, soft hover. */
.card .table-responsive { border-radius: 12px; overflow: hidden; }
.table thead th { padding: .85rem .9rem; background: var(--surface-2); }
.table tbody tr { transition: background .12s ease; }
.cell-actions { white-space: nowrap; }
.cell-actions .btn { margin-left: .3rem; }
/* Icon-only action buttons stay ~38px squares; buttons WITH a text label (e.g. "Manage")
   expand to fit instead of being crushed into the square and clipped. */
.cell-actions .btn-sm { min-width: 38px; height: 38px; padding: 0 .65rem; gap: .35rem; display: inline-flex; align-items: center; justify-content: center; }

/* Badges: pill shape, medium weight. */
.badge { font-weight: 600; border-radius: 999px; padding: .42em .72em; letter-spacing: .01em; }

/* Definition lists (detail views): aligned, readable rows. */
dl.row dt { font-weight: 500; }
dl.row dd { margin-bottom: .35rem; }

/* Section page-title uses the brand label face (Space Grotesk — the ANIRUP wordmark). */
.app-page-title { letter-spacing: -.01em; }

/* KPI tile icon badge. */
.stat-ico { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; background: var(--anirup-red-soft); color: var(--anirup-red); font-size: 1.35rem; margin-bottom: .9rem; }

/* Quick-action cards (dashboard hub). */
.action-card { display: flex; align-items: center; gap: 1rem; padding: 1.15rem 1.3rem; text-decoration: none; color: inherit; height: 100%; }
.action-card .ico { width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center; background: var(--anirup-red-soft); color: var(--anirup-red); font-size: 1.4rem; flex: 0 0 48px; }
.action-card .titles { min-width: 0; }
.action-card .titles .t { font-weight: 600; }
.action-card .titles .s { color: var(--muted); font-size: .9rem; }
.action-card .go { margin-left: auto; color: var(--muted); font-size: 1.15rem; transition: transform .2s ease, color .2s ease; }
.action-card:hover { transform: translateY(-2px); border-color: var(--anirup-red); box-shadow: 0 16px 34px -18px rgba(16, 16, 18, .3); }
.action-card:hover .go { color: var(--anirup-red); transform: translateX(3px); }

/* Dashboard KPI metric cards — number-first, drill into the list on click. */
.kpi-card {
    position: relative; display: flex; flex-direction: column; align-items: flex-start;
    padding: 1.3rem 1.4rem; text-decoration: none; color: inherit; overflow: hidden;
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.kpi-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--anirup-red); opacity: 0; transition: opacity .18s ease; }
.kpi-card:hover { transform: translateY(-3px); border-color: var(--anirup-red-line); box-shadow: 0 18px 38px -20px rgba(16, 16, 18, .32); }
.kpi-card:hover::before { opacity: 1; }
.kpi-ico { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; background: var(--anirup-red-soft); color: var(--anirup-red); font-size: 1.3rem; margin-bottom: 1rem; }
.kpi-label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.kpi-num { font-family: var(--font-display); font-weight: 600; font-size: 2.6rem; line-height: 1; color: var(--ink); margin-top: .15rem; letter-spacing: -.02em; font-optical-sizing: auto; }
.kpi-go { margin-top: .85rem; font-size: .85rem; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: .3rem; transition: color .18s ease, gap .18s ease; }
.kpi-card:hover .kpi-go { color: var(--anirup-red); gap: .5rem; }

/* Dashboard workspace context strip. */
.workspace-card .card-body { padding: 1.15rem 1.4rem; }
.ws-grid { display: flex; align-items: center; gap: 1.6rem; flex-wrap: wrap; }
.ws-item { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.ws-ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--sand); color: var(--ink); font-size: 1.15rem; flex: 0 0 42px; }
.ws-l { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.ws-v { font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; color: var(--text); line-height: 1.15; }
.ws-sep { width: 1px; height: 38px; background: var(--line); flex: 0 0 1px; }
@media (max-width: 720px) { .ws-sep { display: none; } .ws-grid { gap: 1rem 1.6rem; } }

/* Reusable empty state (lists with no rows). */
.empty-state { padding: 1.5rem 1rem; text-align: center; }
.empty-state .empty-ico { font-size: 2.6rem; color: var(--muted); opacity: .45; display: block; margin-bottom: .6rem; }
.empty-state .empty-title { font-weight: 600; color: var(--text); margin-bottom: .15rem; }
.empty-state .empty-sub { color: var(--muted); font-size: .92rem; margin-bottom: 0; }
.empty-state .btn { margin-top: 1rem; }

/* Search toolbar input — rounded group, brand focus. */
.toolbar-search .input-group-text { background: var(--surface); border-right: 0; color: var(--muted); border-radius: 10px 0 0 10px; }
.toolbar-search .form-control { border-left: 0; }
.toolbar-search .input-group:focus-within { box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color); border-radius: 10px; }
.toolbar-search .input-group:focus-within .input-group-text,
.toolbar-search .input-group:focus-within .form-control { border-color: var(--anirup-red); }

/* ============================================================================
   Shared premium primitives — reused by welcome / auth / dashboard surfaces.
   ========================================================================== */

/* Film-grain overlay for dark panels (atmosphere + depth). */
.grain { position: relative; }
.grain::after {
    content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
    opacity: .05; mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Hairline rule with a champagne tick — luxury detailing, used sparingly. */
.u-rule { display: inline-flex; align-items: center; gap: .7rem; color: var(--muted); }
.u-rule::before { content: ""; width: 34px; height: 1px; background: var(--champagne); opacity: .85; }

/* Capability chips (welcome feature strip). */
.chip {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .5rem .9rem; border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .14);
    background: rgba(255, 255, 255, .04);
    color: rgba(255, 255, 255, .82);
    font-size: .92rem; font-weight: 500; white-space: nowrap;
    backdrop-filter: blur(6px);
}
.chip i { color: var(--anirup-red); font-size: 1.05rem; }
.chip-light { border-color: var(--line-warm); background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.chip-light i { color: var(--anirup-red); }

/* Ghost buttons — outline on dark, outline on light. */
.btn-ghost {
    background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .2);
    color: #fff; font-weight: 600;
}
.btn-ghost:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .4); color: #fff; }

/* Animated arrow on CTAs (nudges on hover). */
.btn .bi-arrow-right { transition: transform .2s ease; }
.btn:hover .bi-arrow-right { transform: translateX(4px); }

/* Magnetic CTA hook — JS sets --mx/--my; CSS keeps it smooth + reduced-motion safe. */
.cta-magnetic { will-change: transform; transition: transform .25s cubic-bezier(.2, .8, .2, 1); }
@media (prefers-reduced-motion: reduce) { .cta-magnetic { transform: none !important; } }

/* ============================================================================
   Form controls — premium selects, switches, and searchable Tom Select.
   ========================================================================== */

/* Native select: hover affordance + custom brand caret. */
.form-select { transition: border-color .15s ease, box-shadow .15s ease; }
.form-select:hover { border-color: var(--anirup-red-line); }

/* Read-only / auto-generated fields read as locked, not editable. */
.form-control[readonly] { background: var(--surface-2); color: var(--text); cursor: default; }

/* Input groups (password + suggest, code + lock): one brand focus ring around the group. */
.input-group:focus-within { border-radius: 12px; box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color); }
.input-group:focus-within .form-control,
.input-group:focus-within .btn { border-color: var(--anirup-red); }
.input-group .btn { z-index: 0; }

/* Premium toggle switch — brand red when on, larger thumb, clear gap to its label. */
.form-switch { padding-left: 3.6em; }       /* matches the 2.7em thumb + a comfortable gap */
.form-switch .form-check-input {
    width: 2.7em; height: 1.45em; margin-top: .08em; margin-left: -3.6em;
    background-color: var(--line); border-color: var(--line);
    cursor: pointer;
    transition: background-color .2s ease, border-color .2s ease, background-position .15s ease;
}
.form-switch .form-check-input:checked { background-color: var(--anirup-red); border-color: var(--anirup-red); }
.form-switch .form-check-input:focus { border-color: var(--anirup-red); box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color); }
.form-switch .form-check-label { padding-left: .25rem; line-height: 1.5em; }
.form-check-input:checked { background-color: var(--anirup-red); border-color: var(--anirup-red); }
.form-check-input:focus { border-color: var(--anirup-red); box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color); }
.form-check-label { cursor: pointer; }

/* Numbered step badge for sectioned/wizard forms (onboarding). */
.step-badge {
    display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem;
    border-radius: 50%; background: var(--anirup-red-soft); color: var(--anirup-red);
    font-family: var(--font-label); font-weight: 700; font-size: .85rem; margin-right: .55rem;
}

/* ---- Tom Select skin (searchable dropdowns) — premium, on-brand ---- */
.ts-wrapper { font-family: var(--font-ui); }

/* Tom Select copies the original control's classes (incl. Bootstrap's .form-select / .form-control)
   onto the .ts-wrapper, so the wrapper paints a SECOND border + chevron + shadow around the real
   .ts-control nested inside it — the "double border / input-inside-input" look on every dropdown.
   Strip that Bootstrap chrome from the wrapper; the inner .ts-control IS the visible field. */
.ts-wrapper.form-select,
.ts-wrapper.form-control {
    border: 0;
    padding: 0;
    min-height: 0;
    height: auto;
    background-image: none;
    box-shadow: none;
    border-radius: 0;
}

/* Open dropdown panel: it may be WIDER than its (sometimes narrow) control so options stay readable,
   but it is capped to the screen width and then nudged left/right by JS (AnirupForms.positionDropdown)
   based on where the control sits — so it never runs off either edge, on any device. The panel can
   never exceed the viewport, so even if JS is slow/absent it stays within the screen. */
.ts-dropdown {
    width: max-content;
    min-width: 100%;
    max-width: min(26rem, calc(100vw - 1rem));
    box-sizing: border-box;
}
.ts-wrapper.single .ts-control,
.ts-control {
    position: relative;
    min-height: 48px; padding: .42rem 2.6rem .42rem .9rem;
    border: 1px solid var(--line); border-radius: 12px; background: #fff;
    font-size: 1.05rem; color: var(--text); box-shadow: var(--shadow-sm);
    transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}
/* Chevron drawn as a pseudo-element so it can animate open ↔ closed. */
.ts-wrapper.single .ts-control::after {
    content: ""; position: absolute; right: 1.05rem; top: 0; bottom: 0; margin: auto 0;
    width: .56rem; height: .56rem; pointer-events: none;
    border-right: 1.8px solid var(--muted); border-bottom: 1.8px solid var(--muted);
    transform: translateY(-2px) rotate(45deg);
    transition: transform .2s ease, border-color .16s ease;
}
.ts-wrapper.single.dropdown-active .ts-control::after {
    transform: translateY(2px) rotate(225deg); border-color: var(--anirup-red);
}
.ts-wrapper.single.input-active .ts-control { background-color: #fff; cursor: text; }
.ts-wrapper:hover .ts-control { border-color: var(--anirup-red-line); }
.ts-wrapper.focus .ts-control,
.ts-wrapper.dropdown-active .ts-control {
    border-color: var(--anirup-red); box-shadow: 0 0 0 .22rem var(--bs-focus-ring-color);
}
.ts-wrapper.disabled .ts-control { background: var(--surface-2); opacity: .7; }
.ts-control input { font-size: 1.05rem; color: var(--text); }
.ts-control input::placeholder { color: var(--muted); }
.ts-wrapper .ts-control .item { color: var(--text); }

/* Closed single-select control shows ONE tidy, vertically-centred line — never let a long option
   (e.g. "EIN — Employer Identification Number") wrap onto 3-4 rows, and keep the value centred in the
   control height instead of stretched to the top. */
.ts-wrapper.single .ts-control { display: flex; align-items: center; flex-wrap: nowrap; min-width: 0; }
.ts-wrapper.single .ts-control > .item {
    display: block; min-width: 0; max-width: 100%;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Quotation item picker sits in a flex row (thumbnail + picker). Let that picker column shrink so a
   long selected name ellipsizes inside the control instead of stretching it past the card edge. */
.q-line .flex-grow-1 { min-width: 0; }
/* The hidden/inline typing input must not add height that throws off the centring. */
.ts-wrapper.single .ts-control > input { line-height: normal; }

/* Tom Select inside a Bootstrap .input-group (phone dial-code, tax type): Bootstrap's input-group
   rules only target .form-control/.form-select, so a bare .ts-wrapper sizes to its content and wraps.
   Make it a proper flexible group member that can shrink, and clip the inner control's radii so it
   sits flush against the adjacent number box. */
.input-group > .ts-wrapper { flex: 1 1 auto; width: 1%; min-width: 0; }
.input-group > .ts-wrapper:not(:last-child) .ts-control { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > .ts-wrapper:not(:first-child) .ts-control { border-top-left-radius: 0; border-bottom-left-radius: 0; }
/* Compact prefix pickers size to their short code (+1 / EIN) and leave the number box the rest. */
.input-group > .ts-wrapper.ts-compact { flex: 0 0 auto; width: auto; min-width: 6rem; max-width: 12rem; }
/* Tom Select leaves the original <select> as a hidden first sibling, so the wrapper is never
   :first-child — the reset above then squares BOTH outer corners (all-0). The compact prefix
   pickers always lead their group, so restore their outer (left) corners to match a plain input. */
.input-group > .ts-wrapper.ts-compact .ts-control { border-top-left-radius: 12px; border-bottom-left-radius: 12px; }

/* Multi-select values → brand-tinted pills with a soft remove button. */
.ts-wrapper.multi .ts-control > .item {
    display: inline-flex; align-items: center; gap: .1rem;
    background: var(--anirup-red-soft); color: var(--anirup-red-hover);
    border: 1px solid var(--anirup-red-line); border-radius: 999px;
    padding: .12rem .25rem .12rem .65rem; margin: .12rem .3rem .12rem 0;
    font-weight: 600; font-size: .94rem;
}
.ts-wrapper.multi .ts-control > .item.active { background: var(--anirup-red); color: #fff; border-color: var(--anirup-red); }
.ts-wrapper.multi .ts-control > .item .remove {
    border: 0; color: inherit; opacity: .6; padding: 0 .42rem; margin-left: .15rem;
    border-radius: 999px; font-size: 1.05rem; line-height: 1;
}
.ts-wrapper.multi .ts-control > .item .remove:hover { background: transparent; opacity: 1; }

.ts-dropdown {
    border: 1px solid var(--line-warm); border-radius: 16px;
    box-shadow: 0 1px 0 rgba(255, 255, 255, .9) inset, 0 22px 48px -18px rgba(16, 16, 18, .3), 0 6px 16px -10px rgba(16, 16, 18, .2);
    margin-top: 9px; overflow: hidden; padding: .4rem; animation: tsPop .15s cubic-bezier(.2, .8, .2, 1);
}
@keyframes tsPop { from { opacity: 0; transform: translateY(-7px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
.ts-dropdown .option {
    position: relative; padding: .6rem .8rem .6rem 2.25rem; border-radius: 10px;
    font-size: 1.02rem; color: var(--text); margin-bottom: 1px;
    white-space: normal; overflow-wrap: anywhere;
    transition: background-color .12s ease, color .12s ease;
}
/* Item-picker option: thumbnail + a name that wraps as needed + a price that stays on ONE line,
   pinned to the right — so a price like "250" never breaks into "25 0" on a narrow dropdown. */
.ts-dropdown .q-opt { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.ts-dropdown .q-opt-name { min-width: 0; overflow-wrap: anywhere; }
.ts-dropdown .q-opt-price { flex: 0 0 auto; margin-left: auto; padding-left: .5rem; white-space: nowrap; color: var(--muted); font-size: .9rem; }
/* Tick beside the currently-selected value. */
.ts-dropdown .option.selected { font-weight: 600; }
.ts-dropdown .option.selected::before {
    content: ""; position: absolute; left: .9rem; top: 50%;
    width: .36rem; height: .68rem; margin-top: -.46rem;
    border-right: 2px solid var(--anirup-red); border-bottom: 2px solid var(--anirup-red);
    transform: rotate(45deg);
}
.ts-dropdown .option:hover,
.ts-dropdown .option.active { background: var(--anirup-red-soft); color: var(--anirup-red-hover); }
.ts-dropdown .optgroup-header {
    font-family: var(--font-label); text-transform: uppercase; letter-spacing: .08em;
    font-size: .72rem; color: var(--muted); padding: .55rem .7rem .25rem 2.1rem; background: transparent;
}
.ts-dropdown .no-results,
.ts-dropdown .spinner,
.ts-dropdown .optgroup:last-child { border: 0; }
.ts-dropdown .no-results { padding: .58rem .7rem .58rem 2.1rem; color: var(--muted); }
.ts-dropdown-content { scrollbar-width: thin; max-height: 16rem; }

/* Single selects show the search box INSIDE the dropdown (dropdown_input plugin), so the
   closed control is just a value display — not the field you type into. */
.ts-wrapper.single .ts-control { cursor: pointer; }
.ts-dropdown .dropdown-input-wrap { padding: .4rem .4rem .35rem; }
.ts-dropdown .dropdown-input {
    width: 100%; border: 1px solid var(--line); border-radius: 9px;
    padding: .52rem .7rem .52rem 2.2rem; font-size: 1rem; color: var(--text); background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236B7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='7' cy='7' r='4.6'/%3E%3Cpath d='M10.6 10.6 14 14'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: left .74rem center; background-size: 15px;
    transition: border-color .16s ease, box-shadow .16s ease;
}
.ts-dropdown .dropdown-input::placeholder { color: var(--muted); }
.ts-dropdown .dropdown-input:focus {
    outline: none; border-color: var(--anirup-red); box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color);
}

/* Small variant — for dense tables / repeating rows (mirrors .form-select-sm). */
.ts-wrapper.ts-sm .ts-control { min-height: 38px; padding: .25rem 1.9rem .25rem .65rem; font-size: .92rem; border-radius: 9px; }
.ts-wrapper.ts-sm .ts-control::after { right: .7rem; }
.ts-wrapper.ts-sm .ts-control input { font-size: .92rem; }
.ts-wrapper.ts-sm .ts-dropdown .option { padding: .42rem .6rem .42rem 1.8rem; font-size: .92rem; }
.ts-wrapper.ts-sm .ts-dropdown .option.selected::before { left: .6rem; }
/* Small multi-select control must read as one tidy line when empty, matching its sibling sm inputs. */
.ts-wrapper.ts-sm.multi .ts-control { padding-top: .15rem; padding-bottom: .15rem; }

/* Multi-select (e.g. user → branch access): let value pills wrap, but cap the height with internal
   scroll so selecting several values never balloons the control and shoves the table row taller. */
.ts-wrapper.multi .ts-control { flex-wrap: wrap; row-gap: .15rem; max-height: 5.25rem; overflow-y: auto; }

/* "Manage sub-categories" popup keeps its roomy modal-lg width but gains a steady min-height so it
   never collapses to a cramped sliver in the empty ("No sub-categories yet") state. */
#subcatsModal .modal-body { min-height: 320px; }

/* ---------- Signature evidence list (Details → Evidence) ----------
   dt and dd are flex items of .row, and a flex item's automatic minimum size is its content's min-content
   width — which for one unbroken token (a full user-agent string, a 64-character hash) is the whole thing.
   That beats the column's width:75% and stretches the row until the page itself scrolls sideways, and it
   is also why Bootstrap's .text-truncate silently does nothing here. min-width:0 lets the column win. */
.sign-evidence > dt, .sign-evidence > dd { min-width: 0; }
/* Break mid-token when there is no space to break at. A user agent has spaces; a hash has none. */
.sign-evidence > dd { overflow-wrap: anywhere; }
.sign-evidence-raw { font-size: .78rem; line-height: 1.5; color: var(--muted); }

/* ---------- Quotation history modal: Versions | Sharing ----------
   The scroll lives on the tab content, not the modal body, so the tab strip stays pinned while a long
   list scrolls under it. */
.history-tabs { border-bottom-color: var(--line); margin-bottom: .9rem; }
.history-tabs .nav-link { color: var(--muted); border: 0; border-bottom: 2px solid transparent; padding: .5rem .9rem; }
.history-tabs .nav-link:hover { color: var(--text); border-bottom-color: var(--line); }
.history-tabs .nav-link.active { color: var(--anirup-red); background: transparent; border-bottom-color: var(--anirup-red); font-weight: 600; }
.history-tab-scroll { max-height: 70vh; overflow-y: auto; }

/* One card per link ever issued. The live one is ringed rather than merely labelled — it is the only row
   the customer can still act on. */
.share-log { display: grid; gap: .75rem; }
.share-log-card {
    border: 1px solid var(--line); border-radius: .7rem;
    background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden;
}
.share-log-card.is-live { border-color: var(--anirup-red-line); box-shadow: 0 0 0 1px var(--anirup-red-line); }
.share-log-head {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
    padding: .55rem .85rem; background: var(--sand); border-bottom: 1px solid var(--line);
    font-size: .85rem; color: var(--muted);
}
.share-log-card.is-live .share-log-head { background: var(--anirup-red-soft); }
.share-log-head strong { color: var(--text); }
.share-log-live {
    flex: 0 0 auto; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: var(--anirup-red); background: var(--surface);
    border: 1px solid var(--anirup-red-line); border-radius: 999px; padding: .1rem .5rem;
}
.share-log-body { padding: .7rem .85rem; display: grid; gap: .35rem; font-size: .875rem; }
.share-log-line { display: grid; grid-template-columns: 1.2rem 1fr; align-items: start; gap: .5rem; }
.share-log-line .bi { line-height: 1.5; }
/* Same reason as .sign-evidence above: a grid item's automatic minimum size is its min-content width, so a
   long unbroken address would widen the card past the modal rather than wrapping inside it. */
.share-log-line > * { min-width: 0; }
.share-log-line span { overflow-wrap: anywhere; }
/* Indented under the reply it belongs to — evidence about that signature, not another event. */
.share-log-sub { padding-left: 1.7rem; color: var(--muted); font-size: .8rem; }
.share-log-foot {
    padding: .45rem .85rem; border-top: 1px dashed var(--line);
    color: var(--muted); font-size: .8rem;
}
.share-log-empty { text-align: center; color: var(--muted); }

/* ---------- Modals: no dim behind them, anywhere in the app ----------
   Bootstrap drops a full-screen .modal-backdrop over the page. Every dialog here opens on top of content
   the user is still reading — the quotation being sent, the document being signed — and blacking it out
   hides the very thing the dialog is asking about.

   display:none rather than data-bs-backdrop="false" per modal: the attribute has to be repeated on every
   modal and is easy to forget on the next one. Click-outside-to-close still works — Bootstrap listens on
   the .modal element itself, not on the backdrop.

   The dialog has to carry the separation on its own instead, so it gets a heavier shadow and a defined
   edge; without the dim it would otherwise float ambiguously over the page. */
.modal-backdrop { display: none; }
.modal-content {
    border: 1px solid var(--line);
    box-shadow: 0 1.5rem 3.5rem rgba(17, 17, 17, .28), 0 0 0 1px rgba(17, 17, 17, .06);
}

@media (prefers-reduced-motion: reduce) {
    .ts-dropdown { animation: none; }
    .ts-wrapper.single .ts-control,
    .ts-wrapper.single .ts-control::after,
    .ts-dropdown .option { transition: none; }
}

/* ============================================================================
   Deep UI polish (project-wide) — every form, input, button, table.
   Native inputs/selects are unified with the Tom Select control so each field
   reads as one consistent, premium control. Loaded last so it wins the cascade.
   ========================================================================== */

/* ---- Inputs, selects, textareas — premium, consistent, tactile ---- */
.form-control,
.form-select {
    border: 1px solid var(--line);
    border-radius: 12px;
    background-color: #fff;
    color: var(--text);
    box-shadow: var(--shadow-sm);
    transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}
.form-control:hover:not(:focus):not([readonly]):not(:disabled),
.form-select:hover:not(:focus):not(:disabled) { border-color: var(--anirup-red-line); }
.form-control:focus,
.form-select:focus {
    border-color: var(--anirup-red);
    box-shadow: 0 0 0 .22rem var(--bs-focus-ring-color);
    background-color: #fff;
}
.form-control::placeholder { color: var(--muted); opacity: 1; }
textarea.form-control { min-height: 96px; line-height: 1.5; }
/* Small variant must actually read small — without these it keeps the 1.05rem base font + padding and
   towers ~4px over the Tom Select .ts-sm dropdowns beside it (e.g. address Postal vs Country/State/City). */
.form-control-sm { border-radius: 9px; min-height: 38px; font-size: .92rem; padding: .25rem .65rem; }
.form-select-sm { border-radius: 9px; min-height: 38px; font-size: .92rem; padding: .25rem 1.9rem .25rem .65rem; }
.input-group > .form-control, .input-group > .form-select { box-shadow: none; }

/* Read-only / disabled read as clearly non-editable (e.g. auto-generated codes). */
.form-control[readonly] { background-color: var(--surface-2); color: var(--muted); box-shadow: none; cursor: default; }
.form-control[readonly]:focus { border-color: var(--line); box-shadow: none; }
.form-control:disabled, .form-select:disabled { background-color: var(--surface-2); opacity: .85; }

/* Labels + helper text — quiet, confident hierarchy. */
.form-label { color: var(--text); font-weight: 600; }
.form-text { color: var(--muted); }

/* Validation — invalid native fields get a red ring; messages + summary use brand red. */
.input-validation-error,
.form-control.input-validation-error,
.form-select.input-validation-error {
    border-color: var(--anirup-red) !important;
    box-shadow: 0 0 0 .18rem rgba(232, 22, 31, .12);
}
.field-validation-error { color: var(--anirup-red-hover); font-size: .9rem; }
.alert-danger {
    background: #FDECEC; border: 1px solid var(--anirup-red-line); color: #97131A; border-radius: 12px;
}

/* ---- Buttons — consistent radius, motion, press + focus feedback ---- */
.btn {
    border-radius: 11px; font-weight: 600;
    transition: background-color .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease, transform .1s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 .22rem var(--bs-focus-ring-color); }
.btn-sm { border-radius: 9px; }
.btn-lg { border-radius: 13px; }
.btn-anirup, .btn-brass { box-shadow: 0 10px 22px -13px rgba(232, 22, 31, .65); }
.btn-anirup:hover, .btn-brass:hover { box-shadow: 0 16px 30px -14px rgba(232, 22, 31, .7); transform: translateY(-1px); }
.btn-anirup:active, .btn-brass:active { transform: translateY(0); }
.btn-outline-espresso, .btn-outline-anirup { box-shadow: var(--shadow-sm); }
.btn-outline-espresso:hover, .btn-outline-anirup:hover { background: var(--anirup-red-soft); border-color: var(--anirup-red); color: var(--anirup-red-hover); }
.btn-link { text-decoration: none; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }
/* Icon-only action buttons in tables stay square + tidy. */
.btn-sm.btn-outline-espresso, .btn-sm.btn-outline-danger { box-shadow: none; }

/* ---- Tables — quiet header band, comfortable rows, crisp hover ---- */
.table thead th { background: var(--surface-2); padding: .85rem .9rem; white-space: nowrap; }
.table tbody td { padding: .8rem .9rem; }
.table tbody tr { transition: background-color .12s ease; }
.table > :not(caption) > * > * { border-bottom-color: var(--line); }
/* A card that contains only a table → seamless rounded corners. */
.card > .table-responsive:last-child .table,
.card > .table:last-child { margin-bottom: 0; }

/* ---- Page header helper (title + actions on one row) ---- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.page-head .app-page-title { margin-bottom: .15rem; }

/* iOS Safari zooms into inputs rendered under 16px — pin a 16px floor on touch devices
   (desktop pointers resolve max() to the rem value, so nothing changes there). */
@media (pointer: coarse) {
    .form-control, .form-select, .ts-control, .ts-control input,
    .ts-dropdown .dropdown-input { font-size: max(16px, 1.05rem); }
    .form-control-sm, .form-select-sm { font-size: max(16px, .92rem); }
    .nav-filter input { font-size: max(16px, .85rem); }
    .auth-card .form-control { font-size: max(16px, clamp(1rem, .96rem + .25vw, 1.08rem)); }
}

/* ---- Pagination (_Pager.cshtml) — Bootstrap's component in the brand palette.
   Scoped to .app-pager so nothing else that uses .pagination is affected. */
.app-pager .page-link {
    --bs-pagination-color: var(--ink);
    --bs-pagination-border-color: var(--line);
    --bs-pagination-hover-color: var(--anirup-red-hover);
    --bs-pagination-hover-bg: var(--anirup-red-soft);
    --bs-pagination-hover-border-color: var(--anirup-red-line);
    --bs-pagination-focus-color: var(--anirup-red-hover);
    --bs-pagination-focus-bg: var(--anirup-red-soft);
    min-width: 2.25rem;
    text-align: center;
    font-variant-numeric: tabular-nums;   /* digits keep their width, so the strip doesn't jitter page to page */
}

/* The current page is the one thing the eye should find first. */
.app-pager .page-item.active .page-link {
    background: var(--anirup-red);
    border-color: var(--anirup-red);
    color: #fff;
    font-weight: 600;
}

/* A gap marker and the phone-only "5 / 20" readout are labels, not controls — no border, no hover. */
.app-pager .page-item.disabled .page-link {
    background: transparent;
    border-color: transparent;
    color: var(--bs-secondary-color, #6c757d);
}

/* …but a spent arrow still needs to read as a disabled control rather than vanish. */
.app-pager .page-item.disabled .page-link .bi {
    opacity: .45;
}

.app-pager .page-link:focus-visible {
    outline: 2px solid var(--anirup-red);
    outline-offset: 2px;
    box-shadow: none;
}
