/* ==========================================================================
   OP Software — design system
   --------------------------------------------------------------------------
   One hand-written stylesheet (no CSS framework) so pages stay light and fast.
   The rules for using it (numbers, tables, reports, buttons, empty states …)
   are written down in docs/UI-GUIDE.md — read that before building a screen.

   Structure:
     1. Design tokens (colours, spacing, type, density) for light + dark themes
     2. Base / reset, focus ring
     3. App shell: top menu bar, content area, status bar / phone tab bar
     4. Components: buttons, forms, cards, tables, numbers (money / qty / Dr-Cr),
        badges, alerts, toasts, modals, lookups, tiles, KPI tiles, empty/loading
        states, tally chip, density switch, search field
     5. Auth (login / register) screens
     6. Utilities
     7. Reports (ReportShell: filter bar, sticky headers + totals, phone list)
     8. Voucher entry grid
     9. Responsive: tablet, phone, touch
    10. Print

   Theme: light by default, dark when the OS prefers it, overridable with
   <html data-theme="light|dark"> (set by the theme toggle in the menu bar).
   Density: comfortable by default, <html data-density="compact"> for tighter
   table rows (DensitySwitch component, saved per user).
   Contrast: every text token meets WCAG AA (≥ 4.5:1) on --surface and --bg in
   both themes; --text-faint is for secondary text only, never for numbers.
   ========================================================================== */

/* 1. Design tokens ------------------------------------------------------- */
:root {
    color-scheme: light;

    /* Brand */
    --primary: #4f46e5;            /* 6.3:1 on white */
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --primary-contrast: #ffffff;

    /* Surfaces */
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f8f9fb;          /* table headers, totals, group rows */
    --surface-sunken: #f1f3f8;
    --border: #e4e7ef;
    --border-strong: #cfd4e0;
    --row-hover: #f3f4f6;          /* table row hover */
    --row-zebra: #fafbfc;          /* .table.zebra even rows */

    /* Text (AA on white and on --bg) */
    --text: #111827;               /* 17:1 */
    --text-muted: #4b5563;         /* 7.6:1 — labels, sub-lines, Dr/Cr suffix */
    --text-faint: #6b7280;         /* 4.8:1 — hints, meta lines only */

    /* Status: text colours are AA on white AND on their -soft tint */
    --success: #047857;
    --success-soft: #ecfdf5;
    --danger: #c81e1e;
    --danger-soft: #fef2f2;
    --warning: #b45309;            /* text */
    --warning-fill: #d97706;       /* borders, bars, dots */
    --warning-soft: #fffbeb;
    --info: #1d4ed8;
    --info-soft: #eff6ff;

    /* Focus: data-entry users must always see which field is active */
    --focus-ring: 0 0 0 3px rgb(79 70 229 / .32);
    --focus-outline: 2px solid var(--primary);
    --focus-bg: #fffdf2;

    /* Menu bar */
    --menubar-bg: #1e1b4b;
    --menubar-text: #e0e7ff;
    --menubar-hover: rgb(255 255 255 / .12);

    /* Shape + depth */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgb(16 24 40 / .06);
    --shadow: 0 1px 3px rgb(16 24 40 / .08), 0 1px 2px rgb(16 24 40 / .04);
    --shadow-lg: 0 12px 32px rgb(16 24 40 / .14), 0 4px 8px rgb(16 24 40 / .06);

    /* Type */
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
    --fs-xs: .75rem;
    --fs-sm: .8125rem;
    --fs: .875rem;
    --fs-lg: 1rem;
    --fs-xl: 1.25rem;

    /* Layout */
    --menubar-h: 44px;
    --statusbar-h: 28px;
    --tabbar-h: 58px;
    --control-h: 34px;
    --gutter: 1.5rem;

    /* Table density (comfortable). Compact values are under [data-density="compact"]. */
    --cell-py: .5rem;
    --cell-px: .75rem;
    --report-cell-py: .45rem;
    --table-fs: var(--fs);
}

/* Compact rows: ≈28px instead of ≈36px (DensitySwitch). */
:root[data-density="compact"] {
    --cell-py: .25rem;
    --cell-px: .6rem;
    --report-cell-py: .2rem;
    --table-fs: var(--fs-sm);
}

/* Dark theme values, applied when the OS prefers dark and the user has not forced light … */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --primary: #818cf8;
        --primary-hover: #a5b4fc;
        --primary-soft: rgb(129 140 248 / .14);
        --primary-contrast: #0b0d17;
        --bg: #0b0d17;
        --surface: #141726;
        --surface-2: #181c2e;
        --surface-sunken: #10131f;
        --border: #262b40;
        --border-strong: #353b55;
        --row-hover: #1f2437;
        --row-zebra: #161a2b;
        --text: #e5e7eb;
        --text-muted: #b0b6c3;
        --text-faint: #8f96a3;
        --success: #34d399;
        --success-soft: rgb(52 211 153 / .13);
        --danger: #f87171;
        --danger-soft: rgb(248 113 113 / .13);
        --warning: #fbbf24;
        --warning-fill: #f59e0b;
        --warning-soft: rgb(251 191 36 / .13);
        --info: #60a5fa;
        --info-soft: rgb(96 165 250 / .13);
        --focus-bg: #1b1f35;
        --focus-ring: 0 0 0 3px rgb(129 140 248 / .38);
        --menubar-bg: #0f1120;
        --shadow-lg: 0 12px 32px rgb(0 0 0 / .5);
    }
}

/* … or when the user explicitly chose dark (keep in sync with the block above). */
:root[data-theme="dark"] {
    color-scheme: dark;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: rgb(129 140 248 / .14);
    --primary-contrast: #0b0d17;
    --bg: #0b0d17;
    --surface: #141726;
    --surface-2: #181c2e;
    --surface-sunken: #10131f;
    --border: #262b40;
    --border-strong: #353b55;
    --row-hover: #1f2437;
    --row-zebra: #161a2b;
    --text: #e5e7eb;
    --text-muted: #b0b6c3;
    --text-faint: #8f96a3;
    --success: #34d399;
    --success-soft: rgb(52 211 153 / .13);
    --danger: #f87171;
    --danger-soft: rgb(248 113 113 / .13);
    --warning: #fbbf24;
    --warning-fill: #f59e0b;
    --warning-soft: rgb(251 191 36 / .13);
    --info: #60a5fa;
    --info-soft: rgb(96 165 250 / .13);
    --focus-bg: #1b1f35;
    --focus-ring: 0 0 0 3px rgb(129 140 248 / .38);
    --menubar-bg: #0f1120;
    --shadow-lg: 0 12px 32px rgb(0 0 0 / .5);
}

