/* =============================================================================================
   Billing & Renewals — design system ("the register").
   The books of a small Indian services business: register paper, blue-black ink, and the account
   book's crimson double margin on every surface that holds money. Colours below are validated:
   text pairs >= 4.5:1, chart series by the dataviz six checks (docs/07-ui-design.md).
   No inline styles anywhere: the Content-Security-Policy forbids them.
   ============================================================================================= */

:root {
    /* Ink & paper */
    --ink: #172036;
    --ink-2: #49536b;          /* secondary text (7.7:1 on white, ok on paper) */
    --ink-3: #6b7489;          /* muted text — white surfaces only (4.7:1) */
    --paper: #f3f6fb;          /* page plane: register paper */
    --surface: #ffffff;
    --rule: #d6deea;           /* hairlines */
    --rule-faint: #e9eef6;     /* register ruling */

    /* Accents */
    --khata: #8e1b23;          /* account-book crimson: the margin, and money owed */
    --khata-wash: #f8eaeb;
    --peacock: #0b6e79;        /* actions & links (6:1 on white) */
    --peacock-dark: #08545c;
    --peacock-wash: #e2f0f1;
    --marigold: #e3a23b;       /* "today" marker in charts only */

    /* Status (always with an icon and a label, never colour alone) */
    --good: #1f6b41;
    --good-wash: #e6f3eb;
    --warn: #7a4f00;
    --warn-wash: #fbefd6;
    --bad: #8e1b23;
    --bad-wash: #f8eaeb;
    --neutral: #3b455c;
    --neutral-wash: #eaeef5;

    /* Data viz (validated: categorical pair + ordinal crimson ramp) */
    --series-billed: #c26a2b;
    --series-collected: #0097a7;
    --aging-0: #de8f96;
    --aging-1: #c8606b;
    --aging-2: #a93844;
    --aging-3: #8e1b23;
    --aging-4: #621019;

    /* Type */
    --font-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-display: "Zilla Slab", Georgia, "Times New Roman", serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(23, 32, 54, .06), 0 1px 1px rgba(23, 32, 54, .04);
    --sidebar-width: 15.5rem;

    /* Bootstrap bridge */
    --bs-body-font-family: var(--font-ui);
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--paper);
    --bs-border-color: var(--rule);
    --bs-link-color: var(--peacock);
    --bs-link-color-rgb: 11, 110, 121;
    --bs-link-hover-color: var(--peacock-dark);
    --bs-link-hover-color-rgb: 8, 84, 92;
    --bs-primary: var(--peacock);
    --bs-primary-rgb: 11, 110, 121;
    --bs-secondary-color: var(--ink-2);
    --bs-focus-ring-color: rgba(11, 110, 121, .35);
}

