/* =========================================================
   Collections Desk — design system
   Desktop: dark sidebar · Tablet: icon rail · Phone: bottom tabs + card tables
   ========================================================= */
:root {
  --bg: #f4f5f1; --surface: #ffffff; --surface-2: #f6f7f4; --surface-3: #eef0eb; --line: #e4e7e1; --line-2: #d6dad3;
  --text: #121a16; --text-2: #3b4540; --muted: #6c7670;
  --brand: #0b5d3b; --brand-600: #094d31; --brand-ink: #ffffff; --brand-soft: #e6f2eb; --brand-ring: rgba(11, 93, 59, .18);
  --side-1: #0c3b29; --side-2: #072a1c; --side-ink: rgba(255, 255, 255, .7);
  --gold: #a87b12; --gold-2: #d4a72c; --gold-soft: #fbf4df;
  --red: #c0392b; --red-soft: #fdeeec; --amber: #b56d07; --amber-soft: #fef4e2; --blue: #1d5fa8; --blue-soft: #e9f1fb;
  --green: #17803f; --green-soft: #e5f4ea; --violet: #6b3fb5; --violet-soft: #f1ebfb; --wa: #1faa59;
  --r-lg: 18px; --r: 14px; --r-sm: 10px;
  --sh-1: 0 1px 2px rgba(18, 26, 22, .04), 0 1px 3px rgba(18, 26, 22, .05);
  --sh-2: 0 2px 6px rgba(18, 26, 22, .04), 0 10px 30px rgba(18, 26, 22, .07);
  --sh-3: 0 24px 60px rgba(10, 20, 15, .22);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, "Noto Sans Tamil", "Helvetica Neue", Arial, sans-serif;
  --side-w: 232px; --top-h: 64px; --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1210; --surface: #151c18; --surface-2: #19211d; --surface-3: #1f2924; --line: #26302b; --line-2: #33403a;
    --text: #e9eeeb; --text-2: #c3ccc7; --muted: #8f9a94;
    --brand: #37a874; --brand-600: #2e9365; --brand-ink: #06120c; --brand-soft: #16301f; --brand-ring: rgba(55, 168, 116, .25);
    --side-1: #0b1712; --side-2: #08110d; --gold: #e2b54b; --gold-2: #e2b54b; --gold-soft: #2c2614;
    --red: #f07264; --red-soft: #3a1d1a; --amber: #eaa94a; --amber-soft: #352a16; --blue: #74aaf0; --blue-soft: #172739;
    --green: #50c584; --green-soft: #15301f; --violet: #ad8cf0; --violet-soft: #271f3d;
    --sh-1: 0 1px 2px rgba(0, 0, 0, .3); --sh-2: 0 8px 30px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14.5px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 24px; line-height: 1.2; margin: 2px 0 4px; letter-spacing: -.02em; font-weight: 750; }