/* 2. Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
    font-family: var(--font);
    font-size: var(--fs);
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs); }
p { margin: 0 0 .75rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
kbd, .kbd {
    font-family: var(--font-mono);
    font-size: .6875rem;
    padding: 1px 5px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text-muted);
    white-space: nowrap;
}

/* One visible focus ring for everything keyboard-reachable (inputs have their own, stronger style). */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
    outline: var(--focus-outline);
    outline-offset: 2px;
}

/* Blazor puts focus on the page heading after navigation; don't draw a ring around it. */
h1:focus, h1:focus-visible, h1[tabindex]:focus-visible { outline: none; }

/* 3. App shell ----------------------------------------------------------- */
.app-shell {
    display: grid;
    /* minmax(0,1fr): no child (menu bar, wide table) can make the page wider than the screen. */
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--menubar-h) minmax(0, 1fr) auto;
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
}

/* Top menu bar (desktop-style). */
.menubar {
    display: flex;
    align-items: stretch;
    gap: .25rem;
    padding: 0 .75rem;
    min-width: 0;
    background: var(--menubar-bg);
    color: var(--menubar-text);
    position: relative;
    z-index: 50;
    /* Leave room for window controls when installed with window-controls-overlay. */
    padding-left: max(.75rem, env(titlebar-area-x, 0px));
}

.menubar-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding-right: .75rem;
    margin-right: .25rem;
    border-right: 1px solid rgb(255 255 255 / .12);
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    flex: none;
}
.menubar-brand img { width: 24px; height: 24px; border-radius: 6px; }
.menubar-brand:hover { text-decoration: none; }

.menubar-menus { display: flex; align-items: stretch; gap: 2px; flex: none; }

.menu { position: relative; display: flex; }

.menu-trigger {
    all: unset;
    display: flex;
    align-items: center;
    padding: 0 .75rem;
    margin: 6px 0;
    border-radius: var(--radius-sm);
    font-size: var(--fs);
    font-weight: 500;
    cursor: pointer;
    color: inherit;
    white-space: nowrap;
}
.menu-trigger:hover,
.menu.open > .menu-trigger,
.menu-trigger:focus-visible { background: var(--menubar-hover); color: #fff; }
/* Access-key letter underline (e.g. _M_asters) like Windows menus. */
.menu-trigger u { text-decoration-thickness: 1px; text-underline-offset: 2px; }

.menu-dropdown {
    position: absolute;
    top: calc(100% - 2px);
    left: 0;
    min-width: 260px;
    /* Long menus (Masters, GST) scroll inside themselves instead of running off the screen. */
    max-height: calc(100dvh - var(--menubar-h) - 12px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: none;
}
.menu.open > .menu-dropdown { display: block; }


.menu-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    width: 100%;
    padding: 7px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible, .menu-item.active {
    background: var(--primary-soft);
    color: var(--primary);
    outline: none;
    text-decoration: none;
}
.menu-item .menu-label { flex: 1; }
.menu-item kbd { margin-left: auto; }
.menu-item[aria-disabled="true"] { color: var(--text-faint); cursor: default; }
.menu-item[aria-disabled="true"]:hover { background: none; }
.menu-separator { height: 1px; margin: 6px 4px; background: var(--border); }
.menu-heading {
    padding: 6px 10px 2px;
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}

.menubar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
}

.company-chip {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    padding: 2px 10px;
    border-radius: var(--radius-sm);
    background: rgb(255 255 255 / .08);
    color: #fff;
    line-height: 1.15;
    max-width: 260px;
    cursor: pointer;
    border: 0;
    font: inherit;
    text-align: left;
}
.company-chip:hover { background: rgb(255 255 255 / .16); text-decoration: none; }
.company-chip strong { font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-chip span { font-size: .6875rem; color: var(--menubar-text); opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
    all: unset;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: inherit;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--menubar-hover); }
.icon-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.icon-btn svg { width: 18px; height: 18px; }
.menubar-right form { display: flex; }

/* Mobile menu toggle (hidden on desktop) */
.menubar-toggle { display: none; }

/* Main scrolling content area */
.app-content {
    overflow: auto;
    min-width: 0;
    padding: 1.25rem var(--gutter) 2rem;
}
.page { max-width: 1280px; margin: 0 auto; }
.page-narrow { max-width: 880px; margin: 0 auto; }

/* Bottom bar: shortcut hints + context on desktop, tab bar on phones (StatusBar.razor). */
.statusbar {
    border-top: 1px solid var(--border);
    background: var(--surface);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    min-width: 0;
}
.statusbar-hints {
    display: flex;
    align-items: center;
    gap: 1rem;
    height: var(--statusbar-h);
    padding: 0 1rem;
    overflow: hidden;
    white-space: nowrap;
}
.statusbar .hint { display: inline-flex; align-items: center; gap: 4px; }
.statusbar .spacer { flex: 1; }
.statusbar-year { font-variant-numeric: tabular-nums; }

/* Phone / touch tablet bottom tab bar (shown by the responsive rules in §9). */
.tabbar { display: none; }
.tab {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--tabbar-h);
    padding: 6px 2px;
    border: 0;
    background: none;
    color: var(--text-muted);
    font: inherit;
    font-size: .6875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.tab svg { width: 22px; height: 22px; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { color: var(--primary); }
.tab.active svg { stroke-width: 2.3; }

/* 4. Components ---------------------------------------------------------- */

/* Page header: title on the left, actions on the right */
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: .75rem 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.page-header h1 { margin: 0; }
.page-header .subtitle { color: var(--text-muted); font-size: var(--fs-sm); margin: 2px 0 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.25rem; }
.card-header {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}
.card-header h2 { margin: 0; }
.card-footer {
    padding: .875rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
    align-items: center;
}
/* Cards stacked in normal flow get a gap … */
.card + .card { margin-top: 1rem; }
/* … but never inside grids / flex rows (the gap does the spacing there; this used to push the first
   tile 16px out of line). Use .stack for an explicit vertical stack of anything. */
[class*="grid"] > .card + .card, [class*="split"] > .card + .card, [class*="row"] > .card + .card,
[class*="tiles"] > .card + .card, [class*="kpi"] > .card + .card, .flex > .card + .card,
.report-page > .card + .card { margin-top: 0; }
.stack > * + * { margin-top: 1rem; }

/* Buttons — hierarchy: ONE .btn-primary per screen area (Save / Show / New); .btn is the secondary
   action; .btn-ghost for tertiary / toolbar actions; .btn-danger only for destructive actions;
   .btn-link for inline text actions. */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    height: var(--control-h);
    padding: 0 .9rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s, box-shadow .12s;
    text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--primary); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn kbd { background: transparent; border-color: currentColor; color: inherit; opacity: .7; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-sunken); border-color: transparent; }