/* ------------------------------------------------------------------ base */
html { font-size: 15px; }
body {
    font-family: var(--font-ui);
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
h1, h2, h3, .display {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -.005em;
    color: var(--ink);
}
h1 { font-size: 1.85rem; margin: 0; }
h2 { font-size: 1.25rem; margin: 0; }
h3 { font-size: 1.05rem; margin: 0; }
.mono { font-family: var(--font-mono); font-size: .92em; }
.form-control.mono::placeholder { font-family: var(--font-ui); }
.num { font-variant-numeric: tabular-nums; }        /* columns only (dataviz: never on hero figures) */
.text-muted-2 { color: var(--ink-2) !important; }
.text-owed { color: var(--khata) !important; }
a { text-underline-offset: .18em; }
:focus-visible { outline: 2px solid var(--peacock); outline-offset: 2px; }
.btn:focus-visible, .form-control:focus, .form-select:focus, .form-check-input:focus {
    box-shadow: 0 0 0 .2rem rgba(11, 110, 121, .25);
    border-color: var(--peacock);
}

/* ------------------------------------------------------------------ buttons */
.btn { --bs-btn-font-weight: 500; --bs-btn-border-radius: var(--radius-sm); }
.btn-primary {
    --bs-btn-bg: var(--peacock); --bs-btn-border-color: var(--peacock);
    --bs-btn-hover-bg: var(--peacock-dark); --bs-btn-hover-border-color: var(--peacock-dark);
    --bs-btn-active-bg: var(--peacock-dark); --bs-btn-active-border-color: var(--peacock-dark);
    --bs-btn-disabled-bg: var(--peacock); --bs-btn-disabled-border-color: var(--peacock);
}
.btn-outline-primary {
    --bs-btn-color: var(--peacock); --bs-btn-border-color: var(--peacock);
    --bs-btn-hover-bg: var(--peacock); --bs-btn-hover-border-color: var(--peacock);
    --bs-btn-active-bg: var(--peacock-dark); --bs-btn-active-border-color: var(--peacock-dark);
}
.btn-quiet {
    --bs-btn-color: var(--ink-2); --bs-btn-border-color: var(--rule); --bs-btn-bg: var(--surface);
    --bs-btn-hover-color: var(--ink); --bs-btn-hover-bg: var(--paper); --bs-btn-hover-border-color: var(--rule);
}
.btn-danger-quiet {
    --bs-btn-color: var(--khata); --bs-btn-border-color: #e3bcbf; --bs-btn-bg: var(--surface);
    --bs-btn-hover-color: #fff; --bs-btn-hover-bg: var(--khata); --bs-btn-hover-border-color: var(--khata);
}
.btn .bi { margin-right: .35rem; }
.btn-icon .bi { margin-right: 0; }

/* ------------------------------------------------------------------ app shell */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--ink);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: 1.35rem 1.25rem 1.1rem;
    color: #fff;
    text-decoration: none;
}
.brand:hover { color: #fff; }
.brand-mark {
    width: 2.1rem; height: 2.1rem;
    border-radius: 7px;
    background: #fff;
    position: relative;
    flex: 0 0 auto;
}
/* the mark: a ruled page with the crimson double margin */
.brand-mark::before {
    content: "";
    position: absolute; inset: 7px 5px 7px 12px;
    background: repeating-linear-gradient(to bottom, var(--rule) 0 1px, transparent 1px 5px);
}
.brand-mark::after {
    content: "";
    position: absolute; top: 3px; bottom: 3px; left: 7px; width: 3px;
    border-left: 1px solid var(--khata); border-right: 1px solid var(--khata);
}
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.12rem; line-height: 1.1; }
.brand-sub { display: block; font-family: var(--font-ui); font-size: .76rem; font-weight: 400; color: #a9b3c9; }

.nav-section {
    padding: .9rem 1.25rem .35rem;
    font-size: .7rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #8590a9;
}
.side-nav { list-style: none; margin: 0; padding: 0 .65rem; }
.side-nav a {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .5rem .65rem;
    margin: .05rem 0;
    border-radius: var(--radius-sm);
    color: #d3d9e6;
    text-decoration: none;
    font-weight: 500;
}
.side-nav a .bi { font-size: 1.05rem; opacity: .85; }
.side-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-nav a[aria-current="page"] {
    background: rgba(255, 255, 255, .1);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--marigold);
}
.side-nav .count {
    margin-left: auto;
    font-size: .72rem;
    background: var(--khata);
    color: #fff;
    border-radius: 999px;
    padding: .05rem .45rem;
}
.sidebar-foot { margin-top: auto; padding: 1rem 1.25rem; font-size: .78rem; color: #8590a9; border-top: 1px solid rgba(255, 255, 255, .07); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 1020;
    display: flex; align-items: center; gap: .75rem;
    padding: .65rem 1.75rem;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: saturate(1.4) blur(6px);
    border-bottom: 1px solid var(--rule);
}
.topbar .search { flex: 1 1 auto; max-width: 30rem; position: relative; }
.topbar .search .bi { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.topbar .search input { padding-left: 2.2rem; background: var(--paper); border-color: transparent; }
.topbar .search input:focus { background: var(--surface); }
.avatar {
    width: 2rem; height: 2rem; border-radius: 50%;
    background: var(--peacock-wash); color: var(--peacock-dark);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: .8rem;
}
.content { padding: 1.5rem 1.75rem 3rem; max-width: 92rem; width: 100%; }

.page-header {
    display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1rem;
    margin-bottom: 1.25rem;
}
.page-header .eyebrow {
    display: block; margin-bottom: .25rem;
    font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2);
}
.page-header .eyebrow a { color: inherit; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ------------------------------------------------------------------ surfaces */
.panel {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.panel-head {
    display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .2rem 1rem;
    padding: 1rem 1.15rem .6rem;
}
.panel-head > h2 { flex-shrink: 0; }
.panel-head .hint { font-size: .82rem; color: var(--ink-3); }
.panel-body { padding: 0 1.15rem 1.1rem; }
.panel-flush { padding: 0; }
.panel + .panel, .stack > * + * { margin-top: 1rem; }

/* The signature: the account book's crimson double margin on ruled paper */
.register {
    position: relative;
    padding-left: 2.6rem !important;
    background-color: var(--surface);
    background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--rule-faint) 31px 32px);
}
.register::before, .register::after {
    content: "";
    position: absolute; top: 0; bottom: 0;
    width: 1px;
    background: var(--khata);
    opacity: .85;
}
.register::before { left: 1.3rem; }
.register::after { left: calc(1.3rem + 4px); }

