/* ==========================================================================
   Alfin LMS v2 — design system
   Direction: an operations console for credit teams. Ink-on-paper ledger
   surfaces, one indigo action colour, and an "aging spectrum" that is the
   only place colour is allowed to shout — because in a loan book, age is
   the thing that matters.
   ========================================================================== */

:root {
  /* Surfaces */
  --ink:        #101A2B;
  --ink-2:      #1D2A40;
  --ink-3:      #46556E;
  --ink-4:      #75839A;
  --rule:       #E1E5EC;
  --rule-soft:  #EDF0F4;
  --canvas:     #F4F6F9;
  --paper:      #FFFFFF;
  --paper-2:    #FAFBFD;

  /* Action */
  --indigo:     #2440A6;
  --indigo-600: #1C3288;
  --indigo-50:  #EEF1FB;
  --gold:       #A87A22;
  --gold-50:    #FBF4E4;

  /* Aging spectrum — DPD buckets. Signature palette. */
  --age-0:   #0E9C74;
  --age-30:  #6FA13B;
  --age-60:  #D9A227;
  --age-90:  #DE6E2B;
  --age-180: #C43F3F;
  --age-365: #8A2233;

  --ok:      #0E9C74;
  --ok-50:   #E6F5F0;
  --warn:    #B4791A;
  --warn-50: #FDF4E3;
  --bad:     #C43F3F;
  --bad-50:  #FBECEC;
  --info-50: #EAF1FA;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Manrope", var(--sans);
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --r: 8px;
  --r-lg: 12px;
  --shadow: 0 1px 2px rgba(16,26,43,.06), 0 4px 14px -6px rgba(16,26,43,.12);
  --shadow-lg: 0 18px 48px -14px rgba(16,26,43,.28);
  --sidebar-w: 246px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv05" 1, "ss01" 1;
}
a { color: var(--indigo); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--display); margin: 0; letter-spacing: -.02em; }
h1 { font-size: 21px; font-weight: 800; }
h2 { font-size: 16px; font-weight: 800; }
h3 { font-size: 14px; font-weight: 700; }
:focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; border-radius: 4px; }

.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-4); }
.small { font-size: 12px; }
.eyebrow {
  font-size: 10.5px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-4);
}
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ------------------------------------------------------------------ shell */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--ink); color: #C9D2E2;
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  display: flex; flex-direction: column; overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 7px; flex: none;
  background: linear-gradient(150deg, var(--indigo) 0%, #4A6BD6 100%);
  display: grid; place-items: center;
  font-family: var(--display); font-weight: 800; font-size: 15px; color: #fff;
}
.brand-name { font-family: var(--display); font-weight: 800; color: #fff; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 10px; color: #6F7F99; letter-spacing: .1em; text-transform: uppercase; font-weight: 600; }

.nav { padding: 10px 10px 24px; }
.nav-group { margin-top: 12px; }
.nav-group > .eyebrow { padding: 6px 10px; color: #5F6E88; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: 6px; color: #C2CCDD;
  font-size: 13px; font-weight: 500; text-decoration: none;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--indigo); color: #fff; font-weight: 600; }
.nav a .ico { width: 15px; text-align: center; opacity: .8; font-size: 12px; }
.nav a .badge-n {
  margin-left: auto; background: rgba(255,255,255,.14); color: #fff;
  border-radius: 20px; padding: 0 6px; font-size: 10.5px; font-family: var(--mono);
}

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
  padding: 0 24px; height: 56px; display: flex; align-items: center; gap: 14px;
}
.crumb { font-size: 12px; color: var(--ink-4); }
.crumb b { color: var(--ink); font-weight: 600; }
.topbar .env {
  font-family: var(--mono); font-size: 10.5px; padding: 2px 7px; border-radius: 4px;
  background: var(--gold-50); color: var(--gold); border: 1px solid #EDDCB4;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--indigo-50);
  color: var(--indigo); display: grid; place-items: center;
  font-weight: 700; font-size: 12px; font-family: var(--display);
}
.page { padding: 22px 24px 64px; max-width: 1500px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-4); font-size: 13px; max-width: 70ch; }

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.card-head {
  padding: 13px 16px; border-bottom: 1px solid var(--rule-soft);
  display: flex; align-items: center; gap: 10px;
}
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0,1fr)); }
.g-2-1 { grid-template-columns: minmax(0,2fr) minmax(0,1fr); }
.g-1-2 { grid-template-columns: minmax(0,1fr) minmax(0,2fr); }

.stat { padding: 14px 16px; }
.stat .k { font-size: 11px; font-weight: 600; color: var(--ink-4); letter-spacing: .04em; text-transform: uppercase; }
.stat .v { font-family: var(--display); font-size: 25px; font-weight: 800; letter-spacing: -.03em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .d { font-size: 11.5px; color: var(--ink-4); margin-top: 2px; }
.stat .d.up { color: var(--ok); } .stat .d.dn { color: var(--bad); }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-4); font-weight: 700; padding: 9px 12px;
  border-bottom: 1px solid var(--rule); background: var(--paper-2);
  position: sticky; top: 0; white-space: nowrap;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
