/* ============================================================
   Cooperative Financial Platform — Design System
   Solid colours only. CSS variables driven by the theme engine.
   ============================================================ */

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text, #1a2333);
  background: var(--background, #f4f6fb);
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: var(--primary, #1a3a8a); text-decoration: none; }
a:hover { text-decoration: none; }
ul, ol { list-style: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4, h5 { line-height: 1.25; font-weight: 700; color: var(--text, #1a2333); }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.text-muted { color: var(--text-muted, #6b7a90); }
.text-center { text-align: center; }
.text-success { color: var(--success, #0f9d58); }
.text-danger { color: var(--danger, #d93025); }
.text-warning { color: var(--warning, #e6a700); }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; gap: 12px; } .flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
/* Grid children must be allowed to shrink so wide tables/forms never
   blow the grid out past the viewport. */
.grid-2 > *, .grid-3 > *, .grid-4 > * { min-width: 0; }
.hidden { display: none !important; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border: 1px solid transparent; border-radius: 10px;
  font-weight: 600; font-size: 14px; line-height: 1.2;
  background: var(--button-bg, #1a3a8a); color: var(--button-text, #ffffff);
  transition: filter .15s ease, transform .1s ease, box-shadow .15s ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-outline { background: transparent; color: var(--primary, #1a3a8a); border-color: var(--primary, #1a3a8a); }
.btn-outline:hover { background: var(--primary, #1a3a8a); color: #fff; }
.btn-success { background: var(--success, #0f9d58); }
.btn-danger { background: var(--danger, #d93025); }
.btn-warning { background: var(--warning, #e6a700); color: #1a2333; }
.btn-ghost { background: transparent; color: var(--text, #1a2333); border-color: var(--border, #e3e8f0); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 14px 28px; font-size: 16px; border-radius: 12px; }
.btn-block { width: 100%; }

/* ---- Cards ---- */
.card {
  background: var(--card-bg, #ffffff);
  border: 1px solid var(--border, #e3e8f0);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(15, 37, 87, 0.05);
  transition: box-shadow .2s ease, transform .2s ease;
}
.card:hover { box-shadow: 0 6px 18px rgba(15, 37, 87, 0.09); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-title { font-size: 17px; font-weight: 700; }

/* ---- Stat cards ---- */
.stat-card { position: relative; overflow: hidden; padding: 20px; border-radius: 16px; background: var(--card-bg, #fff); border: 1px solid var(--border, #e3e8f0); box-shadow: 0 1px 3px rgba(15,37,87,.05); transition: box-shadow .2s, transform .2s; }
.stat-card:hover { box-shadow: 0 8px 22px rgba(15,37,87,.1); transform: translateY(-2px); }
.stat-card .stat-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; margin-bottom: 12px; background: var(--primary, #1a3a8a); color: #fff; }
.stat-card .stat-icon.green { background: var(--success, #0f9d58); }
.stat-card .stat-icon.amber { background: var(--warning, #e6a700); color: #1a2333; }
.stat-card .stat-icon.red { background: var(--danger, #d93025); }
.stat-card .stat-icon.blue { background: var(--info, #1a73e8); }
.stat-card .stat-icon.navy { background: var(--secondary, #0f2557); }
.stat-card .stat-label { font-size: 13px; color: var(--text-muted, #6b7a90); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat-card .stat-value { font-size: 24px; font-weight: 800; margin-top: 4px; }

/* ---- Alerts ---- */
.alert { padding: 14px 18px; border-radius: 12px; margin-bottom: 16px; border: 1px solid; font-size: 14px; display: flex; align-items: flex-start; gap: 10px; }
.alert i { margin-top: 2px; }
.alert-success { background: #e9f7ef; border-color: #b8e6cd; color: #0a5c34; }
.alert-error, .alert-danger { background: #fdecea; border-color: #f5c6c1; color: #8c1d18; }
.alert-info { background: #e8f1fd; border-color: #c2d9f7; color: #0d47a1; }
.alert-warning { background: #fdf6e4; border-color: #f3dfae; color: #7a5c00; }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 6px; }
.form-label .req { color: var(--danger, #d93025); }
.form-control, .form-select, .form-textarea {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border, #e3e8f0);
  border-radius: 10px; background: #fff; font-size: 14.5px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary, #1a3a8a);
  box-shadow: 0 0 0 3px rgba(26, 58, 138, 0.12);
}
.form-textarea { min-height: 110px; resize: vertical; }
.form-help { font-size: 12.5px; color: var(--text-muted, #6b7a90); margin-top: 4px; }
.form-error { font-size: 12.5px; color: var(--danger, #d93025); margin-top: 4px; }
.form-check { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.form-check input { margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.input-group { display: flex; }
.input-group .input-addon { display: flex; align-items: center; padding: 0 14px; background: var(--background, #f4f6fb); border: 1.5px solid var(--border, #e3e8f0); border-right: 0; border-radius: 10px 0 0 10px; font-weight: 700; }
.input-group .form-control { border-radius: 0 10px 10px 0; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border, #e3e8f0); border-radius: 14px; background: var(--card-bg, #fff); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
table.table th {
  text-align: left; padding: 13px 16px; background: var(--background, #f4f6fb);
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted, #6b7a90); border-bottom: 1px solid var(--border, #e3e8f0);
  white-space: nowrap;
}
table.table td { padding: 13px 16px; border-bottom: 1px solid var(--border, #e3e8f0); vertical-align: middle; }
table.table tbody tr:last-child td { border-bottom: 0; }
table.table tbody tr:hover { background: #f8fafd; }
table.table .amount { font-weight: 700; white-space: nowrap; }
table.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Badges ---- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.badge-success { background: #e9f7ef; color: #0a5c34; }
.badge-danger { background: #fdecea; color: #8c1d18; }
.badge-warning { background: #fdf6e4; color: #7a5c00; }
.badge-info { background: #e8f1fd; color: #0d47a1; }
.badge-muted { background: #eef1f6; color: #5a6a80; }
.badge-primary { background: #e8eefb; color: var(--primary, #1a3a8a); }

/* ---- Pagination ---- */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 20px; justify-content: center; }
.pagination .page-link {
  min-width: 38px; height: 38px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border, #e3e8f0); border-radius: 10px; background: var(--card-bg, #fff);
  color: var(--text, #1a2333); font-weight: 600; font-size: 14px;
  transition: background .15s, color .15s;
}
.pagination .page-link:hover { background: var(--background, #f4f6fb); }
.pagination .page-link.active { background: var(--primary, #1a3a8a); color: #fff; border-color: var(--primary, #1a3a8a); }
.pagination .page-dots { align-self: center; color: var(--text-muted, #6b7a90); }

/* ---- Auth & public layout ---- */
.public-body { min-height: 100vh; display: flex; flex-direction: column; }
.public-main { flex: 1; }

/* Navbar (public/landing) */
.public-nav {
  position: sticky; top: 0; z-index: 100; background: var(--nav-bg, #ffffff);
  border-bottom: 1px solid var(--border, #e3e8f0);
}
.public-nav-inner { display: flex; align-items: center; justify-content: space-between; height: 68px; gap: 16px; }
.public-nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; color: var(--text, #1a2333); }
.public-nav .brand img { height: 38px; width: auto; }
.public-nav-links { display: flex; gap: 4px; align-items: center; }
.public-nav-links a { padding: 8px 13px; border-radius: 9px; color: var(--nav-text, #1a2333); font-weight: 600; font-size: 14px; }
.public-nav-links a:hover, .public-nav-links a.active { background: var(--background, #f4f6fb); color: var(--primary, #1a3a8a); }
.public-nav-actions { display: flex; gap: 10px; align-items: center; }
.nav-toggle { display: none; background: none; border: 0; font-size: 22px; color: var(--nav-text, #1a2333); }

/* Mobile slide-in nav */
.nav-overlay { position: fixed; inset: 0; background: rgba(10, 20, 40, 0.55); z-index: 200; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
.nav-overlay.open { opacity: 1; pointer-events: auto; }
.mobile-nav {
  position: fixed; top: 0; left: 0; bottom: 0; width: 290px; max-width: 85vw; z-index: 210;
  background: var(--card-bg, #fff); transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
  display: flex; flex-direction: column; box-shadow: 4px 0 24px rgba(10, 20, 40, .18);
}
.mobile-nav.open { transform: translateX(0); }
.mobile-nav-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border, #e3e8f0); }
.mobile-nav-header .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.mobile-nav-header .brand img { height: 32px; }
.mobile-nav .close-btn { background: var(--background, #f4f6fb); border: 0; width: 34px; height: 34px; border-radius: 9px; font-size: 16px; }
.mobile-nav-links { flex: 1; overflow-y: auto; padding: 12px; }
.mobile-nav-links a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 11px; color: var(--text, #1a2333); font-weight: 600; font-size: 14.5px; margin-bottom: 2px; }
.mobile-nav-links a i { width: 20px; text-align: center; color: var(--text-muted, #6b7a90); }
.mobile-nav-links a:hover, .mobile-nav-links a.active { background: var(--primary, #1a3a8a); color: #fff; }
.mobile-nav-links a.active i, .mobile-nav-links a:hover i { color: inherit; }
.mobile-nav-footer { padding: 14px 18px; border-top: 1px solid var(--border, #e3e8f0); font-size: 13px; color: var(--text-muted, #6b7a90); }
body.nav-locked { overflow: hidden; }

/* ---- Dashboard layout ---- */
.dash-body { display: flex; min-height: 100vh; background: var(--background, #f4f6fb); }
.sidebar {
  width: 252px; min-height: 100vh; position: sticky; top: 0; flex-shrink: 0;
  background: var(--sidebar-bg, #0f2557); color: var(--sidebar-text, #c9d6f2);
  display: flex; flex-direction: column; z-index: 120;
  transition: width .2s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px; font-weight: 800; font-size: 16.5px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand img { height: 34px; width: auto; }
.sidebar-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.sidebar-nav .nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; font-weight: 700; opacity: .55; padding: 16px 12px 6px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 11px;
  color: var(--sidebar-text, #c9d6f2); font-size: 14px; font-weight: 600; margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.sidebar-nav a i { width: 20px; text-align: center; font-size: 15px; }
.sidebar-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-nav a.active { background: var(--primary, #1a3a8a); color: #fff; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 110; height: 64px;
  background: var(--nav-bg, #ffffff); border-bottom: 1px solid var(--border, #e3e8f0);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px; gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-weight: 800; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar .hamburger { display: none; background: var(--background, #f4f6fb); border: 0; width: 40px; height: 40px; border-radius: 10px; font-size: 18px; }
.icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; background: var(--background, #f4f6fb); border: 0; font-size: 16px; color: var(--text, #1a2333); }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger, #d93025); border: 2px solid #fff; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary, #1a3a8a); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; }
.avatar img { border-radius: 50%; height: 100%; width: 100%; object-fit: cover; }

/* Dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 210px; z-index: 150;
  background: var(--card-bg, #fff); border: 1px solid var(--border, #e3e8f0); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(10,20,40,.14); padding: 8px; display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-menu a, .dropdown-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px 12px; border-radius: 9px; background: none; border: 0;
  color: var(--text, #1a2333); font-size: 14px; font-weight: 600;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--background, #f4f6fb); }
.dropdown-divider { height: 1px; background: var(--border, #e3e8f0); margin: 6px 4px; }

/* Main content */
.dash-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dash-content { padding: 26px 24px; flex: 1; }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.page-header h1 { font-size: 23px; }
.page-header .page-sub { color: var(--text-muted, #6b7a90); font-size: 14px; margin-top: 2px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stats-grid.triple { grid-template-columns: repeat(3, 1fr); }

/* Charts — fixed responsive containers; canvases always fit their card */
.chart-box { position: relative; height: 300px; min-width: 0; }
.chart-box .card-title { position: relative; z-index: 1; }
.chart-box canvas { max-width: 100%; max-height: 100%; }
@media (max-width: 1200px) {
  .chart-box { height: 250px; }
}
@media (max-width: 768px) {
  .chart-box { height: 220px; }
}
@media (max-width: 430px) {
  .chart-box { height: 200px; }
}

/* Filter bar */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.filter-bar .form-group { margin-bottom: 0; min-width: 150px; }

/* Timeline (loan/complaint) */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--border, #e3e8f0); }
.timeline-item { position: relative; padding-bottom: 18px; }
.timeline-item::before { content: ''; position: absolute; left: -23px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary, #1a3a8a); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--primary, #1a3a8a); }
.timeline-item.done::before { background: var(--success, #0f9d58); box-shadow: 0 0 0 2px var(--success, #0f9d58); }
.timeline-item .tl-title { font-weight: 700; font-size: 14px; }
.timeline-item .tl-time { font-size: 12.5px; color: var(--text-muted, #6b7a90); }
.timeline-item .tl-body { font-size: 13.5px; color: var(--text-muted, #6b7a90); margin-top: 3px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,20,40,.55); z-index: 300; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--card-bg, #fff); border-radius: 18px; max-width: 520px; width: 100%;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(10,20,40,.3);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 0; }
.modal-header h3 { font-size: 18px; }
.modal-close { background: var(--background, #f4f6fb); border: 0; width: 34px; height: 34px; border-radius: 9px; font-size: 15px; }
.modal-body { padding: 18px 22px 22px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border, #e3e8f0); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 16px; font-weight: 700; font-size: 14px; color: var(--text-muted, #6b7a90); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.active, .tabs a:hover { color: var(--primary, #1a3a8a); border-bottom-color: var(--primary, #1a3a8a); }

/* Member bottom nav (mobile) */
.bottom-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 130; background: var(--card-bg, #fff); border-top: 1px solid var(--border, #e3e8f0); }
.bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 4px 12px; font-size: 10.5px; font-weight: 700; color: var(--text-muted, #6b7a90); }
.bottom-nav a.active { color: var(--primary, #1a3a8a); }
.bottom-nav a i { font-size: 17px; }
body.has-bottom-nav .dash-content { padding-bottom: 86px; }

/* Print styles */
@media print {
  .sidebar, .topbar, .bottom-nav, .no-print { display: none !important; }
  body { background: #fff; }
  .dash-content { padding: 0; }
  .card, .table-wrap { border: 1px solid #ccc; box-shadow: none; }
}

/* ---- Responsive ---- */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid.triple { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1024px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .28s cubic-bezier(.4,0,.2,1); width: 268px; }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(10,20,40,.18); }
  .topbar .hamburger { display: inline-flex; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(10,20,40,.55); z-index: 115; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }
  .public-nav-links { display: none; }
  .nav-toggle { display: inline-flex; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .container { padding: 0 16px; }
  .dash-content { padding: 18px 14px; }
  .topbar { padding: 0 14px; height: 58px; }
  .page-header h1 { font-size: 20px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .stats-grid, .stats-grid.triple { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card .stat-value { font-size: 20px; }
  .bottom-nav { display: flex; }
  body.has-bottom-nav { padding-bottom: 0; }
  .btn-lg { padding: 12px 20px; }
  .table-wrap { border-radius: 10px; }
  table.table { font-size: 13px; }
}

@media (max-width: 430px) {
  .stats-grid, .stats-grid.triple { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 14px; }
  .stat-card .stat-value { font-size: 18px; }
  .stat-card .stat-icon { width: 36px; height: 36px; font-size: 16px; }
  .topbar-title { font-size: 16px; }
  .page-header h1 { font-size: 18px; }
  .card { padding: 16px; }
  .btn { padding: 9px 15px; }
}

@media (max-width: 360px) {
  .stats-grid, .stats-grid.triple { grid-template-columns: 1fr; }
  .table-wrap { border-radius: 10px; }
}