/* ------------------------------------------------------------------ receivables hero */
.receivables { padding: 1.35rem 1.5rem 1.3rem; }
.receivables .label { font-size: .85rem; color: var(--ink-2); }
.hero-figure {
    font-family: var(--font-ui);               /* dataviz: hero figure stays in the UI sans */
    font-weight: 600;
    font-size: clamp(2.3rem, 4.2vw, 3.3rem);
    line-height: 1.05;
    letter-spacing: -.02em;
    margin: .2rem 0 .35rem;
}
.hero-sub { color: var(--ink-2); }
.hero-sub strong { color: var(--khata); font-weight: 600; }
.aging-ribbon { display: block; width: 100%; height: 22px; margin: 1.1rem 0 .85rem; }
.aging-ribbon .track { fill: var(--rule-faint); }
.aging-0 { fill: var(--aging-0); background: var(--aging-0); }
.aging-1 { fill: var(--aging-1); background: var(--aging-1); }
.aging-2 { fill: var(--aging-2); background: var(--aging-2); }
.aging-3 { fill: var(--aging-3); background: var(--aging-3); }
.aging-4 { fill: var(--aging-4); background: var(--aging-4); }
.aging-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .6rem 1.25rem; margin: 0; padding: 0; list-style: none; }
.aging-legend .aging-item { display: grid; grid-template-columns: .7rem 1fr; column-gap: .5rem; align-items: baseline;
    margin: -.35rem -.5rem; padding: .35rem .5rem; border-radius: 6px; }
/* A bucket with invoices opens them (dashboard). */
.aging-legend a.aging-item { color: inherit; text-decoration: none; }
.aging-legend a.aging-item:hover { background: var(--paper); }
.aging-legend a.aging-item:hover .bucket { color: var(--ink); text-decoration: underline; }
.aging-legend .swatch { width: .7rem; height: .7rem; border-radius: 2px; transform: translateY(1px); }
.aging-legend .bucket { font-size: .8rem; color: var(--ink-2); }
.aging-legend .amount { grid-column: 2; font-weight: 600; }
.aging-legend .count { grid-column: 2; font-size: .78rem; color: var(--ink-3); }

