/* MPG Books — one stylesheet for the whole app. Tokens first; components below. */
:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e7ee;
    --border-strong: #cfd7e2;
    --text: #1d2733;
    --muted: #677485;
    --faint: #98a3b1;
    --accent: #0e7cb8;
    --accent-ink: #ffffff;
    --accent-soft: #e6f2f9;
    --sidebar: #0f1e33;
    --sidebar-2: #16294430;
    --sidebar-text: #b9c6d6;
    --sidebar-active: #ffffff;
    --green: #178a55;
    --green-soft: #e3f4ec;
    --red: #cf3f3f;
    --red-soft: #fcebeb;
    --amber: #b86e00;
    --amber-soft: #fdf1dc;
    --blue: #1f6fd1;
    --blue-soft: #e7f0fc;
    --purple: #6b4fc8;
    --purple-soft: #efebfb;
    --grey-soft: #eef1f5;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 30, 51, .06), 0 1px 3px rgba(16, 30, 51, .05);
    --shadow-lg: 0 10px 30px rgba(16, 30, 51, .14);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
code, pre, .mono { font-family: var(--mono); font-size: .9em; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem; overflow: auto; white-space: pre; }
.icon { flex: none; vertical-align: middle; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.inline { display: inline; }
.hidden { display: none !important; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; } .mt-sm { margin-top: .5rem; } .mb-0 { margin-bottom: 0; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 1rem; }

/* ---------------------------------------------------------------- shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex: none; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.1rem; color: #fff; font-weight: 700; font-size: 1.05rem; text-decoration: none !important; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; font-size: .8rem; letter-spacing: .5px; }
.nav { padding: .25rem .6rem; flex: 1; }
.nav-link, .nav-group summary { display: flex; align-items: center; gap: .7rem; padding: .5rem .65rem; border-radius: var(--radius-sm); color: var(--sidebar-text); cursor: pointer; font-weight: 500; text-decoration: none !important; list-style: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-link:hover, .nav-group summary:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: var(--accent); color: var(--sidebar-active); }
.nav-group summary .caret { margin-left: auto; transition: transform .15s; opacity: .7; }
.nav-group[open] summary .caret { transform: rotate(180deg); }
.nav-sub { display: block; padding: .38rem .65rem .38rem 2.45rem; border-radius: var(--radius-sm); color: var(--sidebar-text); font-size: .95rem; text-decoration: none !important; }
.nav-sub:hover { color: #fff; background: rgba(255, 255, 255, .05); }
.nav-sub.active { color: #fff; background: rgba(255, 255, 255, .1); box-shadow: inset 3px 0 0 var(--accent); }
.nav-count { margin-left: auto; background: var(--amber); color: #fff; font-size: .75rem; border-radius: 10px; padding: 0 .45rem; font-weight: 600; }
.sidebar-foot { padding: .6rem; border-top: 1px solid rgba(255, 255, 255, .08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .9rem; padding: 0 1.25rem; position: sticky; top: 0; z-index: 20; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .65rem; }
.menu-toggle { display: none; }
.org-btn { display: flex; align-items: center; gap: .5rem; border: 1px solid var(--border); background: var(--surface); padding: .3rem .6rem .3rem .35rem; border-radius: var(--radius); cursor: pointer; font: inherit; font-weight: 600; color: var(--text); max-width: 280px; }
.org-btn:hover { border-color: var(--border-strong); }
.org-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-avatar { width: 26px; height: 26px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); display: inline-grid; place-items: center; font-size: .75rem; font-weight: 700; flex: none; }
.org-avatar.sm { width: 22px; height: 22px; font-size: .68rem; margin-right: .5rem; }
.search { flex: 1; max-width: 460px; display: flex; align-items: center; gap: .45rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 .65rem; color: var(--muted); }
.search input { border: 0; background: transparent; outline: 0; padding: .5rem 0; width: 100%; font: inherit; color: var(--text); }
.search:focus-within { border-color: var(--accent); background: #fff; }
.avatar { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-weight: 700; font-size: .8rem; cursor: pointer; }
.vms-pill { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; font-weight: 600; padding: .25rem .6rem; border-radius: 20px; background: var(--green-soft); color: var(--green); text-decoration: none !important; white-space: nowrap; }
.vms-pill.vms-mock { background: var(--purple-soft); color: var(--purple); }
.vms-pill.vms-alert { background: var(--amber-soft); color: var(--amber); }
.content { padding: 1.4rem 1.6rem 3rem; max-width: 1400px; width: 100%; }

/* dropdowns */
.dropdown { position: relative; }
.menu { display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 230px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: .35rem; z-index: 50; }
.menu-right { left: auto; right: 0; }
.menu-wide { min-width: 520px; }
.dropdown.open > .menu { display: block; }
.menu-item { display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left; padding: .45rem .6rem; border: 0; background: none; border-radius: var(--radius-sm); color: var(--text); font: inherit; cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.current { background: var(--accent-soft); }
.menu-item .muted { margin-left: auto; }
.menu-item.danger { color: var(--red); }
.menu-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: .45rem .6rem .25rem; font-weight: 600; }
.menu-sep { border-top: 1px solid var(--border); margin: .3rem 0; }
.menu-head { padding: .5rem .6rem .6rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .25rem; }

/* ---------------------------------------------------------------- page */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.crumbs { display: flex; align-items: center; gap: .3rem; font-size: .86rem; color: var(--muted); margin-bottom: .25rem; }
.crumbs a { color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { margin: 0; }
.card-body { padding: 1.1rem; }
.card-body.tight { padding: 0; }
.card-foot { padding: .75rem 1.1rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.layout-side { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }

/* stat tiles */
.stat { padding: 1rem 1.1rem; }
.stat-label { color: var(--muted); font-size: .85rem; font-weight: 500; }
.stat-value { font-size: 1.5rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: .82rem; margin-top: .15rem; }
.stat-value.neg { color: var(--red); }

/* ---------------------------------------------------------------- buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .85rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none !important; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--surface-2); border-color: #b9c3d0; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(.93); border-color: var(--accent); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: var(--green); filter: brightness(.93); }
.btn-danger { color: var(--red); border-color: #efc4c4; }
.btn-danger:hover { background: var(--red-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--grey-soft); }
.btn-sm { padding: .28rem .6rem; font-size: .88rem; }
.btn-lg { padding: .65rem 1.2rem; font-size: 1.05rem; }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; }
.icon-btn { border: 0; background: none; color: var(--muted); padding: .3rem; border-radius: var(--radius-sm); cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--grey-soft); color: var(--text); }
.btn-group { display: inline-flex; }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-group .btn:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }

/* ---------------------------------------------------------------- badges */
.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .12rem .5rem; border-radius: 20px; font-size: .76rem; font-weight: 600; white-space: nowrap; letter-spacing: .01em; }
.badge-grey { background: var(--grey-soft); color: #4f5b69; }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .8rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr:hover { background: #fafcfe; }
.table tr.clickable { cursor: pointer; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table td.neg { color: var(--red); }
.table tfoot td { font-weight: 700; background: var(--surface-2); }
.table .sub-row td { padding-top: 0; border-top: 0; }
.table-compact th, .table-compact td { padding: .4rem .6rem; }
.table tr.total td { font-weight: 700; border-top: 2px solid var(--border-strong); }
.table tr.group td { font-weight: 600; background: var(--surface-2); }
.table tr.indent td:first-child { padding-left: 1.8rem; }
.table a.row-link { color: var(--text); font-weight: 500; }
.table a.row-link:hover { color: var(--accent); }

/* ---------------------------------------------------------------- forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1.2rem; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .9rem 1.2rem; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .9rem 1.2rem; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.field label { display: block; font-weight: 500; font-size: .88rem; margin-bottom: .3rem; color: #394452; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.req { color: var(--red); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=url], input[type=tel], input:not([type]), select, textarea {
    width: 100%; padding: .48rem .6rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font: inherit; color: var(--text); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 124, 184, .15); }
input[readonly] { background: var(--surface-2); }
textarea { resize: vertical; }
select { padding-right: 1.6rem; }
.check { display: flex; align-items: flex-start; gap: .5rem; font-weight: 400 !important; cursor: pointer; }
.check input { margin-top: .2rem; width: auto; }
.form-actions { display: flex; gap: .6rem; align-items: center; padding-top: 1rem; margin-top: 1rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.form-actions .spacer { flex: 1; }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface); padding: .8rem 1.1rem; border-top: 1px solid var(--border); display: flex; gap: .6rem; align-items: center; z-index: 5; border-radius: 0 0 var(--radius) var(--radius); }
.input-group { display: flex; }
.input-group > * + * { margin-left: -1px; }
.input-group .addon { padding: .48rem .6rem; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); color: var(--muted); white-space: nowrap; }
.input-group > :first-child:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > :last-child:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .35rem; }

/* line item editor */
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; text-align: left; padding: .5rem .45rem; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.lines td { padding: .4rem .35rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.lines .num { text-align: right; }
.lines input, .lines select { padding: .38rem .45rem; }
.lines .col-item { min-width: 220px; }
.lines .col-qty { width: 80px; }
.lines .col-rate { width: 115px; }
.lines .col-disc { width: 70px; }
.lines .col-tax { width: 150px; }
.lines .col-acc { width: 190px; }
.lines .col-amt { width: 115px; text-align: right; font-variant-numeric: tabular-nums; padding-top: .7rem; font-weight: 500; }
.lines .col-del { width: 34px; }
.lines textarea { margin-top: .3rem; font-size: .9rem; min-height: 34px; }
.line-stock { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.totals { width: 100%; max-width: 380px; margin-left: auto; border-collapse: collapse; }
.totals td { padding: .35rem .4rem; }
.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals tr.grand td { font-weight: 700; font-size: 1.12rem; border-top: 2px solid var(--border-strong); padding-top: .6rem; }
.totals input { max-width: 120px; text-align: right; }

/* ---------------------------------------------------------------- misc components */
.flash { display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash-success { background: var(--green-soft); border-color: #bfe4d0; color: #0f6b40; }
.flash-error { background: var(--red-soft); border-color: #f1c6c6; color: #a52a2a; }
.flash-info { background: var(--blue-soft); border-color: #c7dbf6; color: #1b5bab; }
.flash-warning { background: var(--amber-soft); border-color: #f2d7a6; color: #8a5300; }
.flash-close { margin-left: auto; border: 0; background: none; font-size: 1.2rem; cursor: pointer; color: inherit; opacity: .6; }
.notice { padding: .75rem .9rem; border-radius: var(--radius); background: var(--blue-soft); color: #1b5bab; border: 1px solid #c7dbf6; }
.notice-warn { background: var(--amber-soft); color: #8a5300; border-color: #f2d7a6; }
.notice-danger { background: var(--red-soft); color: #a52a2a; border-color: #f1c6c6; }
.notice-ok { background: var(--green-soft); color: #0f6b40; border-color: #bfe4d0; }
.tabs { display: flex; gap: .15rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: .55rem .85rem; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none !important; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.filterbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.filterbar select, .filterbar input { width: auto; }
.filterbar input[type=search] { min-width: 240px; }
.pager { display: flex; gap: .75rem; align-items: center; justify-content: flex-end; padding: .75rem 1rem; color: var(--muted); font-size: .9rem; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .icon { color: var(--faint); margin-bottom: .6rem; }
.empty h3 { color: var(--text); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: .4rem .8rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .5rem 0 .5rem 1rem; border-left: 2px solid var(--border); position: relative; font-size: .9rem; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: .85rem; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.dl-list { display: flex; flex-direction: column; gap: .35rem; }
.chart-box { height: 240px; }
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding: 0 .25rem; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-chart .bars { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar-chart .bar { width: 42%; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar-chart .bar.in { background: var(--accent); }
.bar-chart .bar.out { background: #f0a24a; }
.bar-chart .lbl { font-size: .72rem; color: var(--muted); }
.legend { display: flex; gap: 1rem; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }

/* document view ("paper") */
.paper { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2.2rem 2.4rem; position: relative; overflow: hidden; }
.paper-head { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 1.6rem; }
.paper-logo { max-height: 64px; max-width: 220px; }
.paper-title { text-align: right; }
.paper-title h2 { font-size: 1.6rem; letter-spacing: .04em; text-transform: uppercase; margin-bottom: .2rem; }
.paper .meta { display: grid; grid-template-columns: auto auto; gap: .15rem 1rem; justify-content: end; font-size: .92rem; }
.paper .meta dt { color: var(--muted); text-align: right; }
.paper .meta dd { margin: 0; text-align: right; }
.paper .bill-to { margin-bottom: 1.4rem; }
.paper table.items { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.paper table.items th { background: #243447; color: #fff; font-weight: 600; font-size: .82rem; padding: .5rem .6rem; text-align: left; }
.paper table.items td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.paper table.items .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.paper .ribbon { position: absolute; top: 22px; left: -46px; transform: rotate(-45deg); width: 180px; text-align: center; padding: .3rem 0; color: #fff; font-weight: 700; font-size: .8rem; letter-spacing: .08em; }
.ribbon-draft { background: #8793a3; } .ribbon-paid { background: var(--green); } .ribbon-void { background: var(--red); } .ribbon-overdue { background: var(--amber); } .ribbon-open { background: var(--blue); }
.fiscal-box { display: flex; gap: 1.2rem; align-items: flex-start; border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 1rem; margin-top: 1.2rem; background: var(--surface-2); }
.fiscal-box .qr svg { width: 132px; height: 132px; display: block; }
.fiscal-box .kv { grid-template-columns: 150px 1fr; font-size: .88rem; }
.fiscal-box h4 { margin-bottom: .5rem; }
.not-fiscal { font-size: 1.3rem; font-weight: 800; text-align: center; border: 2px solid var(--red); color: var(--red); padding: .4rem; margin: 1rem 0; letter-spacing: .04em; }
.journal-text { font-family: var(--mono); font-size: .8rem; line-height: 1.35; white-space: pre; background: #fff; border: 1px solid var(--border); padding: .8rem; overflow-x: auto; }

/* auth / bare pages */
body.bare { background: linear-gradient(160deg, #0f1e33 0%, #17365c 100%); min-height: 100vh; }
.bare-main { max-width: 460px; margin: 0 auto; padding: 8vh 1rem 2rem; }
.bare-main.wide { max-width: 720px; }
.auth-card { background: #fff; border-radius: 12px; padding: 2rem; box-shadow: var(--shadow-lg); }
.auth-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.2rem; margin-bottom: 1.3rem; }
.auth-card .field { margin-bottom: .9rem; }
.portal-main { max-width: 980px; margin: 0 auto; padding: 2rem 1rem; }
body.portal { background: var(--bg); }

.error-page { text-align: center; padding: 4rem 1rem; }
.error-code { font-size: 4rem; font-weight: 800; color: var(--border-strong); }

/* print */
.print-body { background: #fff; padding: 1.5rem; }
.print-toolbar { margin-bottom: 1rem; display: flex; gap: .5rem; }
@media print {
    .no-print, .sidebar, .topbar, .page-actions, .flash, .tabs, .filterbar { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; }
    .card { box-shadow: none; border: 0; }
    .paper { border: 0; box-shadow: none; padding: 0; }
}

/* responsive */
@media (max-width: 1100px) {
    .layout-side { grid-template-columns: 1fr; }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .sidebar { position: fixed; left: -260px; z-index: 60; transition: left .2s; box-shadow: var(--shadow-lg); }
    body.sidebar-open .sidebar { left: 0; }
    .menu-toggle { display: inline-grid; }
    .search { display: none; }
    .content { padding: 1rem; }
    .grid-2, .grid-3, .form-grid, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .menu-wide { min-width: 280px; }
    .quick-grid { grid-template-columns: 1fr; }
    .paper { padding: 1.2rem; }
    .paper-head { flex-direction: column; }
    .org-name { max-width: 120px; }
    .vms-pill { display: none; }
}

/* ---- reports & dashboard */
.neg-text { color: var(--red); }
.pos-text { color: var(--green); }

/* reports index */
.report-index { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.report-index .card + .card { margin-top: 0; }
.report-list { list-style: none; margin: 0; padding: .35rem 0; }
.report-list li { padding: .5rem 1.1rem; }
.report-list li + li { border-top: 1px solid var(--border); }
.report-list a { font-weight: 500; }

/* report page */
.report-filters .filterbar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .75rem; box-shadow: var(--shadow); }
.report-filter { display: inline-flex; align-items: center; gap: .35rem; font-size: .88rem; color: var(--muted); white-space: nowrap; }
.report-filter select { max-width: 260px; }
.report-head { text-align: center; padding: 1.2rem 1rem .9rem; border-bottom: 1px solid var(--border); }
.report-head h2 { font-size: 1.3rem; margin: .15rem 0 .2rem; }
.report-org { font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-size: .8rem; }
.report-body { padding: 0 0 .5rem; }
.report-alert { display: flex; align-items: center; gap: .5rem; margin: .9rem 1.1rem 0; }
.report-table-heading { margin: 1.2rem 1.1rem .5rem; }
.report-empty { padding: 2.5rem 1rem; text-align: center; }
.report-table { font-size: .92rem; }
.report-table td a { color: inherit; }
.report-table td a:hover { color: var(--accent); }
.report-table td.num a { color: var(--accent); }
.report-table tr.group td { text-transform: none; font-size: .9rem; border-top: 1px solid var(--border-strong); }
.report-table tr.subgroup td { font-weight: 600; color: #394452; padding-left: 1.4rem; }
.report-table tr.indent td:first-child { padding-left: 2rem; }
.report-table tr.subtotal td { font-weight: 600; border-top: 1px solid var(--border-strong); }
.report-table tr.total td { font-weight: 700; background: var(--surface-2); }
.report-table tr.grand td { font-weight: 700; font-size: 1.02rem; border-top: 2px solid var(--text); border-bottom: 3px double var(--text); background: var(--surface-2); }
.report-table tr.warn td { background: var(--red-soft); color: var(--red); font-weight: 700; }
.report-table tr.journal-head td { background: var(--surface-2); font-weight: 600; border-top: 1px solid var(--border-strong); }
.report-table tr.muted-row td { font-weight: 400; color: var(--muted); font-size: .85rem; }
.report-table tfoot tr + tr td { border-top: 0; }
.report-notes { padding: .8rem 1.1rem 0; color: var(--muted); font-size: .85rem; }
.report-notes p { margin-bottom: .4rem; }
.report-print .report-head { border-bottom: 2px solid var(--text); margin-bottom: .8rem; }
.report-print .report-alert { margin: .6rem 0; }
.report-print .report-table-heading { margin: 1rem 0 .4rem; }
.report-print .report-notes { padding: .8rem 0 0; }
.report-generated { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: .5rem; }
@media print {
    .report-print .table th { background: #fff; }
    .report-table { font-size: 10.5pt; }
    .report-table tr { page-break-inside: avoid; }
    .report-table thead { display: table-header-group; }
    .report-table a { color: inherit !important; text-decoration: none; }
    .print-body { padding: 0; }
}

/* dashboard */
.dash-tile { display: block; color: var(--text); text-decoration: none !important; transition: border-color .15s, box-shadow .15s; }
.dash-tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.dash-tiles .card + .card { margin-top: 0; }
.dash-split { display: flex; height: 6px; border-radius: 3px; background: var(--grey-soft); overflow: hidden; margin: .55rem 0 .35rem; }
.dash-split .cur { background: var(--accent); }
.dash-split .late { background: var(--red); }
.dash-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .3rem; }
.dash-dot.cur { background: var(--accent); }
.dash-dot.late { background: var(--red); }
.dash-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.dash-row .card + .card, .dash-grid .card + .card { margin-top: 0; }
.dash-chart { width: 100%; height: auto; display: block; }
.dash-chart .grid { stroke: var(--border); stroke-width: 1; }
.dash-chart .base { stroke: var(--border-strong); stroke-width: 1; }
.dash-chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.dash-chart .axis.faint { fill: var(--faint); font-size: 10px; }
.dash-chart .b-in { fill: var(--accent); }
.dash-chart .b-out { fill: #f0a24a; }
.dash-vms .kv { grid-template-columns: 110px 1fr; }
.dash-bars { list-style: none; margin: 0 0 .75rem; padding: 0; }
.dash-bars li + li { margin-top: .7rem; }
.dash-bars .num { font-variant-numeric: tabular-nums; }
.dash-bar { height: 6px; background: var(--grey-soft); border-radius: 3px; margin-top: .3rem; overflow: hidden; }
.dash-bar span { display: block; height: 100%; background: #f0a24a; border-radius: 3px; }
.dash-start { border-color: #c7dbf6; }
.dash-progress { height: 6px; background: var(--grey-soft); border-radius: 3px; overflow: hidden; }
.dash-progress span { display: block; height: 100%; background: var(--green); }
.dash-checklist { list-style: none; margin: 0; padding: 0; }
.dash-checklist li { display: flex; align-items: center; gap: .75rem; padding: .6rem 0; }
.dash-checklist li + li { border-top: 1px solid var(--border); }
.dash-checklist li.done a { color: var(--muted); text-decoration: line-through; }
.dash-check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); display: inline-grid; place-items: center; flex: none; color: #fff; }
.dash-checklist li.done .dash-check { background: var(--green); border-color: var(--green); }
@media (max-width: 1100px) {
    .report-index { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dash-row { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .report-index { grid-template-columns: 1fr; }
}

/* ---- banking & accountant */
.bank-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.bank-cards .card + .card { margin-top: 0; }
.bank-card { display: flex; flex-direction: column; }
.bank-card .card-body { flex: 1; }
.bank-card-off { opacity: .7; }
.bank-balance { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .15rem; }
.bank-balance.neg { color: var(--red); }
.money-in { color: var(--green); }
.stat-value.neg, .stat-value .neg { color: var(--red); }
.grid-input { width: 100%; min-width: 84px; text-align: right; padding: .32rem .45rem !important; font-variant-numeric: tabular-nums; }
.budget-grid th, .budget-grid td { padding: .3rem .3rem; }
.budget-grid .grid-input { min-width: 88px; }
.budget-grid td:first-child, .budget-grid th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 210px; box-shadow: 1px 0 0 var(--border); }
.budget-grid tr.group td:first-child { background: var(--surface-2); }
.recon-bar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.recon-diff.zero { color: var(--green); }
.recon-diff.off { color: var(--red); }
.panel-tabs { margin-bottom: 0; }
.panel[hidden] { display: none; }
details.card > summary { list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
@media (max-width: 860px) {
    .recon-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .bank-cards { grid-template-columns: 1fr; }
}

/* ---- recurring & purchases */
.recur-every { display: flex; gap: .5rem; }
.recur-every input { width: 5rem; flex: none; }
.recur-every select { flex: 1; min-width: 0; }
.recur-ends { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; }
.recur-ends .check { align-items: center; }
.recur-ends .check input { margin-top: 0; }
.recur-ends input[type=date] { flex: 1; min-width: 9.5rem; }
.recur-preview-title { font-size: .95rem; color: var(--muted); margin: 0 0 .5rem; }
.recur-upcoming { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.recur-upcoming li { padding: .35rem 0; display: flex; justify-content: space-between; align-items: center; }
.recur-upcoming li + li { border-top: 1px solid var(--border); }
.purch-progress { height: 6px; background: var(--grey-soft); border-radius: 3px; overflow: hidden; margin-top: .75rem; }
.purch-progress span { display: block; height: 100%; background: var(--green); }
.unbilled-total { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; padding-top: .2rem; }
.bulk-grid th, .bulk-grid td { padding: .3rem .3rem; vertical-align: middle; }
.bulk-grid input, .bulk-grid select { width: 100%; min-width: 0; padding: .32rem .45rem; }
.bulk-grid td:nth-child(2) { min-width: 9.5rem; }
.bulk-grid td:nth-child(3), .bulk-grid td:nth-child(4) { min-width: 11rem; }
.bulk-grid td:nth-child(5) { min-width: 9rem; }
.bulk-grid td:nth-child(6) { min-width: 12rem; }
.bulk-grid td:nth-child(8) { min-width: 6.5rem; }
.bulk-grid .bulk-ref { min-width: 5.5rem; }

/* ---- sales & portal */
.icon.flip { transform: scaleX(-1); }
.copy-field { font-family: var(--mono); font-size: .8rem; }
.email-attach { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .7rem .8rem; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.email-file { display: inline-flex; align-items: center; gap: .35rem; font-weight: 500; }
.placeholder-list { grid-template-columns: 110px 1fr; }
.placeholder-list dt { color: var(--text); }
details.tpl-card > summary { cursor: pointer; }
details.tpl-card > summary .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
details.tpl-card:not([open]) > summary { border-bottom: 0; }
.statement-table td.neg, .ageing-table td.neg { color: var(--red); }
.center-text { text-align: center; }
.statement-print .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
body.portal { min-height: 100vh; display: flex; flex-direction: column; }
.portal-top { background: var(--surface); border-bottom: 1px solid var(--border); border-top: 4px solid var(--accent); }
.portal-top-inner { max-width: 980px; margin: 0 auto; padding: 1rem 1rem .6rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.portal-brand { display: flex; align-items: center; gap: .8rem; color: var(--text); text-decoration: none !important; }
.portal-brand img { max-height: 48px; max-width: 180px; }
.portal-who { text-align: right; }
.portal-nav { max-width: 980px; margin: 0 auto; padding: 0 1rem; border-bottom: 0; margin-bottom: 0; }
.portal-main { flex: 1; width: 100%; }
.portal-main h1 { margin-bottom: .75rem; }
.portal-foot { max-width: 980px; margin: 0 auto; padding: 1rem 1rem 2rem; text-align: center; }
.portal-respond { border-left: 4px solid var(--accent); }
@media (max-width: 860px) {
    .portal-who { text-align: left; }
    .statement .grid-4, .portal-main .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media print {
    .portal-top, .portal-foot { display: none; }
}
