/* ==========================================================================
   TONDAK ACCOUNTING ERP - application stylesheet
   Desktop-first, keyboard-centric, dense data grids (TallyPrime inspired).
   Theme is driven by [data-theme] on <html> so the switch needs no reload.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
    --font-sans: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", monospace;

    --fs-xs: 11px;
    --fs-sm: 12px;
    --fs-base: 13px;
    --fs-md: 14px;
    --fs-lg: 16px;
    --fs-xl: 20px;
    --fs-2xl: 26px;

    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
    --sp-10: 40px;

    --radius-sm: 3px;
    --radius: 6px;
    --radius-lg: 10px;

    --topbar-height: 48px;
    --sidebar-width: 232px;
    --sidebar-width-collapsed: 0px;

    --transition: 120ms ease-in-out;
    --z-sticky: 100;
    --z-dropdown: 300;
    --z-modal: 500;
    --z-toast: 700;
}

html[data-theme="light"] {
    --c-bg: #eef1f6;
    --c-surface: #ffffff;
    --c-surface-2: #f6f8fb;
    --c-surface-3: #eaeef4;
    --c-border: #d3dae5;
    --c-border-strong: #b6c1d1;

    --c-text: #16202e;
    --c-text-muted: #5b6879;
    --c-text-faint: #8c98a8;
    --c-text-invert: #ffffff;

    --c-primary: #0b5ed7;
    --c-primary-hover: #0a53be;
    --c-primary-soft: #e3edfd;
    --c-accent: #b8860b;

    --c-success: #1d7a44;
    --c-success-soft: #e2f4ea;
    --c-warning: #9a6700;
    --c-warning-soft: #fdf3d6;
    --c-danger: #b3261e;
    --c-danger-soft: #fbe6e5;
    --c-info: #1a6b8f;
    --c-info-soft: #e2f1f8;

    --c-debit: #0b5ed7;
    --c-credit: #b3261e;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .08);
    --shadow: 0 4px 12px rgba(16, 24, 40, .1);
    --shadow-lg: 0 16px 40px rgba(16, 24, 40, .18);
    --focus-ring: 0 0 0 3px rgba(11, 94, 215, .3);
}

html[data-theme="dark"] {
    --c-bg: #0f151d;
    --c-surface: #161e28;
    --c-surface-2: #1c2632;
    --c-surface-3: #24313f;
    --c-border: #2c3947;
    --c-border-strong: #3d4c5d;

    --c-text: #e6edf5;
    --c-text-muted: #a2b0c0;
    --c-text-faint: #74839a;
    --c-text-invert: #0f151d;

    --c-primary: #4d94ff;
    --c-primary-hover: #74acff;
    --c-primary-soft: #16283f;
    --c-accent: #e0b13c;

    --c-success: #4bc47f;
    --c-success-soft: #14301f;
    --c-warning: #e2b356;
    --c-warning-soft: #322913;
    --c-danger: #f2776e;
    --c-danger-soft: #351a19;
    --c-info: #58b6dc;
    --c-info-soft: #122c37;

    --c-debit: #4d94ff;
    --c-credit: #f2776e;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 4px 14px rgba(0, 0, 0, .45);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, .6);
    --focus-ring: 0 0 0 3px rgba(77, 148, 255, .35);
}

/* --------------------------------------------------------------------------
   2. Reset & base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

/* A layout rule such as display:flex would otherwise defeat the attribute. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: 1.5;
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; line-height: 1.3; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

kbd {
    display: inline-block;
    min-width: 18px;
    padding: 1px 5px;
    font-family: var(--font-sans);
    font-size: var(--fs-xs);
    text-align: center;
    color: var(--c-text-muted);
    background: var(--c-surface-3);
    border: 1px solid var(--c-border);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: var(--z-toast);
    padding: var(--sp-2) var(--sp-4);
    background: var(--c-primary);
    color: #fff;
}
.skip-link:focus { left: var(--sp-2); top: var(--sp-2); }

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

/* --------------------------------------------------------------------------
   3. Application shell
   Header + sidebar stay fixed; only .app-main scrolls (no sticky gap).
   -------------------------------------------------------------------------- */
body.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.app-body {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: var(--sp-5) var(--sp-6) var(--sp-10);
    -webkit-overflow-scrolling: touch;
}

.topbar {
    position: relative;
    flex: 0 0 var(--topbar-height);
    z-index: var(--z-sticky);
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    height: var(--topbar-height);
    padding: 0 var(--sp-4);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    box-shadow: var(--shadow-sm);
}

.topbar__brand { display: flex; align-items: center; gap: var(--sp-2); }

.topbar__logo { display: flex; align-items: center; gap: var(--sp-3); color: var(--c-text); }
.topbar__logo:hover { text-decoration: none; }

.topbar__logo-mark {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 26px; height: 26px;
    font-weight: 700;
    color: var(--c-text);
    background: transparent;
    border-radius: 0;
}

.topbar__logo-mark--image {
    width: auto;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    overflow: hidden;
}
.topbar__logo-mark--image img {
    width: auto;
    height: 28px;
    max-width: 120px;
    object-fit: contain;
    display: block;
}

.topbar__logo-text {
    font-size: var(--fs-sm);
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.topbar__book { flex: 1 1 auto; display: flex; justify-content: center; }
.topbar__actions { display: flex; align-items: center; gap: var(--sp-2); }

.book-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    max-width: 480px;
    padding: var(--sp-1) var(--sp-3);
    font-size: var(--fs-sm);
    color: var(--c-text);
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: 999px;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}
.book-chip:hover { border-color: var(--c-primary); background: var(--c-primary-soft); text-decoration: none; }
.book-chip__company { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-chip__period { color: var(--c-text-muted); font-variant-numeric: tabular-nums; }
.book-chip--empty { color: var(--c-text-muted); }

.search-trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-1) var(--sp-2) var(--sp-1) var(--sp-3);
    font-size: var(--fs-sm);
    color: var(--c-text-muted);
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    cursor: pointer;
}
.search-trigger:hover { border-color: var(--c-border-strong); }
.search-trigger__label { min-width: 90px; text-align: left; }

.icon-button {
    display: grid;
    place-items: center;
    width: 30px; height: 30px;
    color: var(--c-text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
}
.icon-button:hover { color: var(--c-text); background: var(--c-surface-2); border-color: var(--c-border); }

.user-menu { position: relative; }
.user-menu__trigger {
    display: flex; align-items: center; gap: var(--sp-2);
    padding: var(--sp-1) var(--sp-2);
    background: transparent; border: 1px solid transparent;
    border-radius: var(--radius); cursor: pointer; color: inherit;
}
.user-menu__trigger:hover { background: var(--c-surface-2); border-color: var(--c-border); }
.user-menu__meta { display: none; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-menu__name { font-size: var(--fs-sm); font-weight: 600; }
.user-menu__role { font-size: var(--fs-xs); color: var(--c-text-muted); }

.avatar {
    display: grid; place-items: center;
    width: 28px; height: 28px;
    font-size: var(--fs-xs); font-weight: 700;
    color: #fff; background: var(--c-primary);
    border-radius: 50%;
}

.dropdown {
    position: absolute;
    right: 0; top: calc(100% + 6px);
    z-index: var(--z-dropdown);
    min-width: 200px;
    padding: var(--sp-1);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.dropdown__item {
    display: block; width: 100%;
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--fs-sm); text-align: left; color: var(--c-text);
    background: transparent; border: 0; border-radius: var(--radius-sm); cursor: pointer;
}
.dropdown__item:hover { background: var(--c-surface-2); text-decoration: none; }
.dropdown__item--danger { color: var(--c-danger); }
.dropdown__divider { height: 1px; margin: var(--sp-1) 0; background: var(--c-border); }
.dropdown__form { margin: 0; }

/* Sidebar ---------------------------------------------------------------- */
.sidebar {
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    height: 100%;
    padding: var(--sp-4) var(--sp-2);
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    -webkit-overflow-scrolling: touch;
}
body.sidebar-collapsed .sidebar { display: none; }

.sidebar__group { display: flex; flex-direction: column; gap: 2px; }
.sidebar__group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    width: 100%;
    margin: 0;
    padding: var(--sp-1) var(--sp-3);
    border: 0;
    background: transparent;
    cursor: pointer;
    color: var(--c-text-faint);
    border-radius: var(--radius);
}
.sidebar__group-toggle:hover { background: var(--c-surface-2); color: var(--c-text-muted); }
.sidebar__group-label {
    margin: 0;
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: inherit;
    text-align: left;
}
.sidebar__chevron {
    width: .55rem;
    height: .55rem;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    transition: transform .15s ease;
    flex: 0 0 auto;
}
.sidebar__group-toggle[aria-expanded="false"] .sidebar__chevron,
.sidebar__branch-toggle[aria-expanded="false"] .sidebar__chevron {
    transform: rotate(-45deg);
}
.sidebar__group-toggle[aria-expanded="true"] .sidebar__chevron,
.sidebar__branch-toggle[aria-expanded="true"] .sidebar__chevron {
    transform: rotate(45deg);
}
.sidebar__list,
.sidebar__sublist { margin: 0; padding: 0; list-style: none; }
.sidebar__group.is-collapsed .sidebar__list { display: none; }
.sidebar__item { margin: 0; }
.sidebar__row {
    display: flex;
    align-items: stretch;
    gap: 2px;
}
.sidebar__row .sidebar__link { flex: 1 1 auto; min-width: 0; }
.sidebar__branch-toggle {
    flex: 0 0 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--c-text-faint);
    border-radius: var(--radius);
    cursor: pointer;
}
.sidebar__branch-toggle:hover {
    background: var(--c-surface-2);
    color: var(--c-text);
}
.sidebar__sublist {
    margin: 0 0 var(--sp-1);
    padding-left: var(--sp-3);
    border-left: 1px solid var(--c-border);
    margin-left: var(--sp-3);
}
.sidebar__link {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    color: var(--c-text); border-radius: var(--radius);
    border-left: 2px solid transparent;
}
.sidebar__link--sub {
    padding: .35rem var(--sp-2);
    font-size: var(--fs-sm);
    color: var(--c-text-muted);
}
.sidebar__link .icon { display: none; }
.sidebar__link:hover { background: var(--c-surface-2); text-decoration: none; }
.sidebar__link.is-active {
    background: var(--c-primary-soft);
    border-left-color: var(--c-primary);
    color: var(--c-primary);
    font-weight: 600;
}
.sidebar__link.is-active-parent {
    color: var(--c-primary);
    font-weight: 600;
}
.sidebar__label { flex: 1 1 auto; }
.sidebar__shortcut { font-size: var(--fs-xs); color: var(--c-text-faint); }
.sidebar__footer { margin-top: auto; padding: var(--sp-3); border-top: 1px solid var(--c-border); }
.sidebar__version { margin: 0; font-size: var(--fs-xs); font-weight: 600; color: var(--c-text-muted); }
.sidebar__version-no { margin: 0; font-size: var(--fs-xs); color: var(--c-text-faint); }