/* ------------------------------------------------------------------ KPI tiles */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr)); gap: 1rem; }
.kpi {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: .95rem 1.05rem 1rem;
    display: flex; flex-direction: column; gap: .15rem;
    text-decoration: none; color: inherit;
    transition: border-color .15s ease, box-shadow .15s ease;
}
a.kpi:hover { border-color: #b9c6da; box-shadow: 0 3px 10px rgba(23, 32, 54, .07); color: inherit; }
.kpi .kpi-label { display: flex; align-items: center; gap: .45rem; font-size: .82rem; color: var(--ink-2); }
.kpi .kpi-label .bi { color: var(--ink-3); }
.kpi .kpi-value { font-size: 1.55rem; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.kpi .kpi-note { font-size: .8rem; color: var(--ink-3); }
.kpi.is-owed .kpi-value { color: var(--khata); }
.kpi.is-owed { border-left: 3px solid var(--khata); }

/* ------------------------------------------------------------------ charts */
.chart-frame { position: relative; height: 17.5rem; }   /* includes the x-axis band: no nested scroll */
.table-view { margin-top: .75rem; font-size: .85rem; }
.table-view summary { color: var(--ink-2); cursor: pointer; }
.table-view summary:hover { color: var(--ink); }
.legend-inline { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .82rem; color: var(--ink-2); margin: 0; padding: 0; list-style: none; }
.legend-inline .key { display: inline-block; width: .75rem; height: .75rem; border-radius: 2px; margin-right: .4rem; transform: translateY(1px); }
.key-billed { background: var(--series-billed); }
.key-collected { background: var(--series-collected); }

/* ------------------------------------------------------------------ tables */
.data-table { width: 100%; margin: 0; border-collapse: separate; border-spacing: 0; }
.data-table th {
    font-size: .74rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
    color: var(--ink-3);
    padding: .55rem .85rem;
    border-bottom: 1px solid var(--rule);
    white-space: nowrap;
    background: var(--surface);
}
.data-table td { padding: .7rem .85rem; border-bottom: 1px solid var(--rule-faint); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: #f8fafd; }
.data-table .money, .data-table th.money { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .sub { display: block; font-size: .8rem; color: var(--ink-3); }
.data-table a.row-link { color: var(--ink); font-weight: 500; text-decoration: none; }
.data-table a.row-link:hover { color: var(--peacock); text-decoration: underline; }
.table-scroll { overflow-x: auto; }

/* ------------------------------------------------------------------ chips */
.chip {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .12rem .55rem;
    border-radius: 999px;
    font-size: .76rem; font-weight: 600;
    white-space: nowrap;
    background: var(--neutral-wash); color: var(--neutral);
}
.chip .bi { font-size: .8rem; }
.chip-good { background: var(--good-wash); color: var(--good); }
.chip-warn { background: var(--warn-wash); color: var(--warn); }
.chip-bad { background: var(--bad-wash); color: var(--bad); }
.chip-info { background: var(--peacock-wash); color: var(--peacock-dark); }
.chip-muted { background: transparent; color: var(--ink-3); border: 1px solid var(--rule); }

/* ------------------------------------------------------------------ filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.filter-bar .form-control, .filter-bar .form-select { width: auto; min-width: 11rem; }
.filter-bar .grow { flex: 1 1 16rem; min-width: 14rem; }
/* The dashboard age bucket an invoice list is showing, with the way back to all unpaid invoices. */
.active-filter { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin: -.35rem 0 1rem; font-size: .88rem; color: var(--ink-2); }
.active-filter strong { color: var(--ink); }
.active-filter a { margin-left: .6rem; }

/* ------------------------------------------------------------------ forms */
.form-section { padding: 1.15rem 1.15rem .35rem; border-bottom: 1px solid var(--rule-faint); }
.form-section:last-of-type { border-bottom: 0; }
.form-section h2 { font-family: var(--font-ui); font-size: .95rem; font-weight: 600; margin-bottom: .85rem; }
.form-section h2 + .section-hint { margin-top: -.65rem; }
.form-section .section-hint { font-size: .84rem; color: var(--ink-3); margin-bottom: .85rem; }
.form-label { font-weight: 500; font-size: .9rem; margin-bottom: .3rem; }
.form-text { color: var(--ink-3); }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; padding: 1rem 1.15rem; background: #fafbfd; border-top: 1px solid var(--rule); border-radius: 0 0 var(--radius) var(--radius); }
.form-control, .form-select { border-color: var(--rule); border-radius: var(--radius-sm); }
.input-group-text { background: var(--paper); border-color: var(--rule); color: var(--ink-2); }
.field-validation-error, .text-danger { color: var(--khata) !important; }
.input-validation-error { border-color: var(--khata) !important; }
.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; }

/* ------------------------------------------------------------------ alerts / flash */
.flash {
    display: flex; gap: .65rem; align-items: flex-start;
    padding: .75rem 1rem; margin-bottom: 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}
.flash .bi { font-size: 1.1rem; line-height: 1.3; }
.flash-good { background: var(--good-wash); border-color: #c5e3cf; color: var(--good); }
.flash-bad { background: var(--bad-wash); border-color: #ebc7ca; color: var(--bad); }
.flash-warn { background: var(--warn-wash); border-color: #efd9a6; color: var(--warn); }

/* ------------------------------------------------------------------ empty states */
.empty-state { text-align: center; padding: 2.25rem 1.5rem; color: var(--ink-2); }
.empty-state .bi { font-size: 1.8rem; color: var(--ink-3); display: block; margin-bottom: .5rem; }
.empty-state p { margin: 0 auto .9rem; max-width: 26rem; }
.empty-state.compact { padding: 1.25rem 1rem; }

/* ------------------------------------------------------------------ facts (definition lists) */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem 1.5rem; margin: 0; }
.facts dt { font-size: .78rem; font-weight: 500; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: .15rem 0 0; font-weight: 500; }

/* ------------------------------------------------------------------ tabs */
.nav-tabs { --bs-nav-tabs-border-color: var(--rule); padding: 0 1.15rem; }
.nav-tabs .nav-link { color: var(--ink-2); font-weight: 500; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.nav-tabs .nav-link:hover { color: var(--ink); border-bottom-color: var(--rule); }
.nav-tabs .nav-link.active { color: var(--ink); border-bottom-color: var(--peacock); background: transparent; }
.nav-tabs .badge { background: var(--neutral-wash); color: var(--neutral); font-weight: 600; margin-left: .3rem; }

/* ------------------------------------------------------------------ timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: .8rem; top: .3rem; bottom: .3rem; width: 1px; background: var(--rule); }
.timeline li { position: relative; padding: 0 0 1rem 2.4rem; }
.timeline .dot {
    position: absolute; left: .25rem; top: .1rem;
    width: 1.15rem; height: 1.15rem; border-radius: 50%;
    background: var(--surface); border: 1px solid var(--rule);
    display: flex; align-items: center; justify-content: center;
    font-size: .62rem; color: var(--ink-2);
}
.timeline .dot.money { color: var(--peacock); border-color: #b7d8dc; }
.timeline .dot.owed { color: var(--khata); border-color: #e3bcbf; }
.timeline .what { font-weight: 500; }
.timeline .when { font-size: .78rem; color: var(--ink-3); }
.timeline .note { white-space: pre-line; background: #fbfcfe; border: 1px solid var(--rule-faint); border-radius: var(--radius-sm); padding: .5rem .7rem; margin-top: .2rem; }

/* ------------------------------------------------------------------ pager */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1rem; border-top: 1px solid var(--rule); font-size: .85rem; color: var(--ink-3); }

/* ------------------------------------------------------------------ auth (sign-in) */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--surface); }
.auth-panel {
    position: relative;
    background-color: var(--ink);
    background-image: repeating-linear-gradient(to bottom, transparent 0 39px, rgba(255, 255, 255, .055) 39px 40px);
    color: #fff;
    padding: 3.5rem 3.5rem 3rem 5.5rem;
    display: flex; flex-direction: column; justify-content: space-between;
}
.auth-panel::before, .auth-panel::after { content: ""; position: absolute; top: 0; bottom: 0; width: 1px; background: #c8505a; }
.auth-panel::before { left: 3.2rem; }
.auth-panel::after { left: calc(3.2rem + 5px); }
.auth-panel .brand { padding: 0; }
.auth-panel h1 { color: #fff; font-size: clamp(2rem, 3.2vw, 2.7rem); line-height: 1.15; max-width: 22rem; margin-top: 3rem; }
.auth-panel .lede { color: #c3cbdc; max-width: 25rem; margin-top: 1rem; font-size: 1.02rem; }
.auth-panel .ledger-lines { list-style: none; padding: 0; margin: 2.5rem 0 0; max-width: 24rem; }
.auth-panel .ledger-lines li { display: flex; justify-content: space-between; gap: 1rem; padding: .62rem 0; border-bottom: 1px solid rgba(255, 255, 255, .09); color: #d3d9e6; font-size: .92rem; }
.auth-panel .ledger-lines .bi { color: var(--marigold); margin-right: .5rem; }
.auth-panel .foot { color: #8590a9; font-size: .8rem; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 3rem 2rem; }
.auth-form .inner { width: 100%; max-width: 23rem; }
.auth-form h2 { font-size: 1.6rem; margin-bottom: .35rem; }
.auth-form .lede { color: var(--ink-2); margin-bottom: 1.6rem; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed; z-index: 1045; left: 0; top: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .sidebar.is-open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(23, 32, 54, .35); }
    .topbar { padding: .6rem 1rem; }
    .content { padding: 1.1rem 1rem 2.5rem; }
    .auth { grid-template-columns: 1fr; }
    .auth-panel { padding: 2rem 1.5rem 2rem 3.4rem; }
    .auth-panel::before { left: 1.6rem; }
    .auth-panel::after { left: calc(1.6rem + 5px); }
    .auth-panel h1 { margin-top: 1.5rem; }
    .auth-panel .ledger-lines, .auth-panel .foot { display: none; }
}
@media (min-width: 992px) { .menu-toggle { display: none; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------------------------------------------------------------- segmented filter (invoice status) */
.segmented { display: inline-flex; flex-wrap: wrap; gap: .25rem; padding: .25rem; background: var(--surface); border: 1px solid var(--rule); border-radius: 999px; }
.segmented a { padding: .3rem .85rem; border-radius: 999px; color: var(--ink-2); text-decoration: none; font-size: .88rem; font-weight: 500; }
.segmented a:hover { color: var(--ink); background: var(--neutral-wash); }
.segmented a[aria-current="page"] { background: var(--ink); color: #fff; }

/* ---------------------------------------------------------------- invoice line editor & allocation */
.line-editor { width: 100%; border-collapse: separate; border-spacing: 0 .4rem; min-width: 46rem; }
.line-editor th { font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: 0 .35rem; }
.line-editor td { padding: 0 .35rem; vertical-align: top; }
.line-editor th.qty, .line-editor td:nth-child(2) { width: 6.5rem; }
.line-editor th.rate, .line-editor td:nth-child(3) { width: 9rem; }
.line-editor th.disc, .line-editor td:nth-child(4) { width: 12rem; }
.line-editor td.money, .line-editor th.money { width: 8.5rem; text-align: right; padding-top: .45rem; font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.line-editor td:last-child { width: 2.5rem; }
.line-editor textarea { resize: vertical; min-height: 2.4rem; }
.discount-group .form-select { max-width: 5.2rem; }
.line-editor-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin: .5rem 0 1rem; }
.line-editor-total { font-size: .95rem; color: var(--ink-2); }
.line-editor-total strong { color: var(--ink); font-size: 1.15rem; font-variant-numeric: tabular-nums; margin-left: .35rem; }
.allocation-table td.money input { max-width: 10rem; margin-left: auto; }
.apply-row { display: grid; grid-template-columns: 1fr 9rem; gap: .75rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--rule-faint); }
.apply-row label .sub { display: block; font-size: .8rem; color: var(--ink-3); }
.plain-list { list-style: none; margin: 0; padding: 0 1.15rem 1rem; }
.plain-list li { display: grid; grid-template-columns: 1fr auto; column-gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--rule-faint); }
.plain-list li:last-child { border-bottom: 0; }
.plain-list .sub { grid-column: 1; font-size: .8rem; color: var(--ink-3); }
.plain-list .amount { grid-row: 1; grid-column: 2; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- the invoice / statement document */
.doc-panel { padding: 0; }
.doc { padding: 2rem 2.25rem; color: var(--ink); }
.doc-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1.5rem; padding-bottom: 1.25rem; border-bottom: 2px solid var(--ink); }
.doc-from, .doc-to { display: flex; flex-direction: column; gap: .1rem; font-size: .92rem; color: var(--ink-2); }
.doc-from { margin-bottom: 1.25rem; }
.doc-from strong { font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; color: var(--ink); }
.doc-to strong { font-size: 1.05rem; color: var(--ink); }
.doc-label { font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.doc-meta { display: grid; grid-template-columns: auto auto; gap: .35rem 1.25rem; margin: 0; align-content: start; font-size: .92rem; }
.doc-meta > div { display: contents; }
.doc-meta dt { color: var(--ink-3); font-weight: 500; }
.doc-meta dd { margin: 0; text-align: right; font-weight: 600; }
.doc-note { margin: 1.5rem 0; color: var(--ink-2); }
.doc-lines { width: 100%; margin: 1.25rem 0; border-collapse: collapse; font-size: .93rem; }
.doc-lines th { font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); border-bottom: 1px solid var(--rule); padding: .5rem .4rem; text-align: left; }
.doc-lines td { padding: .6rem .4rem; border-bottom: 1px solid var(--rule-faint); vertical-align: top; }
.doc-lines .num { width: 3rem; text-align: right; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.doc-lines td.num:nth-child(3) { color: var(--ink); width: 4.5rem; }
.doc-lines .money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1.5rem; margin-top: 1rem; }
.doc-notes { flex: 1 1 16rem; font-size: .9rem; color: var(--ink-2); }
.doc-totals { flex: 0 0 17rem; margin: 0; font-variant-numeric: tabular-nums; }
.doc-totals > div { display: flex; justify-content: space-between; padding: .3rem 0; }
.doc-totals dt { font-weight: 500; color: var(--ink-2); }
.doc-totals dd { margin: 0; }
.doc-totals .grand { border-top: 2px solid var(--ink); margin-top: .25rem; padding-top: .5rem; font-size: 1.15rem; font-weight: 700; }
.doc-totals .grand dt { color: var(--ink); }
.doc-totals .due { color: var(--khata); font-weight: 700; }
.doc-footer { margin-top: 1.5rem; padding-top: .75rem; border-top: 1px solid var(--rule); font-size: .85rem; color: var(--ink-3); }

/* QR with its caption centred underneath, as on the PDF. */
.doc-upi { display: inline-flex; flex-direction: column; align-items: center; gap: .4rem; margin-top: .5rem; font-size: .85rem; color: var(--ink-2); text-align: center; }
.doc-upi img { border: 1px solid var(--rule); border-radius: 6px; padding: 4px; background: #fff; }
.doc-upi strong { color: var(--ink); }

/* ---------------------------------------------------------------- statement */
.statement-table tfoot th { padding: .6rem .85rem; border-top: 1px solid var(--rule); font-size: .88rem; }
.statement-table tfoot .money { text-align: right; font-variant-numeric: tabular-nums; }
.statement-table .statement-carry td { font-style: italic; color: var(--ink-2); }
.statement-table .statement-closing th { font-size: 1rem; border-top: 2px solid var(--ink); }

/* ---------------------------------------------------------------- notifications, reports, documents, audit */
.bell { position: relative; }
.bell-count { position: absolute; top: -.25rem; right: -.3rem; min-width: 1.15rem; height: 1.15rem; padding: 0 .3rem; border-radius: 999px;
    background: var(--khata); color: #fff; font-size: .68rem; font-weight: 700; line-height: 1.15rem; text-align: center; }
.notification-list { list-style: none; margin: 0; padding: .5rem 1.15rem; }
.notification-list li { display: flex; gap: .85rem; align-items: flex-start; padding: .8rem 0; border-bottom: 1px solid var(--rule-faint); }
.notification-list li:last-child { border-bottom: 0; }
.notification-list li.is-read { opacity: .72; }
.notification-list .dot { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 1.9rem; height: 1.9rem;
    border-radius: 50%; background: var(--neutral-wash); color: var(--neutral); }
.notification-list .dot.owed { background: var(--bad-wash); color: var(--bad); }
.notification-list .dot.money { background: var(--good-wash); color: var(--good); }
.notification-body { min-width: 0; }
.section-title { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; margin: .5rem 0 .75rem; }
.upload-form { padding: .25rem 0 .75rem; border-bottom: 1px solid var(--rule-faint); }
.attachment-list { padding: 0; }
.attachment-list li { grid-template-columns: 1fr auto; }
.attachment-list form { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.audit-diff .is-changed td { background: var(--warn-wash); }
.amount-filter { max-width: 8.5rem; }

/* ---------------------------------------------------------------- print layout */
.print-body { background: var(--paper); }
.print-toolbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; gap: .5rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--rule); }
.print-page { max-width: 52rem; margin: 1.5rem auto; background: var(--surface); box-shadow: var(--shadow); border-radius: var(--radius); }
.print-watermark { margin: 0; padding: .6rem 2.25rem; background: var(--warn-wash); color: var(--warn); font-weight: 600; border-radius: var(--radius) var(--radius) 0 0; }

@media print {
    .sidebar, .topbar, .page-actions, .filter-bar, .pager, .table-view, .no-print { display: none !important; }
    body, .panel, .register, .print-body { background: #fff !important; box-shadow: none !important; }
    .print-page { max-width: none; margin: 0; box-shadow: none; border-radius: 0; }
    .doc { padding: 0; }
    .print-watermark { border: 1px solid currentColor; }
    .data-table tbody tr:hover td { background: none; }
    a { color: inherit !important; text-decoration: none !important; }
    @page { size: A4; margin: 14mm; }
}

.text-pre { white-space: pre-line; }

/* Forms with a full validation summary render it empty until there is an error; keep it hidden until then. */
.validation-summary-valid { display: none !important; }

/* Two-factor recovery codes (D-132): two columns to copy or print. */
.recovery-codes { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, max-content); gap: .5rem 2.5rem; font-size: 1.05rem; }