.btn-link { border-color: transparent; background: transparent; color: var(--primary); padding: 0 .25rem; height: auto; }
.btn-link:hover { background: transparent; border-color: transparent; text-decoration: underline; }
.btn-sm { height: 28px; padding: 0 .6rem; font-size: var(--fs-sm); }
.btn-block { width: 100%; }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: .875rem 1rem;
}
.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }
.col-2 { grid-column: span 2; }

.form-section-title {
    grid-column: 1 / -1;
    margin: .5rem 0 -.25rem;
    font-size: var(--fs-xs);
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .label {
    font-size: var(--fs-sm);
    font-weight: 550;
    color: var(--text-muted);
}
.field > label .req { color: var(--danger); margin-left: 2px; }
.field .help { font-size: var(--fs-xs); color: var(--text-faint); }

.input, .select, .textarea,
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea {
    width: 100%;
    height: var(--control-h);
    padding: 0 .65rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    transition: border-color .12s, box-shadow .12s, background .12s;
}
.textarea, .field textarea { height: auto; min-height: 72px; padding: .5rem .65rem; resize: vertical; }
.select, .field select { padding-right: 1.75rem; }
::placeholder { color: var(--text-faint); opacity: 1; }

/* Strong, unmistakable focus for fast keyboard entry */
.input:focus, .select:focus, .textarea:focus,
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}
.field input[readonly], .input[readonly] { background: var(--surface-sunken); color: var(--text-muted); }
/* Money / quantity inputs: right aligned, tabular digits (see UI-GUIDE §Money inputs). */
.input.num, .field input.num, input[inputmode="decimal"] { text-align: right; font-variant-numeric: tabular-nums; }
.uppercase { text-transform: uppercase; }

/* A new voucher dated another day than today (VoucherDates / CompanySession.WorkingDate): subtle amber box, so a
   back-dated or advance bill is never typed by accident. The title says which day it is. */
.input.date-not-today { border-color: var(--warning-fill); background: var(--warning-soft); }
.input.date-not-today:focus { border-color: var(--warning-fill); }

/* Validation states (Blazor adds .invalid / .modified) */
.invalid, .field input.invalid, .field select.invalid { border-color: var(--danger) !important; }
.validation-message, .field-error { font-size: var(--fs-xs); color: var(--danger); }
.validation-errors { margin: 0 0 1rem; padding: .75rem 1rem .75rem 2rem; color: var(--danger); background: var(--danger-soft); border-radius: var(--radius); }

.check { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
/* Checkboxes (UI-GUIDE rule 11: options, settings, report toolbars, row ticks): an unmistakable ring when Tab / ↑ ↓
   reach one, so Space can tick it without the mouse. Voucher entry and master forms use <YesNoSelect> (.select ring). */
input[type=checkbox] { accent-color: var(--primary); }
input[type=checkbox]:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: var(--focus-ring); }

/* Amount + Dr/Cr pair. Only the SECOND child of a real pair is the narrow side select — a group's only
   child keeps its full width (it used to shrink single fields such as "Supplier invoice no." to 76px). */
.input-group { display: flex; min-width: 0; }
.input-group > * { min-width: 0; }
.input-group > :first-child:not(:last-child) { border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; flex: 1 1 auto; }
.input-group > :last-child:not(:first-child) {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    margin-left: -1px;
    width: 84px !important;
    flex: none;
}
/* Dr/Cr select: room for the text and the arrow ("Dr" was clipped to "D"). */
.input-group > select:last-child:not(:first-child), .drcr-select { width: 72px !important; padding-left: .6rem; padding-right: 1.5rem; }

/* ----- Numbers: money, quantity, Dr/Cr (Money.razor / Qty.razor; rules in UI-GUIDE §Numbers) ----- */
.money, .qty {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.money.muted { color: var(--text-muted); }
.money.bad, .qty.bad { color: var(--danger); }
.money.good { color: var(--success); }
.money.strong, .qty.strong { font-weight: 700; }
.money.tappable { cursor: pointer; border-radius: 4px; }
.money.tappable:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
/* Dr / Cr suffix: muted, fixed width, so digits of Dr and Cr rows line up in a column. */
.drcr {
    display: inline-block;
    width: 1.55em;
    margin-left: .3em;
    text-align: left;
    font-size: .85em;
    font-weight: 500;
    color: var(--text-muted);
}
/* Unit after a quantity: "12.5 KGS". */
.qty .unit {
    margin-left: .3em;
    font-size: .8em;
    font-weight: 500;
    color: var(--text-muted);
}
/* Amount in words under an <AmountInput Words> (catches an extra zero while typing lakhs / crores). */
.amount-words { display: block; margin-top: 2px; font-size: var(--fs-xs); color: var(--text-muted); text-align: right; }
/* <Money Fit>: exact amount when the host (a .fit-host such as StatTile) is wide, compact when narrow. */
.fit-host { container-type: inline-size; }
.money.fit .m-short { display: none; }
@container (max-width: 200px) {
    .money.fit .m-full { display: none; }
    .money.fit .m-short { display: inline; }
}

/* Data table */
.table-wrap { overflow: auto; border-radius: var(--radius-lg); max-width: 100%; }
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--table-fs);
    font-variant-numeric: tabular-nums;
}
.table th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: .55rem var(--cell-px);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-strong);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .04em;
    text-align: left;
    white-space: nowrap;
}
.table td {
    padding: var(--cell-py) var(--cell-px);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tbody tr { cursor: pointer; outline: none; }
.table tbody tr:hover td { background: var(--row-hover); }
.table.zebra tbody tr:nth-child(even) td { background: var(--row-zebra); }
.table.zebra tbody tr:nth-child(even):hover td { background: var(--row-hover); }
/* Keyboard-selected row (arrow keys) */
.table tbody tr.selected td { background: var(--primary-soft); }
.table tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
/* Column alignment: every money / qty / rate / % column (header AND cells) is .num. */
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .center { text-align: center; }
.table tr:last-child td { border-bottom: 0; }
.table-empty { padding: 3rem 1rem; text-align: center; color: var(--text-muted); }
/* Column helpers */
.col-date { white-space: nowrap; width: 1%; }
.col-no { white-space: nowrap; width: 1%; }
.col-amt { white-space: nowrap; width: 1%; text-align: right; }
.col-fill { width: 100%; }
.cell-ellipsis { max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Totals: group subtotal = 600 on surface-2; grand total = 700 with a strong top rule. */
.table tr.group-row td { background: var(--surface-2); font-weight: 600; }
.table tr.total-row td, .table tfoot td {
    font-weight: 650;
    background: var(--surface-2);
    border-top: 2px solid var(--border-strong);
    border-bottom: 0;
}
.table tr.grand-total td, .table tfoot tr:last-child td { font-weight: 700; }
.table tfoot tr + tr td { border-top: 1px solid var(--border); }

/* Toolbar above lists */
.toolbar { display: flex; gap: .5rem; align-items: center; padding: .75rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: min(200px, 100%); position: relative; }
.toolbar .search input { padding-left: 2rem; }
.toolbar .search svg { position: absolute; left: .6rem; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--text-faint); pointer-events: none; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: var(--fs-xs);
    font-weight: 600;
    background: var(--surface-sunken);
    color: var(--text-muted);
    white-space: nowrap;
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning-fill) 30%, transparent); }