h2 { font-size: 16px; margin: 28px 0 12px; letter-spacing: -.01em; font-weight: 700; }
h3 { font-size: 15px; margin: 0 0 6px; font-weight: 700; }
code { font-size: 12.5px; background: var(--surface-3); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hide { display: none !important; }
.m-only { display: none !important; }
::selection { background: var(--brand-ring); }

/* ---------- layout shell ---------- */
#sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 30; display: flex; flex-direction: column; padding: 18px 14px;
  background: linear-gradient(185deg, var(--side-1), var(--side-2)); color: #fff; }
.side-brand { display: flex; align-items: center; gap: 11px; color: #fff; padding: 4px 8px 20px; }
.side-brand img { width: 38px; height: 38px; border-radius: 11px; box-shadow: 0 4px 14px rgba(0, 0, 0, .3); }
.side-brand span { display: flex; flex-direction: column; line-height: 1.1; }
.side-brand b { font-size: 16px; letter-spacing: -.01em; }
.side-brand small { color: var(--gold-2); font-weight: 700; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; margin-top: 3px; }
#nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
#nav .nav-label { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: rgba(255, 255, 255, .38); padding: 14px 12px 6px; font-weight: 700; }
#nav a { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px; color: var(--side-ink); font-weight: 600; font-size: 14px; transition: background .15s, color .15s; }
#nav a svg { width: 19px; height: 19px; flex: none; opacity: .9; }
#nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
#nav a.on { background: rgba(255, 255, 255, .1); color: #fff; }
#nav a.on::before { content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--gold-2); }
#nav a .count { margin-left: auto; font-size: 11.5px; background: var(--gold-2); color: #1d1503; border-radius: 99px; padding: 0 7px; font-weight: 800; }
.side-user { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, .1); background: rgba(255, 255, 255, .04); color: #fff; cursor: pointer; text-align: left; min-height: 0; justify-content: flex-start; }
.side-user:hover { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .18); }
.side-user .av { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--gold-2); color: #1d1503; font-weight: 800; font-size: 13px; flex: none; }
.side-user .who { min-width: 0; line-height: 1.25; } .side-user .who b { display: block; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .who small { color: rgba(255, 255, 255, .55); font-size: 11.5px; font-weight: 500; }

#mainCol { min-height: 100vh; }
body.authed #mainCol { margin-left: var(--side-w); }
#topbar { position: sticky; top: 0; z-index: 20; height: var(--top-h); display: flex; align-items: center; gap: 14px; padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); }
.top-brand { display: none; }
.top-brand img { width: 34px; height: 34px; border-radius: 10px; display: block; }
#searchForm { position: relative; flex: 1; max-width: 560px; }
#searchForm svg { position: absolute; left: 13px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
#searchBox { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 12px; padding: 0 14px 0 38px; background: var(--surface); box-shadow: var(--sh-1); min-height: 0; }
#searchBox:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
.today-chip { margin-left: auto; font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.avatar-btn { width: 40px; height: 40px; min-height: 0; padding: 0; border-radius: 50%; background: var(--brand); color: var(--brand-ink); border: 0; font-weight: 800; font-size: 13.5px; box-shadow: var(--sh-1); }
.avatar-btn:hover { background: var(--brand-600); }
main { max-width: 1440px; margin: 0 auto; padding: 24px 24px 70px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); font-size: 13.5px; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.back:hover { color: var(--brand); }

/* bottom tab bar (phones only) */
#tabbar { display: none; }

/* ---------- controls ---------- */
.btn, button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line-2); background: var(--surface); padding: 9px 15px;
  border-radius: var(--r-sm); cursor: pointer; font-weight: 650; min-height: 40px; color: var(--text); font-size: 14px; line-height: 1.2; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s; }
.btn:hover, button:hover { border-color: var(--muted); }
.btn:active, button:active { transform: translateY(1px); }
.btn:focus-visible, button:focus-visible, a:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--brand-ring); }
.btn.primary, button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); box-shadow: 0 1px 2px rgba(11, 93, 59, .3); }
.btn.primary:hover, button.primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn.danger, button.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 45%, transparent); background: transparent; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-3); }
button:disabled { opacity: .5; cursor: default; }
.btn.call { background: var(--green-soft); color: var(--green); border-color: transparent; }
.btn.call:hover { border-color: color-mix(in srgb, var(--green) 40%, transparent); }
.btn.wa { background: var(--wa); color: #fff; border-color: var(--wa); }
.btn.sm, button.sm { min-height: 32px; padding: 5px 11px; font-size: 13px; border-radius: 9px; }
.btn svg, button svg { width: 17px; height: 17px; flex: none; }
.btn.icon { padding: 5px 9px; }
input, select, textarea { border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 9px 12px; background: var(--surface); min-height: 42px; width: 100%; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236c7670' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 15px; }
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); }
label.f { display: block; margin: 14px 0 6px; font-size: 12.5px; color: var(--text-2); font-weight: 650; }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; min-height: 34px; padding: 6px 13px; border-radius: 9px; font-size: 13.5px; color: var(--text-2); box-shadow: none; }
.seg button.on { background: var(--surface); box-shadow: var(--sh-1); color: var(--brand); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 13px; min-height: 36px; font-size: 13.5px; font-weight: 650; cursor: pointer; color: var(--text-2); box-shadow: var(--sh-1); }
.chip:hover { border-color: var(--line-2); }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip .n { display: inline-block; min-width: 22px; text-align: center; padding: 0 7px; margin-left: 7px; border-radius: 999px; background: var(--surface-3); color: var(--text); font-size: 12px; font-weight: 750; }
.chip.on .n { background: rgba(255, 255, 255, .22); color: inherit; }
.chip[data-k="broken"] .n { background: var(--red-soft); color: var(--red); } .chip.on[data-k="broken"] .n { background: rgba(255, 255, 255, .22); color: inherit; }

