:root {
  --ink: #0B1733;
  --muted: #55636F;
  --bg: #F1E8D2;
  --card: #FBF6E8;
  --line: #DDD0B2;
  --head: #EADFC3;
  --teal: #12224A;
  --teal-dark: #0B1733;
  --gold: #D4B35A;
  --gold-ink: #7A5F17;
  --input: #8996A3;
  --side: #0B1733;
  --side-active: #1C2F63;
  --side-text: #D8D2BF;
  --paid-bg: #D9F2E1; --paid-ink: #11482A;
  --due-bg: #FCEBBE;  --due-ink: #5C3F00;
  --late-bg: #8A1C1C; --late-ink: #FFFFFF;
  --sched-bg: #DCE9F7; --sched-ink: #12406B;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--teal); }
a:hover { color: var(--teal-dark); }
h1, h2 { font-family: 'Marcellus', 'Cormorant Garamond', Georgia, serif; font-weight: 400; letter-spacing: 0.01em; }
h1 { margin: 0; font-size: 30px; line-height: 1.2; }
.page-head h1::after { content: ''; display: block; width: 44px; height: 2px; background: var(--gold); margin-top: 8px; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0; font-size: 16px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.row-between { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Landlord shell ---- */
.shell { display: flex; min-height: 100vh; }
.side {
  flex: 0 0 236px; background: var(--side); color: var(--side-text);
  padding: 24px 16px; display: flex; flex-direction: column; gap: 24px;
}
.brand { padding: 0; }
.brand img { display: block; width: 100%; height: auto; }
.t-logo { display: block; height: 46px; width: auto; margin: 0 0 10px -4px; }
.auth-logo { background: #0B1733; border-radius: 10px; padding: 6px 14px; margin-bottom: 16px; }
.auth-logo img { display: block; width: 100%; max-width: 300px; height: auto; margin: 0 auto; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: block; padding: 11px 12px; border-radius: 8px; color: var(--side-text); text-decoration: none;
}
.nav a:hover { color: #FFFFFF; background: rgba(255,255,255,0.06); }
.nav a.on { background: var(--side-active); color: var(--gold); font-weight: 600; box-shadow: inset 3px 0 0 var(--gold); }
.side-actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.side-actions .btn-light { background: var(--card); color: var(--ink); }
.side-actions form button {
  width: 100%; min-height: 44px; border-radius: 8px; border: 1px solid #3F4F80; background: transparent;
  color: #FFFFFF; font: inherit; cursor: pointer;
}
.main { flex: 1 1 auto; min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 22px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 4px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { flex: none; padding: 14px 12px; gap: 10px; }
  .brand img { width: auto; height: 52px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; padding: 10px 12px; }
  .side-actions { flex-direction: row; flex-wrap: wrap; margin-top: 0; }
  .side-actions > * { flex: 1 1 140px; }
  .side-actions .btn, .side-actions form button { min-height: 40px; font-size: 14px; white-space: nowrap; }
  .main { padding: 18px 16px 40px; }
  h1 { font-size: 24px; }
}

/* ---- Cards, tiles ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.card-pad { padding: 18px; }
.card-head { padding: 16px 18px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.card-list > div, .card-list > a { padding: 12px 0; border-top: 1px solid var(--line); }
.cols { display: flex; flex-wrap: wrap; gap: 22px; align-items: flex-start; }
.col-main { flex: 999 1 560px; min-width: 0; }
.col-side { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 22px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.tile { border-radius: 12px; padding: 16px 18px; text-decoration: none; color: inherit; display: block; }
.tile .big { font-size: 36px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.tile .label { margin-top: 6px; font-weight: 600; }
.tile-paid { background: var(--paid-bg); color: var(--paid-ink); }
.tile-due { background: var(--due-bg); color: var(--due-ink); }
.tile-partial { background: var(--card); color: var(--due-ink); border: 2px solid #8A5A00; }
.tile-late { background: var(--late-bg); color: var(--late-ink); }
.tile-plain { background: var(--card); border: 1px solid var(--line); }
.tile-dark { background: var(--ink); color: #FFFFFF; }
.tile-dark .label { color: var(--side-text); }
.tile:hover { filter: brightness(0.97); }

/* ---- Pills ---- */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill-paid { background: var(--paid-bg); color: var(--paid-ink); }
.pill-due { background: var(--due-bg); color: var(--due-ink); }
.pill-partial { background: var(--card); color: var(--due-ink); border: 1px solid #8A5A00; padding: 2px 9px; }
.pill-late { background: var(--late-bg); color: var(--late-ink); }
.pill-upcoming { background: var(--head); color: var(--muted); }
.pill-new { background: var(--ink); color: #FFFFFF; }
.pill-scheduled { background: var(--sched-bg); color: var(--sched-ink); }
.pill-waiting { background: var(--due-bg); color: var(--due-ink); }
.pill-done { background: var(--paid-bg); color: var(--paid-ink); }

/* ---- Buttons and chips ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid #CDBF9F;
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { color: var(--ink); background: #F4EBD3; }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #FFFFFF; }
.btn-primary:hover { background: var(--teal-dark); color: #FFFFFF; }
.btn-outline { border-color: var(--teal); color: var(--teal); }
.btn-danger { border-color: #8A1C1C; color: #8A1C1C; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid #CDBF9F; background: var(--card); color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px;
}
.chip:hover { color: var(--ink); background: #F4EBD3; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.inline-form { display: inline; }
.link-button { background: none; border: 0; padding: 4px 0; min-height: 32px; color: #8A1C1C; text-decoration: underline; font: inherit; cursor: pointer; }

/* ---- Forms ---- */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: 14px; font-weight: 600; }
.field .hint { font-size: 13px; color: var(--muted); }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=date],
input[type=month], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--input); border-radius: 8px;
  font: inherit; background: var(--card); color: var(--ink);
}
textarea { padding: 10px 12px; min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible, a:focus-visible {
  outline: 3px solid #C9A640; outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 20px; height: 20px; margin: 0; flex: 0 0 auto; }
fieldset { border: 0; padding: 0; margin: 0; }
.section-title { font-size: 18px; font-weight: 700; }
.flash { background: var(--paid-bg); color: var(--paid-ink); border-radius: 10px; padding: 12px 14px; font-weight: 600; }
.error { background: var(--due-bg); color: var(--due-ink); border-radius: 10px; padding: 12px 14px; font-weight: 600; }
.note { background: var(--head); border-radius: 10px; padding: 12px 14px; }

/* ---- Ledger tables ---- */
.table-wrap { overflow-x: auto; }
table.book { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.book th {
  background: var(--head); color: var(--muted); font-size: 13px; font-weight: 600; text-align: left;
  padding: 9px 12px; white-space: nowrap;
}
table.book td { padding: 9px 12px; border-top: 1px solid var(--line); vertical-align: top; }
table.book th.num, table.book td.num { text-align: right; }
table.book tr.total td { border-top: 2px solid var(--ink); font-weight: 700; }
table.book tr.carry td { font-weight: 600; }
table.book .indent { padding-left: 36px; }
table.book .explain { color: var(--muted); font-style: italic; border-top: 0; padding-top: 0; }
table.book tr.entry-first td { border-top: 1px solid var(--line); }
table.book tr.entry-cont td { border-top: 0; padding-top: 2px; }
table.book td.ref { color: var(--muted); white-space: nowrap; }
.page-title { padding: 12px 18px; border-top: 1px solid var(--line); font-weight: 700; }
.balanced { background: var(--paid-bg); color: var(--paid-ink); padding: 12px 18px; font-weight: 600; font-size: 14px; }
.unbalanced { background: var(--late-bg); color: #FFFFFF; padding: 12px 18px; font-weight: 600; font-size: 14px; }
.photo { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.copy-box { display: flex; gap: 8px; flex-wrap: wrap; }
.copy-box input { flex: 1 1 260px; font-size: 14px; }

/* ---- Auth pages ---- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 420px; padding: 28px; }
.auth h1 { font-size: 24px; margin-bottom: 4px; }

/* ---- Tenant portal ---- */
.t-shell { max-width: 520px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.t-head { background: var(--side); color: #FFFFFF; padding: 24px 20px 20px; }
.t-head .where { font-size: 14px; color: var(--side-text); }
.t-head h1 { font-size: 26px; margin-top: 4px; }
.t-head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.t-head form button { background: transparent; border: 1px solid #3F4F80; color: #FFFFFF; border-radius: 8px; min-height: 36px; padding: 0 10px; font: inherit; font-size: 13px; cursor: pointer; }
.t-body { flex: 1 1 auto; padding: 16px 16px 96px; display: flex; flex-direction: column; gap: 16px; }
.t-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.t-amount { font-size: 34px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.t-list > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.t-nav {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: center; padding: 6px 8px calc(10px + env(safe-area-inset-bottom));
}
.t-nav-inner { display: flex; width: 100%; max-width: 520px; }
.t-nav a {
  flex: 1 1 0; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 500;
}
.t-nav a.on { color: var(--teal); font-weight: 700; }
.t-head { border-bottom: 3px solid var(--gold); }
.t-head h1 { color: var(--gold); }
.brand { border-bottom: 1px solid rgba(212,179,90,0.35); padding-bottom: 18px; }
.card { border-top: 2px solid rgba(212,179,90,0.55); }
.t-nav svg { width: 22px; height: 22px; }

@media print {
  .side, .no-print, .t-nav { display: none !important; }
  .main { padding: 0; }
  body { background: #FFFFFF; }
  .card { border: 0; }
}