table.data tbody tr:hover { background: var(--paper-2); }
table.data tr.clickable { cursor: pointer; }
table.data td.n, table.data th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 700; background: var(--paper-2); border-top: 2px solid var(--rule); }
table.data.compact td, table.data.compact th { padding: 6px 10px; font-size: 12.5px; }
.empty { padding: 44px 20px; text-align: center; color: var(--ink-4); }
.empty h3 { color: var(--ink); margin-bottom: 5px; }

/* ------------------------------------------------------------------ chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
  background: var(--rule-soft); color: var(--ink-3); white-space: nowrap;
}
.chip.ok   { background: var(--ok-50);   color: #0A6F53; }
.chip.warn { background: var(--warn-50); color: #8A5B0F; }
.chip.bad  { background: var(--bad-50);  color: #9A2C2C; }
.chip.info { background: var(--info-50); color: var(--indigo-600); }
.chip.gold { background: var(--gold-50); color: var(--gold); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* aging pills use the spectrum */
.age-0   { background: #E4F5EF; color: #0A6F53; }
.age-30  { background: #EFF4E5; color: #4C7024; }
.age-60  { background: #FBF2DC; color: #8A6413; }
.age-90  { background: #FCEDE2; color: #A24E15; }
.age-180 { background: #FAE9E9; color: #A32E2E; }
.age-365 { background: #F5E4E7; color: #7A1C2B; }

/* --------------------------------------------------- signature: aging ribbon */
.ribbon { display: flex; height: 34px; border-radius: 7px; overflow: hidden; border: 1px solid var(--rule); }
.ribbon-seg {
  display: grid; place-items: center; color: #fff; font-family: var(--mono);
  font-size: 11px; font-weight: 500; cursor: pointer; position: relative;
  transition: flex-grow .35s cubic-bezier(.2,.7,.3,1), filter .15s;
  min-width: 3px;
}
.ribbon-seg:hover { filter: brightness(1.12); }
.ribbon-seg[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--ink); }
.ribbon-key { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 9px; font-size: 11.5px; color: var(--ink-3); }
.ribbon-key span { display: inline-flex; align-items: center; gap: 6px; }
.ribbon-key i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* ----------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 7px 13px; border-radius: 7px; border: 1px solid var(--rule);
  background: var(--paper); color: var(--ink); font-size: 13px; font-weight: 600;
  font-family: var(--sans); cursor: pointer; white-space: nowrap;
  transition: background .13s, border-color .13s, transform .06s;
}
.btn:hover { background: var(--paper-2); border-color: #CFD6E0; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn.primary:hover { background: var(--indigo-600); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { filter: brightness(.94); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-3); }
.btn.ghost:hover { background: var(--rule-soft); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

label.f { display: block; }
.f > .lbl { display: block; font-size: 11.5px; font-weight: 600; color: var(--ink-3); margin-bottom: 4px; }
.f > .lbl .req { color: var(--bad); }
input[type=text], input[type=number], input[type=date], input[type=email],
input[type=password], input[type=tel], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--rule); border-radius: 7px;
  font-family: var(--sans); font-size: 13px; color: var(--ink); background: var(--paper);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-50); }
input[readonly], input:disabled, select:disabled { background: var(--rule-soft); color: var(--ink-3); }
textarea { min-height: 74px; resize: vertical; }
.hint { font-size: 11px; color: var(--ink-4); margin-top: 3px; }
.err  { font-size: 11px; color: var(--bad); margin-top: 3px; }
.form-grid { display: grid; gap: 13px 14px; grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid .span2 { grid-column: span 2; } .form-grid .span3 { grid-column: span 3; }
fieldset { border: 0; padding: 0; margin: 0 0 18px; }
fieldset > legend {
  font-family: var(--display); font-weight: 800; font-size: 12px; padding: 0 0 9px;
  letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3);
  border-bottom: 1px solid var(--rule-soft); width: 100%; margin-bottom: 13px;
}
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { appearance: none; width: 34px; height: 19px; border-radius: 20px; background: #CBD2DD; position: relative; cursor: pointer; transition: background .16s; margin: 0; }
.switch input:checked { background: var(--indigo); }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; transition: transform .16s; }
.switch input:checked::after { transform: translateX(15px); }

.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-bottom: 13px; }
.toolbar input[type=text], .toolbar select { width: auto; min-width: 168px; }
.search { position: relative; }
.search input { padding-left: 30px; min-width: 250px; }
.search::before { content: "⌕"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-4); font-size: 15px; }

/* ------------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); overflow-x: auto; margin-bottom: 16px; }
.tabs button {
  border: 0; background: none; padding: 9px 13px; font-size: 13px; font-weight: 600;
  color: var(--ink-4); cursor: pointer; border-bottom: 2px solid transparent;
  font-family: var(--sans); white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--indigo); border-bottom-color: var(--indigo); }
.tabpane { display: none; } .tabpane.active { display: block; }

/* ------------------------------------------------------------------ misc UI */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; font-size: 13px; }
.kv dt { color: var(--ink-4); font-size: 12px; }
.kv dd { margin: 0; font-weight: 600; text-align: right; }
.def-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px,1fr)); gap: 13px 20px; }
.def-list .k { font-size: 11px; color: var(--ink-4); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.def-list .v { font-weight: 600; margin-top: 1px; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 5px; bottom: 5px; width: 2px; background: var(--rule); }
.timeline li { list-style: none; position: relative; padding: 0 0 15px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--paper); border: 2px solid var(--rule); }
.timeline li.done::before { background: var(--ok); border-color: var(--ok); }
.timeline li.current::before { background: var(--indigo); border-color: var(--indigo); box-shadow: 0 0 0 4px var(--indigo-50); }