/* --------------------------------------------------------------------------
   4. Page furniture
   -------------------------------------------------------------------------- */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
    padding-bottom: var(--sp-3);
    border-bottom: 1px solid var(--c-border);
}
.page-header__title { display: flex; align-items: center; gap: var(--sp-3); }
.page-header__subtitle { margin: var(--sp-1) 0 0; font-size: var(--fs-sm); color: var(--c-text-muted); }
.page-header__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.page-header__actions--company { width: 100%; justify-content: flex-end; }
.page-header__actions--spread { width: 100%; justify-content: space-between; align-items: center; }
.page-header--compact {
    margin-bottom: var(--sp-3);
    padding-bottom: var(--sp-2);
    align-items: center;
}
.page-header--compact .page-header__subtitle { margin-top: .15rem; }
.field--grow { flex: 1 1 auto; min-width: 0; margin: 0; }
.field--company-search { flex: 1 1 28rem; min-width: min(100%, 28rem); max-width: 40rem; margin: 0; }
.input--company-search {
    width: 100%;
    min-height: 2.75rem;
    font-size: var(--fs-md);
    padding: .65rem 1rem;
}

.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--sp-4); }
.card__header {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--c-border);
}
.card__title { font-size: var(--fs-md); font-weight: 600; }
.card__subtitle { margin: 2px 0 0; font-size: var(--fs-xs); color: var(--c-text-muted); }
.card__body { padding: var(--sp-4); }
.card__body--flush { padding: 0; }
.card__footer {
    display: flex; justify-content: flex-end; gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    background: var(--c-surface-2);
    border-top: 1px solid var(--c-border);
    border-radius: 0 0 var(--radius) var(--radius);
}

.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }

.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.row--between { justify-content: space-between; }
.spacer { flex: 1 1 auto; }
.text-muted { color: var(--c-text-muted); }
.text-faint { color: var(--c-text-faint); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.numeric { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.list-bullet { margin: 0; padding-left: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); }

/* --------------------------------------------------------------------------
   5. Forms
   -------------------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-4); align-items: start; }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; }
.col-6 { grid-column: span 6; }
.col-8 { grid-column: span 8; }
.col-9 { grid-column: span 9; }

/* Unified filter bar — inline CSS grid on every page */
.report-filters,
.filters-grid,
.toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: var(--sp-3) var(--sp-4);
}
.report-filters__fields,
.filters-grid__fields,
.toolbar__start {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
    align-items: end;
    gap: var(--sp-3);
    min-width: 0;
}
.report-filters__fields .field,
.filters-grid__fields .field,
.toolbar .field {
    margin: 0;
    width: auto;
    min-width: 0;
}
.report-filters__fields .field--wide,
.filters-grid__fields .field--wide,
.toolbar .field--wide {
    grid-column: span 2;
    min-width: 12rem;
}
.report-filters__fields .field--date,
.filters-grid__fields .field--date,
.toolbar .field--date {
    max-width: 11rem;
}
.report-filters__actions,
.filters-grid__actions,
.toolbar__end {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--sp-2);
    flex: 0 0 auto;
}
.report-filters__summary,
.filters-grid__summary {
    white-space: nowrap;
    font-size: var(--fs-sm);
}

/* Toolbar used as a flat field row (no start/end wrappers) */
.toolbar:not(:has(.toolbar__start)) {
    grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
}
.toolbar:not(:has(.toolbar__start)) > .spacer {
    display: none;
}
.toolbar:not(:has(.toolbar__start)) > .input,
.toolbar:not(:has(.toolbar__start)) > select.input,
.toolbar__start > .input,
.toolbar__start > select.input {
    min-width: 0;
    width: 100%;
}

@media (max-width: 720px) {
    .report-filters,
    .filters-grid,
    .toolbar {
        grid-template-columns: 1fr;
    }
    .report-filters__fields .field--wide,
    .filters-grid__fields .field--wide,
    .toolbar .field--wide {
        grid-column: span 1;
    }
    .report-filters__actions,
    .filters-grid__actions,
    .toolbar__end {
        justify-content: flex-start;
    }
}

/* Ledger statement — opening / current / closing summary */
.ledger-balance-panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: .35rem;
    margin-left: auto;
    width: min(22rem, 100%);
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--c-border);
    background: var(--c-surface-2);
}
.ledger-balance-panel__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-4);
}
.ledger-balance-panel__row--closing {
    margin-top: .15rem;
    padding-top: .45rem;
    border-top: 1px dashed var(--c-border);
}
.ledger-balance-panel__label {
    color: var(--c-text-muted);
    font-size: var(--fs-sm);
}
.ledger-balance-panel__value {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--fs-sm);
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
}
.ledger-balance-panel__value.is-dr { color: var(--c-debit); }
.ledger-balance-panel__value.is-cr { color: var(--c-credit); }
.ledger-balance-panel__value.is-nil { color: var(--c-text-faint); }
.btn--export {
    gap: .4rem;
    padding: .4rem .75rem;
    min-height: 2.375rem;
}
.btn__export-icon {
    width: 1.4rem;
    height: 1.4rem;
    object-fit: contain;
    display: block;
    flex: 0 0 auto;
}
.col-12 { grid-column: span 12; }

.field { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.field__label {
    display: flex;
    align-items: center;
    min-height: 1.15rem;
    font-size: var(--fs-xs);
    font-weight: 600;
    line-height: 1.15;
    color: var(--c-text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}
.field__label .required { color: var(--c-danger); }
.field__hint { font-size: var(--fs-xs); color: var(--c-text-faint); }
.field__error { font-size: var(--fs-xs); color: var(--c-danger); }
.field.is-invalid .input,
.field.is-invalid .select,
.field.is-invalid .textarea { border-color: var(--c-danger); background: var(--c-danger-soft); }

.input, .select, .textarea {
    box-sizing: border-box;
    width: 100%;
    min-height: 2.375rem;
    padding: 6px var(--sp-2);
    font-family: inherit;
    font-size: var(--fs-base);
    line-height: 1.4;
    color: var(--c-text);
    background: var(--c-surface);
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--c-primary); }
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: var(--focus-ring);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--c-surface-3); color: var(--c-text-muted); cursor: not-allowed; }
.input[readonly] { background: var(--c-surface-2); }
.textarea { min-height: 68px; resize: vertical; }
.input--upper { text-transform: uppercase; }

