/* Loan Book — one working column, summary first, ledger detail below */
:root {
  /* CTMD Cream & Royal Blue (from the logo): cream page, white cards, royal blue actions, navy text accents */
  --bg: #FFFBE6; --surface: #FFFFFF; --soft: #F3F4F6; --fg: #111827; --muted: #64748B; --line: #E5E7EB;
  --accent: #1E40AF; --navy: #1E40AF; --primary: #3B82F6; --primary-hover: #2563EB; --accent-soft: #E7F0FF; --on-accent: #ffffff;
  --cream-soft: #FFF7D6;
  --good: #15803D; --good-soft: #E6F6EC; --warn: #B45309; --warn-soft: #FEF3C7;
  --bad: #B91C1C; --bad-soft: #FEE2E2; --info: #1E40AF; --info-soft: #E7F0FF;
  --shadow: 0 1px 2px rgba(17, 24, 39, .05), 0 6px 18px rgba(17, 24, 39, .05);
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --r: 12px;
  color-scheme: light;
}
/* Dark mode is optional: only when the person turns it on (menu → Dark mode). Never forced by the phone's setting. */
:root[data-theme="dark"] {
  --bg: #0B1220; --surface: #111A2E; --soft: #18233A; --fg: #E5E7EB; --muted: #9AA8BD; --line: #24324D;
  --accent: #9DB9FF; --navy: #9DB9FF; --primary: #3B82F6; --primary-hover: #2563EB; --accent-soft: #1A2847; --on-accent: #0B1220;
  --cream-soft: #2A2614;
  --good: #4ADE80; --good-soft: #12301F; --warn: #FBBF24; --warn-soft: #33280F;
  --bad: #F87171; --bad-soft: #3A1717; --info: #9DB9FF; --info-soft: #1A2847;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; }
h1 { font-size: 1.9rem; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px); }
.topbar-in { max-width: 1000px; margin: 0 auto; padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--fg); text-decoration: none; }
.nav-links { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
.nav-links a { color: var(--muted); text-decoration: none; font-weight: 500; padding: 4px 0; border-bottom: 2px solid transparent; }
.nav-links a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); }
.inline { display: inline; margin: 0; }
.linkbtn { background: none; border: 0; padding: 4px 0; color: var(--muted); font-weight: 500; }
.linkbtn:hover, .nav-links a:hover { color: var(--fg); }

.wrap { max-width: 1000px; margin: 0 auto; padding-inline: 16px; padding-block: 26px 64px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; justify-content: space-between; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 8px; font-weight: 500; color: var(--fg); text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 11px 14px; }

.flash { padding: 10px 14px; border-radius: 8px; font-weight: 500; }
.flash.ok { background: var(--good-soft); color: var(--good); }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.flash.info { background: var(--info-soft); color: var(--info); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; min-width: 0; }