/* Toasts: styles live in Components/Layout/ToastHost.razor.css (bottom-right, above the status bar). */

/* Modal dialog */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgb(15 17 32 / .45);
    display: grid;
    place-items: center;
    z-index: 900;
    padding: 1rem;
}
.modal {
    width: min(460px, 100%);
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}
.modal-body { padding: 1.25rem; }
.modal-footer { padding: .875rem 1.25rem; display: flex; justify-content: flex-end; gap: .5rem; border-top: 1px solid var(--border); }

/* Lookup (searchable dropdown). The list may be wider than its input (names + balances on one line). */
.lookup { position: relative; }
.lookup-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: max(100%, min(420px, calc(100vw - 3rem)));
    max-height: 300px;
    overflow: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 60;
}
.lookup-list li {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .75rem;
}
.lookup-list li > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.lookup-list li.active, .lookup-list li:hover { background: var(--primary-soft); color: var(--primary); }
.lookup-list li small { flex: none; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.lookup-list .empty { color: var(--text-muted); cursor: default; }

/* Tiles (company picker, shortcut grids) */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 1rem; }
.tile {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    padding: 1.1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    font: inherit;
    transition: border-color .12s, box-shadow .12s, transform .12s;
}
.tile:hover, .tile:focus-visible, .tile.selected {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
    outline: none;
    text-decoration: none;
}
.tile h3 { margin: 0; font-size: var(--fs-lg); }
.tile .meta { color: var(--text-muted); font-size: var(--fs-sm); }
.tile-new { border-style: dashed; align-items: center; justify-content: center; color: var(--primary); min-height: 120px; }

/* Legacy KPI cards (.card.stat inside .stat-grid). New screens use <StatTile> in a .stat-row. */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 1rem; }
.stat { padding: 1rem 1.25rem; display: flex; flex-direction: column; min-width: 0; }
.stat .label { font-size: var(--fs-sm); font-weight: 550; color: var(--text-muted); }
.stat .value {
    font-size: clamp(1.1rem, .9rem + .8vw, 1.5rem);
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* KPI tiles (StatTile.razor): label · one big number · sub-line. At most 4 in a row. */
.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
    gap: 1rem;
}
.stat-tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: .9rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    color: var(--text);
    text-decoration: none;
    transition: border-color .12s, box-shadow .12s;
}
a.stat-tile:hover { border-color: var(--primary); text-decoration: none; }
a.stat-tile:focus-visible { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.stat-label { font-size: var(--fs-sm); font-weight: 550; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value {
    display: flex;
    align-items: baseline;
    gap: .35rem;
    min-width: 0;
    font-size: clamp(1.25rem, 1rem + .9vw, 1.625rem);
    font-weight: 700;
    letter-spacing: -.015em;
    line-height: 1.25;
    white-space: nowrap;
}
.stat-tile.is-bad .stat-value .money { color: var(--danger); }
.stat-unit { font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); letter-spacing: 0; }
.stat-sub {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .15rem .4rem;
    font-size: var(--fs-xs);
    color: var(--text-muted);
    min-height: 1.1rem;
}
.delta { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta.good { color: var(--success); }
.delta.bad { color: var(--danger); }
.delta.neutral { color: var(--text); }
.delta-vs { color: var(--text-muted); }

/* Empty state (EmptyState.razor) */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: .35rem;
    padding: 2.5rem 1.25rem;
    color: var(--text-muted);
}
.empty-state.compact { padding: 1.25rem 1rem; }
.empty-icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-bottom: .25rem;
    border-radius: 50%;
    background: var(--surface-sunken);
    color: var(--text-muted);
}
.empty-state.compact .empty-icon { width: 34px; height: 34px; }
.empty-icon svg { width: 22px; height: 22px; }
.empty-title { color: var(--text); font-weight: 600; }
.empty-text { font-size: var(--fs-sm); max-width: 46ch; }
.empty-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; margin-top: .5rem; }

/* Loading skeleton (LoadingState.razor) */
.loading-state { padding: .75rem 1.25rem; }
.skeleton-row { display: flex; justify-content: space-between; gap: 2rem; padding: .65rem 0; border-bottom: 1px solid var(--border); }
.loading-state.compact .skeleton-row { padding: .4rem 0; }
.skeleton-row:last-child { border-bottom: 0; }
.skeleton {
    display: block;
    height: .8rem;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--border) 50%, var(--surface-sunken) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.3s ease-in-out infinite;
}
.skeleton.num-skel { width: 90px; flex: none; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Tallied / differs chip (TalliedChip.razor) */
.tally-chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    height: 28px;
    padding: 0 .7rem;
    border-radius: 999px;
    font-size: var(--fs-sm);
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid transparent;
}
.tally-chip.ok { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.tally-chip.ok .money { color: var(--text); font-weight: 600; }
.tally-chip.off { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
a.tally-chip.off:hover { text-decoration: none; border-color: var(--danger); }
.tally-icon { font-weight: 800; }
.tally-side { font-weight: 500; }

/* Density switch (DensitySwitch.razor): two-icon segmented control */
.density-switch { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; height: var(--control-h); }
.density-switch button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0 .55rem;
    font-size: var(--fs-xs);
    font-weight: 600;
    border: 0;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
}
.density-switch button + button { border-left: 1px solid var(--border-strong); }
.density-switch button.on { background: var(--primary-soft); color: var(--primary); }
.density-switch svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }

/* Search field look-alike that opens quick search (QuickSearchButton.razor) */
.search-field {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 100%;
    height: 42px;
    padding: 0 .85rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-muted);
    font: inherit;
    text-align: left;
    cursor: text;
}
.search-field:hover { border-color: var(--primary); }
.search-field svg { width: 18px; height: 18px; flex: none; }
.search-field .search-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn .search-label { flex: none; }

/* Phone list rows (UI-GUIDE §Phones): two lines per record, amount right.
   <ul class="m-list"><li><a class="m-row" href=…>
       <span class="m-title">Party</span><span class="m-amt"><Money …/></span>
       <span class="m-meta">03 Oct · Sale 12</span><span class="m-sub">bal …</span></a></li></ul> */
.m-list { list-style: none; margin: 0; padding: 0; }
.m-list > li + li { border-top: 1px solid var(--border); }
.m-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 1px .75rem;
    padding: .65rem 1.1rem;
    color: var(--text);
    text-decoration: none;
}
a.m-row:hover { background: var(--row-hover); text-decoration: none; }
.m-title { min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-amt { text-align: right; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.m-meta { min-width: 0; font-size: var(--fs-sm); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-sub { text-align: right; font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Shortcut help list */
.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; align-items: center; }

/* 5. Auth screens -------------------------------------------------------- */
.auth-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 1.5rem 1rem;
    background:
        radial-gradient(1200px 600px at 10% -10%, rgb(79 70 229 / .16), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, rgb(14 165 233 / .12), transparent 60%),
        var(--bg);
}
.auth-card {
    width: min(420px, 100%);
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
}
.auth-card.wide { width: min(560px, 100%); }
.auth-brand { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.5rem; font-weight: 700; font-size: var(--fs-lg); }
.auth-brand img { width: 36px; height: 36px; border-radius: 9px; }
.auth-card h1 { font-size: 1.375rem; margin-bottom: .25rem; }
.auth-card .lead { color: var(--text-muted); margin-bottom: 1.5rem; }
.auth-card .field + .field { margin-top: .9rem; }
.auth-card .btn-block { margin-top: 1.25rem; height: 40px; }
.auth-links { margin-top: 1.25rem; display: flex; flex-direction: column; gap: .35rem; text-align: center; font-size: var(--fs-sm); color: var(--text-muted); }
.auth-row { display: flex; justify-content: space-between; align-items: center; margin-top: .9rem; font-size: var(--fs-sm); }

/* Blazor error bar: opaque and above the status bar so it is always readable. */
#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0; right: 0;
    bottom: var(--statusbar-h);
    padding: .65rem 3rem .65rem 1.25rem;
    background: var(--surface);
    color: var(--text);
    border-top: 3px solid var(--warning-fill);
    box-shadow: 0 -6px 18px rgb(16 24 40 / .14);
    font-weight: 500;
    z-index: 1100;
}
#blazor-error-ui .reload { font-weight: 650; margin-left: .35rem; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 1rem; top: .6rem; color: var(--text-muted); }

/* 6. Utilities ----------------------------------------------------------- */
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.w-full { width: 100%; }
.sr-only { position: absolute; left: 0; top: 0; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.show-sm { display: none; }

/* Boot splash while the Blazor circuit connects */
.boot-splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.boot-splash img { width: 56px; height: 56px; border-radius: 14px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.94); } }

/* 7. Reports (ReportShell.razor) — full-screen layout, rules in UI-GUIDE §4 "Report layout" ------------
   One ~38px toolbar (title · period · filters · Show · options │ chips · Excel · Print), then the grid, which
   fills the rest of the screen, then one slim summary line. On desktop the page never scrolls: only the grid
   body scrolls inside its own box (headers stick to its top, totals to its bottom). Reports use the whole width
   of the screen with ~12px gutters; forms keep .page / .page-narrow. */
.page-report {
    max-width: none;
    margin: 0;
    /* Report density: 13px tabular figures, ≈28px rows (≈24px with the compact density switch). */
    --cell-px: .55rem;
    --report-cell-py: .25rem;
    --table-fs: .8125rem;
}
:root[data-density="compact"] .page-report { --report-cell-py: .12rem; }

/* Toolbar */
.report-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    min-height: 38px;
    margin-bottom: 6px;
}
.rt-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex: 0 1 auto; max-width: 30%; }
.rt-title h1 { margin: 0; font-size: .9375rem; font-weight: 650; letter-spacing: 0; white-space: nowrap; }
.rt-meta { min-width: 0; max-width: 200px; font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* The company is in the menu bar too (and in the printed title line): only very wide screens repeat it here. */
@media (max-width: 1999px) { .rt-meta { display: none; } }
.rt-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; flex: 1 1 auto; min-width: 0; }
.rt-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; margin-left: auto; }
.rt-actions > .badge, .rt-actions > .tally-chip { margin-right: 4px; }
/* Small square icon buttons in the toolbar (‹ › previous / next account …). */
.rt-nav { width: 30px; padding: 0; font-size: 1rem; line-height: 1; }

/* Compact controls in the toolbar (and the "More" row): 30px high, 13px text. */
.report-toolbar, .rt-more { --control-h: 30px; }
:is(.report-toolbar, .rt-more) :is(.input, .select),
:is(.report-toolbar, .rt-more) .field :is(input:not([type=checkbox]):not([type=radio]), select) {
    height: 30px;
    padding: 0 .5rem;
    font-size: var(--fs-sm);
}
:is(.report-toolbar, .rt-more) :is(.select, .field select) { padding-right: 1.5rem; }
:is(.report-toolbar, .rt-more) .btn-sm { height: 30px; font-size: var(--fs-sm); }
:is(.report-toolbar, .rt-more) .btn-sm kbd { font-size: .625rem; padding: 0 3px; }

