:root {
  --paper: #f4f0e8;
  --card: #fffcf7;
  --ink: #1c1915;
  --muted: #6d655c;
  --line: #e6dccb;
  --green: #146b45;
  --green-ink: #0d3d28;
  --green-soft: #e7f5ee;
  --rust: #9d3b24;
  --rust-soft: #f8ebe6;
  --gold: #8d6420;
  --shadow: 0 10px 30px rgba(48, 36, 18, 0.06);
  --sans: "Outfit", "Segoe UI", sans-serif;
  --serif: "Lato", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 100% -10%, rgba(20, 107, 69, 0.06), transparent 60%),
    var(--paper);
  font-family: var(--sans);
  line-height: 1.5;
}
a { color: var(--green-ink); }
h1, h2, .brand strong, .brand-lockup {
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: -0.03em;
}
h1 { font-size: 2.15rem; margin: 0; line-height: 1.15; }
h2 { font-size: 1.2rem; margin: 0 0 16px; }
h3 { font-size: 1.05rem; margin: 0 0 10px; font-weight: 600; }
p { margin: 0.35rem 0; }

.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px;
  flex: none;
  padding: 26px 16px 18px;
  background: #1c1915;
  color: #f6f1e8;
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.brand, .brand-lockup {
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
  padding: 0 8px;
}
.brand strong { display: block; font-size: 1.25rem; }
.brand-lockup { font-size: 1.45rem; justify-content: center; }
.brand em {
  display: block;
  margin-top: 2px;
  color: #cbbfae;
  font-style: normal;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0;
}
.logo {
  width: 38px;
  height: 38px;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  flex: none;
}
.logo-invoice {
  width: 84px;
  height: 84px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
}
.statement-head { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.signs { margin-top: 28px; }
.signs h2 { margin-bottom: 12px; }
.sign-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; margin-top: 8px; }
.sign-grid-4 { grid-template-columns: repeat(4, 1fr); gap: 24px; }
.sign-grid-4 p { overflow-wrap: anywhere; }
.sign-role { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted, #6d655c); margin: 0 0 4px; }
.sign-line { border-bottom: 1px solid #1c1915; height: 46px; }
.logo-statement { width: 88px; height: 88px; border-radius: 16px; }
.logo-field { display: grid; gap: 10px; }
.logo-preview {
  width: 84px;
  height: 84px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background:
    linear-gradient(#e7f6ee, #e7f6ee) 9px 16px / 20px 2px no-repeat,
    linear-gradient(#e7f6ee, #e7f6ee) 9px 22px / 13px 2px no-repeat,
    linear-gradient(160deg, #1f8a5b, #0f5a3a);
  flex: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: #f3ece3;
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 10px;
  font-weight: 500;
}
.nav a.active, .nav a:hover { background: rgba(255, 255, 255, 0.08); }
.nav a.active { background: rgba(20, 107, 69, 0.45); color: #fff; }
.nav-parent {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #f3ece3;
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.nav-parent > span:first-child { flex: 1; padding: 9px 0 9px 12px; }
.nav-parent:hover, .nav-group.open > .nav-parent { background: rgba(255, 255, 255, 0.08); }
.nav-arrow {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: none;
}
.nav-arrow::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: transform 0.2s ease;
}
.nav-group.open > .nav-parent .nav-arrow::before,
.nav-group:hover > .nav-parent .nav-arrow::before,
.nav-group:focus-within > .nav-parent .nav-arrow::before {
  transform: rotate(225deg) translate(-1px, -1px);
}
.nav-sub {
  display: grid;
  grid-template-rows: 0fr;
  margin: 0;
  padding-left: 14px;
  opacity: 0;
  visibility: hidden;
  transition: grid-template-rows 0.28s ease, opacity 0.28s ease, margin 0.28s ease, visibility 0s linear 0.28s;
}
.nav-sub-clip {
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transform: translateY(-6px);
  transition: transform 0.28s ease;
}
.nav-group.open > .nav-sub,
.nav-group:hover > .nav-sub,
.nav-group:focus-within > .nav-sub {
  grid-template-rows: 1fr;
  margin: 2px 0 4px;
  opacity: 1;
  visibility: visible;
  transition: grid-template-rows 0.16s ease, opacity 0.16s ease, margin 0.16s ease, visibility 0s;
}
.nav-group.open > .nav-sub .nav-sub-clip,
.nav-group:hover > .nav-sub .nav-sub-clip,
.nav-group:focus-within > .nav-sub .nav-sub-clip { transform: none; }
.nav-sub a { color: #e7dccb; padding-top: 6px; padding-bottom: 6px; }
.side-foot {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 14px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #d9cbb8;
  font-size: 0.88rem;
}
.side-foot small { display: block; color: #b7aa9a; font-size: 0.75rem; font-weight: 500; }
.side-foot a, .side-foot button {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.side-foot button:hover { background: rgba(255, 255, 255, 0.16); }
.main { flex: 1; padding: 40px 44px 64px; max-width: 1180px; }
.main.wide { max-width: none; }
.main.wide .filters { justify-content: flex-start; }
.main.wide .filters label { flex: 0 1 220px; }
.page-head, .panel-head, .row-actions, .actions, .filters {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.page-head { margin-bottom: 28px; }
.page-head > div:first-child { display: grid; gap: 8px; }
.page-head h1,
.page-head p { margin: 0; }
.panel-head { margin-bottom: 14px; align-items: center; }
.panel-head h2 { margin: 0; }
.muted, .foot-note { color: var(--muted); }
.foot-note { margin-top: 32px; font-size: 0.85rem; }
.foot-row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-top: 32px; }
.foot-row .foot-note { margin-top: 0; }
.foot-row-auth { justify-content: center; margin-top: 28px; }
.credit { margin: 0; font-size: 0.85rem; color: var(--muted); }
.credit a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(109, 101, 92, 0.4); }
.credit a:hover { color: var(--ink, #1c1915); text-decoration-color: currentColor; }
.panel, .auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 28px 32px;
  margin-bottom: 22px;
}
.panel > p { margin: 0 0 16px; }
.panel > p:last-child { margin-bottom: 0; }
.narrow { max-width: 560px; }
.stats, .split { display: grid; gap: 18px; margin-bottom: 22px; }
.stats { grid-template-columns: repeat(4, 1fr); }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 22px 20px;
  box-shadow: var(--shadow);
}
.stat span, .invoice-meta span { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 500; }
.stat strong { display: block; margin-top: 8px; font-family: var(--serif); font-size: 1.7rem; font-weight: 700; }
.stat-wide { grid-column: span 1; }
.split { grid-template-columns: 1.15fr 0.85fr; align-items: start; }
.stack { display: grid; gap: 18px; }
.panel.stack > .btn,
.panel .stack > .btn { width: auto; justify-self: start; }
.stack > h2,
.stack > h3,
.stack > p { margin: 0; }
.stack > h2:not(:first-child),
.stack > h3:not(:first-child) {
  margin-top: 6px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.row-actions { justify-content: flex-start; align-items: center; gap: 12px; margin-top: 4px; }
.row-actions.spread { justify-content: space-between; }
.row-actions .btn-end { margin-left: auto; }
.payroll-table input { width: 5.6rem; margin-left: auto; }
.payroll-table td { vertical-align: top; }
.pay-note { display: block; max-width: 16rem; color: var(--rust); font-size: 0.78rem; margin-top: 4px; white-space: normal; }
.tenant-editor { padding: 28px 28px 36px; }
.tenant-editor > h2 { margin-bottom: 18px; }
.tenant-editor .stack { gap: 18px; }
.tenant-editor .stack > p { margin: 0; }
.tenant-editor .row-actions { justify-content: flex-start; gap: 12px; margin-top: 8px; }
.tenant-editor .row-actions .btn-end { margin-left: auto; }
.tenant-block {
  margin-top: 32px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.tenant-block > h2,
.tenant-block > h3 { margin: 0 0 8px; }
.tenant-block > p { margin: 0 0 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
label { display: grid; gap: 6px; font-size: 0.86rem; font-weight: 500; color: #3f3832; }
input, select, textarea {
  width: 100%;
  border: 1px solid #ddd3c3;
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  font-weight: 400;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
select {
  appearance: none;
  padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6.2 8 10.2 12 6.2' stroke='%236d655c' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px 16px;
}
input::placeholder { color: #a3988b; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #7eae93;
  box-shadow: 0 0 0 4px rgba(20, 107, 69, 0.12);
}
input:user-invalid, select:user-invalid, textarea:user-invalid {
  border-color: #d7a89c;
  box-shadow: none;
}
input::-ms-reveal, input::-ms-clear { display: none; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.btn {
  border: 1px solid #ddd3c3;
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 500;
  font-size: 0.92rem;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: #c9bba8; background: #faf7f2; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: #0f5a39; border-color: #0f5a39; color: #fff; }
.btn-danger { background: var(--rust-soft); border-color: #efcfc6; color: var(--rust); }
.btn-danger:hover { background: #f3ddd6; }
.btn-ghost { background: transparent; }
.banner { padding: 12px 14px; border-radius: 12px; margin: 0 0 16px; }
.banner-ok { background: var(--green-soft); color: var(--green-ink); }
.banner-err { background: var(--rust-soft); color: var(--rust); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.panel > .table-wrap + form,
.panel > p.empty + form,
.panel > p.muted + form { margin-top: 22px; }
.panel > .table-wrap + h2,
.panel > .table-wrap + h3 {
  margin-top: 8px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.pay-sheet { max-width: 720px; }
.pay-slip > h2 { margin-bottom: 8px; }
.pay-slip td { padding: 16px 8px; }
.pay-slip tr:last-child td { border-bottom: 0; }
.pay-slip .slip-net td { font-weight: 700; font-size: 1.08rem; padding-top: 18px; padding-bottom: 6px; }
th { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600; }
tbody tr:hover td { background: rgba(255, 252, 247, 0.7); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
a.nowrap { white-space: nowrap; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 120px; min-width: 0; }
.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 9px;
  background: #efe8dc;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 600;
  vertical-align: middle;
}
.pill-open, .pill-partial { background: #f3ead2; color: var(--gold); }
.pill-paid { background: var(--green-soft); color: var(--green-ink); }
.pill-super { background: #1c1915; color: #f7f4ee; }
.pill-void, .pill-overdue, .pill-terminated { background: var(--rust-soft); color: var(--rust); }
.pill-draft { background: #efe8dc; }
.empty { color: var(--muted); }
.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.entry-list strong, .entry-list span { display: block; }
.entry-list span { color: var(--muted); font-size: 0.85rem; }
.line-chip { display: inline-block; margin: 0 8px 6px 0; padding: 4px 8px; background: #f6f1e8; border-radius: 999px; font-size: 0.82rem; }
tr.sub td { border-bottom: 1px solid var(--line); padding-top: 0; }
tr.group th { background: #f7f3eb; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 0.95rem; }
tr.activity-who th {
  background: #f7f3eb;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: 1rem;
  font-weight: 650;
  padding-top: 14px;
  padding-bottom: 14px;
}
tr.activity-who .who-count {
  margin-left: 8px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
}
tr.subtotal td { font-weight: 600; }
tr.grand td { font-family: var(--serif); font-size: 1.15rem; }
table.statement { min-width: 640px; }
table.statement td:first-child, table.statement th:first-child { min-width: 220px; }
tr.stmt-head th {
  background: var(--green);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.78rem;
}
tr.stmt-total td { background: #f6efd4; font-weight: 650; }
tr.stmt-net td { background: var(--green); color: #fff; font-weight: 700; }
.is-archived { opacity: 0.55; }
.balance-readout.warn, .banner-err { color: var(--rust); }
.balanced { color: var(--green-ink); font-weight: 600; }
.filters { margin-bottom: 22px; align-items: end; }
.filters label { min-width: 160px; }
.invoice-meta { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 12px; margin: 12px 0 18px; }
.totals { margin-left: auto; width: min(280px, 100%); }
.totals p { display: flex; justify-content: space-between; }
.notes { white-space: pre-wrap; }
.eyebrow { margin: 0; color: var(--green); letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.75rem; font-weight: 600; }
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(700px 320px at 50% 0%, rgba(20, 107, 69, 0.12), transparent 70%),
    var(--paper);
}
.auth-card { width: min(440px, 100%); padding: 28px; }
.auth-card h1 { margin: 10px 0 4px; }
.lede { color: var(--muted); }

.users-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}
.users-layout .panel { margin-bottom: 0; }
.user-edit { max-width: 560px; }
.people { display: grid; gap: 0; }
.person {
  display: grid;
  gap: 14px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}
.person:first-child { border-top: 0; padding-top: 0; }
.person-id { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: baseline; }
.person-id strong { font-size: 1.02rem; }
.person-id .muted { flex-basis: 100%; }
.person-form {
  display: flex;
  gap: 10px;
  align-items: end;
}
.person-form label { flex: 1; min-width: 0; }
.person-form .btn { margin-bottom: 1px; }
.person-form-wide { display: grid; grid-template-columns: 1fr 1fr auto; }
.secret-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  font-size: 1.05rem;
  word-break: break-all;
}
.recovery-codes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin: 12px 0;
}
.recovery-codes code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 980px) {
  .users-layout, .person-form-wide { grid-template-columns: 1fr; }
  .person-form { flex-wrap: wrap; }
  .recovery-codes { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar {
    width: auto;
    position: sticky;
    top: 0;
    z-index: 2;
    max-height: 100vh;
    overflow: auto;
    padding: 14px 14px 12px;
    gap: 12px;
  }
  .nav { flex-direction: column; overflow: visible; }
  .nav-group:hover > .nav-sub,
  .nav-group:focus-within > .nav-sub {
    grid-template-rows: 0fr;
    margin: 0;
    opacity: 0;
    visibility: hidden;
    transition: grid-template-rows 0.22s ease, opacity 0.18s ease, margin 0.22s ease, visibility 0s linear 0.22s;
  }
  .nav-group:hover > .nav-sub .nav-sub-clip,
  .nav-group:focus-within > .nav-sub .nav-sub-clip { transform: translateY(-6px); }
  .nav-group.open > .nav-sub {
    grid-template-rows: 1fr;
    margin: 2px 0 4px;
    opacity: 1;
    visibility: visible;
    transition: grid-template-rows 0.22s ease, opacity 0.18s ease, margin 0.22s ease, visibility 0s;
  }
  .nav-group.open > .nav-sub .nav-sub-clip { transform: none; }
  .nav-group:hover > .nav-parent .nav-arrow::before,
  .nav-group:focus-within > .nav-parent .nav-arrow::before { transform: rotate(45deg) translate(-1px, -1px); }
  .nav-group.open > .nav-parent .nav-arrow::before { transform: rotate(225deg) translate(-1px, -1px); }
  .side-foot { margin-top: 8px; }
  .main { padding: 28px 20px 48px; }
  .stats, .split, .grid-2, .grid-3, .invoice-meta { grid-template-columns: 1fr; }
  .sign-grid-4 { grid-template-columns: 1fr 1fr; }
}

@page report {
  size: A4 landscape;
  margin: 10mm 8mm;
}
@page invoice {
  size: A4 portrait;
  margin: 14mm 14mm;
}
@media print {
  .sidebar, .no-print, .foot-note, .foot-row, .banner { display: none !important; }
  body, .panel, .invoice-sheet { background: white; box-shadow: none; }
  .shell { display: block; }
  .main { max-width: none; padding: 0; }
  .table-wrap { overflow: visible !important; }
  tr.stmt-head th, tr.stmt-total td, tr.stmt-net td { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .invoice-sheet { page: invoice; border: 0; padding: 0; margin: 0; }
  .invoice-sheet .page-head { margin-bottom: 8px; }
  .invoice-sheet .signs { break-inside: avoid; margin-top: 22px; }
  .invoice-sheet .sign-grid { break-inside: avoid; }
  .invoice-sheet tr { break-inside: avoid; }
  .main.wide { page: report; }
  .main.wide .page-head { margin-bottom: 8px; }
  .main.wide .panel {
    border: 0;
    box-shadow: none;
    padding: 0 0 10px;
    margin: 0 0 14px;
  }
  .main.wide h1 { font-size: 16px; }
  .main.wide h2 { font-size: 13px; margin-bottom: 4px; }
  .main.wide h3 { font-size: 11px; margin-top: 10px; break-after: avoid; }
  .main.wide p { font-size: 10px; }
  .main.wide table { width: 100%; font-size: 8.5px; table-layout: auto; }
  .main.wide table.statement,
  .main.wide table.statement td:first-child,
  .main.wide table.statement th:first-child { min-width: 0; }
  .main.wide th, .main.wide td { padding: 3px 4px; }
  .main.wide tr.grand td { font-family: inherit; font-size: 8.5px; }
  .main.wide th { letter-spacing: 0; font-size: 7.5px; }
  .main.wide thead { display: table-header-group; }
  .main.wide tr { break-inside: avoid; }
}
