:root {
  --navy: #1b2a47;
  --navy-2: #243659;
  --gold: #c9a13b;
  --gold-soft: #f6efdc;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6ec;
  --text: #1a1f2b;
  --muted: #667085;
  --good: #137a3f;
  --good-bg: #e6f4ec;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --info-bg: #e8f0fb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --radius: 10px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: var(--navy); color: #cfd6e4; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand .logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; line-height: 1.15; }
.brand .star { color: var(--gold); font-size: 26px; }
.brand small { display: block; color: #8d9ab3; font-weight: 500; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; margin-top: 2px; }
.nav { padding: 10px 8px; flex: 1; }
.nav .section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: #7b88a3; padding: 14px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #cfd6e4; padding: 8px 12px; border-radius: 7px; font-weight: 500; }
.nav a:hover { background: var(--navy-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--gold); color: var(--navy); }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.main { flex: 1; min-width: 0; padding: 24px 32px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 18px 0; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .note { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi.accent { border-top: 3px solid var(--gold); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
tbody tr:hover { background: #fafbff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 700; border-top: 2px solid var(--text); background: #fafbfc; }
tr.subtotal td { font-weight: 600; background: #fcfcfd; }
tr.group td { font-weight: 700; background: var(--gold-soft); color: var(--navy); }
td.indent { padding-left: 28px; }
.table-wrap { overflow-x: auto; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.lines-sub td { font-size: 12.5px; color: var(--muted); padding-top: 4px; padding-bottom: 4px; border-bottom: none; }
.lines-sub:last-child td { border-bottom: 1px solid var(--border); }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; text-transform: capitalize; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: #1d4f91; }
.badge.muted { background: #eef0f3; color: var(--muted); }
.neg { color: var(--bad); }
.pos { color: var(--good); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Buttons & forms */
button, .btn { font: inherit; font-weight: 600; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { background: #f2f4f7; text-decoration: none; }
button.primary, .btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
button.primary:hover { background: var(--navy-2); }
button.gold { background: var(--gold); border-color: var(--gold); color: var(--navy); }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-bg); }
button.link { border: none; background: none; padding: 2px 6px; color: var(--series-1); font-weight: 500; }
button.link.danger { color: var(--bad); }
button.sm { padding: 4px 10px; font-size: 12.5px; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 7px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(42,120,214,.25); border-color: var(--series-1); }
textarea { min-height: 64px; resize: vertical; }
label { display: block; font-size: 12.5px; font-weight: 600; color: #344054; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 150px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { border: none; background: none; border-radius: 0; padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--navy); border-bottom-color: var(--gold); }
.calc { background: var(--gold-soft); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; font-variant-numeric: tabular-nums; }
.calc div { display: flex; justify-content: space-between; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.error-box { background: var(--bad-bg); color: var(--bad); padding: 10px 12px; border-radius: 7px; margin-bottom: 12px; display: none; }
.error-box.show { display: block; }
.line-table td { padding: 4px; border: none; }
.line-table th { background: none; padding: 4px; }

/* Toast */
#toast { position: fixed; bottom: 24px; right: 24px; background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); opacity: 0; transform: translateY(10px); transition: all .2s; z-index: 100; pointer-events: none; max-width: 420px; }
#toast.show { opacity: 1; transform: none; }
#toast.error { background: var(--bad); }

/* Chart */
.chart-wrap { position: relative; }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.chart-legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--c); vertical-align: -1px; }
.chart-tip { position: absolute; background: #fff; border: 1px solid var(--border); box-shadow: 0 6px 16px rgba(0,0,0,.12); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; pointer-events: none; display: none; white-space: nowrap; z-index: 5; }
.chart-tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
svg text { font-family: inherit; }

/* Printable documents */
.doc { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 40px; max-width: 860px; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.doc-head .co { font-weight: 700; font-size: 18px; color: var(--navy); }
.doc-head .co .star { color: var(--gold); }
.doc-title { font-size: 26px; font-weight: 800; color: var(--navy); letter-spacing: .02em; text-align: right; }
.check { display: inline-flex; gap: 6px; align-items: center; }

@media print {
  .sidebar, .no-print, .page-head .actions, #toast { display: none !important; }
  .main { padding: 0; }
  .card, .doc { border: none; padding: 0; }
  body { background: #fff; }
}
/* Narrower windows keep the full vertical menu (all sections and options), just slimmer */
.menu-toggle { display: none; }
@media (max-width: 1000px) {
  .sidebar { width: 200px; }
  .main { padding: 20px; }
  .grid.two { grid-template-columns: 1fr; }
}
/* Phones: the same full menu opens from a ☰ Menu button */
@media (max-width: 640px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .menu-toggle { display: inline-flex; margin-top: 12px; width: 100%; justify-content: center; background: var(--navy-2); color: #fff; border-color: rgba(255,255,255,.15); }
  body:not(.menu-open) .nav { display: none; }
  .main { padding: 16px; }
}

/* ---- Banking ---- */
.nav-count { margin-left: auto; background: var(--gold); color: var(--navy); border-radius: 99px; font-size: 11px; font-weight: 700; padding: 0 7px; line-height: 18px; }
.nav-count:empty { display: none; }
.nav a.active .nav-count { background: var(--navy); color: #fff; }
.bank-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 18px; }
.bank-card { display: block; text-align: left; white-space: normal; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); font-weight: 400; }
.bank-card.active { border: 2px solid var(--gold); padding: 13px 15px; background: #fffdf6; }
.bank-card .bank-name { font-weight: 700; font-size: 15px; margin: 2px 0 8px; }
.bank-card .bank-bal { font-size: 20px; font-weight: 700; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.review-bar { display: flex; gap: 8px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.review-bar .check { margin: 0; }
table.review td { vertical-align: middle; }
table.review select, table.review input:not([type=checkbox]) { padding: 5px 8px; font-size: 13px; min-width: 150px; }
table.review td.desc { max-width: 280px; }
.desc-btn { text-align: left; white-space: normal; font-weight: 600; color: var(--text); padding: 0; }
tr.detail td { background: #fafbfc; }
.match-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 10px; background: var(--good-bg); border-radius: 7px; margin-bottom: 6px; }

/* ---- Printable check (check-on-top, 3 parts) ---- */
.check-sheet { background: #fff; width: 8.5in; max-width: 100%; border: 1px solid var(--border); border-radius: 6px; position: relative; }
.check-face { height: 3.5in; padding: 0.3in 0.4in; position: relative; border-bottom: 1px dashed #bbb; font-family: "Segoe UI", Arial, sans-serif; }
.cf-top { display: flex; justify-content: space-between; }
.cf-no { font-size: 16px; font-weight: 700; }
.cf-date { position: absolute; right: 0.4in; top: 0.7in; }
.cf-pay { display: flex; align-items: flex-end; gap: 12px; margin-top: 0.62in; border-bottom: 1px solid #333; padding-bottom: 4px; }
.cf-payee { flex: 1; font-size: 15px; font-weight: 600; }
.cf-amt { border: 1px solid #333; padding: 4px 10px; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.cf-words { margin-top: 12px; border-bottom: 1px solid #333; padding-bottom: 4px; white-space: nowrap; overflow: hidden; }
.cf-addr { margin-top: 10px; min-height: 0.5in; font-size: 13px; }
.cf-bottom { position: absolute; left: 0.4in; right: 0.4in; bottom: 0.35in; display: flex; justify-content: space-between; align-items: flex-end; }
.cf-sign { border-top: 1px solid #333; width: 2.8in; text-align: center; font-size: 10px; padding-top: 2px; }
.lbl { font-size: 9px; color: #555; letter-spacing: .05em; }
.check-stub { height: 3.5in; padding: 0.3in 0.4in; border-bottom: 1px dashed #bbb; font-size: 12.5px; overflow: hidden; }
.check-stub:last-child { border-bottom: none; }
.check-stub table th, .check-stub table td { padding: 4px 6px; }
.stub-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.void-mark { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 110px; font-weight: 800; color: rgba(180,35,24,.25); transform: rotate(-12deg); pointer-events: none; }
@media print {
  .check-sheet { border: none; border-radius: 0; width: 8.5in; }
  .check-face, .check-stub { border-bottom: none; }
}

.hint { display: block; font-size: 11.5px; padding: 3px 0 0; white-space: normal; text-align: left; }

/* ---- Multi-company ---- */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content .main { flex: 1; }
.book-switch { margin-top: 14px; }
.book-switch label { color: #8d9ab3; font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; margin-bottom: 4px; }
.book-switch select { background: var(--navy-2); color: #fff; border-color: rgba(255,255,255,.15); font-weight: 600; }
.book-switch select optgroup, .book-switch select option { color: var(--text); background: #fff; }
.book-banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; background: #e8f0fb; border-bottom: 2px solid var(--series-1); padding: 10px 32px; color: #1d4f91; }
body.book-client .sidebar { background: #1d3a5f; }
body:not(.book-client) .book-banner { display: none; }
body.book-client .main-only, body.book-nonfirm .firm-only { display: none !important; }
@media print { #bookBanner { display: none; } }
@media (max-width: 860px) { .book-banner { padding: 10px 16px; } }

.book-banner.personal { background: #e6f4ec; border-bottom-color: var(--good); color: var(--good); }
body[data-book-kind="personal"] .sidebar { background: #1f4536; }
body.book-personal .biz-only { display: none !important; }
.bank-card { cursor: pointer; }

body.no-projects .proj-only { display: none !important; }

body:not(.book-personal) .personal-only { display: none !important; }
table.review select.f-member { min-width: 110px; }

/* ---- Sign-in & roles ---- */
body.signed-out .app { display: none; }
.auth-bg { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: linear-gradient(160deg, var(--navy) 0%, #2c3f66 100%); }
.auth-card { background: #fff; width: 100%; max-width: 400px; border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.auth-logo { font-weight: 800; font-size: 20px; color: var(--navy); margin-bottom: 18px; display: flex; align-items: baseline; gap: 8px; }
.auth-logo .star { color: var(--gold); font-size: 26px; }
.auth-logo small { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.auth-card h2 { margin-bottom: 14px; }
.user-box { padding: 14px 18px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12.5px; }
.user-box .user-name { color: #fff; font-weight: 600; }
.user-box .user-role { color: #8d9ab3; margin: 2px 0 6px; }
.user-box .link { color: var(--gold); padding: 0; font-size: 12.5px; }
body:not([data-role="admin"]) .admin-only { display: none !important; }
/* Read-only access (viewer / client): hide controls that change things — the server refuses them anyway */
body.readonly :is([data-act="new"], [data-act="edit"], [data-act="del"], [data-act="delPay"], [data-act="pay"], [data-act="close"], [data-act="reopen"],
  [data-act="upload"], [data-act="addAcct"], [data-act="editAcct"], [data-act="value"], [data-act="invoice"], [data-act="expense"], [data-act="trust"],
  [data-act="deal"], [data-act="check"], [data-act="k"], [data-act="disb"], [data-act="paid"], [data-act="reimb"], [data-act="undo"], [data-act="restore"],
  [data-act="add"], [data-act="history"], [data-act="newBooks"], [data-act="openBooks"], [data-act="toggle"], [data-add], [data-match], [data-cross], [data-split],
  [data-exclude], .review-bar, #setForm button[type=submit], #backupBtn, [data-act="delImp"]) { display: none !important; }
body.readonly :is(table.review select, table.review input, .who-edit) { pointer-events: none; opacity: .7; }
body.readonly #bookBanner::before { content: "View-only access"; display: block; background: #eef0f3; color: var(--muted); padding: 6px 32px; font-size: 12.5px; font-weight: 600; }