/* Filters: label inline and small, never stacked above the input. */
:is(.rt-filters, .rt-more) > .field { flex-direction: row; align-items: center; gap: 5px; flex: 0 1 auto; min-width: 0; }
:is(.rt-filters, .rt-more) > .field > label { font-size: var(--fs-xs); font-weight: 550; white-space: nowrap; color: var(--text-muted); }
:is(.rt-filters, .rt-more) > .field > label small { display: none; }
/* Widths win over the form rule ".field input { width: 100% }" (a field in a flex row has no width of its own). */
:is(.rt-filters, .rt-more) > .field > :not(label) { flex: 1 1 auto; min-width: 0; width: 130px !important; }
:is(.rt-filters, .rt-more) > .field.col-1 > :not(label) { width: 80px !important; }
:is(.rt-filters, .rt-more) > .field.col-3 > :not(label) { width: 170px !important; }
:is(.rt-filters, .rt-more) > .field.col-4 > :not(label) { width: 210px !important; }
:is(.rt-filters, .rt-more) > .field:is(.col-6, .col-8, .col-12) > :not(label) { width: 260px !important; }
/* A text box / lookup with a placeholder says what it is: its label stays for screen readers only. */
.rt-filters > .field:has(> input[placeholder]:not([data-date]), > .lookup input[placeholder]) > label {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
:is(.rt-filters, .rt-more) > .field .help { display: none; }
:is(.rt-filters, .rt-more) > .check, .rt-options .check { font-size: var(--fs-xs); gap: 4px; color: var(--text-muted); white-space: nowrap; }
:is(.rt-filters, .rt-more) > .check input, .rt-options .check input { width: 14px; height: 14px; }
.rt-period { width: auto !important; max-width: 108px; color: var(--text-muted); }
/* Excel / Print: icon only below 1600px (the tooltip names the key). */
@media (max-width: 1599px) { .rt-icon > span { display: none; } }
.rt-dates { display: flex; align-items: center; gap: 3px; flex: none; }
.rt-dates .input { width: 88px; padding: 0 .3rem; text-align: center; }
.rt-dash { color: var(--text-faint); }
.rt-options { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.rt-more-btn svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; }
.rt-more {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    margin-bottom: 6px;
    padding: 6px 8px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

/* Small icon + text buttons (Excel, Print), ⋯ menu, density switch. */
.rt-icon { gap: 4px; padding: 0 .5rem; font-weight: 550; color: var(--text-muted); }
.rt-icon:hover { color: var(--text); }
.rt-icon svg, .rt-menu svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rt-menu svg circle { fill: currentColor; stroke: none; }
.rt-actions .density-switch { height: 30px; margin-left: 4px; }
.rt-actions .density-switch button { width: auto; padding: 0 .5rem; }
.rt-actions .density-switch svg { width: 14px; height: 14px; }
.rt-menu { position: relative; }
.rt-menu > summary { list-style: none; cursor: pointer; user-select: none; }
.rt-menu > summary::-webkit-details-marker { display: none; }
.rt-menu[open] > summary { background: var(--surface-2); }
.rt-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 41;
    display: flex;
    flex-direction: column;
    min-width: 200px;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.rt-menu-list > :is(a, button), .rt-menu-list > .check {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    height: auto;
    min-height: 30px;
    padding: 4px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    font-size: var(--fs-sm);
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
.rt-menu-list > :is(a, button):hover, .rt-menu-list > :is(a, button):focus-visible { background: var(--row-hover); text-decoration: none; }
.rt-menu-list > :is(a, button):disabled { opacity: .5; cursor: not-allowed; }
.rt-menu-list kbd { margin-left: auto; }
.rt-menu-list hr { width: 100%; margin: 4px 0; border: 0; border-top: 1px solid var(--border); }

/* Section tabs right above the grid frame (ReportShell BeforeGrid). */
.report-tabs { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 4px; min-width: 0; margin-bottom: 4px; }
.report-tabs > * { min-width: 0; max-width: 100%; }

/* Grid frame */
.report-body { position: relative; overflow: hidden; border-radius: var(--radius); }
.report-body .table-wrap { border-radius: 0; }
.table.report { font-size: var(--table-fs); }
.table.report td, .table.report th { padding: var(--report-cell-py) var(--cell-px); }
.table.report th { padding-top: .32rem; padding-bottom: .32rem; font-size: .6875rem; }
.table.report tr.sub-row td:first-child { padding-left: 1.75rem; }
.table.report tr.opening-row td { color: var(--text-muted); font-style: italic; }
.table.report tbody tr { cursor: default; }
.table.report tbody tr[data-row] { cursor: pointer; }
.report-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0; }
.report-split > :first-child { border-right: 1px solid var(--border); }
/* Empty and loading inside a report: one small line, a 2px bar — never a big box. */
.page-report .table-empty { padding: .55rem .75rem; text-align: left; font-size: var(--fs-sm); }
.page-report .empty-state { flex-direction: row; flex-wrap: wrap; justify-content: flex-start; text-align: left; gap: .25rem .5rem; padding: .55rem .75rem; font-size: var(--fs-sm); }
.page-report .empty-state .empty-icon { display: none; }
.page-report .empty-state .empty-actions { margin: 0; }
.report-loading {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 6;
    height: 2px;
    margin-bottom: -2px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent) no-repeat;
    background-size: 40% 100%;
    animation: report-loading 1s linear infinite;
}
@keyframes report-loading { from { background-position: -60% 0; } to { background-position: 160% 0; } }
.report-body.is-loading > :not(.report-loading) { opacity: .55; }

/* Slim summary line under the grid: "12 vouchers · Total 1,24,500.00 · GST 18,200.00". */
.report-summary {
    display: flex;
    align-items: center;
    gap: 2px 16px;
    min-height: 24px;
    padding: 4px 4px 0;
    overflow-x: auto;
    scrollbar-width: thin;
    font-size: var(--fs-xs);
    color: var(--text-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.report-summary b, .report-summary strong { color: var(--text); font-weight: 650; }
.report-summary .bad, .report-summary .text-danger { color: var(--danger); }
.report-summary .good, .report-summary .text-success { color: var(--success); }
.report-summary .badge { font-size: .6875rem; }
.print-only, .report-print-head { display: none; }

/* Phone summary of the filters (hidden on desktop). */
.filter-summary {
    display: none;
    align-items: center;
    gap: .6rem;
    width: 100%;
    min-height: 44px;
    padding: 0 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    text-align: left;
    cursor: pointer;
    order: 4;
}
.filter-summary svg { width: 16px; height: 16px; color: var(--text-muted); flex: none; }
.filter-summary-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.filter-summary-action { color: var(--primary); font-size: var(--fs-sm); }

/* Desktop: no page scroll. The page is exactly the content area; the grid frame takes every spare pixel and is
   the only scrolling box, so column headers stick to its top and the <tfoot> / grand-total row to its bottom. */
@media (min-width: 761px) {
    /* Title and actions stay on the first line; only the filters wrap (inside their own box) when they do not fit. */
    .report-toolbar { flex-wrap: nowrap; align-items: flex-start; }
    .report-toolbar > .rt-title, .report-toolbar > .rt-actions { min-height: 30px; align-items: center; }
    .report-toolbar > .rt-title { align-self: center; }
    .app-content:has(> .page-report) { padding: 10px 12px 8px; }
    .page-report { display: flex; flex-direction: column; height: 100%; min-height: 0; }
    .page-report > :not(.report-body) { flex: none; }
    .page-report > .report-body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
    /* Inner wrappers must not scroll on their own (pages used to cap them with max-height). */
    .report-body .table-wrap { overflow: visible !important; max-height: none !important; }
    .report-body .table tfoot td,
    .report-body .table > tbody:last-of-type > tr.total-row:last-child td,
    .report-body .table tr.grand-total td {
        position: sticky;
        bottom: 0;
        z-index: 2;
        box-shadow: 0 -1px 0 var(--border-strong);
    }
    /* Two-panel statements (T-form, GSTR summaries): panels side by side, each scrolls inside, totals pinned. */
    .report-body.split-body, .report-body:has(> .fs-fill-h) { display: flex; flex-direction: column; overflow: hidden; }
    .report-body:has(> .fs-fill-h) > :not(.fs-fill-h) { flex: none; }
    .report-body.split-body > .report-split { flex: 1 1 auto; min-height: 0; }
    .report-body.split-body > .report-split > * { min-height: 0; overflow: auto; overscroll-behavior: contain; }
}

/* 8. Voucher entry (grid of lines) ------------------------------------------------------- */
.voucher-grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.voucher-grid th { font-size: var(--fs-xs); text-transform: uppercase; color: var(--text-muted); text-align: left; padding: .4rem .35rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.voucher-grid td { padding: .25rem .35rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.voucher-grid td .input, .voucher-grid td input, .voucher-grid td select { height: 30px; }
.voucher-grid .num, .voucher-grid input.num { text-align: right; }
.voucher-grid tfoot td { font-weight: 700; border-bottom: 0; padding-top: .5rem; }
.voucher-totals { display: grid; grid-template-columns: auto auto; gap: .25rem 1.5rem; justify-content: end; font-variant-numeric: tabular-nums; }
.voucher-totals .grand { font-size: var(--fs-lg); font-weight: 700; }

/* 9. Responsive ---------------------------------------------------------------------------- */
@media (max-width: 1100px) {
    /* Narrow desktops / landscape tablets with a mouse: tighten the menu bar so it fits. */
    .menubar-brand span { display: none; }
    .menubar-brand { padding-right: .5rem; }
    .menu-trigger { padding: 0 .5rem; }
    .company-chip { max-width: 170px; }
}

@media (max-width: 960px) {
    /* Never leave a lone tile on its own row: 2 × 2 instead of 3 + 1. */
    .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .col-8, .col-6, .col-4, .col-3 { grid-column: span 12; }
    .col-2 { grid-column: span 6; }
    :root { --gutter: 1rem; }
    .app-content { padding: 1rem var(--gutter) 1.5rem; }
    .statusbar .hint:nth-child(n+4) { display: none; }
    .report-split { grid-template-columns: minmax(0, 1fr); }
    .report-split > :first-child { border-right: 0; border-bottom: 1px solid var(--border); }
}

/* Phones, narrow windows (≤880px) and touch tablets (no hover, ≤1100px): menu sheet + bottom tab bar
   (the full desktop menu bar needs ≈900px). */
@media (max-width: 880px), (hover: none) and (max-width: 1100px) {
    /* The top menu collapses into a sheet opened by the hamburger or the "More" tab. */
    .menubar-toggle { display: grid; }
    .menubar-menus {
        display: none;
        position: absolute;
        top: var(--menubar-h);
        left: 0; right: 0;
        flex-direction: column;
        padding: .5rem;
        background: var(--menubar-bg);
        max-height: calc(100dvh - var(--menubar-h) - var(--tabbar-h) - env(safe-area-inset-bottom, 0px));
        overflow: auto;
        overscroll-behavior: contain;
        box-shadow: var(--shadow-lg);
    }
    .menubar.mobile-open .menubar-menus { display: flex; }
    /* No company open → no menus → no hamburger. */
    .menubar:not(:has(.menubar-menus)) .menubar-toggle { display: none; }
    .menu { flex-direction: column; }
    .menu-trigger { margin: 0; padding: .7rem .75rem; min-height: 44px; box-sizing: border-box; }
    .menu-dropdown { position: static; box-shadow: none; min-width: 0; max-height: none; margin: 0 0 .5rem; }
    .menu-item { min-height: 44px; }

    /* Bottom bar becomes the tab bar: Home · Dues · Sales · Stock · More. */
    .statusbar-hints { display: none; }
    .statusbar:not(:has(.tabbar)) { display: none; }
    .tabbar {
        display: flex;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    /* The "More" tab carries .menubar-toggle (for keyboard.js) — undo the menu-bar button look. */
    .tabbar .tab-more { display: flex; }
    #blazor-error-ui { bottom: var(--tabbar-h); }
}

@media (max-width: 760px) {
    :root { --gutter: 1rem; }
    .app-content { padding: .875rem var(--gutter) 1.25rem; }

    /* Menu bar on a phone: logo, hamburger, company chip (shrinks with an ellipsis), theme, sign-out. */
    .menubar { gap: .35rem; padding-right: .5rem; }
    .menubar-brand { border-right: 0; margin-right: 0; padding-right: 0; }
    .menubar-right { flex: 1 1 auto; justify-content: flex-end; gap: .25rem; }
    .company-chip { max-width: none; flex: 0 1 auto; }
    .company-chip span { display: none; }

    .hide-sm, .table .hide-sm { display: none !important; }
    .show-sm { display: revert; }

    .page-header { margin-bottom: .75rem; }
    .page-header h1 { font-size: 1.125rem; }

    /* Reports: page scrolls naturally; filters fold into a one-line summary button. */
    .filter-summary { display: flex; }
    .rt-title { max-width: none; flex: 1 1 auto; }
    .rt-meta { display: none; }
    .rt-filters { display: none; flex: 1 1 100%; order: 5; }
    .rt-filters.open { display: flex; }
    .rt-filters > .field { flex: 1 1 100%; }
    .rt-filters > .field > :not(label) { width: auto; }
    .rt-actions .density-switch, .rt-icon span { display: none; }
    .report-body { overflow-x: auto; }
    .report-summary { flex-wrap: wrap; white-space: normal; }

    .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .625rem; }
    .stat-tile { padding: .75rem .85rem; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .625rem; }
    .stat { padding: .75rem .85rem; }
    .lookup-list { min-width: 100%; }
}

/* Touch screens: 44px targets, no keyboard hints (there is no keyboard). */
@media (pointer: coarse) {
    .btn { min-height: 44px; height: auto; }
    .btn-sm { min-height: 38px; }
    .icon-btn { width: 40px; height: 40px; }
    .density-switch { height: 44px; }
    .density-switch button { width: 44px; }
    .table td a { display: inline-block; min-height: 32px; line-height: 32px; }
}
@media (hover: none) {
    .btn kbd, .menu-item kbd, .search-field kbd, .tile kbd, .filter-summary kbd { display: none; }
    .menu-trigger u { text-decoration: none; }
}

/* Entry controls (UI-GUIDE §Entry controls) ------------------------------------------------------ */
/* Required field left empty on Enter / Tab (keyboard.js): red outer edge on the control, "Required" pill on its box. */
[data-req-missing] {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 35%, transparent) !important;
}
[data-req-shake] { animation: req-shake .32s ease-in-out; }
@keyframes req-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}
[data-req-msg] { position: relative; }
[data-req-msg]::after {
    content: "Required";
    position: absolute;
    right: 6px;
    top: -9px;
    z-index: 3;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: .6875rem;
    font-weight: 600;
    line-height: 16px;
    pointer-events: none;
}

/* ReadOnlyField: looks like a disabled textbox, same height / alignment as inputs, never focusable. */
.readonly-field {
    display: flex;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    background: var(--surface-sunken);
    color: var(--text-muted);
    border-color: var(--border);
    cursor: default;
    user-select: text;
}
.readonly-field.num { justify-content: flex-end; font-variant-numeric: tabular-nums; }
.readonly-field.is-bad { color: var(--danger); }
.readonly-field .readonly-empty { color: var(--text-faint); }

/* Lookup with quick-create: "F3 New" hint inside the empty box while it has the focus. */
.lookup-f3-hint {
    position: absolute;
    right: 8px;
    top: calc(var(--control-h) / 2);
    transform: translateY(-50%);
    font-size: var(--fs-xs);
    color: var(--text-faint);
    pointer-events: none;
    display: none;
}
.lookup:focus-within .lookup-f3-hint { display: inline-flex; gap: 4px; align-items: center; }
@media (hover: none) { .lookup-f3-hint { display: none !important; } }

/* Quick-create popups (QuickCreateHost) */
.modal.quick-create { width: min(480px, 100%); }
.modal.quick-create-wide { width: min(600px, 100%); }
.quick-create .qc-title { margin: 0 0 .25rem; font-size: 1.05rem; }
.quick-create .qc-sub { margin: 0 0 .75rem; color: var(--text-muted); font-size: var(--fs-sm); }
.quick-create .form-grid { margin-top: .75rem; }
.qc-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.qc-chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    height: 30px;
    padding: 0 .75rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: var(--fs-sm);
    cursor: pointer;
}
.qc-chip:hover { background: var(--row-hover); }
.qc-chip.active { background: var(--primary-soft, var(--row-hover)); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.qc-chip kbd { font-size: .625rem; }
.qc-drcr { flex: 0 0 72px !important; }

/* Speed first: no fades, slides or colour transitions anywhere — menus, dropdowns, toasts and focus
   change instantly. Only the "fill this first" shake on a required field keeps its animation. */
*, *::before, *::after { transition: none !important; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; }
}

/* 10. Print: only the document --------------------------------------------------------------- */
@media print {
    @page { margin: 12mm; }
    :root { color-scheme: light; }
    body { background: #fff !important; color: #000 !important; font-size: 11px; }
    .menubar, .statusbar, .no-print, .toast-host, .modal-backdrop, #blazor-error-ui, .page-actions, .toolbar,
    .filter-summary, .density-switch, .tabbar { display: none !important; }
    .app-shell { display: block; height: auto; }
    .app-content { overflow: visible; padding: 0; }
    .card { border: 0; box-shadow: none; }
    .report-page { display: block; height: auto; }
    .report-body { overflow: visible !important; max-height: none !important; }
    .table th { position: static; background: #f3f4f6 !important; color: #000; }
    .table td, .money, .drcr, .qty .unit { color: #000 !important; }
    .table tfoot td, .table tr.total-row td, .table tr.grand-total td { position: static !important; box-shadow: none !important; }
    .table tfoot tr:last-child td, .table tr.grand-total td { border-bottom: 3px double #000; }
    .table-wrap { overflow: visible; max-height: none !important; }
    a { color: inherit; text-decoration: none; }

    /* Reports: one title line, then the grid across the full page in a small font; the column header repeats on
       every printed page, the totals print once at the end; the summary line prints under the grid. */
    .page-report { page: report; display: block; height: auto; max-width: none; }
    .app-content:has(> .page-report) { padding: 0 !important; overflow: visible !important; }
    .report-toolbar, .rt-more, .report-loading { display: none !important; }
    .report-print-head, .print-only { display: block !important; }
    .report-print-head { display: flex !important; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; margin-bottom: 6px; font-size: 11px; }
    .report-print-head strong { font-size: 13px; }
    .report-body { border: 0 !important; border-radius: 0; }
    .report-body.is-loading > * { opacity: 1 !important; }
    .page-report .table { font-size: 9.5px; }
    .page-report .table th, .page-report .table td { padding: 2px 4px !important; }
    .page-report .table thead { display: table-header-group; }
    .page-report .table tfoot { display: table-row-group; }
    .page-report .table tr { break-inside: avoid; }
    .page-report .cell-ellipsis { white-space: normal; max-width: none; }
    .report-summary { flex-wrap: wrap; white-space: normal; overflow: visible; padding: 6px 0 0; font-size: 10px; color: #000; }
    .report-split > * { overflow: visible !important; }
    .page-report .table tbody tr.selected td { background: none !important; box-shadow: none !important; }
}
@page report { size: auto; margin: 8mm; }