.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.summary.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { padding: 16px 18px; display: grid; gap: 4px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat .label { font-size: 12px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.stat .value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 1.35rem; font-weight: 500; overflow-wrap: anywhere; }
.stat .sub { font-size: 12.5px; color: var(--muted); }
.stat.accent .value { color: var(--accent); }
.stat.late .value { color: var(--bad); }
@media (max-width: 720px) {
  .summary, .summary.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}

.tabs { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; width: fit-content; max-width: 100%; }
.tabs a { padding: 6px 12px; border-radius: 6px; color: var(--muted); font-weight: 500; font-size: 14px; text-decoration: none; }
.tabs a[aria-current="true"] { background: var(--accent-soft); color: var(--fg); }
.tabs .count { font-family: var(--font-mono); font-size: 12px; margin-left: 4px; opacity: 0.8; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.search { display: flex; gap: 6px; flex: 1 1 220px; max-width: 340px; }
.search input { flex: 1; min-width: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.card .table-wrap { border: 0; border-radius: 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: 0.05em; text-transform: uppercase; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td.amt, th.amt { text-align: right; white-space: nowrap; }
td.x { width: 1%; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
td a.rowlink { color: var(--fg); font-weight: 600; text-decoration: none; }
td a.rowlink:hover { text-decoration: underline; }

.chip { display: inline-block; font-size: 11.5px; letter-spacing: 0.05em; text-transform: uppercase; padding: 1px 8px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.chip.active, .chip.expired { background: var(--line); color: var(--muted); }
.chip.paid { background: var(--good-soft); color: var(--good); }
.chip.soon, .chip.pending { background: var(--warn-soft); color: var(--warn); }
.chip.overdue { background: var(--bad-soft); color: var(--bad); }
.chip.online { background: var(--info-soft); color: var(--info); }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.done span { background: var(--good); }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 18px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: 12px; color: var(--muted); letter-spacing: 0.05em; text-transform: uppercase; }
.facts dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.notes { color: var(--muted); margin: 0; white-space: pre-wrap; }

form.stack { display: grid; gap: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); width: 100%; }
.field textarea { min-height: 70px; resize: vertical; }
.field small { color: var(--muted); font-size: 12.5px; }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.checks label { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.auth { min-height: 100vh; display: grid; place-items: center; padding-inline: 16px; padding-block: 32px; }
.auth .card { width: min(410px, 100%); padding: 26px 24px; }
.auth h1 { font-size: 1.7rem; }

.secret { font-family: var(--font-mono); font-size: 1.1rem; background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; user-select: all; overflow-wrap: anywhere; }
.paybox { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.paybox .field { flex: 1 1 160px; }
.loan-block { display: grid; gap: 14px; }
.loan-block + .loan-block { border-top: 1px solid var(--line); padding-top: 18px; }
.mode-badge { font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; padding: 2px 8px; border-radius: 6px; }
.mode-badge.test { background: var(--warn-soft); color: var(--warn); }
.mode-badge.live { background: var(--good-soft); color: var(--good); }
.mode-badge.none { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); display: grid; gap: 10px; justify-items: center; }

/* pay directly + proof review */
.chip.review { background: var(--warn-soft); color: var(--warn); }
.chip.rejected { background: var(--bad-soft); color: var(--bad); }
.review-card { border-color: var(--warn); }
.reason { padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); width: 140px; font-size: 13px; }
.proof-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.qr { width: 180px; max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: 6px; }
.pay-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.pay-option { display: grid; gap: 6px; align-content: start; justify-items: start; padding: 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); min-width: 0; }
.pay-option .label { font-size: 12px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600; }
.pay-num { font-size: 1.2rem; font-weight: 500; overflow-wrap: anywhere; user-select: all; }
.qr-option { justify-items: center; text-align: center; }
.proof-form { border-top: 1px solid var(--line); padding-top: 14px; }

/* repayment schedule */
.schedule tr.next td { background: var(--accent-soft); }
.schedule-box { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; }
.schedule-box summary { cursor: pointer; font-weight: 600; }
.schedule-box[open] summary { margin-bottom: 10px; }
.schedule-preview { background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; font-size: 14px; }
.schedule-preview ol { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.schedule-preview li { display: flex; justify-content: space-between; gap: 12px; max-width: 360px; }

/* loan applications */
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 99px; background: var(--bad); color: #fff; font-size: 11.5px; font-weight: 600; text-align: center; line-height: 18px; }
.chip.app-new { background: var(--info-soft); color: var(--info); }
.chip.app-approved { background: var(--good-soft); color: var(--good); }
.chip.app-declined { background: var(--line); color: var(--muted); }
.apply { max-width: 760px; width: 100%; margin: 0 auto; display: grid; gap: 18px; }
.apply-head p { margin: 6px 0 0; color: var(--muted); }
.apply-done { text-align: left; }
.apply-done p { margin: 0; }
.req { color: var(--bad); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.flash ul { margin: 6px 0 4px; padding-left: 20px; font-weight: 400; }
.field.wide, .answers .wide { grid-column: 1 / -1; }
fieldset.field { border: 0; margin: 0; padding: 0; }
fieldset.field legend { font-size: 13px; color: var(--muted); font-weight: 500; padding: 0; margin-bottom: 6px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices label { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); cursor: pointer; }
.choices label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.other-input { margin-top: 8px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); width: 100%; max-width: 360px; }
.doc-list { display: grid; gap: 10px; }
.doc-row { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.doc-check { display: flex; gap: 8px; align-items: flex-start; }
.doc-check input { margin-top: 4px; }
.doc-row input[type=file] { font-size: 13px; max-width: 100%; }
.consent { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 14px; }
.consent p { margin: 10px 0; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.doc-card { display: grid; gap: 6px; align-content: start; }
.doc-card img, .doc-missing { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.doc-missing { display: grid; place-items: center; color: var(--muted); font-size: 13px; text-align: center; padding: 8px; }
.share-link { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; justify-content: space-between; }
.share-link .secret { padding: 6px 10px; font-size: 13px; }
.field input[type=radio], .field input[type=checkbox] { width: auto; padding: 0; flex: none; accent-color: var(--accent); }
.doc-row input[type=file] { padding: 6px 8px; }
.sig-draw, .sig-upload { display: grid; gap: 6px; }
.sig-draw[hidden], .sig-upload[hidden] { display: none; }
.sig-pad { width: 100%; height: 190px; background: #fff; border: 1px dashed var(--muted); border-radius: 8px; touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.sig-draw .row { justify-content: space-between; align-items: center; }
.sig-draw .row .row { gap: 8px; }
/* Full-screen signing box (phones) */
html.sigfs-open, html.sigfs-open body { overflow: hidden; overscroll-behavior: none; }
.sigfs { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; gap: 8px; padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); background: #e9efec; color: #10201a; height: 100vh; height: 100dvh; }
.sigfs[hidden] { display: none; }
.sigfs-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.sigfs-title { display: grid; gap: 2px; font-size: 14px; }
.sigfs-turn { font-size: 12px; color: #4b5a53; }
.sigfs-btns { display: flex; gap: 8px; }
.sigfs-btns .btn { min-height: 44px; padding: 8px 16px; }
.sigfs-area { position: relative; flex: 1; min-height: 0; }
.sigfs-pad { position: absolute; inset: 0; width: 100%; height: 100%; background: #fff; border: 1px solid #b9c6bf; border-radius: 10px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.sigfs-line { position: absolute; left: 6%; right: 6%; bottom: 22%; border-bottom: 1.5px solid #9aa8a1; color: #9aa8a1; font-size: 18px; line-height: 1; padding-bottom: 2px; pointer-events: none; }
@media (orientation: landscape) and (max-height: 500px) { .sigfs-turn { display: none; } .sigfs { gap: 6px; } .sigfs-title { font-size: 13px; } }
.sig-upload input[type=file] { font-size: 13px; max-width: 100%; padding: 6px 8px; }
.sig-view { display: grid; gap: 6px; justify-items: start; }
.sig-view img { max-width: 100%; width: 340px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.schedule tfoot td { border-top: 2px solid var(--line); border-bottom: 0; }
.schedule-preview .table-wrap { margin-top: 8px; max-height: 340px; overflow: auto; background: var(--surface); }
.schedule-preview table { font-size: 13px; }
.chip.advance { background: var(--accent-soft); color: var(--accent); }
.pay-total { display: block; padding: 9px 11px; border: 1px dashed var(--accent); border-radius: 8px; font-weight: 600; font-size: 1.05rem; background: var(--accent-soft); }

/* ===== v7: ledger, agreements, mobile ===== */
.bad { color: var(--bad); } .good { color: var(--good); }
.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list-rows li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-rows li:last-child { border-bottom: 0; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }
.stack-sm { display: grid; gap: 10px; min-width: 0; }
.hidden-copy { position: absolute; left: -9999px; width: 1px; height: 1px; }
tr.struck td { opacity: 0.55; }
.inline-num { width: 82px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }

/* topbar: menu button on phones */
.topbar-in { max-width: 1240px; }
.navtoggle { display: none; }
.navbtn { display: none; }
.badge { margin-left: 2px; vertical-align: 1px; }
@media (max-width: 1120px) {
  .topbar { position: sticky; top: 0; z-index: 30; }
  .topbar-in { flex-wrap: nowrap; position: relative; }
  .navbtn { display: inline-grid; gap: 4px; padding: 10px 8px; cursor: pointer; position: relative; border-radius: 8px; }
  .navbtn span { display: block; width: 22px; height: 2px; background: var(--fg); border-radius: 2px; }
  .navbtn .dot { position: absolute; top: 6px; right: 2px; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
  .nav-links { display: none; position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--line); padding: 6px 16px 14px; flex-direction: column; align-items: stretch; gap: 0; box-shadow: 0 10px 24px rgba(0,0,0,.12); }
  .nav-links a, .nav-links .linkbtn { padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 16px; text-align: left; width: 100%; }
  .nav-links a[aria-current="page"] { border-bottom-color: var(--line); color: var(--accent); font-weight: 600; }
  .navtoggle:checked ~ .nav-links { display: flex; }
}

/* summary cards */
.summary.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat .bar { margin-top: 4px; }
@media (max-width: 980px) { .summary.five { grid-template-columns: repeat(3, minmax(0, 1fr)); } .summary.five .stat { border-left: 0; border-top: 1px solid var(--line); } .summary.five .stat:nth-child(-n+3) { border-top: 0; } }
@media (max-width: 720px) {
  .summary.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary.five .stat { border-left: 0; border-top: 1px solid var(--line); }
  .summary.five .stat:first-child { grid-column: 1 / -1; border-top: 0; }
  .summary.five .stat:nth-child(odd):not(:first-child) { border-left: 1px solid var(--line); }
}
.next-hero { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; justify-content: space-between; padding: 18px 20px; border-radius: var(--r); background: var(--accent); color: var(--on-accent); }
.next-hero .label { display: block; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; opacity: .85; }
.next-hero .big { display: block; font-size: 2rem; font-weight: 500; line-height: 1.2; }
.next-hero .sub { display: block; font-size: 13.5px; opacity: .9; }
.next-hero .btn.primary { background: var(--on-accent); color: var(--accent); border-color: var(--on-accent); font-weight: 600; padding: 11px 18px; }
.next-hero.late { background: var(--bad); }
.next-hero.late .btn.primary { color: var(--bad); }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.mini-stats > div { display: grid; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-width: 0; align-content: start; }
.mini-stats span { font-size: 11.5px; color: var(--muted); letter-spacing: .05em; text-transform: uppercase; }
.mini-stats b { font-family: var(--font-mono); font-weight: 500; font-size: 1.05rem; overflow-wrap: anywhere; }
.mini-stats small { font-size: 12px; color: var(--muted); }
@media (max-width: 560px) { .mini-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* loan cards and collapsible sections */
.loan-top { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: flex-start; }
details.sect > summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-weight: 600; padding: 4px 0; }
details.sect > summary::-webkit-details-marker { display: none; }
details.sect > summary::before { content: '\203A'; display: inline-block; width: 14px; font-size: 1.3rem; line-height: 1; color: var(--muted); transition: transform .15s; }
details.sect[open] > summary::before { transform: rotate(90deg); }
details.sect > summary h2 { display: inline; }
.loan-card details.sect { border-top: 1px solid var(--line); padding-top: 10px; }
.loan-card details.sect[open] { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
details.card.sect:not([open]) { gap: 0; }
.pay-form { border-top: 1px solid var(--line); padding-top: 14px; }
.pay-form output { display: block; padding: 9px 11px; border: 1px dashed var(--line); border-radius: 8px; }

/* schedule & payment statuses */
.chip.r-upcoming, .chip.r-pending, .chip.pending_release, .chip.closed, .chip.voided, .chip.reversed, .chip.ag-draft, .chip.ag-superseded, .chip.ag-voided, .chip.app-review { background: var(--line); color: var(--muted); }
.chip.r-due_today, .chip.r-partial, .chip.ag-pending, .chip.app-requirements, .chip.app-agreement { background: var(--warn-soft); color: var(--warn); }
.chip.r-paid, .chip.ag-signed, .chip.app-ready { background: var(--good-soft); color: var(--good); }
.chip.r-overdue { background: var(--bad-soft); color: var(--bad); }
.chip.r-covered { background: var(--accent-soft); color: var(--accent); }
.schedule tr.st-overdue td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.schedule tr.st-paid td, .schedule tr.st-covered td { color: var(--muted); }
.schedule tr.st-paid td b, .schedule tr.st-covered td b { color: var(--muted); font-weight: 500; }
.facts.tight { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 14px; }
.facts .wide { grid-column: 1 / -1; }

/* payment history */
.pay-list { display: grid; gap: 8px; }
.pay-item { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.pay-item > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 110px 1fr auto auto; gap: 8px 12px; align-items: center; padding: 10px 12px; }
.pay-item > summary::-webkit-details-marker { display: none; }
.pay-item[open] > summary { border-bottom: 1px solid var(--line); }
.pay-item > dl, .pay-item > .row { padding: 10px 12px; }
.pay-item > .row:empty { display: none; }
.pi-amt { font-weight: 600; text-align: right; }
.pay-item.st-reversed .pi-amt { text-decoration: line-through; }
@media (max-width: 560px) { .pay-item > summary { grid-template-columns: 1fr auto; } .pi-method { grid-column: 1; color: var(--muted); font-size: 13px; } .pi-status { grid-row: 1; grid-column: 2; justify-self: end; } }

/* tables become cards on phones */
@media (max-width: 640px) {
  table.cards-sm thead { display: none; }
  table.cards-sm, table.cards-sm tbody, table.cards-sm tr, table.cards-sm td { display: block; width: 100%; }
  table.cards-sm tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.cards-sm tbody tr:last-child { border-bottom: 0; }
  table.cards-sm td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; white-space: normal; }
  table.cards-sm td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; text-align: left; flex: none; padding-top: 2px; }
  table.cards-sm td:not([data-label])::before { content: none; }
  table.cards-sm td.x { justify-content: flex-start; flex-wrap: wrap; }
  table.cards-sm tfoot { display: block; border-top: 2px solid var(--line); }
  table.cards-sm tfoot tr { display: flex; flex-wrap: wrap; gap: 4px 14px; }
  table.cards-sm tfoot td { width: auto; padding: 0; }
  table.cards-sm tfoot td:empty { display: none; }
  table.cards-sm tr.next { background: var(--accent-soft); }
  .schedule tr.next td { background: transparent; }
  tr.clickable:hover td { background: transparent; }
}

/* how to pay: big QR */
.qr-link { display: block; }
.qr-big { display: none; position: fixed; inset: 0; z-index: 50; background: rgba(8, 20, 15, .88); padding: 24px 16px; place-items: center; align-content: center; gap: 16px; }
.qr-big:target { display: grid; }
.qr-big img { width: min(92vw, 520px); height: auto; background: #fff; border-radius: 12px; padding: 12px; }
.qr-close { position: absolute; top: 10px; right: 18px; color: #fff; font-size: 2.2rem; text-decoration: none; line-height: 1; }

/* lender pages */
.verify-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; align-items: start; }
.verify-proof { display: grid; gap: 6px; }
.verify-proof img { width: 100%; max-height: 360px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
@media (max-width: 640px) { .verify-grid { grid-template-columns: 1fr; } .verify-proof img { max-height: 260px; } }
.coll-list, .ag-list, .notif-list { display: grid; gap: 12px; }
.ag-item { text-decoration: none; color: var(--fg); gap: 6px; }
.ag-item:hover { border-color: var(--accent); }
.wide-search { max-width: none; flex-wrap: wrap; }
.wide-search input[type=date] { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.link-card { border-color: var(--accent); }
.link-card .secret { font-size: 13px; }

/* notifications */
.notif { display: grid; gap: 3px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); text-decoration: none; color: var(--fg); }
.notif.new { border-left: 4px solid var(--accent); background: var(--accent-soft); }
.notif-title { font-weight: 600; }
.notif-body { font-size: 14px; }
.notif.k-overdue .notif-title, .notif.k-late_fee .notif-title, .notif.k-pay_rejected .notif-title { color: var(--bad); }

/* loan terms form */
.toggles .field { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); align-content: start; }
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin-bottom: 10px; }
.calc-grid > div { display: grid; gap: 1px; padding: 8px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); align-content: start; }
.calc-grid span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.calc-grid b { font-family: var(--font-mono); font-weight: 500; }
.calc-grid small { font-size: 11.5px; color: var(--muted); }
.calc-grid .hl { border-color: var(--accent); }
.schedule-preview .table-wrap { max-height: 420px; }

/* the agreement document */
.doc { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; max-width: 820px; margin: 0 auto; width: 100%; font-size: 15px; }
.doc p { margin: 0; line-height: 1.6; }
.doc ul { margin: 0; padding-left: 22px; display: grid; gap: 4px; line-height: 1.55; }
.doc-title { text-align: center; color: var(--accent); font-size: 1.35rem; }
.doc-sub { text-align: center; font-weight: 700; letter-spacing: .02em; margin: -4px 0 6px !important; }
.doc-h { font-size: 1rem; color: var(--accent); border-bottom: 1.5px solid var(--accent); padding-bottom: 3px; margin-top: 10px; }
.doc-pairs { display: grid; margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.doc-pairs > div { display: grid; grid-template-columns: minmax(130px, 38%) 1fr; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--line); }
.doc-pairs > div:last-child { border-bottom: 0; }
.doc-pairs dt { color: var(--muted); font-weight: 600; font-size: 13.5px; }
.doc-pairs dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { .doc-pairs > div { grid-template-columns: 1fr; gap: 1px; } .doc-card-wrap { padding: 16px 12px; } }
.doc-table { font-size: 13.5px; }
.doc-sig { padding: 10px; border: 1px dashed var(--line); border-radius: 8px; background: #fff; max-width: 360px; min-height: 60px; display: grid; place-items: center; }
.doc-sig img { max-width: 100%; max-height: 120px; }
.doc-sig.typed { font-family: "Segoe Script", "Brush Script MT", cursive; font-size: 1.6rem; color: #10204a; }
.doc-sig.empty { color: var(--muted); font-size: 13px; background: var(--bg); }
.doc-card-wrap { padding: 22px 20px; }
.sign-card, .signed-box { border-color: var(--accent); }
.consent-check { align-items: flex-start; flex-wrap: nowrap; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.consent-check input { margin-top: 4px; width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.big-btn { font-size: 1.05rem; font-weight: 700; letter-spacing: .02em; padding: 14px 16px; }

@media print {
  .topbar, .page-head .row, .flash, .sign-card, .form-actions, form, .btn { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 0; padding: 0; }
  .doc { font-size: 11pt; max-width: none; }
}

/* ===== Update 12: mobile-first components ===== */
body { overflow-wrap: break-word; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, canvas, video { max-width: 100%; }
.doc p, .doc li, .doc dd, .notes, .flash { overflow-wrap: anywhere; }
.doc-title { overflow-wrap: anywhere; }
.btn { min-height: 40px; text-align: center; }
.btn.small { min-height: 34px; }
.btn.busy { opacity: .6; cursor: progress; }
.btn.ghost { background: transparent; color: var(--on-accent); border-color: currentColor; }
@media (pointer: coarse) { .btn { min-height: 44px; } .btn.small { min-height: 40px; padding-inline: 12px; } .tabs a { padding: 9px 12px; } }
@media (max-width: 640px) {
  /* 16px inputs: iPhone Safari zooms into smaller ones and leaves the page zoomed */
  .field input, .field select, .field textarea, .search input, .reason, .inline-num, .other-input { font-size: 16px; }
  .page-head .row { width: 100%; }
  .page-head .row .btn { flex: 1 1 auto; }
  .card { padding: 14px; }
  .wrap { padding-block: 16px 48px; gap: 14px; }
  h1 { font-size: 1.55rem; }
  .tabs { width: 100%; }
  .tabs a { flex: 1 1 auto; text-align: center; }
  .paybox .field { flex-basis: 100% !important; }
  .paybox > .btn { width: 100%; }
  .form-actions .btn { flex: 1 1 auto; }
}
details.sub-sect { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: var(--bg); }
details.sub-sect > summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
details.sub-sect[open] { display: grid; gap: 10px; }

/* label / value rows: one figure per line, never overlapping */
dl.rows { margin: 0; display: grid; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
dl.rows > div { display: flex; flex-wrap: wrap; gap: 2px 14px; justify-content: space-between; align-items: baseline; padding: 9px 12px; border-bottom: 1px solid var(--line); }
dl.rows > div:last-child { border-bottom: 0; }
dl.rows dt { color: var(--muted); font-size: 14px; flex: 1 1 160px; min-width: 0; }
dl.rows dt small { display: block; font-size: 12px; }
dl.rows dd { margin: 0; text-align: right; flex: 0 1 auto; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
dl.rows.tight > div { padding: 6px 10px; }
dl.rows.tagged dd { display: flex; flex-wrap: wrap; gap: 4px 8px; justify-content: flex-end; align-items: center; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .03em; padding: 1px 7px; border-radius: 99px; white-space: nowrap; }
.t-income { background: var(--good-soft); color: var(--good); }
.t-capital { background: var(--info-soft); color: var(--info); }
.t-held { background: var(--warn-soft); color: var(--warn); }
.t-deducted { background: var(--line); color: var(--muted); }
.card > h2 .muted, h2 .small { font-family: var(--font-body); font-weight: 400; }

/* summary cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); gap: 10px; }
.kpi { display: grid; gap: 2px; align-content: start; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.kpi > span { font-size: 12px; color: var(--muted); letter-spacing: .05em; text-transform: uppercase; }
.kpi > b { font-size: 1.25rem; font-weight: 500; overflow-wrap: anywhere; }
.kpi > small { font-size: 12.5px; color: var(--muted); }
.kpi.accent { border-color: var(--accent); } .kpi.accent > b { color: var(--accent); }
.kpi.late > b { color: var(--bad); }
@media (max-width: 400px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi > b { font-size: 1.05rem; } }

/* needs attention */
.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.task { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 8px; background: var(--bg); }
.task > div { display: grid; gap: 1px; min-width: 0; }
.task-n { font-size: 1.3rem; font-weight: 600; min-width: 2ch; text-align: center; }
.task.t-warn { border-left-color: var(--warn); } .task.t-bad { border-left-color: var(--bad); }
@media (max-width: 520px) { .task { grid-template-columns: auto minmax(0, 1fr); } .task > .btn { grid-column: 1 / -1; width: 100%; } }

/* timeline / activity cards */
.timeline { gap: 8px; }
.timeline > li { display: grid; gap: 3px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.timeline > li .btn { justify-self: start; margin-top: 4px; }

/* schedule: table on wide screens, cards on phones */
.sched-cards { display: none; }
@media (max-width: 640px) { .sched-table { display: none; } .sched-cards { display: grid; gap: 10px; } }
.inst-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.inst { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.inst.next { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.inst.st-overdue { border-color: var(--bad); box-shadow: inset 4px 0 0 var(--bad); }
.inst.st-paid, .inst.st-covered { background: var(--bg); }
.inst summary { list-style: none; cursor: pointer; display: grid; gap: 4px; padding: 12px 14px; }
.inst summary::-webkit-details-marker { display: none; }
.inst-head { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; justify-content: space-between; }
.inst-line { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.inst-line > span { color: var(--muted); }
.inst-line.bad > span, .inst-line.bad b { color: var(--bad); }
.inst-more { font-size: 13px; color: var(--accent); font-weight: 600; }
.inst details[open] .inst-more { display: none; }
.inst dl.rows { margin: 0 12px 12px; }
.inst-total { display: grid; grid-template-columns: auto auto; gap: 2px 14px; justify-content: space-between; padding: 8px 4px 0; font-size: 14px; }
.inst-total > span { color: var(--muted); }
.inst-total > b { text-align: right; }
.chip.r-next { background: var(--accent); color: var(--on-accent); }

/* receipt thumbnails and the full-screen viewer */
.proof-tile { display: grid; gap: 4px; justify-items: center; text-decoration: none; color: var(--muted); font-size: 13px; }
.proof-tile img { width: 100%; height: 220px; object-fit: contain; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
@media (max-width: 640px) { .proof-tile img { height: 200px; } }
.proof-none { display: grid; place-items: center; height: 120px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: 13px; text-align: center; padding: 8px; }
.verify-proof img { max-height: none; }
html.viewer-open, html.viewer-open body { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; background: rgba(8, 14, 11, .94); color: #fff; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.viewer[hidden] { display: none; }
.viewer-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 12px; }
.viewer-title { font-weight: 600; font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.viewer-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.viewer-btns .btn { color: var(--fg); }
.viewer-btns .btn.primary { color: var(--on-accent); }
.viewer-area { flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; display: flex; padding: 8px; touch-action: pan-x pan-y pinch-zoom; }
.viewer-area img { margin: auto; width: 100%; max-width: none; height: auto; max-height: 100%; object-fit: contain; background: #fff; border-radius: 6px; }

/* how to pay */
.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: 8px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 0 10px; align-items: start; }
.steps li::before { content: counter(step); grid-row: span 2; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 700; }
.steps li span { color: var(--muted); font-size: 14px; }
.pay-line { display: grid; gap: 0; }
.pay-options { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.qr { width: 200px; }
.qr-big { display: none !important; }

/* borrower home */
.next-hero { align-items: flex-end; }
.next-main { display: grid; gap: 4px; min-width: 0; }
.next-hero .big { font-size: 2.2rem; overflow-wrap: anywhere; }
.next-hero .sub { font-size: 15px; opacity: 1; }
.next-btns { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 640px) { .next-btns { width: 100%; } .next-btns .btn { flex: 1 1 140px; min-height: 48px; font-size: 1.05rem; } }
.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.quick a { display: grid; justify-items: center; gap: 4px; padding: 12px 6px; min-height: 76px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); color: var(--fg); text-decoration: none; font-weight: 600; font-size: 14px; }
.quick a span { font-size: 1.3rem; color: var(--accent); line-height: 1; }
@media (max-width: 520px) { .quick { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.progress-text { margin: 0; }
.loan-pick li a { display: grid; gap: 2px; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--fg); }
.loan-pick li:last-child a { border-bottom: 0; }
.big-btn { min-height: 48px; }

/* notifications */
.notif { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 10px; align-items: start; }
.notif-icon { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.notif.k-overdue .notif-icon, .notif.k-late_fee .notif-icon, .notif.k-pay_rejected .notif-icon { background: var(--bad-soft); color: var(--bad); }
.notif-main { display: grid; gap: 4px; min-width: 0; }
.notif-top { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; justify-content: space-between; }
.notif-title { font-family: var(--font-body); font-size: 15.5px; font-weight: 600; }
.notif-body, .notif-meta { margin: 0; }

/* payments filter and allocation preview */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 10px 12px; align-items: end; padding: 14px; }
.filters .wide { grid-column: 1 / -1; }
.filter-btns { display: flex; gap: 8px; }
.filter-btns .btn { flex: 1 1 auto; }
.alloc-preview { flex-basis: 100%; }
.verify-grid { grid-template-columns: 240px minmax(0, 1fr); }
@media (max-width: 640px) { .verify-grid { grid-template-columns: 1fr; } }

/* agreements, release and reconciliation */
.ag-row { display: grid; gap: 8px; }
.ag-row + .ag-row { border-top: 1px solid var(--line); padding-top: 12px; }
.ag-item h2 { font-size: 1.1rem; }
.recon-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.recon-col { display: grid; gap: 8px; align-content: start; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-width: 0; }
.proposal { border: 1px dashed var(--warn); border-radius: 8px; padding: 12px 14px; background: var(--warn-soft); }
.proposal ol { margin: 6px 0; padding-left: 20px; display: grid; gap: 6px; }
.check-line { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.check-line input { width: 20px; height: 20px; accent-color: var(--accent); }
.chip { white-space: normal; max-width: 100%; overflow-wrap: anywhere; }

/* ---------- Update 13: Reminders & FAQs, referrals ---------- */
.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.check-list li { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: start; }
.check-list li::before { content: '\2713'; color: var(--good); font-weight: 700; text-align: center; }
.help-btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 8px; }
.help-btns .btn, .tut .btn { text-align: center; justify-content: center; }
.help-pick { padding: 12px 14px; }
.faq-list { display: grid; gap: 8px; }
details.faq { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 0 12px; }
details.faq > summary { cursor: pointer; list-style: none; display: grid; grid-template-columns: minmax(0, 1fr) 18px; gap: 8px; align-items: center; font-weight: 600; padding: 12px 0; min-height: 44px; }
details.faq > summary::-webkit-details-marker { display: none; }
details.faq > summary::after { content: '+'; font-size: 1.2rem; color: var(--muted); text-align: center; }
details.faq[open] > summary::after { content: '\2212'; }
details.faq[open] { padding-bottom: 12px; display: grid; gap: 8px; }
details.faq p, details.faq ul { margin: 0; }
details.faq ul { padding-left: 20px; }
details.faq .btn { justify-self: start; }
.tut-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 10px; }
.tut { display: grid; gap: 8px; align-content: start; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: var(--bg); min-width: 0; }
.tut h3 { margin: 0; font-size: 1rem; }
.tut ol { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 14.5px; }
.tut > .btn { align-self: end; }
.fb-support { text-align: center; justify-items: center; }
.fb-support .big-btn { width: min(100%, 360px); }

/* Logo (cream background, so it reads as a badge in dark mode too) */
.brand { display: inline-flex; align-items: center; }
.brand-logo { height: 36px; width: auto; display: block; border-radius: 6px; }
.auth-logo { width: min(100%, 320px); height: auto; display: block; border-radius: 10px; }
@media (max-width: 400px) { .brand-logo { height: 30px; } }

/* ---------- Update 14: actions menu, TEST tag, deletion ---------- */
.actions-menu { position: relative; display: inline-block; }
.actions-menu > summary { list-style: none; cursor: pointer; }
.actions-menu:not([open]) .actions-pop { display: none; }
.actions-menu > summary::-webkit-details-marker { display: none; }
.actions-pop { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 210px; max-width: min(280px, 86vw); display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 4px; }
.actions-pop a { padding: 10px 12px; border-radius: 6px; color: var(--fg); text-decoration: none; font-size: 14.5px; min-height: 40px; display: flex; align-items: center; }
.actions-pop a:hover, .actions-pop a:focus-visible { background: var(--bg); }
.actions-pop a.bad { color: var(--bad); }
.chip.test { background: var(--warn-soft); color: var(--warn); border: 1px dashed var(--warn); }
.del-list li.kept::before { content: '\2022'; color: var(--muted); }
.del-list li.kept { color: var(--muted); }
.recon-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.sub-sect-box { display: grid; gap: 8px; padding: 12px; border: 1px dashed var(--line); border-radius: 8px; }
@media (max-width: 640px) {
  .actions-menu[open] { display: block; width: 100%; flex-basis: 100%; }
  .actions-pop { position: static; max-width: none; margin-top: 6px; box-shadow: none; }
}

/* ========== Update 15: CTMD Cream & Royal Blue theme (overrides the rules above) ========== */
h1, h2 { color: var(--navy); }
.card, .kpi, .summary, .quick a, .tut, .notif, .verify-card { box-shadow: var(--shadow); }
.card { border-color: var(--line); }
.kpi > b, .stat .value { color: var(--fg); }
.kpi.accent { border-color: var(--primary); background: var(--accent-soft); } .kpi.accent > b { color: var(--navy); }
.kpi.late { background: var(--bad-soft); border-color: transparent; } .kpi.late > b { color: var(--bad); }
.review-card { border-color: var(--warn); background: linear-gradient(var(--surface), var(--surface)) padding-box; }

/* buttons: primary royal blue, secondary light blue with navy text, destructive red */
.btn { background: var(--accent-soft); color: var(--navy); border: 1px solid #D3E2FF; font-weight: 600; border-radius: 10px; transition: background .15s, border-color .15s, box-shadow .15s; }
.btn:hover { background: #D9E7FF; border-color: #B9D0FF; }
.btn.primary { background: var(--primary); color: #ffffff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); filter: none; }
.btn.danger { background: var(--bad-soft); color: var(--bad); border-color: #FCA5A5; }
.btn.danger:hover { background: #FECACA; }
.btn:focus-visible { outline: 3px solid #93C5FD; outline-offset: 2px; }
.btn[disabled], .btn:disabled, .btn[aria-busy="true"] { opacity: .6; cursor: progress; }
:root[data-theme="dark"] .btn { border-color: #2A3B60; }
:root[data-theme="dark"] .btn:hover { background: #22345C; }
:root[data-theme="dark"] .btn.danger { border-color: #7F1D1D; }

/* forms: white inputs, light gray borders, blue focus */
.field input, .field select, .field textarea, .search input, .reason, .inline-num, .other-input { background: var(--surface); border: 1px solid #D1D5DB; border-radius: 10px; }
.field input:focus, .field select:focus, .field textarea:focus, .search input:focus, .reason:focus, .inline-num:focus, .other-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, .25); }
.field > span, .field legend { color: var(--fg); font-weight: 500; }
.consent-check, .secret { background: var(--soft); }
:root[data-theme="dark"] .field input, :root[data-theme="dark"] .field select, :root[data-theme="dark"] .field textarea { border-color: #2A3B60; }

/* tables and tabs */
th { color: var(--navy); background: #F8FAFF; }
:root[data-theme="dark"] th { background: var(--soft); }
.tabs { background: var(--surface); box-shadow: var(--shadow); }
.tabs a[aria-current="true"] { background: var(--accent-soft); color: var(--navy); font-weight: 600; }
.chip.r-next { background: var(--primary); color: #fff; }

/* header and navigation */
.topbar { background: var(--surface); box-shadow: 0 1px 0 var(--line); }
.nav-links a { color: var(--navy); display: inline-flex; align-items: center; gap: 8px; }
.nav-links .linkbtn { color: var(--navy); display: inline-flex; align-items: center; gap: 8px; }
.nav-links a[aria-current="page"] { color: var(--navy); }
.nav-links .ico { width: 18px; height: 18px; flex: none; color: var(--muted); }
.nav-links a[aria-current="page"] .ico { color: var(--primary); }
.navbtn span { background: var(--navy); }
.brand-logo { border-radius: 8px; }
@media (max-width: 1120px) {
  .nav-links a, .nav-links .linkbtn { display: flex; padding: 12px 10px; border-radius: 8px; border-bottom: 0; }
  .nav-links a[aria-current="page"] { background: var(--accent-soft); color: var(--navy); }
  .nav-links { gap: 2px; max-height: calc(100dvh - 70px); overflow-y: auto; }
}
/* desktop: white sidebar with the logo on top */
@media (min-width: 1121px) {
  body.has-nav { padding-left: 252px; }
  body.has-nav .topbar { position: fixed; top: 0; bottom: 0; left: 0; width: 252px; border-right: 1px solid var(--line); border-bottom: 0; box-shadow: none; overflow-y: auto; z-index: 30; }
  body.has-nav .topbar-in { flex-direction: column; flex-wrap: nowrap; align-items: stretch; justify-content: flex-start; gap: 20px; padding: 20px 14px; max-width: none; margin: 0; }
  body.has-nav .brand { display: block; }
  body.has-nav .brand-logo { height: auto; width: 100%; max-width: 210px; }
  body.has-nav .nav-links { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 2px; }
  body.has-nav .nav-links a, body.has-nav .nav-links .linkbtn { display: flex; width: 100%; padding: 9px 12px; border-radius: 8px; border-bottom: 0; font-weight: 500; text-align: left; }
  body.has-nav .nav-links a:hover, body.has-nav .nav-links .linkbtn:hover { background: var(--soft); color: var(--navy); }
  body.has-nav .nav-links a[aria-current="page"] { background: var(--accent-soft); font-weight: 600; }
  body.has-nav .nav-links .badge { margin-left: auto; }
  body.has-nav .nav-links form.inline { display: block; }
  body.has-nav .nav-sep { height: 1px; background: var(--line); margin: 8px 4px; }
}
.nav-sep { display: none; }
@media (min-width: 1121px) { body.has-nav .nav-sep { display: block; } }

/* borrower home: next payment light blue, overdue soft red, summary tones */
.next-hero { background: var(--accent-soft); color: var(--fg); border: 1px solid #C9DBFF; box-shadow: var(--shadow); }
.next-hero .label { color: var(--navy); opacity: 1; font-weight: 600; }
.next-hero .big { color: var(--navy); }
.next-hero .sub { opacity: 1; color: var(--fg); }
.next-hero .btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.next-hero .btn.ghost { background: var(--surface); color: var(--navy); border-color: #C9DBFF; }
.next-hero.late { background: var(--bad-soft); border-color: #FCA5A5; }
.next-hero.late .label, .next-hero.late .big { color: var(--bad); }
.next-hero.late .btn.primary { background: var(--primary); color: #fff; }
:root[data-theme="dark"] .next-hero { border-color: #2A3B60; }
dl.rows > div.tone-cream { background: var(--cream-soft); }
dl.rows > div.tone-green { background: var(--good-soft); }
dl.rows > div.tone-amber { background: var(--warn-soft); }
dl.rows > div.tone-red { background: var(--bad-soft); }
dl.rows > div.tone-blue { background: var(--accent-soft); }
.quick a span { color: var(--primary); }
.steps li::before { background: var(--primary); color: #fff; }
.bar span { background: var(--primary); }

/* Need Help card (borrower home) */
.need-help { text-align: center; justify-items: center; background: var(--surface); }
.need-help-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--accent-soft); color: var(--primary); }
.need-help .big-btn { width: min(100%, 360px); }

/* signature pad: neutral blue-gray instead of green */
.sigfs { background: #EEF2F7; color: #111827; }
.sigfs-turn { color: #475569; }
.sigfs-pad { border-color: #CBD5E1; }
.sigfs-line { border-bottom-color: #94A3B8; color: #94A3B8; }
.ref-settings { display: grid; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.ref-settings legend { padding: 0 4px; }
.theme-toggle .ico { color: var(--muted); }
.loan-pick .chip { justify-self: start; width: fit-content; }
/* signed-out banner (session guard) */
.session-banner { position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 200; max-width: 520px; margin: 0 auto; display: grid; gap: 8px; padding: 14px 16px; background: var(--surface); color: var(--fg); border: 2px solid var(--warn); border-radius: 12px; box-shadow: 0 12px 32px rgba(17, 24, 39, .25); }
.session-banner ol { margin: 0; padding-left: 20px; }

/* ---------- Update 16: dashboard cards, capital overview, funds, income charts ---------- */
.sect-title { font-size: 1rem; margin: 0 0 8px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.kpis-6 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); }
.kpis-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
a.kpi-link { color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s; min-height: 44px; }
a.kpi-link:hover, a.kpi-link:focus-visible { border-color: var(--primary); box-shadow: 0 2px 10px rgba(30, 64, 175, .12); }
a.kpi-link > small { overflow-wrap: anywhere; }
.tasks.compact .task { padding: 8px 10px; }
.tasks.compact .task-n { font-size: 1.1rem; }
@media (max-width: 520px) { .tasks.compact .task { grid-template-columns: auto minmax(0, 1fr); } .tasks.compact .task > .btn { grid-column: 1 / -1; justify-self: stretch; } }
.quick-actions .btn { min-height: 40px; }
.cap-groups { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.cap-group { display: grid; gap: 8px; align-content: start; min-width: 0; }
.cap-group h3 { margin: 0; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--navy); }
@media (max-width: 1180px) { .cap-groups { grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); } }
.period-bar .row { gap: 6px; }
.fund-form [hidden] { display: none !important; }
.chart-wrap { display: grid; gap: 6px; min-width: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.inc-chart { width: 100%; height: auto; display: block; --s1: #2563EB; --s2: #D97706; --s3: #0D9488; }
.sw.s1, .inc-chart .s1 { background: #2563EB; fill: #2563EB; }
.sw.s2, .inc-chart .s2 { background: #D97706; fill: #D97706; }
.sw.s3, .inc-chart .s3 { background: #0D9488; fill: #0D9488; }
.inc-chart .grid { stroke: var(--line); stroke-width: 1; }
.inc-chart .zero { stroke: var(--muted); stroke-width: 1; }
.inc-chart .ax { fill: var(--muted); font-size: 11px; font-family: var(--font-mono, monospace); }
.inc-chart .hit { fill: transparent; }
.inc-chart .bar-hit:hover .hit, .inc-chart .bar-hit:focus .hit { fill: var(--accent-soft); }
.inc-chart .bar-hit:focus { outline: none; }
.chart-tip { position: absolute; z-index: 50; max-width: min(320px, calc(100vw - 16px)); padding: 8px 10px; border-radius: 8px; background: var(--fg); color: var(--surface); font-size: 13px; pointer-events: none; box-shadow: 0 6px 18px rgba(17, 24, 39, .25); }
:root[data-theme="dark"] .sw.s1, :root[data-theme="dark"] .inc-chart .s1 { background: #3B82F6; fill: #3B82F6; }
:root[data-theme="dark"] .sw.s3, :root[data-theme="dark"] .inc-chart .s3 { background: #0EA597; fill: #0EA597; }
/* transparent logo (Update 16b): in dark mode the black lettering needs a light backing */
:root[data-theme="dark"] .brand-logo, :root[data-theme="dark"] .auth-logo { background: #FFFBE6; padding: 4px 8px; box-sizing: border-box; }

/* ===== Update 17: compact, mobile-first admin ===== */
/* module shortcuts (dashboard) and filter tabs scroll sideways on phones instead of wrapping */
.mod-bar { display: flex; gap: 6px; overflow-x: auto; scroll-snap-type: x proximity; padding: 2px 2px 6px; margin: -2px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.mod-bar a { flex: 0 0 auto; scroll-snap-align: start; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--fg); text-decoration: none; font-size: 14px; font-weight: 500; white-space: nowrap; }
.mod-bar a:hover, .mod-bar a:focus-visible { border-color: var(--primary); color: var(--navy); }
.mod-bar .ico { width: 17px; height: 17px; color: var(--primary); }
.mod-bar .badge, .tabs .badge { margin-left: 2px; }
.scroll-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.scroll-tabs a { flex: 0 0 auto; white-space: nowrap; }
.toolbar .tabs.scroll-tabs { max-width: 100%; }

/* metric grids: always two columns on phones, amounts never cut */
.kpi > b { font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .kpis, .kpis-6, .kpis-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 9px 10px; gap: 1px; }
  .kpi > span { font-size: 10.5px; letter-spacing: .04em; }
  .kpi > b { font-size: 1.02rem; line-height: 1.25; }
  .kpi > small { font-size: 11.5px; line-height: 1.3; }
  .card { padding: 13px; gap: 10px; }
  h1 { font-size: 1.45rem; }
  h2 { font-size: 1.08rem; }
  .page-head { gap: 8px; }
  .page-head p { font-size: 14px; }
  .sect-title { font-size: 1rem; margin-bottom: 6px; }
  .toolbar { gap: 8px; }
  .search { max-width: none; flex-basis: 100%; }
}
.row.toolbar { gap: 6px; justify-content: flex-end; }
.toolbar-left { justify-content: flex-start; gap: 6px; }

/* needs attention: compact rows with icon, count, issue and a small action */
.task-ico .ico { width: 18px; height: 18px; color: var(--info); display: block; }
.task.t-warn .task-ico .ico { color: var(--warn); } .task.t-bad .task-ico .ico { color: var(--bad); }
.tasks.compact { gap: 6px; }
.tasks.compact .task { grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 4px 10px; padding: 7px 10px; }
.tasks.compact .task > div > b { font-size: 14.5px; line-height: 1.3; }
.tasks.compact .task > div > .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) {
  .tasks.compact .task { grid-template-columns: auto auto minmax(0, 1fr) auto; }
  .tasks.compact .task > .btn { grid-column: auto; justify-self: end; width: auto; min-height: 36px; padding-inline: 10px; }
}
.tasks.compact .task:not(:has(.task-ico)) { grid-template-columns: auto minmax(0, 1fr) auto; }

/* recent activity: one compact row each */
.act-rows { list-style: none; margin: 0; padding: 0; display: grid; }
.act-rows li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 4px 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.act-rows li:first-child { border-top: 0; padding-top: 0; }
.act-main { display: grid; min-width: 0; }
.act-main > b { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-main > .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) { .act-rows li { grid-template-columns: minmax(0, 1fr) auto; } .act-rows li > .chip { display: none; } }

/* expandable record lists (borrowers, agreements): one open at a time */
.acc-list { display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.acc-head, .acc-sum { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.3fr) minmax(0, 1.2fr) minmax(0, 1fr); gap: 4px 12px; align-items: center; padding: 10px 14px; }
.acc-head { font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); background: var(--soft); padding-block: 7px; }
.acc-head .amt, .acc-amt { text-align: right; }
.acc { border-top: 1px solid var(--line); }
.acc > summary { list-style: none; cursor: pointer; min-height: 48px; }
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary:hover { background: var(--bg); }
.acc[open] > summary { background: var(--accent-soft); }
.acc-main { display: grid; min-width: 0; }
.acc-main > b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-main > small { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-st { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.acc-n { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.acc-amt { white-space: nowrap; }
.acc-lbl { display: none; }
.acc-body { padding: 4px 14px 14px; display: grid; gap: 10px; border-top: 1px dashed var(--line); }
.acc-body h3 { font-size: .95rem; margin: 6px 0 2px; }
.acc-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 18px; }
.mini-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.mini-rows li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 2px 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.mini-rows li:first-child { border-top: 0; }
.mini-rows li > b:last-child { text-align: right; }
@media (max-width: 640px) {
  .acc-head { display: none; }
  .acc-sum { grid-template-columns: minmax(0, 1fr) auto; padding: 9px 12px; }
  .acc-st { order: 3; }
  .acc-n { order: 4; text-align: right; color: var(--muted); font-size: 13px; }
  .acc-lbl { display: inline; }
  .acc-body { padding: 4px 12px 12px; }
  .acc-cols { grid-template-columns: 1fr; }
  .mini-rows li { grid-template-columns: minmax(0, 1fr) auto; }
}
.actions-pop form { display: block; margin: 0; }
.pop-item { display: flex; width: 100%; align-items: center; min-height: 40px; padding: 10px 12px; border: 0; border-radius: 6px; background: none; color: var(--fg); font: inherit; font-size: 14.5px; text-align: left; cursor: pointer; }
.pop-item:hover, .pop-item:focus-visible { background: var(--bg); }
.pop-item.bad { color: var(--bad); }
.pop-note { display: block; padding: 8px 12px; font-size: 12.5px; color: var(--muted); }
.pager { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }

/* loan details: six metrics, two per row on phones */
.kpis-compact .kpi > small { overflow-wrap: anywhere; }

/* repayment structures */
.schedule tr.st-open td, .inst.st-open { background: var(--cream-soft); }
.chip.r-open { background: var(--cream-soft); color: var(--warn); }
.recon-preview { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--primary); border-radius: 10px; background: var(--accent-soft); }
.recon-preview h3 { font-size: 1rem; }
.flash.small { font-size: 13.5px; padding: 8px 10px; }
.mini-rows li > .chip { justify-self: start; }

/* ---------- Update 18 ---------- */
/* Menu: one vertical column, Logout at the bottom, no sideways scroll; the page doesn't scroll behind it */
.nav-logout { margin: 0; }
@media (max-width: 1120px) {
  .nav-links { flex-wrap: nowrap; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; max-height: calc(100dvh - 64px - env(safe-area-inset-top, 0px)); padding: 6px 12px calc(14px + env(safe-area-inset-bottom, 0px)); }
  .nav-links > a, .nav-links > .linkbtn, .nav-links .nav-logout, .nav-links .nav-logout .linkbtn { width: 100%; max-width: 100%; min-width: 0; }
  .nav-links > a > span, .nav-links .linkbtn > span { min-width: 0; overflow-wrap: anywhere; }
  .nav-links .badge { margin-left: auto; }
  .nav-links .nav-logout { display: block; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
  body.nav-open { overflow: hidden; }
}
@media (min-width: 1121px) { body.has-nav .nav-links form.nav-logout { display: block; } }
/* Dashboard recent activity: name and activity readable on two lines */
.act-main > b, .act-main > .small { white-space: normal; }
.act-main > b { overflow-wrap: anywhere; }
.act-what { font-size: 13px; color: var(--fg); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.act-rows li { grid-template-columns: minmax(0, 1fr) auto; }
.act-side { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: flex-end; }
@media (max-width: 420px) { .act-side .chip { display: inline-flex; } .act-side { flex-direction: column; align-items: flex-end; } }
/* Loans & Capital overview: compact grid (2 columns on phones) */
.cap-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); gap: 8px; }
.cap-grid .kpi { padding: 10px 12px; min-height: 0; }
.cap-grid .kpi > b { font-size: 1.15rem; }
.cap-grid .kpi > small { font-size: 12px; overflow-wrap: anywhere; }
@media (max-width: 720px) { .cap-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cap-grid .kpi > b { font-size: 1rem; } }
/* Fund history rows and wider popovers for correction forms */
.fund-rows .acc-st { font-size: 12.5px; color: var(--muted); }
.acc-amt.struck { text-decoration: line-through; opacity: .6; }
.actions-pop.wide-pop { min-width: min(560px, 92vw); max-width: min(640px, 94vw); }
.fund-fields { grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); }
li.struck { opacity: .6; }
.warn-text { color: var(--warn); }
/* Select Existing Loan picker */
.loan-pick-list li .row { gap: 6px; }
.loan-pick-list li[hidden] { display: none; }
/* Borrower: summary grid and expandable loan details */
.b-sum { grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); }
@media (max-width: 720px) { .b-sum { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.loan-more { display: grid; gap: 8px; }
.loan-more > summary { list-style: none; justify-self: start; }
.loan-more > summary::-webkit-details-marker { display: none; }
.loan-more[open] > summary { background: var(--accent-soft); }
.loan-more-body { display: grid; gap: 8px; }

/* ---------- Update 19: actions menus float above lists (never clipped) and open as a sheet on touch screens ---------- */
.actions-pop.is-floating { position: fixed; right: auto; z-index: 60; max-width: min(300px, calc(100vw - 16px)); margin: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; box-shadow: 0 10px 28px rgba(0,0,0,.22); }
.sheet-head, .sheet-cancel { display: none; }
.actions-backdrop { position: fixed; inset: 0; z-index: 69; background: rgba(10,20,40,.38); }
html.sheet-open, html.sheet-open body { overflow: hidden; }
.actions-menu.as-sheet[open] { display: inline-block; width: auto; flex-basis: auto; }
.actions-menu.as-sheet .actions-pop { position: fixed; top: auto; right: 0; bottom: 0; left: 0; z-index: 70; min-width: 0; max-width: none; max-height: 82dvh; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; margin: 0; border-radius: 14px 14px 0 0; border-bottom: 0; padding: 6px 10px calc(12px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -8px 28px rgba(0,0,0,.25); gap: 2px; }
@media (min-width: 641px) { .actions-menu.as-sheet .actions-pop { left: 50%; right: auto; width: min(460px, calc(100vw - 32px)); transform: translateX(-50%); bottom: 16px; border-radius: 14px; border-bottom: 1px solid var(--line); padding-bottom: 10px; } }
.actions-menu.as-sheet .sheet-head { display: block; padding: 10px 12px 8px; font-size: 13px; color: var(--muted); text-align: center; border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow-wrap: anywhere; }
.actions-menu.as-sheet .pop-item, .actions-menu.as-sheet .actions-pop a { min-height: 48px; font-size: 16px; justify-content: center; text-align: center; }
.actions-menu.as-sheet .pop-note { text-align: center; }
.actions-menu.as-sheet .sheet-cancel { display: flex; margin-top: 6px; border-top: 1px solid var(--line); border-radius: 0 0 6px 6px; font-weight: 600; color: var(--accent, var(--fg)); }

/* ---------- Update 20: borrower Documents & Attachments ---------- */
.bdoc-list { list-style: none; margin: 0; padding: 0; display: grid; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.bdoc-list li { display: flex; align-items: center; gap: 6px 12px; padding: 8px 12px; border-top: 1px solid var(--line); }
.bdoc-list li:first-child { border-top: 0; }
.bdoc-main { display: grid; min-width: 0; flex: 1 1 auto; }
.bdoc-main > b { font-size: 14.5px; overflow-wrap: anywhere; }
.bdoc-main > small { font-size: 12.5px; }
.bdoc-act { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; flex: 0 0 auto; }
.bdoc-act form { margin: 0; }
.bdoc-up > summary { list-style: none; display: inline-flex; width: auto; }
.bdoc-up > summary::-webkit-details-marker { display: none; }
.bdoc-up[open] > summary { margin-bottom: 10px; }
.bdoc-up > form { padding: 12px; border: 1px dashed var(--line); border-radius: 8px; }
@media (max-width: 560px) {
  .bdoc-list li { flex-wrap: wrap; }
  .bdoc-act { width: 100%; justify-content: flex-start; }
  .bdoc-act .btn { flex: 1 1 0; justify-content: center; min-height: 40px; }
  .bdoc-act form { display: flex; flex: 1 1 0; }
  .bdoc-act form .btn { width: 100%; }
}

/* Update 23: application form — character reference accordions, structured address */
.ref-accs { display: grid; gap: 10px; }
.ref-acc { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-width: 0; }
.ref-acc > summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 12px 14px; min-height: 44px; -webkit-tap-highlight-color: transparent; }
.ref-acc > summary::-webkit-details-marker { display: none; }
.ref-acc > summary::before { content: '\203A'; display: inline-block; width: 12px; font-size: 1.3rem; line-height: 1; color: var(--muted); transition: transform .15s; }
.ref-acc[open] > summary::before { transform: rotate(90deg); }
.ref-acc > summary b { font-size: 15px; }
.ref-sum { color: var(--muted); font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.ref-acc[open] .ref-sum { display: none; }
.ref-acc > .grid2 { padding: 0 14px 14px; }
.addr .addr-grid { gap: 10px 12px; }
.addr-grid .field { align-content: start; }
.addr .addr-zip input { max-width: 10em; }

/* Update 24: loan term with its unit (14 | Weeks) */
.field > .term-pair { display: flex; gap: 6px; min-width: 0; font-size: inherit; color: inherit; font-weight: inherit; }
.term-pair input { flex: 1 1 0; min-width: 0; }
.term-pair select { flex: 0 0 auto; width: auto; min-width: 104px; }

/* Update 26: 2×2 ID photo (application form, application review, borrower details). Square frame, never stretched. */
.photo-frame { position: relative; display: grid; place-items: center; align-content: center; gap: 4px; width: 150px; aspect-ratio: 1 / 1; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); overflow: hidden; color: var(--muted); text-decoration: none; flex: 0 0 auto; }
.photo-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 30%; }
.photo-frame img[hidden] { display: none; }
.photo-frame svg { width: 46%; height: auto; fill: none; stroke: currentColor; stroke-width: 1.4; opacity: .55; }
.photo-frame span { font-size: 12px; }
.photo-frame:not(.is-empty) svg, .photo-frame:not(.is-empty) span { visibility: hidden; }
label.photo-frame { cursor: pointer; border-style: dashed; }
label.photo-frame:not(.is-empty) { border-style: solid; }
.photo-frame.sm { width: 104px; }
.photo-box { display: grid; justify-items: center; gap: 8px; text-align: center; }
.photo-box .photo-label { font-weight: 600; font-size: 14px; }
.photo-box small { color: var(--muted); max-width: 240px; }
.photo-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: start; }
.photo-box:focus-within .photo-frame { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (min-width: 760px) {
  .apply-first { grid-template-columns: minmax(0, 1fr) 172px; column-gap: 24px; }
  .apply-first > * { grid-column: 1; }
  .apply-first > .photo-box { grid-column: 2; grid-row: 1 / span 3; align-self: start; }
  .apply-first .photo-frame { width: 160px; }
}
.app-head { align-items: center; justify-content: flex-start; }
.app-head .app-head-main { flex: 1 1 220px; min-width: 0; }
.bprof { grid-template-columns: auto minmax(0, 1fr); align-items: start; column-gap: 18px; }
.bprof .photo-actions { justify-content: flex-start; }
.bprof .bdoc-up[open] { flex-basis: 100%; }
@media (max-width: 560px) {
  .bprof { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .bprof .bprof-main { width: 100%; display: grid; gap: 10px; }
  .bprof .photo-actions { justify-content: center; }
}
.bprof-main { display: grid; gap: 10px; min-width: 0; }
.bdoc-group { font-size: 13px; margin: 4px 0 -6px; color: var(--muted); font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
@media print { .photo-actions, .photo-box small { display: none !important; } }

/* Update 27: Recent activity — completed events only, compact rows; the card is as tall as its rows */
.act-card { align-content: start; gap: 10px; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.card-head h2 { margin: 0; }
.card-head .view-all { margin-left: auto; white-space: nowrap; }
.act-card .act-rows li { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 8px 0; min-height: 0; }
.act-card .act-rows li:first-child { padding-top: 0; }
.act-card .act-rows li:last-child { padding-bottom: 0; }
.act-card .act-main { gap: 2px; }
.act-card .act-main > b { white-space: normal; overflow-wrap: anywhere; line-height: 1.3; font-size: 14.5px; }
.act-card .act-main > b .num { font-weight: 600; }
.act-card .act-what { display: block; -webkit-line-clamp: unset; overflow: visible; color: var(--muted); font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.act-card .act-side { flex-direction: row; flex-wrap: nowrap; align-items: center; justify-content: flex-end; gap: 8px; }
.act-card .act-side .btn { white-space: nowrap; }
@media (max-width: 600px) {
  .act-card .act-rows li { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .act-card .act-side { flex-direction: row; align-items: center; justify-content: space-between; }
}

/* Update 28: fund calculations */
a.kpi-link .kpi-calc { font-style: normal; font-size: .78rem; color: var(--primary); font-weight: 600; margin-top: 2px; }
.calc-table td { padding: 8px 10px; vertical-align: top; }
.calc-table td.num { text-align: right; white-space: nowrap; width: 1%; }
.calc-table tr.sub td { padding-top: 14px; border-bottom: 0; }
.calc-table tr.total td { border-top: 2px solid var(--line, #d9d2c3); font-size: 1.05rem; }
.calc-table small { display: block; }
@media (max-width: 600px) { .calc-table td { padding: 7px 6px; } }
