:root {
  --navy-950: #0b1220;
  --navy-900: #101a2c;
  --navy-800: #16213a;
  --navy-700: #1e2c48;
  --accent: #3b82f6;
  --accent-soft: #93c5fd;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --slate-50: #f7f9fc;
  --slate-100: #eef1f6;
  --slate-200: #e3e8f0;
  --slate-500: #64748b;
  --slate-700: #334155;
  --slate-900: #0f172a;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--slate-50);
  color: var(--slate-900);
  min-height: 100vh;
}

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

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-950), var(--navy-900));
  color: #cbd5e1;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 1000;
  transition: transform .2s ease;
}

.sidebar-brand {
  padding: 22px 20px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .logo-dot {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #22d3ee);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 15px;
}
.sidebar-brand .brand-text { line-height: 1.15; }
.sidebar-brand .brand-text strong { display: block; font-size: 14.5px; color: #fff; }
.sidebar-brand .brand-text span { font-size: 11px; color: #93a3b8; }

.nav-section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: #64748b; padding: 18px 20px 6px;
}

.sidebar .nav-link {
  color: #b7c2d4; padding: 9px 20px; font-size: 14px;
  display: flex; align-items: center; gap: 11px;
  border-left: 3px solid transparent;
}
.sidebar .nav-link i { font-size: 15px; width: 18px; text-align: center; opacity: .85; }
.sidebar .nav-link:hover { color: #fff; background: rgba(255,255,255,.04); }
.sidebar .nav-link.active {
  color: #fff; background: rgba(59,130,246,.14);
  border-left-color: var(--accent);
  font-weight: 600;
}

.main-wrap { margin-left: 260px; flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 64px; background: #fff; border-bottom: 1px solid var(--slate-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 900;
}
.topbar h1 { font-size: 18px; font-weight: 700; margin: 0; color: var(--slate-900); }
.topbar .sub { font-size: 12.5px; color: var(--slate-500); }

.content { padding: 24px; flex: 1; }

.sidebar-toggle { display: none; }

@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
}

/* ---------- Cards ---------- */
.card { border: 1px solid var(--slate-200); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.card-plain { background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius); }

.kpi-card {
  background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius);
  padding: 18px 20px; height: 100%;
}
.kpi-card .kpi-label { font-size: 12.5px; color: var(--slate-500); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-card .kpi-value { font-size: 26px; font-weight: 800; color: var(--slate-900); margin-top: 4px; letter-spacing: -.02em; }
.kpi-card .kpi-sub { font-size: 12.5px; color: var(--slate-500); margin-top: 6px; }
.kpi-card .kpi-icon {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 16px; margin-bottom: 10px;
}
.kpi-icon.blue { background: #eaf1ff; color: var(--accent); }
.kpi-icon.green { background: var(--green-soft); color: var(--green); }
.kpi-icon.amber { background: var(--amber-soft); color: var(--amber); }
.kpi-icon.red { background: var(--red-soft); color: var(--red); }

.text-pos { color: var(--green); }
.text-neg { color: var(--red); }
.text-warn { color: var(--amber); }

.section-title { font-size: 15px; font-weight: 700; color: var(--slate-900); margin-bottom: 2px; }
.section-sub { font-size: 12.5px; color: var(--slate-500); margin-bottom: 16px; }

/* ---------- Tables ---------- */
.table-clean { font-size: 13.5px; margin-bottom: 0; }
.table-clean thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--slate-500);
  border-bottom: 1px solid var(--slate-200); font-weight: 700; padding: 10px 12px; white-space: nowrap;
}
.table-clean tbody td { padding: 11px 12px; vertical-align: middle; border-bottom: 1px solid var(--slate-100); }
.table-clean tbody tr:last-child td { border-bottom: none; }
.table-clean tbody tr:hover { background: var(--slate-50); }

/* ---------- Badges ---------- */
.badge-soft { font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px; text-transform: capitalize; }
.badge-active, .badge-paid, .badge-fully_returned { background: var(--green-soft); color: #15803d; }
.badge-partial, .badge-partially_returned, .badge-pending, .badge-on_hold { background: var(--amber-soft); color: #b45309; }
.badge-overdue, .badge-cancelled { background: var(--red-soft); color: #b91c1c; }
.badge-converted, .badge-completed { background: #e0e7ff; color: #4338ca; }
.badge-manual { background: var(--slate-100); color: var(--slate-700); }
.badge-funded_by_expense { background: #ede9fe; color: #6d28d9; }

/* ---------- Alerts panel ---------- */
.risk-item { display: flex; gap: 12px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--slate-200); margin-bottom: 8px; }
.risk-item.high { border-color: #fecaca; background: #fef2f2; }
.risk-item.medium { border-color: #fde68a; background: #fffbeb; }
.risk-item.low { border-color: var(--slate-200); background: var(--slate-50); }
.risk-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.risk-item.high .risk-dot { background: var(--red); }
.risk-item.medium .risk-dot { background: var(--amber); }
.risk-item.low .risk-dot { background: var(--slate-500); }
.risk-type { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--slate-500); }
.risk-msg { font-size: 13.5px; color: var(--slate-900); margin-top: 1px; }

/* ---------- Insights ---------- */
.insight-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--slate-200); font-size: 13.5px; }
.insight-item:last-child { border-bottom: none; }
.insight-item i { color: var(--accent); margin-top: 2px; }

/* ---------- Forms ---------- */
.form-label { font-size: 13px; font-weight: 600; color: var(--slate-700); }
.form-control, .form-select { font-size: 13.5px; border-radius: 9px; border-color: var(--slate-200); }
.form-control:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.form-hint { font-size: 12px; color: var(--slate-500); margin-top: 4px; }

.btn { border-radius: 9px; font-size: 13.5px; font-weight: 600; }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: #2563eb; border-color: #2563eb; }
.btn-outline-secondary { border-color: var(--slate-200); color: var(--slate-700); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #16213a, #0b1220 60%);
  padding: 20px;
}
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 18px; padding: 34px 30px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }

/* ---------- Money flow diagram ---------- */
.flow-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 0; }
.flow-node {
  background: #fff; border: 1.5px solid var(--slate-200); border-radius: 12px; padding: 12px 16px;
  min-width: 150px; text-align: center;
}
.flow-node .fn-label { font-size: 11px; text-transform: uppercase; color: var(--slate-500); font-weight: 700; }
.flow-node .fn-value { font-size: 16px; font-weight: 800; margin-top: 2px; }
.flow-arrow { color: var(--slate-500); font-size: 20px; }

/* ---------- Matrix heatmap ---------- */
.matrix-table td.cell { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.matrix-table td.cell.zero { color: var(--slate-500); font-weight: 400; }

/* ---------- Misc ---------- */
.chart-card { background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius); padding: 18px 20px; }
.divider-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--slate-500); margin: 22px 0 10px; font-weight: 700; }
code.small-code { background: var(--slate-100); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.progress { height: 8px; border-radius: 999px; background: var(--slate-100); }
