/* LoanDesk — admin console */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --hover: #eef3f0;
  --border: #e0e6e3;
  --border-strong: #c9d3ce;
  --text: #15201b;
  --text-2: #435049;
  --muted: #69766f;
  --brand: #0f5132;
  --brand-hover: #0b4128;
  --brand-ink: #ffffff;
  --brand-soft: #e2f1e9;
  --ok: #146c43;
  --ok-soft: #dcf2e5;
  --warn: #8a5200;
  --warn-soft: #fff0d3;
  --bad: #b02a37;
  --bad-soft: #fde3e6;
  --info: #1c5cab;
  --info-soft: #e2edfb;
  /* DPD ageing ramp: one hue, light → dark (validated ordinal ramp) */
  --age-1: #86b6ef;
  --age-2: #5598e7;
  --age-3: #2a78d6;
  --age-4: #1c5cab;
  --age-5: #104281;
  --age-6: #0b3263;
  --age-7: #072248;
  --focus: 0 0 0 3px rgb(15 81 50 / .28);
  --shadow-sm: 0 1px 2px rgb(16 24 20 / .06);
  --shadow: 0 1px 3px rgb(16 24 20 / .08), 0 1px 2px rgb(16 24 20 / .04);
  --shadow-lg: 0 18px 48px rgb(16 24 20 / .18);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar: 248px;
  --topbar: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #171d1a;
    --surface-2: #1c2420;
    --hover: #212b26;
    --border: #2a3530;
    --border-strong: #3a4842;
    --text: #e7eeea;
    --text-2: #bac7c0;
    --muted: #8d9b94;
    --brand: #2c9c66;
    --brand-hover: #35b075;
    --brand-soft: #173a29;
    --ok: #4cc286;
    --ok-soft: #173a29;
    --warn: #f0a23a;
    --warn-soft: #3a2c12;
    --bad: #ef6a77;
    --bad-soft: #3d1c21;
    --info: #86b6ef;
    --info-soft: #182a42;
    --age-1: #1c5cab;
    --age-2: #3987e5;
    --age-3: #6da7ec;
    --age-4: #9ec5f4;
    --age-5: #cde2fb;
    --age-6: #e2eefc;
    --age-7: #f3f8fe;
    --focus: 0 0 0 3px rgb(44 156 102 / .4);
    --shadow: 0 1px 3px rgb(0 0 0 / .4);
    --shadow-lg: 0 18px 48px rgb(0 0 0 / .55);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; font-weight: 650; }
