:root {
  color-scheme: light;
  --bg: #f4f7f3;
  --panel: #ffffff;
  --ink: #1c2a24;
  --muted: #64736d;
  --line: #dbe4dd;
  --green: #116b4f;
  --green-2: #0c523d;
  --gold: #b98216;
  --red: #b42318;
  --blue: #255c99;
  --shadow: 0 18px 45px rgba(28, 42, 36, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: inherit; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px clamp(14px, 4vw, 36px);
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand {
  font-weight: 800;
  color: var(--green);
  text-decoration: none;
  white-space: nowrap;
}
nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
nav a {
  flex: 0 0 auto;
  padding: 9px 11px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
}
nav a.active, nav a:hover {
  color: var(--green);
  background: #e8f2ed;
}
.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px clamp(12px, 4vw, 30px) 60px;
}
.auth-page, body:has(.auth-card) {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.install-shell { width: min(760px, 100%); padding: 18px; }
.auth-card {
  width: min(430px, calc(100vw - 28px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  box-shadow: var(--shadow);
}
.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(16px, 4vw, 24px);
  box-shadow: var(--shadow);
}
.narrow-panel {
  max-width: 520px;
}
.heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
h1, h2 { margin: 0 0 14px; line-height: 1.14; letter-spacing: 0; }
h1 { font-size: clamp(28px, 6vw, 42px); }
h2 { font-size: 20px; }
.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0;
}
.muted { color: var(--muted); }
.success { color: var(--green); font-weight: 700; }
.error { color: var(--red); font-weight: 700; }
.toast {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
}
.toast.success { border-color: #b9ddcf; background: #edf8f3; }
.toast.error { border-color: #f0b8b3; background: #fff1ef; }
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.metric {
  min-width: 0;
  min-height: 100px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.metric strong {
  display: block;
  margin-top: 12px;
  font-size: 25px;
  overflow-wrap: anywhere;
}
.details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}
.grid-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.wide { grid-column: 1 / -1; }
.stack { display: grid; gap: 13px; }
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.loan-amount-field {
  color: var(--ink);
  font-size: 16px;
}
.loan-amount-field input {
  min-height: 54px;
  padding: 13px 14px;
  border: 2px solid #137457;
  font-size: 20px;
  font-weight: 800;
}
.field-help {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cbd8d1;
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}
textarea { resize: vertical; }
.loan-type-menu {
  display: grid;
  gap: 10px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  min-inline-size: 0;
}
.loan-type-menu legend {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.limit-summary {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
}
.limit-summary h2 {
  margin-bottom: 12px;
  font-size: 18px;
}
.limit-summary dl {
  grid-template-columns: 1fr auto;
  gap: 8px 18px;
}
.limit-summary dd {
  text-align: right;
}
.loan-summary {
  padding: 16px;
  border: 1px solid #b9ddcf;
  border-radius: 8px;
  background: #edf8f3;
}
.loan-summary h2 { margin-bottom: 12px; font-size: 18px; }
.loan-summary dl { grid-template-columns: 1fr auto; gap: 8px 18px; }
.loan-summary dd { text-align: right; }
.rate-schedule-panel { margin-top: 18px; }
.rate-schedule { margin-top: 18px; }
.rate-schedule h3 { margin: 0 0 8px; font-size: 17px; }
.loan-type-button {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 62px;
  padding: 12px 14px;
  border: 2px solid #cbd8d1;
  border-radius: 8px;
  color: var(--ink) !important;
  background: #fff !important;
  text-align: left;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.loan-type-button + .loan-type-button { margin-top: 8px; }
.loan-type-button.is-active {
  border-color: var(--green);
  background: #0f7658 !important;
  color: #fff !important;
  box-shadow: 0 0 0 3px rgba(14, 116, 88, .14);
}
.loan-type-button.is-active small { color: #e5f5ee; }
.loan-type-button strong {
  font-size: 15px;
}
.loan-type-button small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.loan-type-option {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 11px;
  min-height: 62px;
  padding: 12px 14px;
  border: 1px solid #cbd8d1;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}
.collateral-fields[hidden] { display: none; }
.loan-type-option:has(input:checked) {
  border-color: var(--green);
  background: #e8f2ed;
  box-shadow: 0 0 0 2px rgba(14, 116, 88, .12);
}
.loan-type-option input {
  width: 18px;
  min-height: 18px;
  flex: 0 0 auto;
}
.loan-type-option span {
  display: grid;
  gap: 3px;
}
.loan-type-option strong {
  font-size: 15px;
}
.loan-type-option small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.check {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
}
.check input { width: 18px; min-height: 18px; }
.button, button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
.primary { background: var(--green); color: #fff; }
.primary:hover { background: var(--green-2); }
.secondary { background: #e8f2ed; color: var(--green); }
.danger { background: var(--red); color: #fff; }
.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}
.small {
  min-height: 34px;
  padding: 7px 10px;
  background: #edf3f8;
  color: var(--blue);
}
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  background: #fff;
}
th, td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #f9fbfa;
}
.access-table { min-width: 1120px; }
.access-table input[type="checkbox"] { width: 18px; min-height: 18px; }
.access-table input[type="number"] { min-width: 150px; }
.borrower-access-list {
  display: grid;
  gap: 12px;
}
.borrower-access-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.borrower-access-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.borrower-access-heading strong,
.borrower-access-heading small {
  display: block;
}
.borrower-access-heading strong {
  color: var(--ink);
  font-size: 17px;
}
.borrower-access-heading small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.borrower-access-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-top: 14px;
}
.borrower-access-fields label:last-child {
  grid-column: 1 / -1;
}
@media (max-width: 640px) {
  .borrower-access-heading {
    display: grid;
  }
  .borrower-access-fields {
    grid-template-columns: 1fr;
  }
  .borrower-access-fields label:last-child {
    grid-column: auto;
  }
}
dl {
  display: grid;
  grid-template-columns: minmax(120px, .45fr) 1fr;
  gap: 12px;
  margin: 0;
}
dt { color: var(--muted); font-weight: 800; }
dd { margin: 0; font-weight: 700; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  background: #edf3f8;
  color: var(--blue);
}
.badge.pending { color: var(--gold); background: #fff5dc; }
.badge.approved, .badge.disbursed, .badge.active { color: var(--green); background: #e8f2ed; }
.badge.rejected { color: var(--red); background: #fff1ef; }
.badge.paid { color: #33543f; background: #e4efe6; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.photo-grid img, .avatar {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.avatar { max-width: 180px; }

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }
  .topbar nav {
    grid-column: 1 / -1;
    order: 3;
  }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .details-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .app-shell { padding-top: 14px; }
  .heading {
    align-items: stretch;
    flex-direction: column;
  }
  .metrics, .grid-form { grid-template-columns: 1fr; }
  .panel, .auth-card { padding: 16px; }
  dl { grid-template-columns: 1fr; gap: 4px; }
  .metric strong { font-size: 21px; }
  .button, button { width: 100%; }
  .topbar form .ghost { width: auto; }
}
