:root{
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-2: #14b8a6;
  --sidebar: #0f172a;
  --sidebar-soft: #111827;
  --sidebar-text: #cbd5e1;
  --sidebar-active: rgba(20,184,166,.16);
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, .06);

  --topbar-height: 64px;
  --sidebar-width: 270px;
  --radius: 16px;
}

/* =========================
   RESET
========================= */
*{
  box-sizing: border-box;
}

html,
body{
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

body.sidebar-open{
  overflow: hidden;
}

a{
  text-decoration: none;
}

img{
  max-width: 100%;
  height: auto;
}

/* =========================
   TOPBAR
========================= */
.topbar{
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  height: var(--topbar-height);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 1100;
}

.topbar-left{
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.menu-toggle{
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(15,23,42,.05);
}

.brand{
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand img{
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
}

.brand-text{
  min-width: 0;
}

.brand-title{
  display: block;
  font-size: .92rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-subtitle{
  display: block;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 500;
  margin-top: 2px;
}

.user-area{
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-chip{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.user-avatar{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .82rem;
  font-weight: 700;
}

.user-meta{
  line-height: 1.1;
}

.user-name{
  font-size: .84rem;
  font-weight: 700;
  color: var(--text);
}

.user-role{
  color: var(--muted);
  font-size: .72rem;
}

.logout-btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: .78rem;
  font-weight: 600;
  line-height: 1;
}

.logout-btn:hover{
  color: var(--danger);
  border-color: #fecaca;
  background: #fff5f5;
}

/* =========================
   SIDEBAR
========================= */
#sidebar{
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-soft));
  z-index: 1200;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,.04);
}

.sidebar-inner{
  padding: 18px 14px 24px;
  padding-top: calc(var(--topbar-height) + 12px);
}

.sidebar-section-title{
  color: #94a3b8;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 16px 10px 8px;
}

.nav-item{
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 9px 12px;
  margin-bottom: 6px;
  border-radius: 14px;
  color: var(--sidebar-text);
  font-size: .84rem;
  font-weight: 500;
  transition: .2s ease;
}

.nav-item:hover{
  color: #fff;
  background: rgba(255,255,255,.06);
}

.nav-item.active{
  color: #fff;
  background: var(--sidebar-active);
  box-shadow: inset 0 0 0 1px rgba(45,212,191,.12);
}

.icon-field{
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.nav-label{
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.sub-nav{
  margin: 4px 0 12px 40px;
  padding-left: 8px;
  border-left: 1px solid rgba(148,163,184,.18);
}

.sub-nav a{
  display: block;
  color: #94a3b8;
  font-size: .8rem;
  padding: 8px 10px;
  border-radius: 10px;
  margin-bottom: 4px;
}

.sub-nav a:hover,
.sub-nav a.active{
  background: rgba(255,255,255,.06);
  color: #fff;
}

.badge-wallet{
  margin-left: 6px;
  font-size: .66rem;
}

/* =========================
   MAIN CONTENT
========================= */
.app-content{
  margin-top: var(--topbar-height);
  margin-left: var(--sidebar-width);
  min-height: calc(100vh - var(--topbar-height));
  padding: 20px;
}

/* =========================
   CARDS / TABLES / FORMS
========================= */
.card{
  border: 1px solid rgba(226,232,240,.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  background: var(--surface);
}

.card-header{
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  font-weight: 700;
  font-size: .92rem;
}

.card-body{
  padding: 16px 18px;
}

.form-control,
.form-select,
input,
select,
textarea{
  border-radius: 12px !important;
  border: 1px solid #dbe3ee !important;
  min-height: 38px;
  font-size: .84rem !important;
  box-shadow: none !important;
}

.form-control:focus,
.form-select:focus,
input:focus,
select:focus,
textarea:focus{
  border-color: rgba(20,184,166,.65) !important;
  box-shadow: 0 0 0 4px rgba(20,184,166,.10) !important;
}

label{
  font-size: .78rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 6px;
}

.table-responsive{
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table{
  margin-bottom: 0;
  width: 100%;
}

.table th{
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #64748b;
  background: #f8fafc;
  border-top: 0 !important;
  white-space: nowrap;
  padding: 10px 8px;
}

.table td{
  font-size: .8rem;
  vertical-align: middle;
  padding: 10px 8px;
}

.table td p,
.table td div{
  margin-bottom: 4px;
}

.table td small{
  font-size: .72rem;
  color: var(--muted);
}

.modal-content{
  border-radius: 18px;
  border: 0;
  box-shadow: 0 20px 60px rgba(15,23,42,.18);
}

.toast{
  position: fixed;
  top: 84px;
  right: 20px;
  z-index: 2000;
}

/* =========================
   BUTTONS
========================= */
.btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 12px;
  font-size: .76rem;
  font-weight: 600;
  line-height: 1.1;
  border-radius: 10px;
}

.btn.btn-sm{
  min-height: 28px;
  padding: 4px 8px;
  font-size: .7rem;
  border-radius: 8px;
}

.btn i{
  font-size: .72rem;
  line-height: 1;
}

.card-header .btn{
  min-height: 32px;
}

.table .btn{
  vertical-align: middle;
}

.table td .btn + .btn,
.table td .btn + a,
.table td a + .btn{
  margin-left: 4px;
}

.badge{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .66rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
}

/* =========================
   DATATABLE / PAGE STRUCTURE
========================= */
.container-fluid{
  width: 100%;
}

.row.mx-0{
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.col-12.px-0,
.col-lg-12{
  padding-left: 0 !important;
  padding-right: 0 !important;
}

/* =========================
   MOBILE OVERLAY
========================= */
.sidebar-overlay{
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,.45);
  opacity: 0;
  visibility: hidden;
  transition: .25s ease;
  z-index: 1190;
}

.sidebar-overlay.show{
  opacity: 1;
  visibility: visible;
}

/* =========================
   MOBILE
========================= */
@media (max-width: 991px){
  .menu-toggle{
    display: inline-flex;
  }

  #sidebar{
    left: -290px;
    transition: left .25s ease;
    box-shadow: 0 24px 60px rgba(2,6,23,.35);
  }

  #sidebar.open{
    left: 0;
  }

  .topbar{
    left: 0;
    width: 100%;
  }

  .app-content{
    margin-left: 0;
    padding: 14px;
  }

  .brand-subtitle,
  .user-role,
  .user-name,
  .logout-btn span{
    display: none;
  }

  .user-chip{
    padding: 4px;
    border: 0;
    background: transparent;
  }

  .logout-btn{
    width: 36px;
    height: 36px;
    padding: 0;
  }
}

@media (max-width: 768px){
  .btn{
    min-height: 30px;
    padding: 5px 9px;
    font-size: .72rem;
  }

  .btn.btn-sm{
    min-height: 26px;
    padding: 3px 7px;
    font-size: .66rem;
  }

  .table th{
    font-size: .68rem;
    padding: 8px 6px;
  }

  .table td{
    font-size: .76rem;
    padding: 8px 6px;
  }
}

@media (max-width: 575px){
  .topbar{
    padding: 0 12px;
  }

  .brand-title{
    font-size: .78rem;
    max-width: 160px;
  }

  .brand img{
    width: 32px;
    height: 32px;
  }

  .app-content{
    padding: 12px;
  }

  .card-header,
  .card-body{
    padding-left: 12px;
    padding-right: 12px;
  }
}

#loan-list td,
#loan-list th {
  vertical-align: middle;
}

#loan-list .btn {
  white-space: nowrap;
}

#loan-list .badge {
  min-width: 62px;
}

.table-borderless th {
  width: 150px;
  color: #64748b;
  font-weight: 600;
}

#loan-ledger-table td,
#loan-ledger-table th,
#payment-history-table td,
#payment-history-table th {
  vertical-align: middle;
}

@media print {
  .topbar,
  #sidebar,
  .sidebar-overlay,
  .btn,
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_paginate,
  .dataTables_wrapper .dataTables_info {
    display: none !important;
  }

  .app-content {
    margin: 0 !important;
    padding: 0 !important;
  }

  .card {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
  }
}
.chart-box{
  position: relative;
  width: 100%;
  height: 280px;
}

@media (max-width: 768px){
  .chart-box{
    height: 220px;
  }
}

#loan-list .table-danger td {
  background-color: #ffdcdc !important;
}

#loan-list .table-warning td {
  background-color: #faf1e0 !important;
}
