/* ===== ROOT VARIABLES ===== */
:root {
  --primary: #1E3A8A;
  --primary-light: #2d52b8;
  --secondary: #3B82F6;
  --success: #16a34a;
  --warning: #ea580c;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --sidebar-width: 240px;
  --topbar-height: 60px;
}

/* ===== BASE ===== */
* { box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: #1e293b; margin: 0; }
a { text-decoration: none; color: inherit; }

/* ===== SIDEBAR ===== */
#sidebar {
  width: var(--sidebar-width);
  background: var(--primary);
  height: 100vh;
  position: fixed;
  top: 0; left: 0;
  overflow-y: auto;
  z-index: 1000;
  transition: transform .3s;
}
#sidebar .sidebar-brand {
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; gap: 10px;
}
#sidebar .sidebar-brand img { width: 36px; height: 36px; border-radius: 8px; }
#sidebar .sidebar-brand span { color: #fff; font-weight: 700; font-size: 15px; line-height: 1.2; }
#sidebar .nav-section { padding: 8px 12px 4px; font-size: 10px; text-transform: uppercase; color: rgba(255,255,255,.4); letter-spacing: 1px; }
#sidebar .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; color: rgba(255,255,255,.75);
  border-radius: 6px; margin: 1px 8px;
  font-size: 13.5px; transition: all .2s;
}
#sidebar .nav-link:hover, #sidebar .nav-link.active {
  background: rgba(255,255,255,.12); color: #fff;
}
#sidebar .nav-link i { width: 18px; text-align: center; font-size: 14px; }

/* ===== TOPBAR ===== */
#topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  position: fixed;
  top: 0; left: var(--sidebar-width); right: 0;
  display: flex; align-items: center; padding: 0 20px;
  gap: 12px; z-index: 999;
}
#topbar .search-box {
  flex: 1; max-width: 320px;
  position: relative;
}
#topbar .search-box input {
  width: 100%; padding: 7px 12px 7px 36px;
  border: 1px solid #e2e8f0; border-radius: 8px;
  font-size: 13px; background: var(--bg); outline: none;
}
#topbar .search-box i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: #94a3b8; font-size: 13px; }
#topbar .ms-auto { margin-left: auto; }
.topbar-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: #475569; cursor: pointer;
  position: relative; border: none; font-size: 15px;
}
.topbar-icon .badge-dot {
  width: 8px; height: 8px; background: var(--danger);
  border-radius: 50%; position: absolute; top: 4px; right: 4px;
  border: 2px solid #fff;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; cursor: pointer;
}