/* Visual uppercase while typing; value is forced by auto-caps.js */
input.input:not([data-no-auto-caps]):not([name*="narration" i]):not([id*="narration" i]):not([type="password"]):not([type="email"]):not([type="number"]):not([type="date"]):not([type="datetime-local"]):not([type="time"]):not([type="month"]):not([type="search"]),
textarea.textarea:not([data-no-auto-caps]):not([name*="narration" i]):not([id*="narration" i]),
textarea.input:not([data-no-auto-caps]):not([name*="narration" i]):not([id*="narration" i]) {
    text-transform: uppercase;
}
.input--numeric { font-family: var(--font-mono); text-align: right; }

.select {
    appearance: none;
    height: 2.375rem;
    padding-right: var(--sp-6);
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}
.period-range {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-3);
}
.period-range__label {
    margin: 0;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--c-text);
}
.period-range__hint {
    margin: 0;
    font-size: var(--fs-xs);
    color: var(--c-text-faint);
}

.checkbox, .radio { display: inline-flex; align-items: flex-start; gap: var(--sp-2); font-size: var(--fs-base); cursor: pointer; }
.checkbox input, .radio input { margin-top: 2px; accent-color: var(--c-primary); }

.switch { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-panel {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: var(--sp-3) var(--sp-4);
}
.switch-panel .switch {
    min-height: 2.25rem;
    padding: var(--sp-2) var(--sp-3);
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
}
.switch__track {
    position: relative;
    width: 34px; height: 18px;
    background: var(--c-border-strong);
    border-radius: 999px;
    transition: background var(--transition);
}
.switch__track::after {
    content: "";
    position: absolute; top: 2px; left: 2px;
    width: 14px; height: 14px;
    background: #fff; border-radius: 50%;
    transition: transform var(--transition);
}
.switch input:checked + .switch__track { background: var(--c-primary); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--focus-ring); }

.card__header--split {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
}
.mt-4 { margin-top: var(--sp-4); }

.fieldset { border: 1px solid var(--c-border); border-radius: var(--radius); padding: var(--sp-4); margin: 0 0 var(--sp-4); }
.fieldset__legend { padding: 0 var(--sp-2); font-size: var(--fs-sm); font-weight: 700; color: var(--c-text-muted); text-transform: uppercase; letter-spacing: .05em; }

.input-group { display: flex; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: 0; }

/* --------------------------------------------------------------------------
   6. Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 6px var(--sp-4);
    font-family: inherit;
    font-size: var(--fs-base);
    font-weight: 600;
    line-height: 1.4;
    color: var(--c-text);
    background: var(--c-surface);
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.btn:hover { background: var(--c-surface-2); text-decoration: none; }
.btn:disabled, .btn.is-busy { opacity: .6; cursor: not-allowed; }
.btn--primary { color: #fff; background: var(--c-primary); border-color: var(--c-primary); }
.btn--primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }
.btn--danger { color: #fff; background: var(--c-danger); border-color: var(--c-danger); }
.btn--danger:hover { filter: brightness(1.05); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--c-primary); }
.btn--ghost:hover { background: var(--c-primary-soft); }
.btn--sm { padding: 3px var(--sp-2); font-size: var(--fs-sm); }
.btn--block { width: 100%; }
.btn__key {
    font-size: var(--fs-xs);
    font-weight: 700;
    opacity: .75;
}

/* --------------------------------------------------------------------------
   7. Tables
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    font-size: var(--fs-base);
}
.table th, .table td {
    box-sizing: border-box;
    padding: 6px var(--sp-3);
    text-align: left;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}
.table th.text-right,
.table td.text-right,
.table .text-right {
    text-align: right;
}
.table th.numeric,
.table td.numeric,
.table th.num,
.table td.num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    text-align: right;
}
.table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--c-text-muted);
    background: var(--c-surface-2);
    border-bottom: 1px solid var(--c-border-strong);
    white-space: nowrap;
}
.table thead th.numeric,
.table thead th.text-right {
    text-align: right;
}
.table tbody tr:hover { background: var(--c-surface-2); }
.table tbody tr.is-selected { background: var(--c-primary-soft); }
.table tbody tr[data-href] { cursor: pointer; }
.ledger-link {
    color: inherit;
    text-decoration: none;
}
.ledger-link:hover {
    color: var(--c-primary);
    text-decoration: underline;
}
.table tfoot td { font-weight: 700; background: var(--c-surface-2); border-top: 2px solid var(--c-border-strong); }
.table--compact th, .table--compact td { padding: 3px var(--sp-2); }
.table__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-1);
    justify-content: flex-end;
    align-items: center;
    white-space: nowrap;
}
.table__actions-head { text-align: right; width: 11rem; }
.table__empty { padding: var(--sp-8); text-align: center; color: var(--c-text-muted); }

/* Masters list tables — fixed columns so headers line up with cells */
.table--masters {
    table-layout: fixed;
    width: 100%;
}
.table--masters th,
.table--masters td {
    overflow: hidden;
    text-overflow: ellipsis;
}
.table--masters .col-name { width: 26%; }
.table--masters .col-under { width: 18%; }
.table--masters .col-nature { width: 12%; }
.table--masters .col-opening { width: 12%; }
.table--masters .col-flags { width: 14%; }
.table--masters .col-actions,
.table--masters th.table__actions-head,
.table--masters td:last-child { width: 11rem; }
.table--masters td:last-child {
    overflow: visible;
}

.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
    gap: var(--sp-3);
}
.report-tile {
    display: block;
    padding: var(--sp-4);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
    color: inherit;
    text-decoration: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.report-tile:hover {
    border-color: var(--c-primary);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
}
.report-tile__title {
    margin: 0 0 var(--sp-1);
    font-size: var(--fs-md);
    font-weight: 700;
}
.report-tile__hint {
    margin: 0;
    font-size: var(--fs-sm);
    color: var(--c-text-muted);
}

.definition-list { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: var(--sp-2) var(--sp-4); margin: 0; }
.definition-list dt { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--c-text-faint); }
.definition-list dd { margin: 0; }

