/* Thiruvelan Capitals - Main Stylesheet */

/* Tamil font support */
html[lang="ta"] body,
html[lang="ta"] .modal-content,
html[lang="ta"] .toast-text,
html[lang="ta"] input,
html[lang="ta"] select,
html[lang="ta"] textarea,
html[lang="ta"] button {
  font-family: 'Noto Sans Tamil', 'Inter', sans-serif;
}

/* Remove number input spinners globally */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

:root {
  --primary: #2563EB;
  --primary-dark: #1D4ED8;
  --sidebar-bg: #0F172A;
  --sidebar-hover: #1E293B;
  --sidebar-active: #1E3A5F;
  --sidebar-text: #94A3B8;
  --sidebar-active-text: #FFFFFF;
  --page-bg: #F1F5F9;
  --card-bg: #FFFFFF;
  --text-primary: #0F172A;
  --text-secondary: #64748B;
  --border: #E2E8F0;
  --success: #059669;
  --danger: #DC2626;
  --warning: #D97706;
  --info: #0284C7;
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --transition: all 0.2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--page-bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* iOS tap highlight — remove blue flash on all interactive elements */
a, button, [role="button"], input, select, textarea, label,
.nav-link, .btn, .bottom-nav-item, .file-upload-zone, .loan-card, .clickable {
  -webkit-tap-highlight-color: transparent;
}

/* Remove 300ms tap delay on iOS */
button, a, .btn, .bottom-nav-item, .file-upload-zone, .clickable {
  touch-action: manipulation;
}

/* Form elements: inherit font on iOS (Safari ignores body font for inputs by default) */
input, textarea, select, button {
  font-family: inherit;
  font-size: inherit;
}

/* SIDEBAR */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  background-color: var(--sidebar-bg);
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  z-index: 1040;
  -webkit-transition: -webkit-transform 0.3s ease;
  transition: transform 0.3s ease;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  text-decoration: none;
  min-height: var(--topbar-height);
}

.sidebar-brand .brand-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 18px; flex-shrink: 0;
}

.sidebar-brand .brand-name {
  font-size: 18px; font-weight: 700; color: #FFFFFF; letter-spacing: -0.3px;
}

.sidebar-brand .brand-name span { color: #60A5FA; }

.sidebar-nav { padding: 12px 0; flex: 1; }

.sidebar-section-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.8px;
  color: #475569; padding: 16px 20px 6px;
}

.sidebar-nav .nav-item { margin: 2px 10px; }

.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--sidebar-text); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  transition: var(--transition); position: relative;
}

.sidebar-nav .nav-link i { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-nav .nav-link:hover { background-color: var(--sidebar-hover); color: #CBD5E1; }

.sidebar-nav .nav-link.active { background-color: var(--sidebar-active); color: var(--sidebar-active-text); }

.sidebar-nav .nav-link.active::before {
  content: '';
  position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; background: var(--primary); border-radius: 0 3px 3px 0;
}

.sidebar-footer { padding: 16px 10px; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid rgba(255,255,255,0.06); }

.sidebar-footer .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--sidebar-text); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  transition: var(--transition); cursor: pointer;
}

.sidebar-footer .nav-link:hover { background-color: var(--sidebar-hover); color: #F87171; }

.sidebar-footer .nav-link i { font-size: 16px; width: 20px; text-align: center; }

/* TOPBAR */
#topbar {
  position: fixed; top: 0;
  left: var(--sidebar-width); right: 0;
  height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
  background-color: var(--card-bg);
  border-bottom: 1px solid var(--border);
  z-index: 1030;
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px;
  padding-top: env(safe-area-inset-top, 0px);
  box-shadow: var(--shadow-sm);
  transition: left 0.3s ease;
}

.topbar-title { font-size: 17px; font-weight: 600; color: var(--text-primary); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-user { display: flex; align-items: center; gap: 10px; }

.topbar-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7C3AED);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 14px; font-weight: 600; flex-shrink: 0;
}

.topbar-user-info { text-align: right; }
.topbar-user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); line-height: 1.3; }
.topbar-user-role { font-size: 11px; color: var(--text-secondary); }

.topbar-hamburger {
  display: none; background: none; border: none;
  color: var(--text-primary); font-size: 22px; cursor: pointer; padding: 4px;
}

/* MAIN CONTENT */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
  padding: 24px;
  min-height: calc(100vh - var(--topbar-height) - env(safe-area-inset-top, 0px));
  transition: margin-left 0.3s ease;
}

/* CARDS */
.card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card-header-flex {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}

.card-title { font-size: 15px; font-weight: 600; color: var(--text-primary); margin: 0; }

/* KPI STAT CARDS */
.stat-card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  gap: 16px;
  -webkit-transition: var(--transition);
  transition: var(--transition);
}

/* gap fallback for iOS < 14.5 */
.stat-card .stat-icon { margin-right: 16px; }
@supports (gap: 1px) { .stat-card .stat-icon { margin-right: 0; } }

.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

.stat-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}