/* ---------- cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--sh-1); }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); }
.kpi { position: relative; overflow: hidden; padding: 16px 18px 15px; }
.kpi::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); opacity: .85; }
.grid > .kpi:nth-child(4n+2)::after { background: var(--gold-2); }
.grid > .kpi:nth-child(4n+3)::after { background: var(--blue); }
.grid > .kpi:nth-child(4n+4)::after { background: var(--violet); }
.kpi .l { font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.kpi .v { font-size: 25px; font-weight: 780; letter-spacing: -.025em; font-variant-numeric: tabular-nums; margin-top: 4px; line-height: 1.15; }
.kpi .s { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--surface-3); color: var(--text-2); white-space: nowrap; line-height: 1.5; }
.b-GOLD { background: var(--gold-soft); color: var(--gold); }
.b-UNSECURE { background: var(--violet-soft); color: var(--violet); }
.b-BIKE, .b-CAR { background: var(--blue-soft); color: var(--blue); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-green { background: var(--green-soft); color: var(--green); }
.b-blue { background: var(--blue-soft); color: var(--blue); }
.empty { text-align: center; padding: 56px 16px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--r); }
.more { display: flex; width: 100%; margin-top: 14px; }
.alert { padding: 12px 14px; border-radius: 12px; background: var(--amber-soft); color: var(--amber); font-weight: 600; font-size: 13.5px; border: 1px solid color-mix(in srgb, var(--amber) 22%, transparent); }
.alert a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 4px 0 16px; }
details summary { cursor: pointer; font-weight: 650; padding: 4px 0; }
pre { white-space: pre-wrap; font-size: 12px; background: var(--surface-2); padding: 12px; border-radius: 12px; overflow: auto; max-height: 420px; border: 1px solid var(--line); }
.bar { height: 9px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--gold-2)); border-radius: 99px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); box-shadow: var(--sh-1); max-height: calc(100vh - 250px); }
.tbl-wrap.tall { max-height: calc(100vh - 290px); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13.5px; }
th, td { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 2; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); background: var(--surface-2); font-weight: 750; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.c, th.c { text-align: center; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--brand-soft); }
.grid-tbl td { vertical-align: top; }
.grid-tbl th, .grid-tbl td { padding-left: 7px; padding-right: 7px; }
.grid-tbl td:first-child, .grid-tbl th:first-child { width: 1%; white-space: nowrap; padding-left: 14px; }
.grid-tbl tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.grid-tbl tbody tr.click:hover td { background: var(--brand-soft); }
.grid-tbl td.name { min-width: 160px; max-width: 230px; white-space: normal; }
.grid-tbl td.name b { font-weight: 700; }
.grid-tbl td.wrap { white-space: normal; min-width: 128px; max-width: 260px; }
.grid-tbl td.wrap-s { white-space: normal; min-width: 110px; max-width: 150px; }
.grid-tbl td.wrap-t { white-space: normal; max-width: 150px; }
.grid-tbl td.wrap-t .badge { margin: 0 3px 4px 0; }
.grid-tbl .clip { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.grid-tbl td.nowrap { white-space: nowrap; }
.grid-tbl td.due { color: var(--amber); font-weight: 700; }
.grid-tbl a.phone { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.grid-tbl td.act > * + * { margin-left: 6px; }
.sheet td { vertical-align: middle; }
.sheet tbody tr:nth-child(even) td { background: transparent; }
.sheet tr.grp td { border-top: 1px solid var(--line-2); }
.sheet tr.cont td { border-bottom-color: color-mix(in srgb, var(--line) 60%, transparent); }
.sheet tbody tr.sub td { background: var(--surface-2); font-weight: 700; font-size: 12.5px; color: var(--text-2); }
.sheet tbody tr.click:hover td { background: var(--brand-soft); }

/* ---------- customer page ---------- */
.hero { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; padding: 20px 22px; }
.hero .av { width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #fff;
  background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 55%, var(--gold-2))); box-shadow: var(--sh-2); }
