/* eLend Dashboard - MSuite look (light header/footer, brand blue #0B5DD3, navy #133459).
   Chart colours follow the validated dataviz palette; text never wears a series colour. */
:root {
  color-scheme: light;
  --brand: #0B5DD3;
  --brand-dark: #133459;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e0e0e0;
  --border-strong: #cfd4db;
  --text: #1b2430;
  --text-2: #4b5563;
  --text-3: #6b7280;
  --band: #2a78d6;          /* in pipeline view */
  --band-soft: #cde2fb;
  --event: #133459;
  --cursor: #eb6834;
  --good: #0ca30c;  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b; --critical-text: #b42323;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 2px 8px rgba(16,24,40,.04);
  --header-h: 60px;
  --footer-h: 40px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.4;
  padding: calc(var(--header-h) + 16px) 16px calc(var(--footer-h) + 20px); }
h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.linkbtn { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: var(--brand); }
.linkbtn:hover { text-decoration: underline; }

/* ---------- header (MSuite page-header) ---------- */
.appbar { position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); z-index: 1000; display: flex; align-items: center;
  justify-content: space-between; gap: 16px; padding: 0 20px; background: #fff; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo img { height: 36px; width: auto; display: block; }
.sep { width: 1px; height: 28px; background: var(--border-strong); }
.brand h1 { font-size: 17px; color: var(--brand-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-right { display: flex; align-items: center; gap: 14px; min-width: 0; }
.health { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.ok { background: var(--good); } .dot.stale { background: var(--warning); } .dot.bad { background: var(--critical); }
.user { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-dark); color: #fff; display: grid; place-items: center;
  font-size: 11px; font-weight: 600; }
@media (max-width: 760px) { .brand h1, .uname, .sep { display: none; } .health span:last-child { max-width: 130px; overflow: hidden; text-overflow: ellipsis; } }

/* ---------- footer (MSuite footer-main) ---------- */
.appfooter { position: fixed; bottom: 0; left: 0; right: 0; height: var(--footer-h); z-index: 1000; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; padding: 0 20px; background: #fff; border-top: 1px solid var(--border);
  font-size: 12px; font-weight: 500; color: var(--text-2); }
.appfooter .fleft { display: flex; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.powered { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.powered span { opacity: .6; }
.powered img { height: 20px; width: auto; }
.appfooter .fleft img { height: 22px; width: auto; display: block; }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; margin-bottom: 14px; }
.ctl { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-3); }
.ctl.grow { flex: 1 1 240px; max-width: 360px; }
.ctl input { font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 6px 9px; min-width: 140px; }
.tz { margin-left: auto; font-size: 12px; color: var(--text-3); align-self: center; }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px; min-height: 96px; border-top: 3px solid var(--brand); }
.tile .lbl { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.tile .val { font-size: 30px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.15; color: var(--brand-dark); }
.tile .sub { font-size: 12px; color: var(--text-3); }

/* ---------- list card + tabs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.listcard { padding: 0 0 6px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 8px; overflow-x: auto; }
.tab { font: inherit; font-size: 13.5px; font-weight: 500; color: var(--text-2); background: none; border: 0; border-bottom: 3px solid transparent;
  padding: 12px 12px 10px; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--brand-dark); }
.tab[aria-selected="true"] { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 600; }
.tab .count { display: inline-block; min-width: 22px; padding: 1px 7px; margin-left: 4px; border-radius: 999px; background: var(--surface-2);
  color: var(--text-2); font-size: 12px; font-weight: 600; text-align: center; }
.tab[aria-selected="true"] .count { background: #e3edfb; color: var(--brand-dark); }

.tablewrap { overflow-x: auto; padding: 4px 8px 0; }
/* Fit the viewport: text wraps, dates/numbers stay on one line, low-priority columns drop out on narrow screens. */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
table.data th, table.data td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: normal; overflow-wrap: anywhere; vertical-align: top; }
table.data th { color: var(--text-2); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; background: var(--surface); vertical-align: bottom; line-height: 1.25; overflow-wrap: normal; }
table.data td.dt, table.data td.num, table.data tbody tr:not(.empty) td:first-child { white-space: nowrap; overflow-wrap: normal; }
@media (max-width: 1180px) { table.data .c-md { display: none; } }
@media (max-width: 1000px) { table.data .c-sm { display: none; } }
@media (max-width: 760px)  { table.data .c-xs { display: none; } table.data th, table.data td { padding: 6px 5px; font-size: 12px; } }
table.data th:hover { color: var(--brand-dark); }
table.data th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
table.data th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: #f7f9fc; }
table.data td.muted, .muted { color: var(--text-3); }
.loanlink { font: inherit; font-weight: 600; color: var(--brand); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.loanlink:hover { text-decoration: underline; }
.since { color: var(--text-3); margin-left: 6px; }
.est { border-bottom: 1px dashed var(--text-3); cursor: help; }

  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.empty td { color: var(--text-3); padding: 18px 10px; }
.empty td.err { color: var(--critical-text); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- sign-in gate ---------- */
.gate { display: flex; justify-content: center; padding: 10vh 0 0; }
.gatecard { max-width: 520px; width: 100%; padding: 18px 20px; }
.gatecard h2 { font-size: 17px; color: var(--brand-dark); margin-bottom: 8px; }
.gatemsg { color: var(--text-2); margin: 0 0 14px; }
.gatebtns { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { font: inherit; font-size: 13px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--brand); background: var(--brand); color: #fff; cursor: pointer; }
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.ghost:hover { background: #eef4fd; }

/* ---------- loan modal ---------- */
.modal { width: min(1120px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(16,24,40,.25); color: var(--text); }
.modal::backdrop { background: rgba(19, 52, 89, .35); }
.mhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px 12px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: #fff; z-index: 2; }
.mhead h2 { font-size: 17px; color: var(--brand-dark); }
.msub { margin: 4px 0 0; color: var(--text-2); font-size: 13px; }
.iconbtn { font: inherit; font-size: 16px; width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--border); background: #fff; cursor: pointer; color: var(--text-2); }
.iconbtn:hover { background: var(--surface-2); }
.mbody { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 0; }
@media (max-width: 900px) { .mbody { grid-template-columns: 1fr; } }
.mtimeline { padding: 14px 20px 18px; min-width: 0; }
.mcriteria { padding: 14px 18px 18px; border-left: 1px solid var(--border); background: #fafbfc; }
@media (max-width: 900px) { .mcriteria { border-left: 0; border-top: 1px solid var(--border); } }
.mlegend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; align-items: center; }
.mlegend .mhint { color: var(--text-3); }
.sw { display: inline-block; width: 12px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.sw.band { background: var(--band); }
.sw.ev { width: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--event); }
.sw.cur { width: 2px; height: 12px; background: var(--cursor); }
.tlwrap { position: relative; }
#timeline { width: 100%; display: block; cursor: crosshair; touch-action: none; border-radius: 6px; }
#timeline:focus { outline: none; }
#timeline:focus-visible { outline: 2px solid #9ec5f4; outline-offset: 2px; }
#timeline .lane-label { font-size: 11px; fill: var(--text-3); }
#timeline .tick { font-size: 10.5px; fill: var(--text-3); }
#timeline .grid { stroke: var(--border); stroke-width: 1; }
#timeline .axis { stroke: var(--border-strong); stroke-width: 1; }
#timeline .bandbg { fill: var(--surface-2); }
#timeline .band { fill: var(--band); }
#timeline .stem { stroke: var(--border-strong); stroke-width: 1; }
#timeline .mk { fill: #fff; stroke: var(--event); stroke-width: 2; cursor: pointer; }
#timeline .mk.pick { fill: var(--good); stroke: #fff; }
#timeline .mk.est { stroke-dasharray: 2 2; }
#timeline .mk.sel { stroke: var(--cursor); stroke-width: 3; }
#timeline .hit { fill: transparent; cursor: pointer; }
#timeline .cursor { stroke: var(--cursor); stroke-width: 2; }
#timeline .cursorhead { fill: var(--cursor); }
.tip { position: absolute; z-index: 5; background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 12px;
  box-shadow: var(--shadow); pointer-events: none; color: var(--text); max-width: 280px; }

.events { list-style: none; margin: 12px 0 0; padding: 0; border-top: 1px solid var(--border); max-height: 240px; overflow-y: auto; }
.events li { display: grid; grid-template-columns: 150px 1fr; gap: 10px; padding: 6px 4px; border-bottom: 1px solid var(--border); font-size: 12.5px;
  cursor: pointer; }
.events li:hover { background: #f7f9fc; }
.events li.sel { background: #fff4ee; box-shadow: inset 3px 0 0 var(--cursor); }
.events .t { color: var(--text-2); font-variant-numeric: tabular-nums; }
.events .d { color: var(--text); }
.events .d small { color: var(--text-3); }

.mcriteria h3 { font-size: 14px; color: var(--brand-dark); }
.cat { margin: 4px 0 8px; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.cverdict { margin: 0 0 10px; font-size: 13px; font-weight: 600; padding: 8px 10px; border-radius: 6px; background: var(--surface-2); }
.cverdict.met { background: #e7f6e7; color: var(--good-text); }
.cverdict.not { background: #fdecec; color: var(--critical-text); }
.clist { list-style: none; margin: 0; padding: 0; }
.clist li { display: grid; grid-template-columns: 22px 1fr; gap: 6px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.clist .ic { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; margin-top: 1px; }
.clist .ic.met { background: var(--good); } .clist .ic.not { background: var(--critical); } .clist .ic.unk { background: var(--text-3); }
.clist .cname { color: var(--text); }
.clist .cname b { font-weight: 600; }
.clist .cval { color: var(--text-3); font-size: 12px; }
.cnote { margin: 10px 0 0; font-size: 11.5px; color: var(--text-3); }
/* In Pipeline View leads the Pipeline View list: keep it left-aligned next to the loan number */
table.data th.first-num, table.data td.first-num { text-align: left; }