/* --------------------------------------------------------------------------
   8. Feedback
   -------------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px var(--sp-2);
    font-size: var(--fs-xs);
    font-weight: 600;
    border-radius: 999px;
    border: 1px solid transparent;
}
.badge--success { color: var(--c-success); background: var(--c-success-soft); }
.badge--warning { color: var(--c-warning); background: var(--c-warning-soft); }
.badge--danger { color: var(--c-danger); background: var(--c-danger-soft); }
.badge--info { color: var(--c-info); background: var(--c-info-soft); }
.badge--muted { color: var(--c-text-muted); background: var(--c-surface-3); }

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border: 1px solid transparent;
    border-left-width: 3px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-base);
}
.alert--success { color: var(--c-success); background: var(--c-success-soft); border-left-color: var(--c-success); }
.alert--error, .alert--danger { color: var(--c-danger); background: var(--c-danger-soft); border-left-color: var(--c-danger); }
.alert--warning { color: var(--c-warning); background: var(--c-warning-soft); border-left-color: var(--c-warning); }
.alert--info { color: var(--c-info); background: var(--c-info-soft); border-left-color: var(--c-info); }
.alert__close { margin-left: auto; background: none; border: 0; font-size: var(--fs-lg); line-height: 1; color: inherit; cursor: pointer; }
.flash-stack { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-4); }

.toast-stack {
    position: fixed;
    right: var(--sp-4);
    bottom: var(--sp-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    max-width: 380px;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    color: var(--c-text);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-left: 3px solid var(--c-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: toast-in 140ms ease-out;
}
.toast--success { border-left-color: var(--c-success); }
.toast--error { border-left-color: var(--c-danger); }
.toast--warning { border-left-color: var(--c-warning); }
.toast__body { flex: 1 1 auto; }
.toast__title { font-weight: 600; }
.toast__message { font-size: var(--fs-sm); color: var(--c-text-muted); }
.toast__close { background: none; border: 0; color: var(--c-text-faint); cursor: pointer; font-size: var(--fs-lg); line-height: 1; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.empty-state { padding: var(--sp-10) var(--sp-4); text-align: center; color: var(--c-text-muted); }
.empty-state__title { font-size: var(--fs-lg); font-weight: 600; color: var(--c-text); }
.empty-state__body { margin: var(--sp-2) auto var(--sp-4); max-width: 460px; }

.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 620ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.is-loading { position: relative; pointer-events: none; opacity: .65; }

/* --------------------------------------------------------------------------
   9. Modal & command palette
   -------------------------------------------------------------------------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: grid;
    place-items: start center;
    padding: 6vh var(--sp-4);
    background: rgba(9, 14, 21, .55);
    overflow-y: auto;
}
.modal {
    width: min(720px, 100%);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: modal-in 140ms ease-out;
}
.modal--wide { width: min(1040px, 100%); }
@keyframes modal-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

.modal__header {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--c-border);
}
.modal__title { font-size: var(--fs-md); font-weight: 600; }
.modal__close { background: none; border: 0; font-size: var(--fs-xl); line-height: 1; color: var(--c-text-muted); cursor: pointer; }
.modal__body { padding: var(--sp-4); }
.modal__footer {
    display: flex; justify-content: flex-end; gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    background: var(--c-surface-2);
    border-top: 1px solid var(--c-border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.modal__footer:empty { display: none; }

.command-palette {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: grid;
    place-items: start center;
    padding: 12vh var(--sp-4);
    background: rgba(9, 14, 21, .5);
}
.command-palette__panel {
    width: min(620px, 100%);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.command-palette__input {
    width: 100%;
    padding: var(--sp-4);
    font-family: inherit;
    font-size: var(--fs-lg);
    color: var(--c-text);
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--c-border);
}
.command-palette__input:focus { outline: none; }
.command-palette__results { margin: 0; padding: var(--sp-1); list-style: none; max-height: 46vh; overflow-y: auto; }
.command-palette__result {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.command-palette__result[aria-selected="true"] { background: var(--c-primary-soft); }
.command-palette__result-title { font-weight: 600; }
.command-palette__result-meta { margin-left: auto; font-size: var(--fs-xs); color: var(--c-text-faint); }
.command-palette__hint {
    padding: var(--sp-2) var(--sp-4);
    font-size: var(--fs-xs);
    color: var(--c-text-faint);
    background: var(--c-surface-2);
    border-top: 1px solid var(--c-border);
}

/* --------------------------------------------------------------------------
   10. Tabs
   -------------------------------------------------------------------------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--c-border); margin-bottom: var(--sp-4); }
.tabs__tab {
    padding: var(--sp-2) var(--sp-4);
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--c-text-muted);
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    cursor: pointer;
}
.tabs__tab:hover { color: var(--c-text); }
.tabs__tab.is-active { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.tab-panel[hidden] { display: none; }

/* --------------------------------------------------------------------------
   11. Module 1 specific
   -------------------------------------------------------------------------- */
.company-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-4); }