.stat-icon.blue { background: #EFF6FF; color: var(--primary); }
.stat-icon.green { background: #ECFDF5; color: var(--success); }
.stat-icon.red { background: #FEF2F2; color: var(--danger); }
.stat-icon.amber { background: #FFFBEB; color: var(--warning); }
.stat-icon.purple { background: #F5F3FF; color: #7C3AED; }
.stat-icon.cyan { background: #F0F9FF; color: var(--info); }
.stat-icon.indigo { background: #EEF2FF; color: #4F46E5; }
.stat-icon.pink { background: #FDF2F8; color: #DB2777; }

.stat-body { flex: 1; min-width: 0; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text-primary); line-height: 1.2; margin-bottom: 2px; }
.stat-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.stat-sub { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

/* TABLES */
.table-container {
  overflow-x: auto;
  border-radius: var(--border-radius);
  border: 1px solid var(--border);
}

.table { margin: 0; font-size: 13px; }

.table thead th {
  background: #F8FAFC;
  color: var(--text-secondary);
  font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}

.table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid #F1F5F9;
  color: var(--text-primary);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background-color: #F8FAFC; }
.table tbody tr.clickable { cursor: pointer; }

.table-empty { text-align: center; padding: 40px 20px; color: var(--text-secondary); }
.table-empty i { font-size: 36px; display: block; margin-bottom: 8px; opacity: 0.4; }

/* BADGES */
.badge-status {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.3px;
}

.badge-active { background: #ECFDF5; color: #059669; }
.badge-inactive { background: #FEF2F2; color: #DC2626; }
.badge-overdue { background: #FFFBEB; color: #D97706; }
.badge-closed { background: #F1F5F9; color: #64748B; }
.badge-pending { background: #EFF6FF; color: #2563EB; }
.badge-partial { background: #FFF7ED; color: #EA580C; }
.badge-paid { background: #ECFDF5; color: #059669; }

/* FORMS */
.form-control, .form-select {
  border-radius: var(--border-radius-sm);
  border-color: var(--border);
  font-size: 13.5px; padding: 9px 12px;
  color: var(--text-primary); transition: var(--transition);
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
  outline: none;
}

.form-label { font-size: 13px; font-weight: 500; color: var(--text-primary); margin-bottom: 6px; }
.form-text { font-size: 11.5px; color: var(--text-secondary); }
.input-group-text { border-color: var(--border); background: #F8FAFC; font-size: 13px; color: var(--text-secondary); }

/* BUTTONS */
.btn {
  border-radius: var(--border-radius-sm);
  font-size: 13.5px; font-weight: 500;
  padding: 9px 18px;
  -webkit-transition: var(--transition);
  transition: var(--transition);
  display: -webkit-inline-flex;
  display: inline-flex;
  -webkit-align-items: center;
  align-items: center;
  gap: 6px;
  touch-action: manipulation;
}
/* gap fallback for iOS < 14.5: add right-margin to icons inside buttons */
.btn > i { margin-right: 2px; }
@supports (gap: 1px) { .btn > i { margin-right: 0; } }

.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.btn-primary { background-color: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background-color: var(--primary-dark); border-color: var(--primary-dark); color: white; }

.btn-outline-primary { border-color: var(--primary); color: var(--primary); }
.btn-outline-primary:hover { background-color: var(--primary); color: white; }

/* FILTER BAR */
.filter-bar {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex; gap: 12px;
  flex-wrap: wrap; align-items: flex-end;
  box-shadow: var(--shadow-sm);
}

.filter-bar .form-group { flex: 1; min-width: 160px; }

/* PAGINATION */
.pagination {
  --bs-pagination-color: var(--primary);
  --bs-pagination-active-bg: var(--primary);
  --bs-pagination-active-border-color: var(--primary);
  --bs-pagination-border-color: var(--border);
  font-size: 13px;
}

.page-link { border-radius: 6px !important; margin: 0 2px; }

/* TOAST */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 360px;
}

.toast-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--shadow-md);
  display: flex; align-items: flex-start; gap: 12px;
  animation: slideInRight 0.3s ease;
  min-width: 280px;
}

.toast-item.toast-success { border-left: 4px solid var(--success); }
.toast-item.toast-danger { border-left: 4px solid var(--danger); }
.toast-item.toast-warning { border-left: 4px solid var(--warning); }
.toast-item.toast-info { border-left: 4px solid var(--info); }

.toast-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.toast-success .toast-icon { color: var(--success); }
.toast-danger .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--info); }

.toast-text { flex: 1; font-size: 13.5px; color: var(--text-primary); font-weight: 500; }
.toast-close { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 14px; padding: 0; flex-shrink: 0; }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* LOADING OVERLAY */
#loading-overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(255,255,255,0.85);
  z-index: 9998;
  display: none; align-items: center; justify-content: center;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.loading-spinner { text-align: center; }
.loading-spinner .spinner-border { width: 3rem; height: 3rem; color: var(--primary); }
.loading-spinner p { margin-top: 12px; color: var(--text-secondary); font-size: 13px; font-weight: 500; }

/* MODAL */
.modal-content { border-radius: var(--border-radius); border: none; box-shadow: var(--shadow-md); }
.modal-header { border-bottom: 1px solid var(--border); padding: 18px 20px; }
.modal-footer { border-top: 1px solid var(--border); padding: 14px 20px; }

/* STEPPER */
.stepper {
  display: flex; margin-bottom: 28px;
  position: relative;
}

.stepper::before {
  content: '';
  position: absolute; top: 16px; left: 16px; right: 16px;
  height: 2px; background: var(--border); z-index: 0;
}

.step-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; gap: 6px;
  position: relative; z-index: 1;
}

.step-circle {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  transition: var(--transition);
}

.step-item.active .step-circle { border-color: var(--primary); background: var(--primary); color: white; }
.step-item.completed .step-circle { border-color: var(--success); background: var(--success); color: white; }

.step-label { font-size: 11.5px; font-weight: 500; color: var(--text-secondary); text-align: center; }
.step-item.active .step-label { color: var(--primary); font-weight: 600; }

/* FILE UPLOAD */
.file-upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--border-radius-sm);
  padding: 24px; text-align: center;
  cursor: pointer; transition: var(--transition);
  background: #FAFBFC;
}

.file-upload-zone:hover { border-color: var(--primary); background: #EFF6FF; }
.file-upload-zone i { font-size: 28px; color: var(--text-secondary); display: block; margin-bottom: 8px; }
.file-upload-zone p { font-size: 13px; color: var(--text-secondary); margin: 0; }

.file-preview {
  margin-top: 10px; display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: #F1F5F9; border-radius: 6px;
  font-size: 12.5px; color: var(--text-secondary);
}

.file-preview img { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; }

/* FILE IMAGE PREVIEW (KYC upload) */
.file-img-preview {
  margin-top: 10px;
  padding: 14px 12px;
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: var(--border-radius-sm);
  text-align: center;
}

.file-img-preview img {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
  box-shadow: var(--shadow-sm);
}

.file-img-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  margin-top: 10px;
  word-break: break-all;
}

.file-img-size {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
  margin-bottom: 4px;
}

/* OFFCANVAS */
.offcanvas { --bs-offcanvas-width: 480px; }

/* SEARCH RESULT CARD */
.search-result-card {
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 16px 20px;
  background: var(--card-bg);
  margin-top: 16px;
}

.customer-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7C3AED);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 18px; font-weight: 600; flex-shrink: 0;
}

/* LOAN CARD */
.loan-card {
  border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
  cursor: pointer; transition: var(--transition);
  background: var(--card-bg);
}

.loan-card:hover, .loan-card.selected { border-color: var(--primary); background: #EFF6FF; }
.loan-card.selected { border-width: 2px; }

/* INSTALLMENT */
.installment-row.selectable { cursor: pointer; }
.installment-row.selectable:hover td { background: #EFF6FF !important; }
.installment-row.selected td { background: #DBEAFE !important; }

/* PAGE HEADER */
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 22px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.page-header p { color: var(--text-secondary); font-size: 13.5px; margin: 0; }

/* LOGIN PAGE */
.login-bg {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--page-bg);
  display: flex; align-items: stretch;
}

.login-left {
  flex: 0 0 480px; max-width: 480px;
  background: white; padding: 48px 48px;
  display: flex; flex-direction: column; justify-content: center;
  box-shadow: var(--shadow-md);
}

.login-right {
  flex: 1;
  background: linear-gradient(135deg, #1E3A5F 0%, #0F172A 50%, #1E3A5F 100%);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}

.login-right::before {
  content: '';
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%232563EB' fill-opacity='0.08'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.login-hero-text { position: relative; z-index: 1; text-align: center; padding: 40px; }
.login-hero-text h2 { font-size: 32px; font-weight: 700; color: white; margin-bottom: 16px; }
.login-hero-text p { color: rgba(255,255,255,0.7); font-size: 16px; line-height: 1.7; max-width: 360px; }

.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 40px; }
.login-logo-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 24px;
}

.login-logo-text { font-size: 28px; font-weight: 800; color: var(--text-primary); letter-spacing: -0.5px; }
.login-logo-text span { color: var(--primary); }

/* SIDEBAR OVERLAY (mobile) */
.sidebar-overlay {
  display: none; position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(0,0,0,0.5); z-index: 1049;
}
.sidebar-overlay.show { display: block; }

/* ── MOBILE BOTTOM NAV BAR ───────────────────────────────────────────────── */
#bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  background: #FFFFFF;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
  z-index: 1039;
  padding: 0 4px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-inner {
  display: flex;
  height: 64px;
  align-items: stretch;
}

.bottom-nav-item {
  flex: 1;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 500;
  padding: 6px 4px 4px;
  border-radius: 10px;
  margin: 6px 2px;
  -webkit-transition: background 0.15s ease, color 0.15s ease;
  transition: background 0.15s ease, color 0.15s ease;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.bottom-nav-item i {
  font-size: 20px;
  line-height: 1;
  margin-bottom: 2px; /* gap fallback for iOS < 14.5 */
  -webkit-transition: -webkit-transform 0.15s ease;
  transition: transform 0.15s ease;
}

.bottom-nav-item.active {
  color: var(--primary);
  background: #EFF6FF;
}

.bottom-nav-item.active i { transform: scale(1.1); }

.bottom-nav-item:active {
  background: #EFF6FF;
  transform: scale(0.95);
}

/* ── MOBILE-FIRST TOUCH TARGETS ─────────────────────────────────────────── */
@media (max-width: 767.98px) {
  /* Sidebar: slide off-screen; hamburger opens it */
  #sidebar { -webkit-transform: translateX(-100%); transform: translateX(-100%); z-index: 1050; }
  #sidebar.show { -webkit-transform: translateX(0); transform: translateX(0); }
  #topbar { left: 0; padding: 0 12px; padding-top: env(safe-area-inset-top, 0px); }
  .topbar-hamburger { display: flex; align-items: center; justify-content: center; min-width: 44px; height: 44px; flex-shrink: 0; }
  .topbar-title { font-size: 15px; }

  /* Main content: no sidebar margin, pad for topbar + bottom nav */
  .main-content {
    margin-left: 0;
    padding: 16px 12px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* Show bottom nav */
  #bottom-nav { display: block; }

  /* Bigger stat values */
  .stat-value { font-size: clamp(15px, 4.8vw, 19px); overflow-wrap: anywhere; }
  .stat-card { padding: 14px; gap: 8px; flex-direction: column; align-items: flex-start; }
  .stat-icon { width: 44px; height: 44px; font-size: 18px; border-radius: 10px; }

  /* Filter bar: stack vertically */
  .filter-bar { padding: 12px; gap: 10px; }
  .filter-bar .form-group { min-width: 100%; flex: none; }

  /* Bigger touch targets for buttons */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 44px; padding: 6px 14px; }

  /* Form controls: larger touch targets */
  .form-control, .form-select { padding: 11px 12px; font-size: 16px; min-height: 44px; }
  /* font-size 16px prevents iOS auto-zoom on focus */

  /* Login: full-width, no right panel */
  .login-left { flex: 1 0 auto; max-width: 100%; padding: 32px 24px; width: 100%; }
  .login-right { display: none; }
  .login-bg { flex-direction: column; }

  /* Tables: force horizontal scroll, no wrapping */
  .table-container { border-radius: 8px; }
  .table-container > .table { min-width: 480px; }
  .table thead th,
  .table tbody td { padding: 10px 12px; }

  /* Page header */
  .page-header h1 { font-size: 19px; }
  .page-header { margin-bottom: 16px; }

  /* Cards */
  .card { padding: 14px; border-radius: 10px; }

  /* Modals: slide up from bottom (bottom sheet style) */
  .modal.fade .modal-dialog { -webkit-transform: translateY(60px); transform: translateY(60px); -webkit-transition: -webkit-transform 0.3s ease; transition: transform 0.3s ease; }
  .modal.show .modal-dialog { -webkit-transform: translateY(0); transform: translateY(0); }
  /* .modal is block layout, so the dialog itself becomes a full-height flex box
     that pins the content to the bottom; only .modal-body scrolls. Selectors are
     prefixed with .modal to out-rank Bootstrap's .modal-dialog-centered / -scrollable. */
  .modal .modal-dialog,
  .modal .modal-dialog-centered {
    margin: 0;
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    display: flex;
    align-items: flex-end;
  }
  .modal .modal-dialog .modal-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    overflow: hidden;
    border-radius: 20px 20px 0 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }
  /* If a modal wraps header/body/footer in a <form>, keep the flex chain intact */
  .modal .modal-content > form {
    display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow: hidden;
  }
  .modal .modal-content .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    flex: 1 1 auto;
  }
  .modal .modal-header, .modal .modal-footer { flex-shrink: 0; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1 1 auto; }
  .modal-footer .me-auto { margin-right: 0 !important; flex-basis: 100%; }

  /* Offcanvas: full width on mobile */
  .offcanvas { --bs-offcanvas-width: 100%; }

  /* Stepper: smaller on mobile */
  .stepper::before { top: 14px; left: 14px; right: 14px; }
  .step-circle { width: 28px; height: 28px; font-size: 11px; }
  .step-label { font-size: 10px; }

  /* Pagination: compact */
  .pagination { font-size: 12px; }
  .pagination { flex-wrap: wrap; justify-content: center; }
  .pagination .page-item { margin: 0; }
  .page-link {
    min-width: 38px; min-height: 38px; padding: 0; margin: 0 1px;
    display: flex; align-items: center; justify-content: center;
  }
  .btn-close { padding: 12px; box-sizing: content-box; }
  .toast-close {
    min-width: 36px; min-height: 36px;
    display: flex; align-items: center; justify-content: center;
    margin: -8px -8px -8px 0;
  }

  /* Toast: full width at bottom */
  .toast-container {
    right: 12px; left: 12px; bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    max-width: none;
  }
  .toast-item { min-width: 0; }

  /* Search result card: comfortable padding */
  .search-result-card { padding: 14px; }

  /* Loan card: slightly compact */
  .loan-card { padding: 12px; }

  /* File upload zone: easier tap target */
  .file-upload-zone { padding: 20px 16px; }

  /* Audit page — override injected small font sizes */
  .session-meta span { font-size: 13px !important; }
  .action-badge { font-size: 12px !important; min-height: 0; }
  .tl-meta { font-size: 13px !important; }
  .tl-status { font-size: 12px !important; }
  .tl-time-badge { font-size: 12px !important; }
  .tl-action { font-size: 14px !important; }

  /* Drawer full-width on mobile */
  #audit-drawer { width: 100vw !important; }
  .drawer-body { padding: 16px 16px 40px !important; }

  /* Session grid: full width on mobile */
  .session-card { padding: 14px 16px; }

  /* Reports max-width remark cells: let them flow on mobile */
  .table td[style*="max-width"] { max-width: 120px !important; }

  /* Report tabs: horizontal swipe on mobile — no wrapping */
  #report-tabs { flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  #report-tabs { scrollbar-width: none; -ms-overflow-style: none; }
  #report-tabs::-webkit-scrollbar { display: none; }
  #report-tabs .nav-link { padding: 6px 10px; font-size: 12px; white-space: nowrap; min-height: 44px; display: flex; align-items: center; }

  /* Wide data tables need more horizontal scroll room */
  .table-wide { min-width: 700px; }
  .table-xwide { min-width: 800px; }
  /* keep wide variants winning over `.table-container > .table` (higher specificity) */
  .table-container > .table-wide { min-width: 700px; }
  .table-container > .table-xwide { min-width: 800px; }

  /* Icon-only action buttons: meet 44px minimum touch width */
  .action-btns .btn-sm { min-width: 44px; justify-content: center; }
}

/* ── DASHBOARD LAYOUT ───────────────────────────────────────────────────── */
/* Desktop: lock to viewport so nothing scrolls — charts fill remaining space */
.dash-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-height) - 48px);
}

/* Mobile: remove fixed height, let page scroll naturally */
@media (max-width: 767.98px) {
  .dash-layout {
    height: auto;
    min-height: 0;
  }

  /* Charts row: no flex-shrink tricks on mobile — just flow and give each chart a real height */
  .dash-charts-row {
    flex: none !important;
    min-height: 0 !important;
  }

  .dash-chart-col {
    display: block !important;
    min-height: 0 !important;
  }

  .dash-chart-col .card {
    height: auto !important;
    min-height: 0 !important;
  }

  /* Each chart canvas gets a fixed height on mobile */
  .dash-chart-col canvas {
    min-height: 220px !important;
    max-height: 260px !important;
  }

  /* Bounded chart wrapper (Chart.js responsive container) so it cannot resize-loop */
  .dash-chart-col .card > div[style*="position:relative"] {
    height: 260px !important;
    min-height: 260px !important;
    flex: none !important;
  }
}

/* Short viewports (landscape phones / small windows): release the 100vh lock */
@media (max-height: 700px) {
  .dash-layout { height: auto; }
}
@media (max-height: 700px) and (min-width: 768px) {
  .dash-charts-row { min-height: 280px !important; }
}

/* ── SMALL PHONES (≤374px) ──────────────────────────────────────────────── */
@media (max-width: 374px) {
  .stat-value { font-size: 16px; }
  .stat-icon { width: 38px; height: 38px; font-size: 16px; }
  .bottom-nav-item { font-size: 9px; }
  .bottom-nav-item i { font-size: 18px; }
  .tl-left { width: 36px !important; }
  .tl-dot { width: 30px !important; height: 30px !important; font-size: 13px !important; }
}

/* ── TABLET (768px–1023px) ──────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --sidebar-width: 220px; }
  .main-content { padding: 20px; }
  .stat-value { font-size: 21px; }
}

/* UTILITY */
.fw-600 { font-weight: 600; }
.text-muted-sm { font-size: 12px; color: var(--text-secondary); }
.no-print { }

/* FONT SIZE VARIANTS — zoom on html scales everything uniformly (px, rem, fixed elements) */
html[data-font-size="small"]  { zoom: 0.875; }
html[data-font-size="large"]  { zoom: 1.125; }
/* medium = zoom:1 (default, no rule needed) */

/* COMPACT MODE */
body.compact .card { padding: 0; }
body.compact .card-header-flex { padding: 8px 14px; }
body.compact .stat-card { padding: 12px 14px; }
body.compact .stat-value { font-size: 20px; }
body.compact .table td, body.compact .table th { padding: 6px 10px; }
body.compact .page-header { margin-bottom: 16px; }

/* SETTINGS PAGE */
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-info { flex: 1; min-width: 0; }
.setting-label { font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.setting-desc  { font-size: 12px; color: var(--text-secondary); }
.setting-preview {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; background: var(--page-bg);
  border: 1px solid var(--border); color: var(--text-secondary);
}

/* PRINT */
@media print {
  #sidebar, #topbar, #bottom-nav, .filter-bar, .btn, .pagination, .no-print { display: none !important; }
  .main-content { margin-left: 0; margin-top: 0; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  body { background: white; }
}

/* Topbar date pill */
.topbar-date-pill {
  font-size: 11.5px; color: #64748B; background: #F8FAFC;
  padding: 3px 11px; border-radius: 20px; border: 1px solid #E2E8F0;
  white-space: nowrap; margin-right: 8px;
}
[data-theme="dark"] .topbar-date-pill {
  color: var(--text-secondary); background: #21262D; border-color: #30363D;
}

/* Loan summary info box (customer-onboard & collect-payment) */
.loan-info-box {
  background: #F8FAFC; border-radius: 10px; border: 1px solid #E2E8F0;
  display: flex; flex-wrap: wrap; overflow: hidden;
}
[data-theme="dark"] .loan-info-box {
  background: #21262D; border-color: #30363D;
}
[data-theme="dark"] .loan-info-box [style*="border-right"] { border-right-color: #30363D !important; }
[data-theme="dark"] .loan-info-box [style*="border-top"]   { border-top-color: #30363D !important; }

/* Collect-payment loan insight stat boxes */
.loan-stat-neutral { background: #f1f5f9; }
.loan-stat-green   { background: #f0fdf4; }
.balance-stat-box  { background: #fff7ed; }
[data-theme="dark"] .loan-stat-neutral { background: #21262D; }
[data-theme="dark"] .loan-stat-green   { background: #052e16; }
[data-theme="dark"] .balance-stat-box  { background: #422006; }

/* Loan summary calculation box */
.loan-summary-box { background: #EFF6FF; border: 1px solid #BFDBFE; }
[data-theme="dark"] .loan-summary-box { background: #1e3a5f; border-color: #1e40af; }
[data-theme="dark"] .loan-summary-box [style*="border-right"] { border-right-color: #1e40af !important; }
[data-theme="dark"] .loan-summary-box [style*="border-top"]   { border-top-color: #1e40af !important; }

/* Wallet withdraw source option labels */
/* (dark border-color overrides on #wd-opt-invest / #wd-opt-interest removed so the JS selection highlight works) */

/* Dashboard mini-card icon chip base colors (light mode) */
.dash-chip-pink   { background: #FDF2F8; }
.dash-chip-blue   { background: #EFF6FF; }
.dash-chip-red    { background: #FEF2F2; }
.dash-chip-indigo { background: #EEF2FF; }
.dash-chip-amber  { background: #FFFBEB; }

/* ============================================================
   DARK THEME
   ============================================================ */
[data-theme="dark"] {
  --page-bg:        #0D1117;
  --card-bg:        #161B22;
  --text-primary:   #E6EDF3;
  --text-secondary: #8B949E;
  --border:         #30363D;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --shadow:         0 4px 6px -1px rgba(0,0,0,.6);
}

body[data-theme="dark"] {
  --bs-body-color:     #E6EDF3;
  --bs-body-bg:        #0D1117;
  --bs-border-color:   #30363D;
  --bs-card-bg:        #161B22;
  --bs-card-color:     #E6EDF3;
  background-color: var(--page-bg);
  color: var(--text-primary);
}

/* Topbar */
[data-theme="dark"] #topbar { background-color: #161B22; border-bottom-color: #30363D; }

/* Filter bar */
[data-theme="dark"] .filter-bar { background: #161B22; border-color: #30363D; }

/* Forms */
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
  background-color: #0D1117; color: var(--text-primary); border-color: #30363D;
}
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
  background-color: #0D1117; color: var(--text-primary);
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.2);
}
[data-theme="dark"] .form-control::placeholder { color: #6E7681; }
[data-theme="dark"] .form-label { color: var(--text-secondary); }
[data-theme="dark"] .input-group-text { background: #21262D; border-color: #30363D; color: var(--text-secondary); }
[data-theme="dark"] select option { background-color: #161B22; color: var(--text-primary); }
[data-theme="dark"] .form-text { color: var(--text-secondary); }
[data-theme="dark"] .form-check-label { color: var(--text-primary); }

/* Tables — reset Bootstrap's --bs-table-bg which defaults to white */
[data-theme="dark"] .table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text-primary);
  --bs-table-border-color: #21262D;
  --bs-table-striped-bg: #21262D;
  --bs-table-hover-bg: #21262D;
  --bs-table-hover-color: var(--text-primary);
  color: var(--text-primary);
}
[data-theme="dark"] .table > :not(caption) > * > * {
  background-color: transparent;
  color: var(--text-primary);
  border-bottom-color: #21262D;
}
[data-theme="dark"] .table thead th {
  background-color: #0D1117 !important; color: var(--text-secondary); border-bottom-color: #30363D;
}
[data-theme="dark"] .table tbody tr:hover > * { background-color: #21262D !important; }
[data-theme="dark"] .table tbody tr:last-child td { border-bottom: none; }
[data-theme="dark"] .table-container { border-color: #30363D; }
[data-theme="dark"] .table-empty { color: var(--text-secondary); }

/* Badges */
[data-theme="dark"] .badge.bg-light { background-color: #21262D !important; color: var(--text-primary) !important; }
[data-theme="dark"] .badge.bg-secondary,
[data-theme="dark"] .badge.bg-secondary.bg-opacity-10 { background-color: #30363D !important; color: #94A3B8 !important; }
[data-theme="dark"] .badge.text-dark { color: var(--text-primary) !important; }

/* Status badges — keep intent colors, darken backgrounds */
[data-theme="dark"] .badge-active   { background: #052e16; color: #4ade80; }
[data-theme="dark"] .badge-inactive { background: #450a0a; color: #f87171; }
[data-theme="dark"] .badge-overdue  { background: #422006; color: #fbbf24; }
[data-theme="dark"] .badge-closed   { background: #1e293b; color: #94a3b8; }
[data-theme="dark"] .badge-pending  { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .badge-partial  { background: #431407; color: #fb923c; }
[data-theme="dark"] .badge-paid     { background: #052e16; color: #4ade80; }

/* Stat icon chips */
[data-theme="dark"] .stat-icon.blue   { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .stat-icon.green  { background: #052e16; color: #4ade80; }
[data-theme="dark"] .stat-icon.red    { background: #450a0a; color: #f87171; }
[data-theme="dark"] .stat-icon.amber  { background: #422006; color: #fbbf24; }
[data-theme="dark"] .stat-icon.purple { background: #2e1065; color: #a78bfa; }
[data-theme="dark"] .stat-icon.cyan   { background: #0c4a6e; color: #38bdf8; }
[data-theme="dark"] .stat-icon.indigo { background: #1e1b4b; color: #818cf8; }
[data-theme="dark"] .stat-icon.pink   { background: #500724; color: #f472b6; }

/* Dashboard inline mini-card icon chips (class-based so CSS can override) */
[data-theme="dark"] .dash-chip-pink   { background: #500724 !important; }
[data-theme="dark"] .dash-chip-blue   { background: #1e3a5f !important; }
[data-theme="dark"] .dash-chip-red    { background: #450a0a !important; }
[data-theme="dark"] .dash-chip-indigo { background: #1e1b4b !important; }
[data-theme="dark"] .dash-chip-amber  { background: #422006 !important; }

/* Bottom nav */
[data-theme="dark"] #bottom-nav { background: #161B22; border-top-color: #30363D; }
[data-theme="dark"] .bottom-nav-item { color: #8B949E; }
[data-theme="dark"] .bottom-nav-item.active { color: #60a5fa; background: #1e3a5f; }
[data-theme="dark"] .bottom-nav-item:active { background: #21262D; }

/* Loading overlay */
[data-theme="dark"] #loading-overlay { background: rgba(13,17,23,.85); }
[data-theme="dark"] .loading-spinner p { color: var(--text-secondary); }

/* Modals */
[data-theme="dark"] .modal-content { background-color: #161B22; color: var(--text-primary); border: 1px solid #30363D; }
[data-theme="dark"] .modal-header  { border-bottom-color: #30363D; }
[data-theme="dark"] .modal-footer  { border-top-color: #30363D; }
[data-theme="dark"] .modal-title,
[data-theme="dark"] .modal-body h5,
[data-theme="dark"] .modal-body h6,
[data-theme="dark"] .modal-body label { color: var(--text-primary); }
[data-theme="dark"] .modal-body p,
[data-theme="dark"] .modal-body small { color: var(--text-secondary); }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(1); }

/* Nav tabs */
[data-theme="dark"] .nav-tabs { border-bottom-color: #30363D; }
[data-theme="dark"] .nav-tabs .nav-link { color: #8B949E; border-color: transparent; }
[data-theme="dark"] .nav-tabs .nav-link:hover { color: var(--text-primary); border-color: transparent; }
[data-theme="dark"] .nav-tabs .nav-link.active {
  background-color: #161B22; color: var(--text-primary);
  border-color: #30363D #30363D #161B22;
}

/* Pagination */
[data-theme="dark"] .pagination .page-link { background-color: #161B22; border-color: #30363D; color: var(--text-primary); }
[data-theme="dark"] .pagination .page-item.active .page-link { background-color: var(--primary); border-color: var(--primary); color: white; }
[data-theme="dark"] .pagination .page-item.disabled .page-link { color: #4B5563; background-color: #0D1117; }

/* Bootstrap card color fix — .card sets --bs-card-color locally, breaking normal inheritance */
[data-theme="dark"] .card { color: var(--text-primary); }

/* Loan cards */
[data-theme="dark"] .loan-card { background: #161B22; border-color: #30363D; color: var(--text-primary); }
[data-theme="dark"] .loan-card:hover,
[data-theme="dark"] .loan-card.selected { border-color: var(--primary); background: #1e3a5f; }

/* Installment rows */
[data-theme="dark"] .installment-row.selectable:hover td { background: #1e3a5f !important; }
[data-theme="dark"] .installment-row.selected td { background: #1e3a5f !important; }

/* Search result card */
[data-theme="dark"] .search-result-card { background: #161B22; border-color: #30363D; color: var(--text-primary); }

/* File upload */
[data-theme="dark"] .file-upload-zone { background: #0D1117; border-color: #30363D; }
[data-theme="dark"] .file-upload-zone:hover { border-color: var(--primary); background: #1e3a5f; }
[data-theme="dark"] .file-preview { background: #21262D; color: var(--text-secondary); }
[data-theme="dark"] .file-img-preview { background: #21262D; border-color: #30363D; }

/* Login */
[data-theme="dark"] .login-left { background: #161B22; }
[data-theme="dark"] .login-logo-text { color: var(--text-primary); }
[data-theme="dark"] .login-left .form-control { background-color: #0D1117; color: var(--text-primary); border-color: #30363D; }

/* Stepper */
[data-theme="dark"] .stepper::before { background: #30363D; }
[data-theme="dark"] .step-circle { background: #161B22; border-color: #30363D; color: #8B949E; }
[data-theme="dark"] .step-label { color: #8B949E; }

/* Alerts */
[data-theme="dark"] .alert-danger  { background-color: #450a0a; color: #f87171; border-color: #7f1d1d; }
[data-theme="dark"] .alert-success { background-color: #052e16; color: #4ade80; border-color: #14532d; }
[data-theme="dark"] .alert-warning { background-color: #422006; color: #fbbf24; border-color: #78350f; }
[data-theme="dark"] .alert-info    { background-color: #0c4a6e; color: #38bdf8; border-color: #0369a1; }

/* Offcanvas */
[data-theme="dark"] .offcanvas { background-color: #161B22; color: var(--text-primary); }
[data-theme="dark"] .offcanvas-header { border-bottom-color: #30363D; }

/* Bootstrap text utilities */
[data-theme="dark"] .text-dark { color: var(--text-primary) !important; }
[data-theme="dark"] .text-muted { color: var(--text-secondary) !important; }
[data-theme="dark"] .border { border-color: #30363D !important; }
[data-theme="dark"] .bg-light { background-color: #21262D !important; }
[data-theme="dark"] .bg-white { background-color: #161B22 !important; }

/* Dividers */
[data-theme="dark"] hr { border-color: #30363D; }

/* Theme toggle button in sidebar */
.theme-toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; margin-bottom: 4px; border-radius: 8px;
  cursor: pointer; transition: background .15s;
}
.theme-toggle-row:hover { background: var(--sidebar-hover); }
.theme-toggle-row > span { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--sidebar-text); }
.theme-toggle-row > span i { font-size: 16px; width: 20px; text-align: center; }

.theme-switch { position: relative; width: 38px; height: 20px; flex-shrink: 0; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.theme-switch-slider {
  position: absolute; inset: 0; border-radius: 20px;
  background: #334155; cursor: pointer; transition: background .2s;
}
.theme-switch-slider::before {
  content: ''; position: absolute;
  width: 14px; height: 14px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: transform .2s;
}
.theme-switch input:checked + .theme-switch-slider { background: var(--primary); }
.theme-switch input:checked + .theme-switch-slider::before { transform: translateX(18px); }

/* WALLET PAGE — compact layout */
.wallet-compact .card { padding: 12px 14px; }
.wallet-compact .card-header-flex { margin-bottom: 10px; gap: 8px; }
.wallet-compact .table td, .wallet-compact .table th { padding: 7px 10px; font-size: 12.5px; }

/* ============================================================
   RESPONSIVE / DARK-MODE FIXES (appended block)
   ============================================================ */

/* Select arrow needs room (custom padding shorthand removed it) */
.form-select { padding-right: 2.25rem; }

/* Bottom-nav labels: never overflow the item */
.bottom-nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Collapsed state hook for customer-list expandable child rows */
.loan-child-row { background: #F8FAFC; }

/* Partners / wallet modals */
#partners-list-modal .table { min-width: 0; }
#partners-list-modal td { word-break: break-word; }

/* Settings: compact mode */
body.compact .setting-row { padding: 10px 14px; }

/* Settings: stack controls under the label on small phones */
@media (max-width: 575.98px) {
  .setting-row { flex-wrap: wrap; }
  .setting-info { flex: 1 1 100%; }
  .setting-row .btn-group { width: 100%; }
  .setting-row .btn-group .btn { flex: 1 1 0; }
  .setting-row > .d-flex { width: 100%; flex-wrap: wrap; }
}

/* Phones: sticky columns for wide tables */
@media (max-width: 767.98px) {
  /* Customer name stays visible while scrolling the wide customer list */
  .table-xwide td:nth-child(2),
  .table-xwide th:nth-child(2) {
    position: sticky; left: 0; z-index: 2;
    background: var(--card-bg);
    box-shadow: 2px 0 4px -2px rgba(0,0,0,.15);
  }
  .table-xwide th:nth-child(2) { z-index: 3; background: #F8FAFC; }

  /* Reusable: add class "table-sticky-actions" to a table to pin its last (actions) column */
  .table-sticky-actions th:last-child,
  .table-sticky-actions td:last-child {
    position: sticky; right: 0; z-index: 2;
    background: var(--card-bg);
    box-shadow: -6px 0 8px -6px rgba(0,0,0,.2);
  }
  .table-sticky-actions th:last-child { z-index: 3; background: #F8FAFC; }
}

/* ---- Dark mode additions ---- */
[data-theme="dark"] .loan-child-row { background: #0D1117; }

/* Sticky cells need an opaque dark background */
[data-theme="dark"] .table-xwide td:nth-child(2),
[data-theme="dark"] .table-sticky-actions td:last-child { background-color: var(--card-bg); }

/* Bootstrap text colors on dark cards */
[data-theme="dark"] .text-success { color: #4ade80 !important; }
[data-theme="dark"] .text-danger  { color: #f87171 !important; }
[data-theme="dark"] .text-primary { color: #60a5fa !important; }
[data-theme="dark"] .text-warning { color: #fbbf24 !important; }
[data-theme="dark"] .text-info    { color: #38bdf8 !important; }

/* Inline small texts hard-coded for light backgrounds
   (:not([style*="background"]) avoids recolouring elements that are filled with these colours) */
[data-theme="dark"] [style*="color:#DC2626" i]:not([style*="background"]),
[data-theme="dark"] [style*="color: #DC2626" i]:not([style*="background"]) { color: #F87171 !important; }
[data-theme="dark"] [style*="color:#64748B" i]:not([style*="background"]),
[data-theme="dark"] [style*="color: #64748B" i]:not([style*="background"]) { color: var(--text-secondary) !important; }

/* Loan summary boxes */
[data-theme="dark"] #l-total,
[data-theme="dark"] #al-total { color: #93C5FD !important; }
[data-theme="dark"] .loan-summary-box [style*="64748B" i] { color: #94A3B8 !important; }

/* Dashboard chips: lighter icons + sub-text on dark chips */
[data-theme="dark"] .dash-chip-blue   i { color: #60a5fa !important; }
[data-theme="dark"] .dash-chip-pink   i { color: #f472b6 !important; }
[data-theme="dark"] .dash-chip-red    i { color: #f87171 !important; }
[data-theme="dark"] .dash-chip-indigo i { color: #a5b4fc !important; }
[data-theme="dark"] .dash-chip-amber  i { color: #fbbf24 !important; }
[data-theme="dark"] #due-today-amt { color: #60a5fa !important; }
[data-theme="dark"] #due-week-amt  { color: #a5b4fc !important; }
[data-theme="dark"] #due-month-amt { color: #fbbf24 !important; }

/* Outline-secondary buttons readable on dark */
[data-theme="dark"] .btn-outline-secondary { --bs-btn-color: #9DA7B3; --bs-btn-border-color: #444C56; }

/* Wallet top-up confirm modal */
[data-theme="dark"] #topup-confirm-modal .modal-header { background: rgba(245,158,11,.15) !important; }
[data-theme="dark"] #topup-confirm-modal .modal-title  { color: var(--text-primary) !important; }