.hero h1 { margin: 0 0 2px; }
.hero .meta { color: var(--muted); font-size: 13px; }
.hero .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.hero .totals { display: flex; gap: 26px; text-align: right; }
.hero .totals .l { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; }
.hero .totals .v { font-size: 22px; font-weight: 780; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.hero .totals .v.due { color: var(--amber); }
.actionbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 4px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr); gap: 22px; align-items: start; }
.two-col > div > h2:first-child { margin-top: 22px; }
.loan { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; background: var(--surface); box-shadow: var(--sh-1); }
.loan.closed { opacity: .6; }
.loan-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.loan-head b { font-size: 15px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 10px 16px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.kv div span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 650; }
.kv div b { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 14px; }
.docs { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.doc { font-size: 12.5px; border: 1px dashed var(--line-2); border-radius: 999px; padding: 4px 11px; cursor: pointer; background: transparent; min-height: 30px; font-weight: 650; color: var(--muted); box-shadow: none; }
.doc.on { border-style: solid; background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, transparent); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 14px 1fr; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--line-2); box-shadow: 0 0 0 3px var(--surface); }
.dot.PAID, .dot.pay { background: var(--green); } .dot.PROMISE { background: var(--amber); } .dot.REFUSED, .dot.WRONG_NUMBER { background: var(--red); } .dot.NO_ANSWER, .dot.SWITCHED_OFF { background: var(--muted); }

/* ---------- dialog / sheet ---------- */
#sheetWrap { position: fixed; inset: 0; z-index: 60; }
.scrim { position: absolute; inset: 0; background: rgba(8, 18, 13, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade .15s ease-out; }
#sheet { position: absolute; left: 16px; right: 16px; top: 6vh; max-height: 88vh; overflow: auto; background: var(--surface); border-radius: 20px; padding: 22px 24px;
  max-width: 660px; margin: 0 auto; animation: pop .18s cubic-bezier(.2, .9, .3, 1.2); box-shadow: var(--sh-3); border: 1px solid var(--line); }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.outcomes { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 8px; }
.outcomes button { min-height: 58px; flex-direction: column; gap: 2px; font-size: 13.5px; text-align: center; line-height: 1.25; white-space: normal; border-radius: 12px; }
.outcomes button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
.outcomes button small { font-weight: 500; opacity: .7; font-size: 11px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; position: sticky; bottom: -22px; background: var(--surface); padding: 12px 0 2px; }
.sheet-actions button { flex: 1; min-height: 48px; font-size: 15px; border-radius: 12px; }
#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: #10201a; color: #fff; padding: 12px 18px; border-radius: 14px; opacity: 0; pointer-events: none;
  transition: .22s; z-index: 80; max-width: calc(100% - 32px); font-weight: 600; box-shadow: var(--sh-3); font-size: 14px; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--red); }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; margin: -24px -24px -70px; }