.company-card {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    padding: var(--sp-4);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-left: 3px solid var(--c-border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.company-card:hover { border-left-color: var(--c-primary); box-shadow: var(--shadow); transform: translateY(-1px); }
.company-card.is-active { border-left-color: var(--c-success); background: var(--c-surface); }
.company-card.is-inactive { opacity: .72; }
.company-card__head { display: flex; align-items: flex-start; gap: var(--sp-3); }
.company-card__logo {
    display: grid; place-items: center;
    width: 42px; height: 42px;
    flex: 0 0 42px;
    font-size: var(--fs-lg); font-weight: 700; color: #fff;
    background: linear-gradient(140deg, var(--c-primary), var(--c-accent));
    border-radius: var(--radius);
    overflow: hidden;
}
.company-card__logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.company-card__name { font-size: var(--fs-md); font-weight: 600; }
.company-card__meta { font-size: var(--fs-xs); color: var(--c-text-muted); }
.company-card__stats { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-xs); color: var(--c-text-muted); }
.company-card__stat strong { display: block; font-size: var(--fs-base); color: var(--c-text); font-variant-numeric: tabular-nums; }
.company-card__actions { display: flex; gap: var(--sp-2); margin-top: auto; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--sp-3); }
.stat-tile {
    padding: var(--sp-3) var(--sp-4);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
}
.stat-tile__label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--c-text-faint); }
.stat-tile__value { font-size: var(--fs-xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-tile__meta { font-size: var(--fs-xs); color: var(--c-text-muted); }
.stat-tile--link {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.stat-tile--link:hover { border-color: var(--c-primary); box-shadow: var(--shadow-sm); }
.stat-tile--loading { opacity: .7; }

.hint { margin: 0; font-size: var(--fs-sm); color: var(--c-text-muted); }
.meta-list { margin: 0; padding: 0; list-style: none; }
.meta-list li {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-2) 0;
    border-bottom: 1px dashed var(--c-border);
    font-size: var(--fs-sm);
}
.meta-list li:last-child { border-bottom: 0; }
.meta-list span { color: var(--c-text-muted); }
.meta-list strong { font-variant-numeric: tabular-nums; }

.dash-quick { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.dash-quick__item {
    display: inline-flex;
    align-items: center;
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--c-text);
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    text-decoration: none;
}
.dash-quick__item:hover { border-color: var(--c-primary); color: var(--c-primary); }

.dash-chart { min-height: 200px; }
.dash-chart__legend {
    display: flex;
    gap: var(--sp-4);
    margin-bottom: var(--sp-2);
    font-size: var(--fs-xs);
    color: var(--c-text-muted);
}
.dash-chart__swatch {
    display: inline-block;
    width: 10px; height: 10px;
    margin-right: 4px;
    border-radius: 2px;
    vertical-align: -1px;
}
.dash-chart__swatch--sales { background: var(--c-primary); }
.dash-chart__swatch--purchase { background: var(--c-accent, #c27803); }
.dash-chart__svg { width: 100%; height: 180px; display: block; }
.dash-chart__bar--sales { fill: var(--c-primary); }
.dash-chart__bar--purchase { fill: var(--c-accent, #c27803); opacity: .85; }
.dash-chart__axis { fill: var(--c-text-faint); font-size: 10px; font-family: var(--font-mono); }

.dash-bars { display: flex; flex-direction: column; gap: var(--sp-3); }
.dash-bars__row { display: grid; grid-template-columns: 52px 1fr 110px; gap: var(--sp-3); align-items: center; }
.dash-bars__label { font-size: var(--fs-xs); color: var(--c-text-muted); font-variant-numeric: tabular-nums; }
.dash-bars__track { height: 10px; background: var(--c-surface-3); border-radius: 999px; overflow: hidden; }
.dash-bars__fill { height: 100%; background: linear-gradient(90deg, var(--c-primary), var(--c-accent, #c27803)); border-radius: 999px; }
.dash-bars__value { font-size: var(--fs-xs); text-align: right; font-variant-numeric: tabular-nums; }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.gstin-verify-row {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: var(--sp-2);
}
.gstin-verify-row .input {
    flex: 1 1 14rem;
    min-width: 0;
}
.gstin-verify-row .btn {
    flex: 0 0 auto;
    white-space: nowrap;
    align-self: stretch;
}
.code-block {
    margin: 0;
    padding: var(--sp-3);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    max-height: 220px;
    overflow: auto;
}

.checklist { margin: 0; padding: 0; list-style: none; }
.checklist__item { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-2) 0; border-bottom: 1px dashed var(--c-border); }
.checklist__item:last-child { border-bottom: 0; }
.checklist__mark {
    display: grid; place-items: center;
    flex: 0 0 18px; width: 18px; height: 18px; margin-top: 2px;
    font-size: 11px; font-weight: 700;
    border: 1px solid var(--c-border-strong); border-radius: 50%;
    color: var(--c-text-faint);
}
.checklist__item.is-done .checklist__mark { color: #fff; background: var(--c-success); border-color: var(--c-success); }
.checklist__label { font-weight: 600; }
.checklist__hint { font-size: var(--fs-xs); color: var(--c-text-muted); }

.gstin-preview { display: flex; flex-wrap: wrap; gap: var(--sp-2); font-size: var(--fs-xs); }
.gstin-preview__part { padding: 1px var(--sp-2); background: var(--c-surface-3); border-radius: var(--radius-sm); font-family: var(--font-mono); }
.gstin-preview.is-invalid .gstin-preview__part { color: var(--c-danger); background: var(--c-danger-soft); }

.logo-upload { display: flex; align-items: center; gap: var(--sp-4); }
.logo-upload__preview {
    display: grid; place-items: center;
    width: 96px; height: 96px;
    background: var(--c-surface-2);
    border: 1px dashed var(--c-border-strong);
    border-radius: var(--radius);
    overflow: hidden;
}
.logo-upload__preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-upload__hint { font-size: var(--fs-xs); color: var(--c-text-muted); }

.period-bar { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-mono); font-size: var(--fs-sm); }
.period-bar__sep { color: var(--c-text-faint); }

/* Auth screen ------------------------------------------------------------ */
.auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: var(--sp-6);
    background:
        radial-gradient(1200px 480px at 12% -10%, var(--c-primary-soft), transparent 60%),
        var(--c-bg);
}
.auth__panel {
    width: min(420px, 100%);
    padding: var(--sp-8);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.auth__brand { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-6); }
.auth__brand-mark {
    display: grid; place-items: center;
    width: 40px; height: 40px;
    font-size: var(--fs-xl); font-weight: 700; color: #fff;
    background: linear-gradient(140deg, var(--c-primary), var(--c-accent));
    border-radius: var(--radius);
}
.auth__title { font-size: var(--fs-lg); }
.auth__subtitle { font-size: var(--fs-xs); color: var(--c-text-muted); letter-spacing: .06em; text-transform: uppercase; }
.auth__footer { margin-top: var(--sp-5); font-size: var(--fs-xs); color: var(--c-text-faint); text-align: center; }
.auth__aside { margin-top: var(--sp-4); font-size: var(--fs-sm); text-align: center; }

.password-meter { height: 4px; background: var(--c-surface-3); border-radius: 999px; overflow: hidden; }
.password-meter__bar { height: 100%; width: 0; background: var(--c-danger); transition: width var(--transition), background var(--transition); }
.password-meter__bar[data-score="2"] { background: var(--c-warning); }
.password-meter__bar[data-score="3"] { background: var(--c-info); }
.password-meter__bar[data-score="4"] { background: var(--c-success); }

/* Error screen ----------------------------------------------------------- */
.error-page { display: grid; place-items: center; min-height: 100vh; padding: var(--sp-6); text-align: center; }
.error-page__code { font-size: 64px; font-weight: 800; color: var(--c-text-faint); line-height: 1; }
.error-page__title { margin: var(--sp-3) 0; }
.error-page__detail {
    margin-top: var(--sp-5);
    padding: var(--sp-4);
    text-align: left;
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    overflow-x: auto;
    max-width: 900px;
}

/* --------------------------------------------------------------------------
   12. Icons (inline SVG masks - no icon font, no external requests)
   -------------------------------------------------------------------------- */
.icon {
    display: inline-block;
    width: 16px; height: 16px;
    flex: 0 0 16px;
    background-color: currentColor;
    -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
    -webkit-mask-position: center; mask-position: center;
    -webkit-mask-size: contain; mask-size: contain;
}
.icon-menu { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1 3h14v1.6H1zM1 7.2h14v1.6H1zM1 11.4h14V13H1z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1 3h14v1.6H1zM1 7.2h14v1.6H1zM1 11.4h14V13H1z'/%3E%3C/svg%3E"); }
.icon-search { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M11.7 10.3a6 6 0 1 0-1.4 1.4l3.3 3.3 1.4-1.4-3.3-3.3zM7 11a4 4 0 1 1 0-8 4 4 0 0 1 0 8z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M11.7 10.3a6 6 0 1 0-1.4 1.4l3.3 3.3 1.4-1.4-3.3-3.3zM7 11a4 4 0 1 1 0-8 4 4 0 0 1 0 8z'/%3E%3C/svg%3E"); }
.icon-theme { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a7 7 0 1 0 7 7 5.5 5.5 0 0 1-7-7z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a7 7 0 1 0 7 7 5.5 5.5 0 0 1-7-7z'/%3E%3C/svg%3E"); }
.icon-chevron-down { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L2.5 5.5 3.9 4.1 8 8.2l4.1-4.1 1.4 1.4z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L2.5 5.5 3.9 4.1 8 8.2l4.1-4.1 1.4 1.4z'/%3E%3C/svg%3E"); }
.icon-building { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 15V2a1 1 0 0 1 1-1h7a1 1 0 0 1 1 1v3h2a1 1 0 0 1 1 1v9zM4 3v2h2V3zm0 4v2h2V7zm0 4v2h2v-2zm4-8v2h2V3zm0 4v2h2V7zm0 4v2h2v-2zm4 0v2h1v-2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 15V2a1 1 0 0 1 1-1h7a1 1 0 0 1 1 1v3h2a1 1 0 0 1 1 1v9zM4 3v2h2V3zm0 4v2h2V7zm0 4v2h2v-2zm4-8v2h2V3zm0 4v2h2V7zm0 4v2h2v-2zm4 0v2h1v-2z'/%3E%3C/svg%3E"); }
.icon-gauge { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 2a6 6 0 0 0-5.2 9h10.4A6 6 0 0 0 8 2zm.7 7.4a1 1 0 1 1-1.4-1.4l3-2.2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 2a6 6 0 0 0-5.2 9h10.4A6 6 0 0 0 8 2zm.7 7.4a1 1 0 1 1-1.4-1.4l3-2.2z'/%3E%3C/svg%3E"); }
.icon-dot { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='3'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='3'/%3E%3C/svg%3E"); }
.icon-users { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 1.2c-2.5 0-5 1.2-5 2.9V14h10v-1.9c0-1.7-2.5-2.9-5-2.9zm6.2-1.5a2.6 2.6 0 1 0 0-5.2 2.6 2.6 0 0 0 0 5.2zM12 9.2c-.4 0-.8 0-1.2.1 1 .7 1.7 1.7 1.7 2.8V14H16v-1.9c0-1.6-2-2.9-4-2.9z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 1.2c-2.5 0-5 1.2-5 2.9V14h10v-1.9c0-1.7-2.5-2.9-5-2.9zm6.2-1.5a2.6 2.6 0 1 0 0-5.2 2.6 2.6 0 0 0 0 5.2zM12 9.2c-.4 0-.8 0-1.2.1 1 .7 1.7 1.7 1.7 2.8V14H16v-1.9c0-1.6-2-2.9-4-2.9z'/%3E%3C/svg%3E"); }
.icon-shield { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1l6 2.2v4.3c0 3.5-2.5 6.6-6 7.5-3.5-.9-6-4-6-7.5V3.2zm-.8 9.6l4-4-1.1-1.1-2.9 2.9-1.3-1.3-1.1 1.1z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1l6 2.2v4.3c0 3.5-2.5 6.6-6 7.5-3.5-.9-6-4-6-7.5V3.2zm-.8 9.6l4-4-1.1-1.1-2.9 2.9-1.3-1.3-1.1 1.1z'/%3E%3C/svg%3E"); }
.icon-history { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a7 7 0 1 0 6.7 9h-2.1A5 5 0 1 1 8 3v3l4-3.5L8 0z'/%3E%3Cpath d='M7.2 4.6v4l3.3 2 .8-1.3-2.6-1.6V4.6z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a7 7 0 1 0 6.7 9h-2.1A5 5 0 1 1 8 3v3l4-3.5L8 0z'/%3E%3Cpath d='M7.2 4.6v4l3.3 2 .8-1.3-2.6-1.6V4.6z'/%3E%3C/svg%3E"); }
.icon-tree { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M7.2 1h1.6v3.2H12v1.6H8.8v2.4H12v1.6H8.8V15H7.2v-5.2H4V8.2h3.2V5.8H4V4.2h3.2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M7.2 1h1.6v3.2H12v1.6H8.8v2.4H12v1.6H8.8V15H7.2v-5.2H4V8.2h3.2V5.8H4V4.2h3.2z'/%3E%3C/svg%3E"); }
.icon-book { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 2.5A1.5 1.5 0 0 1 3.5 1H13v12H3.5A1.5 1.5 0 0 0 2 14.5zm1.5-.5a.5.5 0 0 0-.5.5V13h9V2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 2.5A1.5 1.5 0 0 1 3.5 1H13v12H3.5A1.5 1.5 0 0 0 2 14.5zm1.5-.5a.5.5 0 0 0-.5.5V13h9V2z'/%3E%3C/svg%3E"); }
.icon-voucher { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 1h10a1 1 0 0 1 1 1v12l-2.2-1.4L9.6 14 7.4 12.6 5.2 14 3 12.6V2a1 1 0 0 1 1-1zm2 3v1.5h6V4zm0 3v1.5h6V7zm0 3v1.5h4V10z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 1h10a1 1 0 0 1 1 1v12l-2.2-1.4L9.6 14 7.4 12.6 5.2 14 3 12.6V2a1 1 0 0 1 1-1zm2 3v1.5h6V4zm0 3v1.5h6V7zm0 3v1.5h4V10z'/%3E%3C/svg%3E"); }
.icon-box { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1.5 4.2L8 1l6.5 3.2v7.6L8 15l-6.5-3.2zm1.5.9v5.7L7.2 13V7.2zm10 0L8.8 7.2V13l4.2-2.2zM8 2.7L3.8 4.8 8 6.8l4.2-2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1.5 4.2L8 1l6.5 3.2v7.6L8 15l-6.5-3.2zm1.5.9v5.7L7.2 13V7.2zm10 0L8.8 7.2V13l4.2-2.2zM8 2.7L3.8 4.8 8 6.8l4.2-2z'/%3E%3C/svg%3E"); }
.icon-bank { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1l7 3.5V6H1V4.5zm-5.5 6h2v5h-2zm4 0h2v5h-2zm4 0h2v5h-2zM1 13h14v1.5H1z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1l7 3.5V6H1V4.5zm-5.5 6h2v5h-2zm4 0h2v5h-2zm4 0h2v5h-2zM1 13h14v1.5H1z'/%3E%3C/svg%3E"); }

/* Chart of Accounts tree ------------------------------------------------- */
.groups-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
    gap: var(--sp-4);
    align-items: start;
}
@media (max-width: 960px) {
    .groups-layout { grid-template-columns: 1fr; }
}
.groups-tree-body { max-height: calc(100vh - 220px); overflow: auto; padding-top: 0; }
.group-tree, .group-tree__children {
    list-style: none;
    margin: 0;
    padding: 0;
}
.group-tree__row {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 6px 8px 6px calc(8px + (var(--depth, 0) * 16px));
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.group-tree__row:hover { background: var(--c-surface-2); }
.group-tree__row.is-selected {
    background: var(--c-accent-soft, var(--c-surface-3));
    outline: 1px solid var(--c-border-strong, var(--c-border));
}
.group-tree__toggle {
    width: 22px;
    height: 22px;
    border: 1px solid var(--c-border);
    background: var(--c-surface);
    border-radius: 4px;
    line-height: 1;
    cursor: pointer;
    color: var(--c-text);
    flex: 0 0 22px;
}
.group-tree__toggle--spacer {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 0;
    flex: 0 0 22px;
}
.group-tree__name { font-weight: 600; flex: 1 1 auto; min-width: 0; }
.group-tree__meta {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex: 0 1 auto;
    font-size: var(--fs-sm);
}
.badge--muted { opacity: 0.8; }
.badge--assets { color: var(--c-info); }
.badge--liabilities { color: var(--c-warning); }
.badge--income { color: var(--c-success); }
.badge--expenses { color: var(--c-danger); }
.detail-list {
    display: grid;
    gap: var(--sp-3);
    margin: 0;
}
.detail-list > div {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: var(--sp-3);
}
.detail-list dt { color: var(--c-text-muted); font-weight: 500; }
.detail-list dd { margin: 0; }

/* --------------------------------------------------------------------------
   12b. Register toolbars, pagination and permission matrix
   -------------------------------------------------------------------------- */
.toolbar { margin-bottom: var(--sp-3); }
.card__header.toolbar {
    margin-bottom: 0;
    width: 100%;
}

.pagination,
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--sp-3);
    padding: .65rem var(--sp-4);
    margin-top: 0;
    border-top: 1px solid var(--c-border);
    background: var(--c-surface-2);
    font-size: var(--fs-sm);
    color: var(--c-text-muted);
}
.pagination:empty,
.pagination-bar:empty { display: none; }
.pagination__status {
    display: inline-flex;
    align-items: baseline;
    gap: .35rem;
    margin-right: auto;
    font-variant-numeric: tabular-nums;
    color: var(--c-text-muted);
}
.pagination__range {
    font-weight: 600;
    color: var(--c-text);
}
.pagination__sep { color: var(--c-text-faint); }
.pagination__total {
    font-weight: 600;
    color: var(--c-text);
}
.pagination__controls {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.pagination__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 1.85rem;
    padding: 0 .55rem;
    margin: 0;
    border: 0;
    border-right: 1px solid var(--c-border);
    background: transparent;
    color: var(--c-text);
    font: inherit;
    font-size: var(--fs-md);
    line-height: 1;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.pagination__btn:last-of-type { border-right: 0; }
.pagination__btn:hover:not(:disabled) {
    background: var(--c-primary-soft);
    color: var(--c-primary);
}
.pagination__btn:focus-visible {
    outline: none;
    box-shadow: inset var(--focus-ring);
    z-index: 1;
}
.pagination__btn:disabled {
    color: var(--c-text-faint);
    cursor: default;
    opacity: .55;
}
.pagination__page {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    min-height: 1.85rem;
    padding: 0 var(--sp-3);
    border-right: 1px solid var(--c-border);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--c-text-muted);
}
.pagination__page strong {
    font-weight: 700;
    color: var(--c-primary);
}

/* Inside a card: act as the soft footer under the table */
.card > .pagination:last-child,
.card__body > .pagination:last-child {
    border-radius: 0 0 var(--radius) var(--radius);
}

/* Standalone pagers (users, audit, etc.) sit in a framed strip */
.table-wrap + .pagination,
.toolbar + .pagination {
    margin-top: var(--sp-3);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
}
.card__body > .table-wrap + .pagination,
.card__body > .pagination {
    margin-top: 0;
    border: 0;
    border-top: 1px solid var(--c-border);
    border-radius: 0 0 var(--radius) var(--radius);
}

#role-rows tr { cursor: pointer; }
#role-rows tr.is-selected { background: var(--c-primary-soft); }

.permission-matrix { display: flex; flex-direction: column; gap: var(--sp-4); }
.permission-module__title {
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--c-text-muted);
    margin-bottom: var(--sp-2);
}
.permission-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--sp-1) var(--sp-4);
}
.permission-item { display: flex; align-items: center; gap: var(--sp-2); padding: 2px 0; font-size: var(--fs-sm); }
.permission-item__code { color: var(--c-text-faint); font-family: var(--font-mono); font-size: var(--fs-xs); }
.permission-item.is-write .permission-item__code { color: var(--c-warning); }

/* Three-state control for a per-user exception: inherit, allow, deny. */
.effect-toggle { display: inline-flex; border: 1px solid var(--c-border); border-radius: var(--radius-sm); overflow: hidden; }
.effect-toggle button {
    padding: 1px var(--sp-2);
    font-size: var(--fs-xs);
    background: transparent;
    border: 0;
    border-left: 1px solid var(--c-border);
    color: var(--c-text-muted);
    cursor: pointer;
}
.effect-toggle button:first-child { border-left: 0; }
.effect-toggle button.is-active { color: #fff; background: var(--c-primary); }
.effect-toggle button.is-active[data-effect="deny"] { background: var(--c-danger); }

.session-badge { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--c-success); }
.credential-box {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3);
    font-family: var(--font-mono);
    font-size: var(--fs-md);
    background: var(--c-surface-2);
    border: 1px dashed var(--c-border-strong);
    border-radius: var(--radius);
    word-break: break-all;
}

/* --------------------------------------------------------------------------
   13. Responsive & print
   -------------------------------------------------------------------------- */
@media (min-width: 900px) {
    .user-menu__meta { display: flex; }
}

@media (max-width: 1200px) {
    .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid--sidebar { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        z-index: var(--z-dropdown);
        height: calc(100dvh - var(--topbar-height));
        max-height: calc(100vh - var(--topbar-height));
        box-shadow: var(--shadow-lg);
        display: none;
    }
    body.sidebar-open .sidebar { display: flex; }
    body.sidebar-collapsed .sidebar { display: none; }
    .grid--2, .grid--3 { grid-template-columns: minmax(0, 1fr); }
    .col-2, .col-3, .col-4, .col-6, .col-8, .col-9 { grid-column: span 12; }
    .app-main { padding: var(--sp-4); }
}

@media (max-width: 640px) {
    .topbar__logo-text, .search-trigger__label, .search-trigger kbd { display: none; }
    .company-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Voucher entry (Module 6) */
.voucher-entry { display: flex; flex-direction: column; gap: var(--sp-4); }
.voucher-grid {
    table-layout: fixed;
}
.voucher-grid th,
.voucher-grid td {
    padding: 4px var(--sp-2);
}
.voucher-grid .col-num,
.voucher-grid th.col-num,
.voucher-grid td.col-num {
    width: 8rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
}
.voucher-grid .col-gst,
.voucher-grid th.col-gst,
.voucher-grid td.col-gst {
    width: 6rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
}
.voucher-grid td.col-gst--sign {
    width: 2.5rem;
    text-align: center;
    color: var(--c-muted, #6b7280);
    font-weight: 600;
    user-select: none;
}
.voucher-grid .col-idx { width: 3.25rem; text-align: center; }
.voucher-grid .col-side { width: 5.5rem; text-align: center; }
.voucher-grid .col-action { width: 3rem; text-align: center; }
.voucher-grid .col-cc { width: 10rem; }
.voucher-grid .col-side .input--bare,
.voucher-grid select.input--bare {
    text-align: center;
    font-weight: 700;
    cursor: pointer;
}
.voucher-grid .input--bare {
    width: 100%;
    border: 0;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    padding: .35rem .25rem;
    font: inherit;
}
.voucher-grid .input--bare.text-right,
.voucher-grid .col-num .input--bare,
.voucher-grid .col-gst .input--bare {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
}
.voucher-grid tbody tr:focus-within { background: var(--c-surface-2); }
.voucher-grid tfoot td {
    white-space: nowrap;
    overflow: visible;
}
.voucher-totals-label {
    text-align: right;
    vertical-align: middle;
}
.voucher-totals-label strong {
    margin-right: var(--sp-2);
}
.voucher-balance-status {
    display: inline-block;
    min-width: 5.5rem;
    padding: .15rem .55rem;
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
}
.voucher-balance-status.is-balanced {
    color: var(--c-success);
    background: var(--c-success-soft);
}
.voucher-balance-status.is-diff {
    color: var(--c-warning);
    background: var(--c-warning-soft);
}
.voucher-entry__actions { padding: var(--sp-3); }
.text-success { color: var(--c-success, #1b7a3d); }

/* Party autocomplete on voucher header */
.party-autocomplete {
    position: relative;
}
.party-suggest {
    position: absolute;
    z-index: var(--z-dropdown, 300);
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    max-height: 14rem;
    overflow: auto;
    background: var(--c-surface);
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}
.party-suggest[hidden] { display: none !important; }
.party-suggest__item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: .5rem .7rem;
    cursor: pointer;
    border-bottom: 1px solid var(--c-border);
}
.party-suggest__item:last-child { border-bottom: 0; }
.party-suggest__item:hover,
.party-suggest__item.is-active {
    background: var(--c-primary-soft);
}
.party-suggest__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-3);
}
.party-suggest__balance {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--fs-sm);
    font-weight: 700;
    white-space: nowrap;
}
.party-suggest__balance.is-dr { color: var(--c-debit); }
.party-suggest__balance.is-cr { color: var(--c-credit); }
.party-suggest__balance.is-nil { color: var(--c-text-faint); font-weight: 600; }
.party-suggest__meta {
    font-size: var(--fs-xs);
    color: var(--c-text-muted);
}
.party-suggest__empty {
    padding: .65rem .7rem;
    color: var(--c-text-muted);
    font-size: var(--fs-sm);
}
.party-balance-chip {
    margin-left: auto;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--fs-xs);
    font-weight: 700;
}
.party-balance-chip.is-dr { color: var(--c-debit); }
.party-balance-chip.is-cr { color: var(--c-credit); }
.party-balance-chip.is-nil { color: var(--c-text-faint); }
#party-field .field__label {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
}

/* Particulars ledger autocomplete — fixed so table overflow does not clip it */
.ledger-inline-suggest {
    position: fixed;
    top: 0;
    left: 0;
    right: auto;
    width: 20rem;
    max-width: calc(100vw - 1rem);
    z-index: var(--z-dropdown, 300);
}
.ledger-cell {
    position: relative;
    min-width: 12rem;
}

.ledger-picker {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 40);
    background: rgba(15, 23, 32, .35);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
}
.ledger-picker[hidden] { display: none !important; }
.ledger-picker__panel {
    width: min(36rem, calc(100vw - 2rem));
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md, .5rem);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-3);
}
.ledger-picker__list {
    list-style: none;
    margin: .75rem 0 0;
    padding: 0;
    max-height: 16rem;
    overflow: auto;
}
.ledger-picker__list li {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .55rem .65rem;
    border-radius: var(--radius-sm, .35rem);
    cursor: pointer;
}
.ledger-picker__list li.is-active,
.ledger-picker__list li:hover {
    background: var(--c-surface-2);
}
.ledger-picker__hint { margin: .5rem 0 0; font-size: .85rem; }

/* —— Tally-style ledger / report print —— */
.print-toolbar {
    display: flex;
    gap: var(--sp-2);
    justify-content: flex-end;
    margin-bottom: var(--sp-4);
}
.tally-print {
    max-width: 210mm;
    margin: 0 auto;
    padding: 12mm 14mm;
    background: #fff;
    color: #000;
    font-family: "Times New Roman", Times, "Liberation Serif", serif;
    font-size: 11pt;
    line-height: 1.35;
}
.tally-print__company {
    text-align: center;
    margin-bottom: .75rem;
}
.tally-print__company-name {
    margin: 0;
    font-size: 16pt;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
}
.tally-print__company-meta {
    margin: .25rem 0 0;
    font-size: 9pt;
    color: #222;
}
.tally-print__title-block {
    text-align: center;
    margin: .85rem 0 1rem;
}
.tally-print__report-title {
    margin: 0;
    font-size: 12pt;
    font-weight: 700;
    text-decoration: underline;
}
.tally-print__ledger-name {
    margin: .35rem 0 0;
    font-size: 13pt;
    font-weight: 700;
}
.tally-print__period {
    margin: .2rem 0 0;
    font-size: 10pt;
}
.tally-print__table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.tally-print__table thead th {
    border-top: 2px solid #000;
    border-bottom: 2px solid #000;
    padding: .35rem .3rem;
    font-size: 10pt;
    font-weight: 700;
    text-align: left;
    background: transparent;
    color: #000;
}
.tally-print__table tbody td,
.tally-print__table tfoot td {
    padding: .28rem .3rem;
    vertical-align: top;
    border: 0;
    font-size: 10pt;
}
.tally-print__table .col-date { width: 12%; white-space: nowrap; }
.tally-print__table .col-particulars { width: 34%; }
.tally-print__table .col-type { width: 14%; }
.tally-print__table .col-vch { width: 12%; }
.tally-print__table .col-amt {
    width: 14%;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.tally-print__table thead th.col-amt { text-align: right; }
.tally-row--opening td { padding-top: .45rem; }
.tally-row--subtotal td,
.tally-row--closing td,
.tally-row--grand td {
    padding-top: .35rem;
    padding-bottom: .35rem;
}
/* Tally: rules only under Debit / Credit columns */
.tally-print__table .tally-line-top {
    border-top: 1px solid #000;
    padding-top: .4rem;
}
.tally-print__table .tally-line-box {
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
    padding-top: .4rem;
    padding-bottom: .4rem;
}
.tally-row--closing td {
    padding-top: .2rem;
    padding-bottom: .45rem;
}
.tally-print__footer {
    margin-top: 1rem;
    font-size: 8pt;
    color: #444;
    text-align: right;
}

@media print {
    .topbar,
    .sidebar,
    .page-header,
    .page-header__actions,
    .toast-stack,
    .print-toolbar,
    .no-print,
    .btn,
    .command-palette,
    .sidebar__version,
    .sidebar__version-no { display: none !important; }

    body,
    body[data-page="reports-print"] {
        background: #fff !important;
        color: #000 !important;
    }
    .app-shell,
    .app-main,
    .app-content,
    main {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: none !important;
        background: #fff !important;
        box-shadow: none !important;
    }
    .card {
        border: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
    }
    .tally-print {
        max-width: none;
        padding: 0;
        margin: 0;
    }
    .tally-print__table thead { display: table-header-group; }
    .tally-print__table tfoot { display: table-footer-group; }
    .tally-row { break-inside: avoid; }

    @page {
        size: A4 portrait;
        margin: 12mm 12mm 14mm;
    }
}

/* Ledger period summary rows */
.ledger-period-row { cursor: pointer; }
.ledger-period-row:hover,
.ledger-period-row:focus {
    background: #ffe566;
}

/* —— Tally-style method register (months → vouchers) —— */
.register-tally__meta {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-4);
    align-items: flex-start;
}
.register-tally__totals {
    min-width: 14rem;
    border: 1px solid var(--c-border-strong);
    padding: var(--sp-2) var(--sp-3);
    text-align: right;
}
.register-tally__totals-label {
    font-weight: 700;
    margin-bottom: .35rem;
}
.register-tally__totals-cols,
.register-tally__totals-vals {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-3);
    font-size: var(--fs-sm);
}
.register-tally__totals-cols {
    color: var(--c-text-muted);
    border-bottom: 1px solid var(--c-border);
    padding-bottom: .25rem;
    margin-bottom: .25rem;
}
.register-tally__months th:first-child {
    letter-spacing: .12em;
}
.register-tally__month-row {
    cursor: pointer;
}
.register-tally__month-row.is-active,
.register-tally__month-row:hover {
    background: #ffe566;
}
.register-tally__month-row.is-active td {
    font-weight: 600;
}
.register-tally__list-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--sp-3);
}
.register-tally__list-title {
    margin: 0;
    font-size: var(--fs-md);
    font-weight: 700;
}
.register-tally__voucher-row {
    cursor: pointer;
}
.register-tally__voucher-row:hover,
.register-tally__voucher-row:focus {
    background: var(--c-primary);
    color: #fff;
}
.register-tally__voucher-row:hover td,
.register-tally__voucher-row:focus td {
    color: inherit;
}
@media (max-width: 720px) {
    .register-tally__meta { flex-direction: column; }
    .register-tally__totals { width: 100%; }
}

/* —— Balance Sheet (Tally horizontal / T-format) —— */
.card--flush { padding: 0; overflow: hidden; }
.card--flush > .card__body,
.card--flush > #report-sheet { margin: 0; }
.field--check {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    margin: 0;
    font-size: var(--fs-sm);
    color: var(--c-text);
    cursor: pointer;
    user-select: none;
}
.field--check input { margin: 0; }

.bs-tally {
    --bs-ink: #111111;
    --bs-muted: #555555;
    --bs-line: #222222;
    --bs-select: #f0f0f0;
    --bs-amt: 7.5rem;
    color: var(--bs-ink);
    background: #ffffff;
    border: 1px solid var(--bs-line);
    font-family: "Segoe UI", "Trebuchet MS", "Verdana", sans-serif;
    font-size: 13px;
    line-height: 1.35;
}
.bs-tally__bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .75rem;
    padding: .45rem .85rem;
    background: #ffffff;
    color: var(--bs-ink);
    font-weight: 700;
    border-bottom: 2px solid var(--bs-line);
}
.bs-tally__bar-title { justify-self: start; }
.bs-tally__bar-company { justify-self: center; letter-spacing: .02em; }
.bs-tally__bar-hint {
    justify-self: end;
    font-size: 11px;
    font-weight: 500;
    color: var(--bs-muted);
}
.bs-tally__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 28rem;
    background: #ffffff;
}
.bs-tally__col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #ffffff;
}
.bs-tally__col + .bs-tally__col {
    border-left: 1px solid #111;
}
.bs-tally__col-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .75rem;
    padding: .4rem .75rem .35rem;
    border-bottom: 2px solid var(--bs-line);
    background: #ffffff;
}
.bs-tally__side {
    font-weight: 800;
    font-size: 14px;
}
.bs-tally__as-on {
    color: var(--bs-muted);
    font-size: 12px;
    text-align: right;
}
.bs-tally__body {
    flex: 1;
    padding: .35rem 0 .75rem;
    background: #ffffff;
}
.bs-tally__empty {
    padding: 1rem .75rem;
    color: var(--bs-muted);
    font-style: italic;
}
.bs-tally__group { margin: 0; }
.bs-tally__group.is-selected > .bs-tally__row--primary {
    background: var(--bs-select);
}
.bs-tally__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .5rem;
    width: 100%;
    margin: 0;
    padding: .18rem .75rem;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: default;
}
button.bs-tally__row {
    cursor: pointer;
}
button.bs-tally__row:hover {
    background: #f7f7f7;
}
button.bs-tally__row:focus-visible {
    outline: 2px solid var(--bs-line);
    outline-offset: -2px;
}
.bs-tally__row--primary .bs-tally__name {
    font-weight: 700;
}
.bs-tally__row--child .bs-tally__name {
    padding-left: 1.1rem;
    font-style: italic;
    font-weight: 500;
}
.bs-tally__row--leaf .bs-tally__name {
    padding-left: 2.1rem;
    font-style: italic;
    font-weight: 400;
    color: #222;
}
.bs-tally__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bs-tally__amts {
    display: grid;
    grid-template-columns: var(--bs-amt) var(--bs-amt);
    gap: .35rem;
    flex: 0 0 calc(var(--bs-amt) * 2 + .35rem);
}
.bs-tally__amt {
    display: block;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.bs-tally__amt--inner { color: #111; }
.bs-tally__amt--outer { font-weight: 600; }
.bs-tally__amt--rule {
    border-bottom: 1px solid #111;
    padding-bottom: 1px;
}
.bs-tally__total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    margin-top: auto;
    padding: .45rem .75rem;
    border-top: 2px solid var(--bs-line);
    border-bottom: 2px solid var(--bs-line);
    background: #ffffff;
    font-weight: 800;
}
.bs-tally__total .bs-tally__amt--outer {
    min-width: var(--bs-amt);
    border-top: 1px solid #111;
    border-bottom: 3px double #111;
    padding: .1rem 0;
}

@media (max-width: 900px) {
    .bs-tally__grid { grid-template-columns: 1fr; }
    .bs-tally__col + .bs-tally__col {
        border-left: 0;
        border-top: 1px solid #111;
    }
    .bs-tally__bar {
        grid-template-columns: 1fr;
        text-align: center;
    }
    .bs-tally__bar-title,
    .bs-tally__bar-company,
    .bs-tally__bar-hint { justify-self: center; }
}

/* —— Profit & Loss A/c (Tally T-format, white) —— */
.pl-tally {
    --pl-ink: #111;
    --pl-muted: #555;
    --pl-line: #222;
    --pl-bar: #9dc3e6;
    --pl-select: #f0c36d;
    --pl-amt: 7.5rem;
    color: var(--pl-ink);
    background: #fff;
    border: 1px solid var(--pl-line);
    font-family: "Segoe UI", "Trebuchet MS", "Verdana", sans-serif;
    font-size: 13px;
    line-height: 1.35;
}
.pl-tally__bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .75rem;
    padding: .4rem .85rem;
    background: var(--pl-bar);
    color: var(--pl-ink);
    font-weight: 700;
    border-bottom: 1px solid var(--pl-line);
}
.pl-tally__bar-title { justify-self: start; }
.pl-tally__bar-company { justify-self: center; }
.pl-tally__bar-hint {
    justify-self: end;
    font-size: 11px;
    font-weight: 500;
    color: var(--pl-muted);
}
.pl-tally__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 22rem;
    background: #fff;
}
.pl-tally__col {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.pl-tally__col + .pl-tally__col { border-left: 1px solid #111; }
.pl-tally__col-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .75rem;
    padding: .45rem .75rem .35rem;
    border-bottom: 1px solid var(--pl-line);
    background: #fff;
}
.pl-tally__particulars { font-weight: 700; }
.pl-tally__period {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
    font-size: 12px;
    line-height: 1.3;
}
.pl-tally__body { flex: 1; padding: .25rem 0 .5rem; }
.pl-tally__empty {
    padding: 1rem .75rem;
    color: var(--pl-muted);
    font-style: italic;
}
.pl-tally__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .5rem;
    width: 100%;
    margin: 0;
    padding: .2rem .75rem;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: default;
}
button.pl-tally__row { cursor: pointer; }
button.pl-tally__row:hover { background: #f7f7f7; }
.pl-tally__row.is-selected,
.pl-tally__row--group.is-selected { background: var(--pl-select); }
.pl-tally__row--group .pl-tally__name { font-weight: 700; }
.pl-tally__row--ledger .pl-tally__name { font-style: italic; }
.pl-tally__row--nett .pl-tally__name {
    font-weight: 700;
    font-style: italic;
    text-decoration: underline;
}
.pl-tally__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pl-tally__amts {
    display: grid;
    grid-template-columns: var(--pl-amt) var(--pl-amt);
    gap: .35rem;
    flex: 0 0 calc(var(--pl-amt) * 2 + .35rem);
}
.pl-tally__amt {
    display: block;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.pl-tally__amt--outer { font-weight: 600; }
.pl-tally__row--subtotal .pl-tally__amt--outer,
.pl-tally__row--group .pl-tally__amt--outer { font-weight: 700; }
.pl-tally__total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    margin-top: auto;
    padding: .4rem .75rem;
    border-top: 1px solid var(--pl-line);
    background: #fff;
    font-weight: 800;
}

@media (max-width: 900px) {
    .pl-tally__grid { grid-template-columns: 1fr; }
    .pl-tally__col + .pl-tally__col {
        border-left: 0;
        border-top: 1px solid #111;
    }
    .pl-tally__bar {
        grid-template-columns: 1fr;
        text-align: center;
    }
    .pl-tally__bar-title,
    .pl-tally__bar-company,
    .pl-tally__bar-hint { justify-self: center; }
}