h2 { font-size: 1rem; font-weight: 650; }
h3 { font-size: .9rem; font-weight: 600; }
code { font: .85em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: transform .2s ease;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; height: var(--topbar); padding: 0 18px; border-bottom: 1px solid var(--border); }
.sidebar .brand img { width: 30px; height: 30px; border-radius: 8px; }
.sidebar .brand b { font-size: .98rem; }
.sidebar .brand small { display: block; color: var(--muted); font-size: .72rem; font-weight: 500; letter-spacing: .02em; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-label { padding: 14px 10px 6px; font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .count { margin-left: auto; font-size: .72rem; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); }
.sidebar-foot { padding: 12px 18px; border-top: 1px solid var(--border); font-size: .75rem; color: var(--muted); }

.main { margin-left: var(--sidebar); min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar); padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .title { flex: 1; min-width: 0; font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .menu-btn { display: none; }
.content { padding: 24px 28px 48px; max-width: 1320px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.scrim { position: fixed; inset: 0; z-index: 35; background: rgb(10 16 13 / .45); }

/* user menu */
.usermenu { position: relative; }
.usermenu > summary { list-style: none; display: flex; align-items: center; gap: 9px; padding: 5px 8px 5px 5px; border-radius: 99px; cursor: pointer; border: 1px solid transparent; }
.usermenu > summary::-webkit-details-marker { display: none; }
.usermenu > summary:hover, .usermenu[open] > summary { background: var(--surface); border-color: var(--border); }
.usermenu .who { line-height: 1.2; }
.usermenu .who small { display: block; color: var(--muted); font-size: .72rem; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.menu button:hover { background: var(--hover); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

.avatar {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  font-size: .75rem; font-weight: 700; letter-spacing: .02em;
}
.avatar.lg { width: 44px; height: 44px; font-size: .9rem; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; white-space: nowrap; cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:focus-visible, .input:focus, .select:focus, .icon-btn:focus-visible, textarea:focus { outline: none; box-shadow: var(--focus); border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-ghost { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger-ghost:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: none; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }

.input, .select, textarea {
  width: 100%; min-height: 38px; padding: 8px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit;
}
.select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
.search { position: relative; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 36px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 550; font-size: .86rem; color: var(--text-2); }
.field .hint { font-size: .8rem; color: var(--muted); }
.field .req { color: var(--bad); }
.form { display: flex; flex-direction: column; gap: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; min-width: 0; }
.error-box { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); font-size: .88rem; }
.error-box:empty { display: none; }
.info-box { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--info-soft); color: var(--text); font-size: .88rem; }
.warn-box { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--text); font-size: .88rem; }

.roles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.role-opt { position: relative; display: block; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; }
.role-opt input { position: absolute; opacity: 0; }
.role-opt b { display: block; font-size: .88rem; }
.role-opt small { display: block; color: var(--muted); font-size: .76rem; line-height: 1.35; margin-top: 2px; }
.role-opt:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.role-opt:has(input:focus-visible) { box-shadow: var(--focus); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 260px; max-width: 380px; }
.toolbar .select { width: auto; min-width: 150px; flex: 0 1 auto; }
.toolbar .spacer { flex: 1; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head p { margin: 2px 0 0; font-size: .82rem; color: var(--muted); }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: 1.4fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
@media (min-width: 1600px) { .kpis { grid-template-columns: repeat(6, 1fr); } }
.kpi { padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); color: inherit; display: block; }
a.kpi:hover { border-color: var(--border-strong); text-decoration: none; }
.kpi .label { display: flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 550; color: var(--muted); }
.kpi .value { margin-top: 6px; font-size: 1.6rem; font-weight: 680; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi .sub { margin-top: 2px; font-size: .8rem; color: var(--muted); }
.kpi.alert .value { color: var(--bad); }
.kpi.attention { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
.data th {
  position: sticky; top: 0;
  padding: 10px 14px; text-align: left; white-space: nowrap;
  font-size: .74rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data tbody tr:last-child td { border-bottom: 0; }
.data tbody tr.clickable { cursor: pointer; }
.data tbody tr:hover td { background: var(--hover); }
.data tbody tr.selected td { background: var(--brand-soft); }
.data .right, .data th.right { text-align: right; }
.data .check { width: 40px; padding-right: 0; }
.data th button.sort { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.data th button.sort:focus-visible { box-shadow: var(--focus); border-radius: 4px; }
.data th button.sort[aria-sort] { color: var(--text); }
.cell-main { font-weight: 560; }
.cell-sub { font-size: .8rem; color: var(--muted); }
.row-actions { display: flex; justify-content: flex-end; gap: 2px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--border); font-size: .85rem; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 6px; }
.pager .select { min-height: 32px; padding-top: 4px; padding-bottom: 4px; width: auto; }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty .icon { width: 36px; height: 36px; stroke-width: 1.5; margin-bottom: 8px; color: var(--border-strong); }
.empty b { display: block; color: var(--text); font-size: .95rem; margin-bottom: 4px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.age { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-variant-numeric: tabular-nums; }
.age i { width: 10px; height: 10px; border-radius: 3px; }
.a-current { background: var(--age-1); } .a-1-30 { background: var(--age-2); } .a-31-60 { background: var(--age-3); }
.a-61-90 { background: var(--age-4); } .a-90\+ { background: var(--age-5); } .a-closed { background: var(--border-strong); }

/* ---------- ageing chart ---------- */
.ageing { display: flex; flex-direction: column; gap: 4px; }
.ageing-row { position: relative; display: grid; grid-template-columns: 112px 1fr 150px; align-items: center; gap: 12px; padding: 7px 8px; margin: 0 -8px; border-radius: var(--radius-sm); color: inherit; }
.ageing-row:hover { background: var(--hover); text-decoration: none; }
.ageing-row .lbl { font-size: .85rem; color: var(--text-2); }
.ageing-row .track { height: 14px; display: flex; align-items: center; }
.ageing-row .bar { height: 14px; min-width: 3px; border-radius: 0 4px 4px 0; }
.ageing-row .val { text-align: right; font-size: .84rem; font-variant-numeric: tabular-nums; }
.ageing-row .val b { font-weight: 650; }
.ageing-row .tip {
  position: absolute; left: 124px; bottom: calc(100% - 2px); z-index: 5;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--surface);
  font-size: .78rem; line-height: 1.45; white-space: nowrap;
  opacity: 0; transform: translateY(4px); pointer-events: none; transition: .12s;
}
.ageing-row:hover .tip, .ageing-row:focus-visible .tip { opacity: 1; transform: none; }

/* ---------- activity ---------- */
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--border); }
.activity li:last-child { border-bottom: 0; }
.activity .what { flex: 1; min-width: 0; }
.activity .when { font-size: .78rem; color: var(--muted); white-space: nowrap; }

/* ---------- bulk bar ---------- */
.bulkbar {
  position: sticky; top: calc(var(--topbar) + 8px); z-index: 20;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px;
  background: var(--text); color: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.bulkbar .select { width: auto; min-width: 220px; min-height: 34px; padding-top: 4px; padding-bottom: 4px; }
.bulkbar .btn { min-height: 34px; }
.bulkbar .linkish { all: unset; cursor: pointer; text-decoration: underline; font-size: .85rem; opacity: .85; }
.bulkbar .count { font-weight: 650; }

/* ---------- drawer & dialog ---------- */
.drawer {
  position: fixed; inset: 0 0 0 auto; z-index: 60;
  width: min(560px, 100vw);
  display: flex; flex-direction: column;
  background: var(--surface); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .22s ease;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-head .grow { flex: 1; min-width: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }
.drawer-scrim { position: fixed; inset: 0; z-index: 55; background: rgb(10 16 13 / .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer-scrim.open { opacity: 1; pointer-events: auto; }

dialog.dlg {
  width: min(460px, calc(100vw - 32px)); padding: 0;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.dlg::backdrop { background: rgb(10 16 13 / .5); }
.dlg-body { padding: 22px 22px 6px; }
.dlg-body h2 { font-size: 1.05rem; margin-bottom: 8px; }
.dlg-body p { margin: 0 0 12px; color: var(--text-2); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 20px; }
.secret { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--border-strong); font: 600 1.15rem ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; }

.dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; margin: 0; font-size: .9rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.section { margin-bottom: 24px; }
.section > h3 { margin-bottom: 10px; font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.section.fold > summary { list-style: none; cursor: pointer; }
.section.fold > summary::-webkit-details-marker { display: none; }
.section.fold > summary > h3 { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.section.fold > summary:hover > h3 { color: var(--text); }
.fold-caret { width: 14px; height: 14px; transition: transform .15s; }
.section.fold[open] .fold-caret { transform: rotate(90deg); }
.mini-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 22px; }
.mini-kpis div { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.mini-kpis span { display: block; font-size: .72rem; color: var(--muted); }
.mini-kpis b { font-size: 1.02rem; font-variant-numeric: tabular-nums; }
.compact td, .compact th { padding: 7px 10px; font-size: .84rem; }

/* ---------- import ---------- */
.steps { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-weight: 550; font-size: .85rem; }
.step i { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); font-style: normal; font-size: .78rem; font-weight: 700; }
.step.active { color: var(--brand); border-color: var(--brand); }
.step.active i { background: var(--brand); color: var(--brand-ink); }
.step.done i { background: var(--brand-soft); color: var(--brand); }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 220px; padding: 28px; text-align: center;
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); cursor: pointer; transition: .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }
.dropzone .icon { width: 40px; height: 40px; stroke-width: 1.5; color: var(--brand); }
.dropzone b { font-size: 1rem; }
.cols { columns: 2; column-gap: 28px; margin: 0; padding-left: 18px; font-size: .86rem; }
.cols li { margin-bottom: 4px; break-inside: avoid; }
.stat-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-row .kpi .value { font-size: 1.35rem; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 40px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg); font-size: .9rem; animation: toast-in .2s ease; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art {
  display: flex; flex-direction: column; justify-content: space-between; padding: 48px;
  background: linear-gradient(150deg, #0f5132 0%, #0b3d26 60%, #08301e 100%); color: #e8f3ed;
}
.login-art h1 { font-size: 2rem; color: #fff; margin: 18px 0 10px; }
.login-art p { max-width: 420px; color: #b9d6c6; font-size: 1rem; }
.login-art ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.login-art li { display: flex; gap: 10px; align-items: center; color: #d6eadf; }
.login-art li .icon { color: #7fd1a6; }
.login-art img { width: 46px; height: 46px; border-radius: 12px; }
.login-form { display: grid; place-items: center; padding: 32px 20px; }
.login-card { width: min(380px, 100%); }
.login-card h2 { font-size: 1.4rem; margin-bottom: 6px; }
.login-card > p { color: var(--muted); margin: 0 0 24px; }
.login-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

/* Language toggle (login card and account menu) */
.lang-toggle { display: inline-flex; flex: none; padding: 2px; gap: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
.lang-toggle button { min-height: 28px; padding: 0 9px; border: 0; border-radius: 5px; background: none; color: var(--text-2); font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; }
.lang-toggle button:hover { background: var(--hover); }
.lang-toggle button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.lang-toggle button:focus-visible { outline: none; box-shadow: var(--focus); }
.menu-lang { display: flex; align-items: center; gap: 10px; padding: 6px 10px; color: var(--text); }
.menu-lang .lang-toggle { flex: 1; }
.menu-lang .lang-toggle button { flex: 1; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .grid.two { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .shell.nav-open .sidebar { transform: none; }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 40px; }
  .login { grid-template-columns: 1fr; }
  .login-art { display: none; }
}
@media (max-width: 760px) {
  .usermenu .who { display: none; }
  .page-head { align-items: stretch; flex-direction: column; }
  .page-actions .btn { flex: 1; }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .toolbar .select { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .form-row { grid-template-columns: 1fr; }
  .roles { grid-template-columns: 1fr; }
  .mini-kpis { grid-template-columns: repeat(2, 1fr); }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .cols { columns: 1; }
  .ageing-row { grid-template-columns: 84px 1fr; }
  .ageing-row .val { grid-column: 2; text-align: left; margin-top: -4px; }
  .ageing-row .tip { display: none; }
  .bulkbar .select { min-width: 0; flex: 1 1 100%; }
  .kpi .value { font-size: 1.3rem; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 13px 14px; }
  .dl.keep { grid-template-columns: 1fr auto; gap: 8px 16px; }
  .dl.keep dd { margin: 0; text-align: right; }

  /* tables become cards */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { position: relative; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  table.responsive tbody tr:hover td { background: none; }
  /* label left, value(s) stacked on the right */
  table.responsive td { display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: baseline; padding: 4px 0; border: 0; text-align: right; }
  table.responsive td > * { grid-column: 2; justify-self: end; }
  table.responsive td::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 3; color: var(--muted); font-size: .8rem; text-align: left; }
  table.responsive td.primary { display: block; text-align: left; padding-bottom: 6px; padding-right: 36px; }
  table.responsive td.primary > * { justify-self: start; }
  table.responsive td.primary::before, table.responsive td.check::before, table.responsive td.actions::before { content: none; }
  table.responsive td.check { position: absolute; right: 14px; top: 14px; width: auto; padding: 0; }
  table.responsive td.actions { display: block; padding-top: 8px; }
  table.responsive td.actions .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  table.responsive td:empty { display: none; }
  .drawer-body { padding: 16px; }
  .toasts { right: 12px; left: 12px; bottom: 12px; max-width: none; }
}

@media print {
  .sidebar, .topbar, .page-actions, .toolbar, .bulkbar, .table-foot { display: none !important; }
  .main { margin: 0; }
}

/* ---------- help & guides ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); flex-wrap: wrap; }
.seg-btn { border: 0; background: none; color: var(--text-2); font: inherit; font-weight: 550; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.seg-btn:hover { background: var(--hover); }
.seg-btn.active { background: var(--brand); color: var(--brand-ink); }
.seg-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.help-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; margin-bottom: 12px; }
.help-index { position: sticky; top: calc(var(--topbar) + 12px); max-height: calc(100vh - var(--topbar) - 40px); overflow-y: auto; padding: 8px; }
.help-cat { padding: 12px 10px 4px; font-size: .7rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.help-link { display: block; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-size: .9rem; }
.help-link:hover { background: var(--hover); text-decoration: none; color: var(--text); }
.help-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.help-content .card-head { align-items: flex-start; }
.help-for { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.help-article { line-height: 1.6; font-size: .95rem; max-width: 760px; }
.help-article h4 { margin: 18px 0 6px; font-size: .95rem; }
.help-article ul, .help-article ol { padding-left: 22px; margin: 8px 0; }
.help-article li { margin-bottom: 6px; }
.help-steps { counter-reset: step; list-style: none; padding-left: 0 !important; }
.help-steps li { counter-increment: step; position: relative; padding-left: 40px; min-height: 28px; margin-bottom: 10px !important; }
.help-steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); font-size: .82rem; font-weight: 700;
}
.help-tips { margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--info-soft); }
.help-tips ul { margin: 6px 0 0; }
.help-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: .9rem; }
.help-table th, .help-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.help-table th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.help-dl { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0; }
.help-dl dt { font-weight: 650; }
.help-dl dd { margin: 0; }

.checklist { margin-bottom: 16px; border-color: color-mix(in srgb, var(--brand) 35%, var(--border)); }
.check-steps { list-style: none; margin: 0; padding: 8px 18px 14px; display: grid; gap: 4px; }
.check-steps li { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.check-steps li > a:first-of-type { flex: 1; font-weight: 550; color: var(--text); }
.check-steps li.done > a:first-of-type { color: var(--muted); text-decoration: line-through; }
.check-mark { width: 22px; height: 22px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--border-strong); }
.check-steps li.done .check-mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.check-mark .icon { width: 14px; height: 14px; stroke-width: 3; }

#print-area { display: none; }
@media (max-width: 1023px) {
  .help-layout { grid-template-columns: 1fr; }
  .help-index { position: static; max-height: none; }
}
@media (max-width: 760px) {
  .seg { width: 100%; }
  .seg-btn { flex: 1; padding: 6px 6px; font-size: .85rem; }
  .help-dl { grid-template-columns: 1fr; gap: 2px; }
  .help-dl dd { margin-bottom: 8px; }
  .help-content .card-head { flex-direction: column; }
  .help-for { justify-content: flex-start; }
}
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block; color: #000; }
  #print-area h1 { font-size: 20pt; margin-bottom: 4pt; }
  #print-area .print-cat { font-size: 15pt; margin: 18pt 0 6pt; border-bottom: 1px solid #999; padding-bottom: 4pt; }
  #print-area .print-topic { break-inside: avoid; margin-bottom: 12pt; max-width: none; }
  #print-area h3 { font-size: 12.5pt; margin: 10pt 0 2pt; }
  #print-area .help-steps li::before { background: #000; color: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print-area .help-tips { background: #f2f2f2; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- plan features and support sessions ---------- */
/* Anything marked data-needs="feature" disappears when the company's plan doesn't include it. */
body[data-off~="loan_import"] [data-needs~="loan_import"],
body[data-off~="loan_export"] [data-needs~="loan_export"],
body[data-off~="audit_log"] [data-needs~="audit_log"],
body[data-off~="bank_deposits"] [data-needs~="bank_deposits"] { display: none !important; }

.support-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 16px;
  color: #fff; font-size: .88rem; line-height: 1.35;
  background: repeating-linear-gradient(135deg, #a3202e 0 14px, #8d1a26 14px 28px);
  box-shadow: 0 -4px 16px rgb(0 0 0 / .2);
}
.support-banner > span { flex: 1; min-width: 0; }
.support-banner .btn { background: #fff; color: #8d1a26; border-color: #fff; font-weight: 650; }
.shell.with-banner { padding-bottom: 72px; }
.shell.with-banner .sidebar { bottom: 52px; }
@media (max-width: 760px) {
  .shell.with-banner { padding-bottom: 110px; }
  .shell.with-banner .sidebar { bottom: 88px; }
}

/* Areas: state → district → pincode */
.card.area { margin-bottom: 12px; overflow: hidden; }
.area-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; cursor: pointer; list-style: none; }
.area-head::-webkit-details-marker { display: none; }
.area-head:hover { background: var(--hover); }
.area-caret { transition: transform .15s; flex: none; }
details[open] > .area-head > .area-caret { transform: rotate(90deg); }
.area-fig { color: var(--muted); font-size: .86rem; font-variant-numeric: tabular-nums; }
.area-district { border-top: 1px solid var(--border); }
.area-district > .area-head { padding-left: 34px; }
.area-district .table-wrap { border-top: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: -6px 0 18px; border-bottom: 1px solid var(--border); }
.tabs a { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; color: var(--text-2); text-decoration: none; font-weight: 600; font-size: .9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs a svg { width: 16px; height: 16px; }
.field.inline { display: flex; flex-direction: column; gap: 4px; }
/* Reports: the filters with quick periods, and two tables side by side */
.report-bar { align-items: flex-end; }
.report-periods { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); border-radius: 99px; padding: 6px 12px; font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; }
.chip:hover { color: var(--text); }
.chip.on { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
/* Many columns: the name keeps its width and the table scrolls sideways. */
.report-table td.primary { min-width: 190px; }
.report-table th, .report-table td.num { white-space: nowrap; }
.report-scroll .table-wrap { max-height: 440px; overflow: auto; }
.report-two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 900px) { .report-two { grid-template-columns: 1fr; } }
.field.inline span { font-size: .76rem; color: var(--muted); }

/* Team: hierarchy tree and reporting line */
.tree-bar { flex-wrap: wrap; }
.tree-bar .tree-state { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.tree-bar .tree-state .select { width: auto; min-width: 200px; }
.home-area { display: flex; gap: 8px; align-items: flex-start; line-height: 1.5; }
.home-area svg { flex: none; margin-top: 2px; }
.tree-row { display: grid; grid-template-columns: minmax(300px, 2.2fr) 56px 84px 110px 110px 92px 190px; align-items: center; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--border); }
.tree-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; border-top: 0; }
.tree-row .num { text-align: right; font-variant-numeric: tabular-nums; }
.tree-row .who { display: flex; gap: 10px; align-items: center; min-width: 0; }
.tree-row.lvl1 .who { padding-left: 28px; }
.tree-row.lvl2 { background: var(--surface-2); }
.tree-row.lvl2 .who { padding-left: 56px; }
.tree-row .row-actions { justify-content: flex-end; }
.tree .caret svg { transition: transform .15s; }
.tree .caret.open svg { transform: rotate(90deg); }
.tree .caret-space { width: 34px; flex: none; }
.post { font-size: .66rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.post.os { background: #fef3c7; color: #92400e; } .post.sh { background: #ede9fe; color: #5b21b6; } .post.dc { background: #e0f2fe; color: #075985; } .post.ag { background: var(--brand-soft); color: var(--brand); }
.chain { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .88rem; }
.chain .node { padding: 5px 11px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); }
.chain .node.on { background: var(--brand-soft); color: var(--brand); border-color: transparent; font-weight: 650; }
.chain .node.new { border: 1.5px dashed var(--brand); color: var(--brand); font-weight: 650; background: transparent; }
.chain svg { width: 14px; height: 14px; color: var(--muted); }
@media (max-width: 900px) {
  .tree-row { grid-template-columns: 1fr 1fr; }
  .tree-head { display: none; }
  .tree-row .who { grid-column: 1 / -1; }
  .tree-row .num::before { content: attr(data-label) ': '; color: var(--muted); font-size: .75rem; }
  .tree-row .num { text-align: left; }
  .tree-row .row-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* Circle editor */
.circle-state { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin: 0; }
.circle-state .row { display: flex; gap: 8px; align-items: center; }
.circle-districts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; margin: 8px 0 0 24px; font-size: .88rem; }
.modes-table .input { min-width: 120px; padding: 6px 8px; }
.settings-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.settings-row .row { display: flex; gap: 6px; align-items: center; }
.settings-row .grow { flex: 1; }
.settings-row .input { max-width: 320px; }
.wa-msg { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 4px; }
.wa-msg textarea { width: 100%; margin-top: 8px; }
.state-pick { max-height: 52vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.state-pick fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px 10px; margin: 0; }
.state-pick legend { font-weight: 600; font-size: .85rem; padding: 0 4px; }
.state-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 12px; font-size: .88rem; }
.state-grid .row { display: flex; gap: 8px; align-items: center; }
/* Billing tree */
.bill-row td:first-child { white-space: nowrap; }
.bill-row.l1 td:first-child { padding-left: 34px; } .bill-row.l2 td:first-child { padding-left: 58px; } .bill-row.l3 td:first-child { padding-left: 82px; }
.bill-row.l0 { font-weight: 650; } .bill-row.l3 { color: var(--text-2); }

/* Recovery desk: seven ageing bands, 0–30 days to over 2 years */
.ab-0 { background: var(--age-1); } .ab-1 { background: var(--age-2); } .ab-2 { background: var(--age-3); }
.ab-3 { background: var(--age-4); } .ab-4 { background: var(--age-5); } .ab-5 { background: var(--age-6); } .ab-6 { background: var(--age-7); }
.tabs .count { font-size: .75rem; color: var(--muted); margin-left: 4px; }

/* ID cards: settings with a sample card beside them, photo thumbnails in the approvals table */
.idc-settings { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 24px; align-items: start; }
.idc-fields .field { display: block; margin-bottom: 10px; }
.idc-fields .field .input { display: block; width: 100%; max-width: 480px; margin-top: 4px; }
.idc-preview { display: grid; gap: 10px; position: sticky; top: 12px; }
.idc-preview img { width: 100%; aspect-ratio: 540 / 856; border-radius: 10px; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .12); }
.idc-thumb { width: 44px; height: 55px; object-fit: cover; border-radius: 4px; background: #dde4ec; display: block; }
.idc-sig-thumb { width: 105px; height: 35px; object-fit: contain; display: block; background: #fff; border: 1px solid var(--border); border-radius: 4px; }
@media (max-width: 760px) { .idc-settings { grid-template-columns: 1fr; } .idc-preview { grid-template-columns: 1fr 1fr; position: static; } .idc-preview > div { grid-column: 1 / -1; } }

/* Team → People by state */
.by-state button.link { all: unset; cursor: pointer; color: var(--brand); font-weight: 600; }
.by-state button.link:hover, .by-state button.link:focus-visible { text-decoration: underline; }
.by-state tfoot th { border-top: 2px solid var(--border-strong); font-weight: 700; }
/* People by state: folded away at first */
.by-state-fold > p { margin: 0 16px 10px; }
.by-state-fold[open] > .area-head { border-bottom: 1px solid var(--border); margin-bottom: 10px; }
/* A District Coordinator's districts, ticked */
.dist-pick .state-pick { max-height: 40vh; margin: 6px 0; }
.dist-pick .dist-dc { display: block; color: var(--warn); }
.dist-pick .state-grid .row { align-items: flex-start; }
