/* Ekeza Ledger */
:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #f8faf7;
  --ink: #17211b;
  --ink-2: #4a5a50;
  --muted: #6b7a70;
  --line: #e1e7e2;
  --brand: #166534;
  --brand-2: #15803d;
  --brand-soft: #dcfce7;
  --accent: #b45309;
  --accent-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --info-soft: #e0f2fe;
  --side: #0f2a1b;
  --side-ink: #cfe3d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 24, .06), 0 1px 1px rgba(16, 40, 24, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.25; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; margin-top: 1rem; }
p { margin: 0 0 .8rem; }
code, .mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.faint { color: #c3ccc5; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pos { color: var(--brand-2); }
.neg { color: var(--danger); }
.warn { color: var(--accent); }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex: 0 0 240px; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: .7rem; align-items: center; padding: 1.1rem 1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { width: 38px; height: 38px; border-radius: 9px; background: var(--brand-2); color: #fff; display: grid; place-items: center; font-weight: 800; letter-spacing: .5px; flex: none; }
.brand-mark.lg { width: 48px; height: 48px; font-size: 1.1rem; }
.brand-name { color: #fff; font-weight: 650; font-size: .9rem; line-height: 1.25; }
.brand-sub { font-size: .75rem; opacity: .7; }
.sidebar nav { padding: .6rem .5rem; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: .6rem; color: var(--side-ink); padding: .5rem .7rem; border-radius: 7px; font-size: .9rem; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: rgba(134, 239, 172, .14); color: #fff; font-weight: 600; }
.ico { width: 1.2rem; text-align: center; opacity: .85; }
.nav-section { text-transform: uppercase; font-size: .68rem; letter-spacing: .08em; opacity: .55; padding: 1rem .7rem .3rem; }
.sidebar-foot { padding: .8rem 1rem; font-size: .75rem; opacity: .5; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .8rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.page-title { font-size: 1.15rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box { display: flex; align-items: center; gap: .6rem; }
.user-link { color: var(--ink-2); font-size: .85rem; }
.menu-btn { display: none; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: .3rem .6rem; font-size: 1.1rem; cursor: pointer; }
.content { padding: 1.4rem 1.5rem 3rem; max-width: 1400px; width: 100%; }
.nav-backdrop { display: none; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 760px; }
.card.highlight { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .9rem 1.2rem; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; }
.card-head.plain { padding: 0 0 .6rem; border: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.grid-main-side { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1.1rem; align-items: start; }
.grid-2 > .card, .grid-main-side > .card { margin-bottom: 0; }
.grid-2, .grid-main-side { margin-bottom: 1.1rem; }

/* KPIs */
.kpis { display: grid; gap: .8rem; margin: .4rem 0 1.1rem; }
.kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.card .kpi { box-shadow: none; background: var(--surface-2); }
.kpi-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.35rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.kpi-strong { background: var(--brand) !important; border-color: var(--brand); color: #fff; }
.kpi-strong .kpi-label, .kpi-strong .kpi-sub { color: rgba(255,255,255,.8); }
.big-number { font-size: 2rem; font-weight: 800; color: var(--brand); margin-bottom: .5rem; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: .55rem .8rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr:hover { background: #fafcf9; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--line); }
.table.compact th, .table.compact td { padding: .35rem .55rem; font-size: .85rem; }
.table .num { text-align: right; white-space: nowrap; }
.table .empty, .empty { text-align: center; color: var(--muted); padding: 1.6rem; }
.table.summary td { padding: .38rem .2rem; font-size: .88rem; }
.table.summary tr.sep td { border-top: 2px solid var(--line); }
.table.summary tr.total td { font-weight: 800; font-size: 1rem; color: var(--brand); border-top: 2px solid var(--brand); }
tr.clickable { cursor: pointer; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions > * { margin-left: .6rem; }

/* Contribution grid */
.grid-table td.cell { padding: .2rem .25rem; }
.grid-table input.amt { width: 4.6rem; padding: .3rem .35rem; text-align: right; font-variant-numeric: tabular-nums; border: 1px solid transparent; background: var(--surface-2); border-radius: 5px; font-size: .85rem; }
.grid-table input.amt:hover { border-color: var(--line); }
.grid-table input.amt:focus { border-color: var(--brand-2); background: #fff; outline: none; box-shadow: 0 0 0 2px var(--brand-soft); }
.grid-table input.amt.changed { background: var(--accent-soft); border-color: #f5c46b; }
.sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 160px; }
thead .sticky-col, tfoot .sticky-col { background: var(--surface-2); }
.fill-btn { display: block; margin: .15rem auto 0; font-size: .65rem; border: 1px solid var(--line); background: #fff; border-radius: 4px; color: var(--brand-2); cursor: pointer; padding: 0 .3rem; text-transform: lowercase; }
.fill-btn:hover { background: var(--brand-soft); }
.sticky-actions { position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem 1rem; box-shadow: 0 -4px 12px rgba(0,0,0,.05); margin-bottom: 1rem; }

/* Forms */
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .8rem; color: var(--ink-2); }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; font: inherit; font-weight: 400; color: var(--ink); padding: .5rem .65rem; border: 1px solid #cdd6cf; border-radius: 7px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type=file] { padding: .35rem; }
input[type=checkbox], input[type=radio] { width: auto; display: inline-block; margin: 0 .4rem 0 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.hint { display: block; font-weight: 400; font-size: .8rem; color: var(--muted); margin-top: .25rem; }
p.hint { margin: -.3rem 0 .8rem; }
.actions { display: flex; gap: .6rem; align-items: center; margin-top: .4rem; }
.inline { display: inline; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .9rem 1.2rem; border-top: 1px solid var(--line); }
.card > .inline-form:first-child, .card .inline-form.top { border-top: 0; padding: 0; }
.card:not(.flush) .inline-form { padding: .6rem 0 0; border-top: 0; }
.inline-form input, .inline-form select { width: auto; margin: 0; }
.inline-label { display: flex; align-items: center; gap: .5rem; margin: 0; }
.inline-label select, .inline-label input { width: auto; margin: 0; }
.check { display: flex; align-items: flex-start; gap: .4rem; font-weight: 400; }
.radio-group { border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem .2rem; margin: .4rem 0 .8rem; }
.input-with-btn { display: flex; gap: .3rem; margin-top: .25rem; }
.input-with-btn input { margin: 0; }
.calc-box { background: var(--brand-soft); border-radius: 8px; padding: .6rem .9rem; margin: 0 0 .9rem; font-size: .9rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600; font-size: .88rem; padding: .5rem .95rem; border-radius: 7px; border: 1px solid transparent; cursor: pointer; text-decoration: none !important; white-space: nowrap; line-height: 1.3; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: #cdd6cf; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: #fff; color: var(--danger); border-color: #f1b4b4; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.link { background: none; border: 0; padding: 0; color: var(--brand-2); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }
.link.danger, .danger { color: var(--danger); }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; flex: 1; }
.filters input, .filters select { width: auto; margin: 0; min-width: 0; }
.filters input[name=q] { min-width: 200px; }

/* Tags & statuses */
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: #eef2ef; color: var(--ink-2); }
.tag-green { background: var(--brand-soft); color: var(--brand); }
.tag-amber { background: var(--accent-soft); color: var(--accent); }
.status { display: inline-block; font-size: .74rem; font-weight: 700; padding: .12rem .55rem; border-radius: 999px; }
.status.big { font-size: .9rem; padding: .3rem .8rem; }
.status-active { background: var(--info-soft); color: #075985; }
.status-overdue { background: var(--danger-soft); color: var(--danger); }
.status-closed { background: #eef2ef; color: var(--muted); }
.role-pill { font-size: .7rem; font-weight: 700; padding: .08rem .45rem; border-radius: 999px; background: #eef2ef; color: var(--ink-2); }
.role-admin { background: #ede9fe; color: #5b21b6; }
.role-treasurer { background: var(--brand-soft); color: var(--brand); }
.act-delete { background: var(--danger-soft); color: var(--danger); }
.act-create { background: var(--brand-soft); color: var(--brand); }
.act-restore, .act-update, .act-import { background: var(--accent-soft); color: var(--accent); }

/* Alerts */
.alert { padding: .7rem .95rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; font-size: .9rem; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #7f1d1d; }
.alert-warn { background: #fffbeb; border-color: #fde68a; color: #78350f; }
.alert-info { background: #f0f9ff; border-color: #bae6fd; color: #0c4a6e; }

/* Misc */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 .8rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.profile { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.profile-name { font-size: 1.3rem; font-weight: 750; }
.loan-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .8rem; }
.progress { height: 8px; background: #eef2ef; border-radius: 99px; overflow: hidden; margin: .3rem 0 .2rem; }
.progress > div { height: 100%; background: var(--brand-2); border-radius: 99px; }
.bar-row { margin-bottom: .7rem; }
.bar-label { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: .2rem; }
.bar { height: 8px; background: #eef2ef; border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 99px; }
.chart-box { position: relative; height: 290px; }
.pre { background: #0f1f16; color: #d1fae5; padding: .65rem .8rem; border-radius: 7px; font: .8rem/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; margin: .25rem 0 .9rem; cursor: copy; }
.notes { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin: .8rem 0; }
.notes ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.file-list { list-style: none; padding: 0; margin: 0; }
.file-list li { padding: .35rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.checklist { list-style: none; padding: 0; margin: 0 0 1rem; }
.checklist li { padding: .2rem 0; }
.steps li { margin-bottom: .4rem; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; }
.dialog { border: 0; border-radius: 12px; padding: 1.4rem; max-width: 460px; width: calc(100% - 2rem); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(10, 25, 15, .45); }
.print-head { display: none; }

/* Auth */
.auth-body { background: linear-gradient(160deg, #0f2a1b 0%, #166534 100%); min-height: 100vh; }
.auth-wrap { max-width: 420px; margin: 0 auto; padding: 8vh 1rem 2rem; }
.auth-wrap.wide { max-width: 720px; padding-top: 4vh; }
.auth-card { padding: 1.6rem; }
.auth-brand { display: flex; gap: .9rem; align-items: center; margin-bottom: 1.2rem; }
.auth-title { font-weight: 750; font-size: 1.1rem; }

/* Responsive */
@media (max-width: 1100px) {
  .kpis-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main-side { grid-template-columns: 1fr; }
  .form-grid.cols-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
  .menu-btn { display: block; }
  .topbar { padding: .6rem 1rem; }
  .content { padding: 1rem 1rem 3rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .user-link { display: none; }
}
@media (max-width: 560px) {
  .kpis-4 { grid-template-columns: 1fr; }
  .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .filters input[name=q] { min-width: 0; width: 100%; }
  .sticky-actions { flex-direction: column; align-items: stretch; }
}

/* Print */
@media print {
  .sidebar, .topbar, .no-print, .toolbar, .sticky-actions, .nav-backdrop { display: none !important; }
  body { background: #fff; font-size: 11px; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .print-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .8rem; border-bottom: 2px solid #000; }
  .kpi-strong { background: #fff !important; color: #000; border: 2px solid #000; }
  .kpi-strong .kpi-label, .kpi-strong .kpi-sub { color: #333; }
  a { color: #000; }
}

/* v1.1 — Analysis & Excel update */
.kpis-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.section-title { font-size: 1.05rem; margin: 1.6rem 0 .8rem; padding-bottom: .4rem; border-bottom: 2px solid var(--line); color: var(--brand); }
.chart-box.sm { height: 240px; margin-bottom: .8rem; }
.findings { list-style: none; margin: 0; padding: 0; }
.finding { display: flex; gap: .8rem; align-items: flex-start; padding: .7rem .8rem; border-radius: 8px; margin-bottom: .5rem; border-left: 4px solid; }
.finding .small { color: var(--ink-2); margin-top: .15rem; }
.f-tag { flex: none; font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: .15rem .5rem; border-radius: 999px; margin-top: .1rem; min-width: 4.6rem; text-align: center; }
.f-risk { background: #fef2f2; border-color: var(--danger); } .f-risk .f-tag { background: var(--danger); color: #fff; }
.f-watch { background: #fffbeb; border-color: #f59e0b; } .f-watch .f-tag { background: #f59e0b; color: #fff; }
.f-good { background: #f0fdf4; border-color: var(--brand-2); } .f-good .f-tag { background: var(--brand-2); color: #fff; }
.split-bar { height: 16px; border-radius: 99px; background: #fde68a; overflow: hidden; }
.split-bar > div { height: 100%; background: var(--brand-2); }
.legend { display: flex; gap: 1rem; margin-top: .4rem; flex-wrap: wrap; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: middle; }
.sw-loan { background: var(--brand-2); } .sw-cash { background: #fde68a; }
.xl-in { color: #1d4ed8; font-weight: 700; }
.xl-info { background: #f3f4f6; color: #6b7280; padding: 0 .3rem; border-radius: 3px; font-weight: 600; }
.chg { display: inline-block; margin-right: .8rem; }
.chg del { color: var(--danger); } .chg ins { color: var(--brand); text-decoration: none; font-weight: 600; }
ul.tight { margin: .4rem 0 0; padding-left: 1.2rem; }
@media (max-width: 1100px) { .kpis-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpis-5 { grid-template-columns: 1fr 1fr; } }
@media print { .section-title { break-after: avoid; } .finding { break-inside: avoid; } .chart-box.sm { height: 200px; } }
.grid-2 > *, .grid-main-side > * { min-width: 0; }
