:root {
  --paper: #f6f8f4;
  --panel: #ffffff;
  --ink: #1b2b27;
  --muted: #5d6d67;
  --rule: #d5ddd7;
  --leaf: #2f6b4f;
  --leaf-dark: #23513c;
  --leaf-wash: #e6f0ea;
  --grape: #5b3561;
  --grape-wash: #f1e9f2;
  --debt: #a1392b;
  --debt-wash: #f8e8e5;
  --amber: #8a5a00;
  --amber-wash: #fbf1dc;
  --radius-sm: 4px;
  --radius: 8px;
  font-family: 'Public Sans', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 0.75rem; }
a { color: var(--leaf); }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.neg { color: var(--debt); }

/* Shell ------------------------------------------------------------------ */

.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.shell > * { min-width: 0; }
.rail { background: var(--ink); color: #dfe8e3; padding: 1.5rem 1rem; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 0.25rem; }
.brand svg { flex: none; }
.brand strong { font-size: 1.05rem; color: #fff; }
.env { font-size: 0.8rem; color: #a9bcb3; margin: 0 0 1.75rem 2.4rem; }
.rail nav { display: flex; flex-direction: column; gap: 2px; }
.rail a {
  color: #dfe8e3; text-decoration: none; padding: 0.5rem 0.75rem; border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
}
.rail a:hover { background: rgba(255,255,255,0.06); }
.rail a[aria-current="page"] { background: rgba(255,255,255,0.08); border-left-color: #b98bc0; color: #fff; font-weight: 600; }

main { padding: 2rem 2.5rem 4rem; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head p { margin: 0.35rem 0 0; color: var(--muted); }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.biz-switch { display: block; margin: 0 0 1.5rem; }
.biz-switch span { display: block; font-size: 0.78rem; color: #a9bcb3; font-weight: 500; margin-bottom: 0.25rem; }
.biz-switch select { background: #26403a; color: #fff; border-color: #3b5a52; }

/* Controls ---------------------------------------------------------------- */

button, .btn {
  font: inherit; font-weight: 600; font-size: 0.93rem; cursor: pointer;
  padding: 0.5rem 0.95rem; border-radius: var(--radius-sm);
  border: 1px solid var(--rule); background: var(--panel); color: var(--ink);
}
button:hover { border-color: #aebbb4; }
button.primary { background: var(--leaf); border-color: var(--leaf); color: #fff; }
button.primary:hover { background: var(--leaf-dark); }
button.danger { color: var(--debt); }
button.link { border: none; background: none; padding: 0.2rem 0.3rem; color: var(--leaf); font-weight: 600; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--grape); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 0.45rem 0.6rem; width: 100%;
}
input[type="checkbox"] { width: auto; }
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.25rem; }
.field { margin-bottom: 0.9rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
.check { display: flex; gap: 0.5rem; align-items: center; font-weight: 500; }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.25rem; }
.tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 0.6rem 0.9rem; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--grape); }

/* Figures strip ------------------------------------------------------------ */

.figures { display: grid; grid-template-columns: repeat(6, 1fr); background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 1.5rem; }
.figures div { padding: 1rem 1.1rem; border-left: 1px solid var(--rule); }
.figures div:first-child { border-left: none; }
.figures span { display: block; font-size: 0.82rem; color: var(--muted); }
.figures strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.panel h2 { margin-bottom: 0.75rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

.checks { list-style: none; padding: 0; margin: 0; }
.checks li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.55rem 0; border-top: 1px solid var(--rule); }
.checks li:first-child { border-top: none; }
.ok { color: var(--leaf); font-weight: 700; }
.bad { color: var(--debt); font-weight: 700; }

/* Tables -------------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; }
.list { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.list th { text-align: left; font-size: 0.82rem; font-weight: 600; color: var(--muted); padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--rule); background: #fbfcfa; }
.list td { padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.list tr:last-child td { border-bottom: none; }
.list tr.clickable { cursor: pointer; }
.list tr.clickable:hover td { background: var(--leaf-wash); }
.scroll { overflow-x: auto; }

.tag { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 99px; background: #eef1ef; color: var(--muted); white-space: nowrap; }
.tag.paid, .tag.succeeded { background: var(--leaf-wash); color: var(--leaf); }
.tag.open { background: #eaf0f5; color: #2b5170; }
.tag.partial, .tag.processing { background: var(--amber-wash); color: var(--amber); }
.tag.overdue, .tag.failed { background: var(--debt-wash); color: var(--debt); }
.tag.void { text-decoration: line-through; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 0.5rem; }

.rail { display: flex; flex-direction: column; }
.userbox { margin-top: auto; padding-top: 1.25rem; border-top: 1px solid #33504a; font-size: 0.88rem; }
.userbox p { margin: 0 0 0.5rem; }
.userbox span { color: #a9bcb3; }
.link-light { background: none; border: none; color: #dfe8e3; padding: 0.2rem 0; margin-right: 0.9rem; font-size: 0.88rem; }
.link-light:hover { color: #fff; text-decoration: underline; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.gate-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 2rem; }
.gate-card h1 { margin: 0.5rem 0 1rem; font-size: 1.4rem; }
.gate-brand strong { color: var(--ink); }
button.wide { width: 100%; margin-top: 0.25rem; }
.small { font-size: 0.85rem; margin-top: 1rem; }
.audit-scroll { max-height: 420px; overflow-y: auto; }

/* Banking ------------------------------------------------------------------------- */

.bank-accounts { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.bank-acct {
  display: grid; gap: 0.1rem; text-align: left; min-width: 230px; padding: 0.85rem 1rem;
  font-weight: 400; border-radius: var(--radius); background: var(--panel);
}
.bank-acct strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.bank-acct .bank-name { font-weight: 600; }
.bank-acct .bank-meta { font-size: 0.82rem; color: var(--muted); margin-top: 0.35rem; }
.bank-acct[aria-pressed="true"] { border-color: var(--grape); box-shadow: inset 0 0 0 1px var(--grape); }
.review-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.review-bar p { margin: 0; }
.review-action { min-width: 300px; }
.review-action select { width: auto; max-width: 240px; }
.review-action .match { display: inline-block; margin-right: 0.5rem; }
td.ok { color: var(--leaf); }
.rec-figures { grid-template-columns: repeat(4, 1fr); }
label.attach { display: inline; font-size: 0.93rem; cursor: pointer; margin: 0 0 0 0.4rem; }
a.btn { text-decoration: none; display: inline-block; font-weight: 600; font-size: 0.93rem; }

.linkbox { display: flex; gap: 0.5rem; align-items: flex-end; margin-top: 1rem; }
.linkbox label { flex: 1; margin: 0; }
.linkbox input { font-size: 0.85rem; color: var(--muted); }
.email-frame { width: 100%; height: 520px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: #f6f8f4; }
a.link-a { color: var(--leaf); font-weight: 600; font-size: 0.93rem; padding: 0.2rem 0.3rem; text-decoration: none; }
.tabs.scroll { overflow-x: auto; white-space: nowrap; }

.statement.wide td:first-child { min-width: 12rem; }
tr.drill { cursor: pointer; }
tr.drill:hover td { background: var(--leaf-wash); }
.statement .sc-num { width: 3rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.statement table.schc td:nth-child(2) { padding-left: 0.25rem; }
.note.bad-note { color: var(--debt); }
dialog.dialog-wide { width: min(1200px, 96vw); }
.budget-grid input { min-width: 4.5rem; padding: 0.35rem 0.4rem; }
.budget-grid td { padding-right: 0.25rem; }

.import-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: 1rem 0; }
.import-slot { border: 1px dashed var(--rule); border-radius: var(--radius); padding: 0.8rem; }
.import-slot input[type=file] { margin-top: 0.4rem; font-size: 0.85rem; }
.small-note { font-size: 0.83rem; margin: 0.4rem 0 0; }
.danger-zone { border-color: #e7c6c0; }
a.btn.primary-link { background: var(--leaf); border-color: var(--leaf); color: #fff; }
@media (max-width: 900px) { .import-grid { grid-template-columns: 1fr; } }

.feedbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; background: var(--leaf-wash); border-radius: var(--radius); padding: 0.6rem 0.9rem; margin-bottom: 1rem; font-size: 0.93rem; }

.brand-logo { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.brand-logo img { max-height: 56px; max-width: 220px; border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 0.35rem; background: #fff; }
label.btn { cursor: pointer; margin: 0; }

/* Journal ----------------------------------------------------------------------- */

.entry { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 0.75rem; }
.entry-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--rule); }
.entry-head .when { font-variant-numeric: tabular-nums; color: var(--muted); margin-right: 0.75rem; }
.entry table td { padding: 0.35rem 0.9rem; font-size: 0.92rem; }
.entry td.cr { padding-left: 2.2rem; }
.entry.reversed { opacity: 0.6; }

/* Financial statements: set like a printed ledger ------------------------------ */

.statement { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 2.25rem 2.5rem 2.5rem; max-width: 760px; }
.statement header { text-align: center; margin-bottom: 1.75rem; }
.statement header .co { font-weight: 600; margin: 0; }
.statement header h2 { font-size: 1.45rem; margin: 0.2rem 0; }
.statement header .period { color: var(--muted); margin: 0; }
.statement td { padding: 0.28rem 0; font-variant-numeric: tabular-nums; }
.statement td.num { width: 9.5rem; }
.statement tr.head td { font-weight: 700; padding-top: 1.1rem; }
.statement tr.line td:first-child { padding-left: 1.25rem; }
.statement tr.sub td { font-weight: 600; }
.statement tr.sub td.num { border-top: 1px solid var(--ink); }
.statement tr.total td { font-weight: 700; padding-top: 0.6rem; }
.statement tr.total td.num { border-top: 1px solid var(--ink); border-bottom: 3px double var(--ink); }
.statement .note { margin-top: 1.5rem; font-size: 0.88rem; color: var(--muted); }
.statement.wide { max-width: none; }
.statement.wide td, .statement.wide th { padding: 0.35rem 0.5rem; }
.statement.wide th { font-size: 0.82rem; text-align: right; color: var(--muted); border-bottom: 1px solid var(--ink); }
.statement.wide th:first-child { text-align: left; }

.report-controls { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.25rem; }
.report-controls .field { margin: 0; }
.report-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.report-picker button[aria-pressed="true"] { background: var(--grape-wash); border-color: var(--grape); color: var(--grape); }

/* Dialogs ----------------------------------------------------------------------- */

dialog { border: none; border-radius: var(--radius); padding: 0; width: min(760px, 94vw); max-height: 90vh; box-shadow: 0 20px 60px rgba(20, 40, 34, 0.25); }
dialog::backdrop { background: rgba(20, 35, 30, 0.45); }
dialog form, dialog .body { padding: 1.4rem 1.5rem; }
dialog .dhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
dialog .dfoot { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.error { background: var(--debt-wash); color: var(--debt); padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); margin-bottom: 0.9rem; }
.lines td { padding: 0.25rem 0.3rem 0.25rem 0; vertical-align: middle; }
.lines th { text-align: left; font-size: 0.8rem; color: var(--muted); padding: 0 0.3rem 0.25rem 0; }
.totalbar { display: flex; justify-content: flex-end; gap: 1.5rem; font-weight: 600; margin-top: 0.5rem; font-variant-numeric: tabular-nums; }
#stripe-element { margin: 1rem 0; min-height: 120px; }

.toast { position: fixed; bottom: 1.25rem; right: 1.25rem; background: var(--ink); color: #fff; padding: 0.75rem 1rem; border-radius: var(--radius); max-width: 380px; z-index: 50; }
.toast.err { background: var(--debt); }

/* Mobile ------------------------------------------------------------------------ */

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; padding: 0.9rem 1rem; }
  .userbox { margin-top: 0.75rem; padding-top: 0.75rem; }
  .env { margin: 0 0 0.6rem 2.4rem; }
  .rail nav { flex-direction: row; overflow-x: auto; }
  .rail a { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .rail a[aria-current="page"] { border-bottom-color: #b98bc0; }
  main { padding: 1.25rem 1rem 3rem; }
  .figures, .rec-figures { grid-template-columns: repeat(2, 1fr); }
  .bank-acct { min-width: 0; flex: 1 1 100%; }
  .figures div:nth-child(odd) { border-left: none; }
  .figures div { border-top: 1px solid var(--rule); }
  .two, .grid2, .grid3 { grid-template-columns: 1fr; }
  .statement { padding: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media print {
  .rail, .page-head .actions, .report-controls, .report-picker, .tabs, .toast { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  body, :root { background: #fff; }
  .statement { border: none; padding: 0; max-width: none; }
}