/* ===== MAIN CONTENT ===== */
#main {
  margin-left: var(--sidebar-width);
  padding-top: var(--topbar-height);
  min-height: 100vh;
}
.page-content { padding: 24px; }
.page-header { margin-bottom: 20px; }
.page-header h4 { font-size: 20px; font-weight: 700; color: var(--primary); margin: 0; }
.page-header p { font-size: 13px; color: #64748b; margin: 2px 0 0; }
.breadcrumb { font-size: 12px; }
.breadcrumb-item + .breadcrumb-item::before { color: #94a3b8; }

/* ===== STAT CARDS ===== */
.stat-card {
  background: #fff; border-radius: 12px;
  padding: 18px 20px; border: 1px solid #e2e8f0;
  display: flex; align-items: center; gap: 14px;
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.stat-card .label { font-size: 12px; color: #64748b; margin: 0; }
.stat-card .value { font-size: 22px; font-weight: 700; color: #1e293b; margin: 0; line-height: 1.2; }
.stat-card .change { font-size: 11px; margin: 2px 0 0; }

/* ===== CARDS ===== */
.card { border: 1px solid #e2e8f0; border-radius: 12px; box-shadow: none; }
.card-header { background: #fff; border-bottom: 1px solid #e2e8f0; padding: 14px 18px; font-weight: 600; font-size: 14px; border-radius: 12px 12px 0 0 !important; }
.card-body { padding: 18px; }

/* ===== TABLES ===== */
.table-card { background: #fff; border-radius: 12px; border: 1px solid #e2e8f0; overflow: hidden; }
.table-toolbar { padding: 14px 18px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #f1f5f9; flex-wrap: wrap; }
.table-toolbar h6 { margin: 0; font-size: 14px; font-weight: 600; }
.table thead th { background: #f8fafc; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: #64748b; border-bottom: 1px solid #e2e8f0; padding: 10px 14px; white-space: nowrap; }
.table tbody td { font-size: 13px; padding: 11px 14px; vertical-align: middle; border-bottom: 1px solid #f1f5f9; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }

/* ===== BADGES ===== */
.badge { font-size: 11px; font-weight: 500; padding: 4px 9px; border-radius: 20px; }
.badge-active { background: #dcfce7; color: #16a34a; }
.badge-pending { background: #fef9c3; color: #ca8a04; }
.badge-closed { background: #f1f5f9; color: #64748b; }
.badge-overdue { background: #fee2e2; color: #dc2626; }
.badge-verified { background: #dcfce7; color: #16a34a; }
.badge-rejected { background: #fee2e2; color: #dc2626; }
.badge-approved { background: #dbeafe; color: #1d4ed8; }

/* ===== BUTTONS ===== */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-light); border-color: var(--primary-light); }
.btn-sm { font-size: 12px; padding: 4px 10px; }
.btn-icon { width: 30px; height: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; font-size: 13px; }

/* ===== FORMS ===== */
.form-label { font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 5px; }
.form-control, .form-select {
  font-size: 13px; border: 1px solid #d1d5db; border-radius: 8px;
  padding: 8px 12px; transition: border-color .2s;
}
.form-control:focus, .form-select:focus { border-color: var(--secondary); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
.required::after { content: ' *'; color: var(--danger); }
.input-group-text { font-size: 13px; background: #f8fafc; border-color: #d1d5db; }

/* ===== TABS ===== */
.nav-tabs .nav-link { font-size: 13px; color: #64748b; border: none; padding: 10px 16px; border-bottom: 2px solid transparent; }
.nav-tabs .nav-link.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; background: none; }
.nav-tabs { border-bottom: 1px solid #e2e8f0; }

/* ===== PROFILE ===== */
.profile-avatar {
  width: 90px; height: 90px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 700; margin: 0 auto 10px;
}
.profile-photo { width: 90px; height: 90px; border-radius: 50%; object-fit: cover; border: 3px solid #e2e8f0; }
.info-row { display: flex; gap: 8px; margin-bottom: 10px; font-size: 13px; }
.info-row .label { color: #64748b; min-width: 140px; }
.info-row .value { font-weight: 500; }

/* ===== LOAN DETAIL ===== */
.loan-detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.loan-detail-item { background: #f8fafc; border-radius: 8px; padding: 12px 14px; }
.loan-detail-item .ld-label { font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: .5px; }
.loan-detail-item .ld-value { font-size: 15px; font-weight: 600; color: #1e293b; margin-top: 2px; }

/* ===== PROGRESS ===== */
.progress { height: 6px; border-radius: 10px; background: #e2e8f0; }
.progress-bar { background: var(--secondary); border-radius: 10px; }

/* ===== UPLOAD ===== */
.upload-box {
  border: 2px dashed #d1d5db; border-radius: 10px;
  padding: 24px; text-align: center; cursor: pointer;
  transition: border-color .2s; background: #f8fafc;
}
.upload-box:hover { border-color: var(--secondary); }
.upload-box i { font-size: 28px; color: #94a3b8; }
.upload-box p { font-size: 12px; color: #64748b; margin: 6px 0 0; }

/* ===== TOAST ===== */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; }

/* ===== LOGIN ===== */
.login-page { min-height: 100vh; background: linear-gradient(135deg, var(--primary) 0%, #1e40af 50%, #1d4ed8 100%); display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border-radius: 16px; padding: 40px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.login-logo { width: 64px; height: 64px; background: var(--primary); border-radius: 14px; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; }
.login-logo i { font-size: 28px; color: #fff; }

/* ===== FOOTER ===== */
.main-footer { background: #fff; border-top: 1px solid #e2e8f0; padding: 12px 24px; font-size: 12px; color: #94a3b8; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }

/* ===== CHART CONTAINER ===== */
.chart-container { position: relative; height: 220px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 991px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.show { transform: translateX(0); }
  #topbar { left: 0; }
  #main { margin-left: 0; }
  .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 999; }
  .sidebar-overlay.show { display: block; }
}
@media (max-width: 576px) {
  .page-content { padding: 16px; }
  .stat-card .value { font-size: 18px; }
}

/* ===== PROFESSIONAL A4 PRINT SYSTEM ===== */
.print-document-header,
.print-document-footer,
.print-field-value { display: none; }

@media print {
  @page { size: A4 portrait; margin: 15mm; }

  html, body {
    width: auto !important;
    min-width: 0 !important;
    background: #fff !important;
    color: #111827 !important;
    font-family: 'Inter', Arial, sans-serif !important;
    font-size: 9.5pt !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #sidebar, #topbar, .sidebar-overlay, .main-footer, .toast-container,
  .breadcrumb, .pagination, button, .btn, .dropdown-menu, .no-print,
  .table-toolbar .ms-auto, .page-header .btn, input[type="checkbox"] {
    display: none !important;
  }

  #main {
    margin: 0 !important;
    padding: 0 !important;
    min-height: 0 !important;
  }

  .page-content {
    padding: 0 !important;
    width: 100% !important;
  }

  .print-document-header {
    display: flex !important;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16mm;
    padding-bottom: 6mm;
    margin-bottom: 7mm;
    border-bottom: 2px solid #1e293b;
  }

  .print-brand {
    display: flex;
    align-items: center;
    gap: 3mm;
  }

  .print-brand-mark {
    width: 11mm;
    height: 11mm;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2mm;
    background: #1e3a8a !important;
    color: #fff !important;
    font-size: 16pt;
  }

  .print-brand-name {
    color: #1e3a8a !important;
    font-size: 15pt;
    font-weight: 700;
    line-height: 1.1;
  }

  .print-brand-subtitle,
  .print-meta {
    color: #64748b !important;
    font-size: 8pt;
    line-height: 1.5;
  }

  .print-title {
    max-width: 90mm;
    color: #111827 !important;
    font-size: 14pt;
    font-weight: 700;
    line-height: 1.2;
    text-align: right;
    text-transform: uppercase;
  }

  .print-document-footer {
    display: flex !important;
    justify-content: space-between;
    gap: 8mm;
    margin-top: 10mm;
    padding-top: 3mm;
    border-top: 1px solid #cbd5e1;
    color: #64748b !important;
    font-size: 7.5pt;
  }

  .page-header {
    margin: 0 0 5mm !important;
    padding: 0 0 3mm !important;
    border-bottom: 1px solid #e2e8f0;
  }

  .page-header h4 {
    color: #111827 !important;
    font-size: 14pt !important;
  }

  .page-header p { color: #64748b !important; font-size: 8.5pt !important; }

  .card, .table-card, .stat-card, .loan-detail-item {
    box-shadow: none !important;
    border-color: #cbd5e1 !important;
    border-radius: 2mm !important;
    break-inside: avoid;
  }

  .table-card > .table-toolbar,
  .card > .card-header {
    background: #f8fafc !important;
    border-left: 1mm solid #1e3a8a !important;
  }

  .row { --bs-gutter-x: 4mm !important; --bs-gutter-y: 4mm !important; }
  .card { margin-bottom: 4mm !important; }
  .card-header {
    padding: 2.5mm 3mm !important;
    background: #f1f5f9 !important;
    color: #1e3a8a !important;
    border-color: #cbd5e1 !important;
    font-size: 9pt !important;
  }
  .card-body { padding: 3mm !important; }

  .stat-card { padding: 3mm !important; gap: 3mm !important; }
  .stat-icon { width: 9mm !important; height: 9mm !important; font-size: 12pt !important; }
  .stat-card .value { font-size: 13pt !important; }
  .stat-card .label, .stat-card .change { font-size: 7.5pt !important; }

  .table-responsive { overflow: visible !important; }
  .table { width: 100% !important; border-collapse: collapse !important; }
  .table thead { display: table-header-group; }
  .table tfoot { display: table-footer-group; }
  .table tr { break-inside: avoid; }
  .table thead th {
    padding: 2.2mm 2mm !important;
    background: #1e293b !important;
    color: #fff !important;
    border: 1px solid #cbd5e1 !important;
    font-size: 7.2pt !important;
    letter-spacing: .2px !important;
    white-space: normal !important;
  }
  .table tbody td {
    padding: 2mm !important;
    color: #111827 !important;
    border: 1px solid #e2e8f0 !important;
    font-size: 7.8pt !important;
    vertical-align: top !important;
  }

  .print-hidden-column { display: none !important; }
  .badge {
    padding: 1mm 2mm !important;
    border: 1px solid currentColor !important;
    background: transparent !important;
    color: #334155 !important;
    font-size: 7pt !important;
  }

  .loan-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 3mm !important;
  }

  .loan-detail-item {
    padding: 3mm !important;
    background: #f8fafc !important;
  }

  .loan-detail-item .ld-label {
    color: #64748b !important;
    font-size: 7pt !important;
  }

  .loan-detail-item .ld-value {
    color: #111827 !important;
    font-size: 9pt !important;
  }

  .form-control, .form-select, .input-group-text {
    min-height: 0 !important;
    padding: 1.5mm 2mm !important;
    border-color: #cbd5e1 !important;
    border-radius: 1mm !important;
    background: #fff !important;
    color: #111827 !important;
    font-size: 8pt !important;
    box-shadow: none !important;
  }

  .print-form-snapshot .form-control,
  .print-form-snapshot .form-select,
  .print-form-snapshot textarea,
  .print-form-snapshot input[type="file"],
  .print-form-snapshot .upload-box {
    display: none !important;
  }

  .print-form-snapshot .print-field-value {
    display: block !important;
    min-height: 8mm;
    padding: 2mm 2.5mm;
    border: 1px solid #cbd5e1;
    border-radius: 1mm;
    background: #fff !important;
    color: #111827 !important;
    font-size: 8.5pt;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  .print-form-snapshot .input-group .print-field-value {
    flex: 1 1 auto;
  }

  .print-form-snapshot [style*="position:sticky"],
  .print-form-snapshot [style*="position: sticky"] {
    position: static !important;
    top: auto !important;
  }

  textarea { min-height: 16mm !important; resize: none !important; }
  .form-label { margin-bottom: 1mm !important; font-size: 7.5pt !important; }
  .form-text { font-size: 7pt !important; }
  .upload-box { padding: 3mm !important; border: 1px solid #cbd5e1 !important; }
  .upload-box i { display: none !important; }

  .chart-container {
    height: 55mm !important;
    break-inside: avoid;
  }

  a { color: #111827 !important; text-decoration: none !important; }
  a[href]::after { content: none !important; }

  body.print-modal-only > *:not(.print-target) { display: none !important; }
  body.print-modal-only .print-target {
    display: block !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
  }
  body.print-modal-only .print-target .modal-dialog {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    transform: none !important;
  }
  body.print-modal-only .print-target .modal-content {
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  body.print-modal-only .print-target .modal-header,
  body.print-modal-only .print-target .modal-footer { display: none !important; }
  body.print-modal-only .print-target .modal-body { padding: 0 !important; }
}
