/* NBFC LMS — application stylesheet. Light/dark themes, five accent colours. */
:root {
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 10px;
  --radius-sm: 7px;
  --nav-w: 264px;
  --nav-mini: 64px;
  --top-h: 58px;

  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --line: #e3e8ec;
  --line-strong: #cfd7de;
  --text: #17212b;
  --text-2: #4b5a68;
  --muted: #7a8794;
  --nav-bg: #ffffff;
  --nav-text: #2f3d4a;
  --nav-hover: #f1f5f7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);

  --accent: #0f8b8d;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3f3;
  --ok: #1a7f4b;
  --ok-soft: #e3f4ea;
  --warn: #a15c07;
  --warn-soft: #fdf1dc;
  --bad: #c0352b;
  --bad-soft: #fbe6e4;
  --info: #2457b3;
  --info-soft: #e6eefb;
}
:root[data-accent="indigo"] { --accent: #4a4fc4; --accent-soft: #e9e9fb; }
:root[data-accent="rose"]   { --accent: #c23a63; --accent-soft: #fbe7ee; }
:root[data-accent="amber"]  { --accent: #b86e00; --accent-soft: #fdf0db; }
:root[data-accent="slate"]  { --accent: #3f5568; --accent-soft: #e7edf2; }

:root[data-theme="dark"] {
  --bg: #0f151b;
  --surface: #171f27;
  --surface-2: #1c252e;
  --line: #27323d;
  --line-strong: #34414d;
  --text: #e6ecf1;
  --text-2: #b4c0cb;
  --muted: #8796a4;
  --nav-bg: #131a21;
  --nav-text: #c9d3dc;
  --nav-hover: #1d2731;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, .55);
  --accent-soft: rgba(15, 139, 141, .18);
  --ok-soft: rgba(26, 127, 75, .2);
  --warn-soft: rgba(161, 92, 7, .22);
  --bad-soft: rgba(192, 53, 43, .22);
  --info-soft: rgba(36, 87, 179, .25);
}
:root[data-theme="dark"][data-accent="indigo"] { --accent: #7b80f0; --accent-soft: rgba(123, 128, 240, .18); }
:root[data-theme="dark"][data-accent="rose"]   { --accent: #e3648b; --accent-soft: rgba(227, 100, 139, .18); }
:root[data-theme="dark"][data-accent="amber"]  { --accent: #e09a2c; --accent-soft: rgba(224, 154, 44, .18); }
:root[data-theme="dark"][data-accent="slate"]  { --accent: #8aa3b8; --accent-soft: rgba(138, 163, 184, .18); }
:root[data-theme="dark"]:not([data-accent]), :root[data-theme="dark"][data-accent="teal"] { --accent: #2bb3b5; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 21px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ic { flex: none; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--nav-w); flex: none; background: var(--nav-bg); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; transition: width .18s ease; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none !important; min-height: var(--top-h); }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 17px; flex: none; }
.brand-mark.big { width: 56px; height: 56px; font-size: 28px; border-radius: 14px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { color: var(--muted); font-size: 11.5px; }
.nav-search { margin: 10px 12px 4px; display: flex; align-items: center; gap: 6px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--muted); background: var(--surface-2); }
.nav-search input { border: 0; background: transparent; padding: 7px 0; width: 100%; color: var(--text); outline: none; font: inherit; }
.nav { overflow-y: auto; padding: 6px 8px 20px; flex: 1; }
.nav-top, .nav-group-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--nav-text); font: inherit; font-weight: 500; background: none; border: 0; cursor: pointer; text-align: left; text-decoration: none !important; }
.nav-top:hover, .nav-group-btn:hover { background: var(--nav-hover); }
.nav-top.active { background: var(--accent-soft); color: var(--accent); }
.nav-group-btn span { flex: 1; }
.nav-group-btn .ic:last-child { transition: transform .15s; opacity: .6; }
.nav-group.open .nav-group-btn .ic:last-child { transform: rotate(90deg); }
.nav-items { display: none; padding: 2px 0 6px 30px; }
.nav-group.open .nav-items { display: block; }
.nav-items a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--text-2); font-size: 13.3px; text-decoration: none; position: relative; }
.nav-items a:hover { background: var(--nav-hover); color: var(--text); }
.nav-items a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.nav-items a.pending::after { content: ""; position: absolute; right: 10px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--line-strong); }
.nav-mini .sidebar { width: var(--nav-mini); }
.nav-mini .brand-text, .nav-mini .nav-search, .nav-mini .nav-group-btn span, .nav-mini .nav-group-btn .ic:last-child, .nav-mini .nav-items, .nav-mini .nav-top span { display: none; }
.nav-mini .nav-top, .nav-mini .nav-group-btn { justify-content: center; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--top-h); display: flex; align-items: center; gap: 12px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.context { display: flex; gap: 8px; }
.context label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.context select { padding: 5px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font: inherit; font-size: 12.5px; max-width: 190px; }
.icon-btn { border: 1px solid transparent; background: none; color: var(--text-2); width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--nav-hover); color: var(--text); }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer; padding: 4px 6px; border-radius: 8px; color: var(--text); font: inherit; }
.user-btn:hover { background: var(--nav-hover); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; }
.user-meta { display: flex; flex-direction: column; text-align: left; line-height: 1.15; }
.user-meta small { color: var(--muted); font-size: 11px; }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 230px; padding: 6px; display: none; }
.dropdown.show { display: block; }
.dropdown-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-weight: 600; display: flex; flex-direction: column; }
.dropdown-head small { color: var(--muted); font-weight: 400; }
.dropdown a, .dropdown button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: 7px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; text-decoration: none; }
.dropdown a:hover, .dropdown button:hover { background: var(--nav-hover); }
.dropdown form { margin: 0; }
.accent-row { display: flex; gap: 8px; padding: 8px 10px; }
.swatch { width: 20px !important; height: 20px; padding: 0 !important; border-radius: 50% !important; border: 2px solid var(--surface) !important; box-shadow: 0 0 0 1px var(--line-strong); }
.sw-teal { background: #0f8b8d !important; } .sw-indigo { background: #4a4fc4 !important; } .sw-rose { background: #c23a63 !important; } .sw-amber { background: #b86e00 !important; } .sw-slate { background: #3f5568 !important; }

.content { padding: 20px 22px 32px; flex: 1; }
.footer { padding: 10px 22px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }

/* ------------------------------------------------------------------ page parts */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card.narrow { max-width: 460px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-2); }
.err-code { font-size: 46px; color: var(--accent); }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--ok-soft); color: var(--ok); }
.alert-error { background: var(--bad-soft); color: var(--bad); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-warning { background: var(--warn-soft); color: var(--warn); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi small { color: var(--muted); font-size: 12px; display: block; }
.kpi strong { font-size: 21px; display: block; margin-top: 4px; letter-spacing: -.01em; }
.kpi em { font-style: normal; font-size: 12px; color: var(--text-2); }
.kpi.accent { border-top: 3px solid var(--accent); }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1100px) { .two-col, .three-col { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ forms */
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px 14px; }
.form-section { grid-column: 1 / -1; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--line); padding: 8px 0 6px; margin-top: 4px; }
.fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.col-1 { grid-column: span 1; } .col-2 { grid-column: span 2; } .col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; } .col-6 { grid-column: span 6; } .col-8 { grid-column: span 8; } .col-12 { grid-column: 1 / -1; }
@media (max-width: 900px) { .form-grid .fld { grid-column: span 6; } }
@media (max-width: 560px) { .form-grid .fld { grid-column: 1 / -1; } }
.fld > label, label.fld > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.req { color: var(--bad); font-weight: 700; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 7px 10px; min-height: 36px; width: 100%; }
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[readonly], input:disabled, select:disabled, textarea[readonly] { background: var(--surface-2); color: var(--text-2); }
.fld.has-err input, .fld.has-err select, .fld.has-err textarea { border-color: var(--bad); }
.fld .err { color: var(--bad); font-size: 12px; min-height: 0; }
.fld .err:empty { display: none; }
.hint { color: var(--muted); font-size: 12px; }
.select-filter { min-height: 30px; padding: 4px 8px; font-size: 12.5px; border-style: dashed; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; margin-top: 4px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: 24px; cursor: pointer; transition: background .15s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.form-actions.inline { margin-top: 0; align-self: end; grid-column: span 2; }
.filter-form { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px 14px; align-items: end; }
.filter-form .form-grid { display: contents; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; min-height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: var(--bad); filter: brightness(1.08); }
.btn-success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.btn-xs { min-height: 26px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg .btn { border: 0; border-radius: 0; border-right: 1px solid var(--line-strong); }
.seg .btn:last-child { border-right: 0; }

/* ------------------------------------------------------------------ grids */
.grid-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.grid-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.grid-search { width: 220px; min-height: 30px; padding: 4px 10px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { background: var(--surface-2); color: var(--text-2); font-weight: 600; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
table.grid th.sortable { cursor: pointer; }
table.grid th.sortable:hover { color: var(--accent); }
table.grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tbody tr:hover td { background: var(--surface-2); }
table.grid tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--line-strong); }
table.grid .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.grid td.empty { text-align: center; color: var(--muted); padding: 26px; }
table.grid tr.group-row td { background: var(--accent-soft); font-weight: 700; color: var(--accent); }
table.grid tr.row-bad td { background: var(--bad-soft); }
table.grid tr.row-ok td { background: var(--ok-soft); }
.actions-col { text-align: right; white-space: nowrap; width: 1%; }
.actions-col .btn + .btn { margin-left: 4px; }
.grid-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; color: var(--muted); font-size: 12.5px; gap: 10px; flex-wrap: wrap; }
.pager { display: flex; gap: 4px; align-items: center; }
.loading { position: relative; }
.loading::after { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--surface) 55%, transparent); border-radius: var(--radius); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; }
.badge-active, .badge-approved, .badge-yes, .badge-paid, .badge-disbursed, .badge-closed, .badge-settled, .badge-verified { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-pending, .badge-due, .badge-partial, .badge-requested, .badge-submitted, .badge-in-progress { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-rejected, .badge-blocked, .badge-overdue, .badge-cancelled, .badge-no { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge-new, .badge-open, .badge-sanctioned { background: var(--info-soft); color: var(--info); border-color: transparent; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 600; }

/* ------------------------------------------------------------------ toasts / modal */
.toast-host { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 9px; box-shadow: var(--shadow-lg); max-width: 380px; transition: opacity .3s, transform .3s; }
.toast-success { background: var(--ok); color: #fff; }
.toast-error { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
.modal-host { position: fixed; inset: 0; background: rgba(10, 16, 22, .45); display: grid; place-items: center; z-index: 90; padding: 20px; }
.modal-host.modal-stacked { z-index: 92; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: min(480px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal-wide { width: min(980px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }

/* ------------------------------------------------------------------ charts */
.chart { width: 100%; height: 240px; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--line); }
.chart .bar { fill: var(--accent); }
.chart .bar.alt { fill: #e09a2c; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; background: var(--accent); vertical-align: -1px; }
.legend i.alt { background: #e09a2c; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

/* ------------------------------------------------------------------ login */
.login-page { background: var(--bg); }
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-side { background: linear-gradient(150deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #0b1a24)); color: #fff; padding: 64px 56px; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.login-side .brand-mark { background: rgba(255, 255, 255, .18); }
.login-side h1 { font-size: 30px; }
.login-side ul { margin: 10px 0 0; padding-left: 18px; opacity: .92; line-height: 1.9; }
.login-card { align-self: center; justify-self: center; width: min(380px, 90%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card .fld { gap: 6px; }
@media (max-width: 860px) { .login-wrap { grid-template-columns: 1fr; } .login-side { padding: 32px 24px; } }

/* ------------------------------------------------------------------ responsive shell */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  .context span, .user-meta { display: none; }
  .content { padding: 14px; }
}
@media print {
  .sidebar, .topbar, .footer, .form-actions, .grid-tools, .pager, .toast-host { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; }
}