.auth-brand { position: relative; overflow: hidden; color: #fff; padding: 56px 60px; display: flex; flex-direction: column; justify-content: space-between; gap: 30px;
  background: radial-gradient(1200px 500px at -10% 110%, rgba(212, 167, 44, .25), transparent 60%), linear-gradient(160deg, #0f4a33, #062419); }
.auth-brand::after { content: ""; position: absolute; right: -120px; top: -120px; width: 420px; height: 420px; border-radius: 50%; border: 1px solid rgba(212, 167, 44, .25); box-shadow: 0 0 0 60px rgba(255, 255, 255, .02), 0 0 0 120px rgba(255, 255, 255, .015); pointer-events: none; }
.auth-brand .mark { display: flex; align-items: center; gap: 12px; font-weight: 750; font-size: 18px; }
.auth-brand .mark img { width: 44px; height: 44px; border-radius: 12px; }
.auth-brand h2 { font-size: 38px; line-height: 1.12; letter-spacing: -.03em; margin: 0 0 14px; max-width: 460px; font-weight: 780; }
.auth-brand h2 em { font-style: normal; color: var(--gold-2); }
.auth-brand p { color: rgba(255, 255, 255, .7); max-width: 430px; margin: 0; font-size: 15px; }
.auth-points { display: grid; gap: 12px; margin-top: 30px; }
.auth-points div { display: flex; gap: 10px; align-items: center; color: rgba(255, 255, 255, .85); font-size: 14px; }
.auth-points i { width: 26px; height: 26px; border-radius: 8px; background: rgba(212, 167, 44, .18); color: var(--gold-2); display: grid; place-items: center; font-style: normal; font-weight: 800; font-size: 13px; flex: none; }
.auth-foot { color: rgba(255, 255, 255, .45); font-size: 12.5px; }
.auth-side { display: grid; place-items: center; padding: 40px 24px; }
.auth-form { width: 100%; max-width: 400px; padding: 32px 30px; border-radius: 22px; box-shadow: var(--sh-2); }
.auth-form h1 { font-size: 26px; }
.auth-form .logo-m { display: none; }
.auth-form button.primary { width: 100%; margin-top: 20px; min-height: 48px; font-size: 15px; border-radius: 12px; }

/* =========================================================
   Responsive
   ========================================================= */
/* Tablet / small laptop: icon rail */
@media (max-width: 1100px) {
  :root { --side-w: 76px; }
  .side-brand span, #nav a span, #nav .nav-label, .side-user .who { display: none; }
  .side-brand { justify-content: center; padding: 4px 0 18px; }
  #nav a { justify-content: center; padding: 12px; }
  #nav a .count { position: absolute; top: 3px; right: 5px; margin: 0; font-size: 10px; padding: 0 5px; }
  .side-user { justify-content: center; padding: 8px; }
  #topbar { padding: 0 20px; } main { padding: 22px 20px 60px; }
  .two-col { grid-template-columns: 1fr; }
  .auth { margin: -22px -20px -60px; }
  .auth-brand { padding: 44px 40px; } .auth-brand h2 { font-size: 32px; }
}

/* Phones: bottom tab bar + tables become cards */
@media (max-width: 760px) {
  html, body { font-size: 14px; }
  #sidebar { display: none !important; }
  body.authed #mainCol { margin-left: 0; }
  #topbar { padding: 0 12px; gap: 10px; height: 58px; }
  .top-brand { display: block; }
  .today-chip { display: none; }
  #searchBox { height: 40px; font-size: 15px; }
  main { padding: 16px 14px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom)); }
  h1 { font-size: 21px; }
  h2 { margin-top: 22px; }
  #tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; justify-content: space-around; gap: 2px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); }
  #tabbar[hidden] { display: none !important; }
  #tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; border-radius: 12px; color: var(--muted); font-size: 10.5px; font-weight: 700; position: relative; min-width: 0; }
  #tabbar a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  #tabbar a svg { width: 22px; height: 22px; }
  #tabbar a.on { color: var(--brand); }
  #tabbar a.on svg { background: var(--brand-soft); border-radius: 10px; padding: 3px 8px; width: 40px; height: 28px; margin: -3px 0; }
  #tabbar a .count { position: absolute; top: 0; left: 56%; font-size: 11px; background: var(--red); color: #fff; border-radius: 99px; padding: 0 5px; font-weight: 800; }
  #toast { bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom)); }

  .page-head { align-items: stretch; }
  .page-head > .row { width: 100%; }
  .page-head > .row > * { flex: 1; min-width: 0; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin-left: -14px; margin-right: -14px; padding: 2px 14px 6px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  #sheet .chips { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
  .seg { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
  .seg button { flex: none; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 13px 14px; } .kpi .v { font-size: 19px; } .kpi .l { font-size: 10.5px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .card { padding: 14px; }

  /* every data table becomes a list of cards */
  .tbl-wrap { max-height: none !important; overflow: visible; border: 0; background: transparent; box-shadow: none; }
  .tbl-wrap table, .tbl-wrap tbody, .tbl-wrap tr, .tbl-wrap td { display: block; width: auto; }
  .tbl-wrap thead { display: none; }
  .tbl-wrap tbody tr { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
    padding: 14px; margin-bottom: 10px; box-shadow: var(--sh-1); }
  .tbl-wrap tbody tr td { padding: 0; border: 0 !important; background: transparent !important; white-space: normal; text-align: left !important; max-width: none !important; min-width: 0 !important; width: auto !important; font-size: 13.5px; }
  .tbl-wrap td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 1px; }
  .tbl-wrap td:empty, .tbl-wrap td.dash, .tbl-wrap td.mh { display: none; }
  .tbl-wrap tbody tr td, .tbl-wrap tbody tr td.nowrap { white-space: normal !important; overflow-wrap: anywhere; }
  .tbl-wrap tbody tr td .badge { white-space: nowrap; }
  .doc { min-height: 38px; padding: 6px 13px; font-size: 13px; }
  input[type="checkbox"] { width: 24px; height: 24px; }
  main, .card, .loan, .hero { overflow-wrap: anywhere; }
  .hero h1 { font-size: 19px; }
  .tbl-wrap td.name, .tbl-wrap td.wrap, .tbl-wrap td.full, .tbl-wrap td[colspan] { grid-column: 1 / -1; }
  .tbl-wrap td.name { order: -2; font-size: 15.5px; padding-right: 54px; }
  .tbl-wrap td.name::before { display: none !important; }
  .tbl-wrap td.sno { position: absolute; top: 14px; right: 14px; font-size: 12px; color: var(--muted); }
  .tbl-wrap td.sno::before { display: inline !important; content: "#" !important; font-size: 12px !important; letter-spacing: 0 !important; text-transform: none !important; font-weight: 500 !important; }
  .tbl-wrap td.act { grid-column: 1 / -1; display: flex !important; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line) !important; }
  .tbl-wrap td.act::before { display: none !important; }
  .tbl-wrap td.act > * { flex: 1; min-height: 42px; margin: 0 !important; }
  .m-only { display: inline-flex !important; }
  span.m-only { display: inline !important; }
  .grid-tbl .clip { white-space: normal; max-width: none; }
  .sheet tr.cont { margin-top: -4px; }
  .sheet tbody tr.sub { background: var(--surface-3); box-shadow: none; padding: 10px 14px; border-style: dashed; }
  .sheet tbody tr.sub td::before { display: none !important; }

  .hero { grid-template-columns: auto 1fr; padding: 16px; gap: 14px; }
  .hero .av { width: 48px; height: 48px; font-size: 17px; border-radius: 14px; }
  .hero .totals { grid-column: 1 / -1; justify-content: space-between; text-align: left; padding-top: 12px; border-top: 1px dashed var(--line); }
  .hero .totals .v { font-size: 20px; }
  .actionbar { display: grid; grid-template-columns: 1fr 1fr; }
  .actionbar > * { width: 100%; }
  .kv { grid-template-columns: 1fr 1fr; }

  #sheet { left: 0; right: 0; top: auto; bottom: 0; max-height: 92vh; border-radius: 22px 22px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .22s cubic-bezier(.2, .9, .3, 1); border-bottom: 0; }
  #sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 9px; background: var(--line-2); margin: 0 auto 12px; }
  .outcomes { grid-template-columns: 1fr 1fr; }
  .sheet-actions { bottom: calc(-16px - env(safe-area-inset-bottom)); padding-bottom: 6px; }

  .auth { grid-template-columns: 1fr; margin: -16px -14px 0; min-height: 100vh; }
  .auth-brand { display: none; }
  .auth-side { padding: 24px 16px; align-content: center; background: radial-gradient(600px 300px at 50% -10%, var(--brand-soft), transparent 70%); }
  .auth-form { padding: 26px 20px; }
  .auth-form .logo-m { display: block; width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px; box-shadow: var(--sh-2); }
  .auth-form h1, .auth-form > p { text-align: center; }
}
@keyframes up { from { transform: translateY(40px); opacity: .3; } }
@media (max-width: 380px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .kpi .v { font-size: 17px; }
  .filters { grid-template-columns: 1fr; }
  #tabbar a { font-size: 10.5px; padding: 6px 0; }
  #tabbar a svg { width: 21px; height: 21px; }
}

/* ---------- edit forms ---------- */
.form-sec { border: 0; margin: 14px 0 0; padding: 14px 0 0; border-top: 1px solid var(--line); min-width: 0; }
.form-sec:first-of-type { border-top: 0; padding-top: 4px; }
.form-sec legend { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--brand); padding: 0; float: left; width: 100%; margin-bottom: 2px; }
.form-sec legend + * { clear: both; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; clear: both; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label.f { margin-top: 10px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.note-box { margin-top: 10px; padding: 8px 11px; border-radius: 10px; background: var(--gold-soft); color: var(--text-2); font-size: 13px; border: 1px solid color-mix(in srgb, var(--gold-2) 25%, transparent); }
.edit-lines { margin-top: 4px; color: var(--text-2); line-height: 1.6; }
.edit-lines s { color: var(--muted); }
.dot.edit { background: var(--blue); }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }

/* follow-up date & time */
.when { display: grid; gap: 10px; }
.when-time { display: grid; gap: 6px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.when-time .chip { box-shadow: none; }
.next-at { display: inline-block; margin-top: 4px; font-size: 12px; font-weight: 700; color: var(--blue); background: var(--blue-soft); border-radius: 8px; padding: 1px 8px; }