/* stage rail for LOS */
.rail { display: flex; gap: 3px; margin: 0 0 16px; flex-wrap: wrap; }
.rail-step {
  flex: 1 1 0; min-width: 96px; padding: 8px 11px; background: var(--paper); border: 1px solid var(--rule);
  font-size: 11.5px; position: relative;
}
.rail-step:first-child { border-radius: 7px 0 0 7px; } .rail-step:last-child { border-radius: 0 7px 7px 0; }
.rail-step .s { font-size: 10px; color: var(--ink-4); text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.rail-step .t { font-weight: 600; margin-top: 1px; }
.rail-step.done { background: var(--ok-50); border-color: #BFE5D8; }
.rail-step.done .t { color: #0A6F53; }
.rail-step.active { background: var(--indigo); border-color: var(--indigo); }
.rail-step.active .t, .rail-step.active .s { color: #fff; }
.rail-step.active .s { color: #B9C8F0; }

.bar { height: 7px; border-radius: 4px; background: var(--rule-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--indigo); border-radius: 4px; }

.alert { padding: 11px 14px; border-radius: 8px; font-size: 13px; border: 1px solid; display: flex; gap: 10px; }
.alert.info { background: var(--info-50); border-color: #C6D8F2; color: #1B3B78; }
.alert.warn { background: var(--warn-50); border-color: #EFDCAF; color: #7C5310; }
.alert.bad  { background: var(--bad-50);  border-color: #F0C9C9; color: #92292A; }
.alert.ok   { background: var(--ok-50);   border-color: #BFE5D8; color: #0A6F53; }

/* ledger tape: the waterfall used when posting a receipt */
.tape { border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; background: var(--paper-2); }
.tape-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; padding: 7px 12px; font-size: 12.5px; border-bottom: 1px dashed var(--rule); align-items: center; }
.tape-row:last-child { border-bottom: 0; }
.tape-row .amt { font-family: var(--mono); font-weight: 600; }
.tape-row .bal { font-family: var(--mono); color: var(--ink-4); font-size: 11.5px; }
.tape-row.head { background: var(--ink); color: #fff; font-weight: 600; }
.tape-row.head .bal { color: #93A2BC; }
.tape-row.total { background: var(--indigo-50); font-weight: 700; border-top: 2px solid var(--indigo); }
.tape-row.zero { opacity: .45; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(16,26,43,.45); z-index: 90; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--paper); border-radius: 12px; box-shadow: var(--shadow-lg); width: min(760px, 100%); max-height: 88vh; display: flex; flex-direction: column; }
.modal-head { padding: 15px 18px; border-bottom: 1px solid var(--rule); display: flex; align-items: center; gap: 12px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--rule); display: flex; justify-content: flex-end; gap: 9px; background: var(--paper-2); border-radius: 0 0 12px 12px; }

/* toast */
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 120; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 15px; border-radius: 9px;
  box-shadow: var(--shadow-lg); font-size: 13px; max-width: 380px;
  animation: rise .22s cubic-bezier(.2,.8,.3,1);
}
.toast.ok  { background: #0B6A50; } .toast.bad { background: #9A2C2C; }
@keyframes rise { from { opacity: 0; transform: translateY(9px); } }

/* charts */
.chart { width: 100%; display: block; }
.chart .grid-line { stroke: var(--rule-soft); stroke-width: 1; }
.chart .axis { fill: var(--ink-4); font-size: 10px; font-family: var(--mono); }
.chart .bar-r { fill: var(--indigo); }
.chart .bar-r.alt { fill: #93A6E0; }
.chart .line { fill: none; stroke: var(--indigo); stroke-width: 2; }

/* login */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.auth-art { background: var(--ink); color: #fff; padding: 46px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art::after {
  content: ""; position: absolute; inset: auto -80px -140px auto; width: 460px; height: 460px;
  border-radius: 50%; background: radial-gradient(circle, rgba(36,64,166,.55), transparent 68%);
}
.auth-form { display: grid; place-items: center; padding: 40px; }
.auth-form .box { width: min(390px, 100%); }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; } .auth-art { display: none; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .g2,.g3,.g4,.g5,.g-2-1,.g-1-2,.form-grid,.form-grid.two { grid-template-columns: 1fr; }
  .form-grid .span2, .form-grid .span3 { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print {
  .sidebar, .topbar, .toolbar, .btn { display: none !important; }
  .main { margin: 0; } .card { box-shadow: none; break-inside: avoid; }
}
