/* =====================================================
   MAHAVIR FINANCE — PROFESSIONAL EDITION
   Clean · Colourful · Premium
   ===================================================== */

:root {
  /* Primary brand — deep indigo */
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --primary-faint: rgba(79,70,229,0.08);
  --primary-faint2: rgba(79,70,229,0.15);

  /* Gold accent */
  --gold: #f59e0b;
  --gold-light: #fcd34d;
  --gold-dark: #d97706;
  --gold-faint: rgba(245,158,11,0.08);
  --gold-faint2: rgba(245,158,11,0.15);
  --account-gold: #b45309;
  --account-glow: rgba(245,158,11,0.2);
  --account-bg: rgba(245,158,11,0.12);

  /* Backgrounds */
  --bg: #f8f7ff;
  --bg2: #ffffff;
  --bg3: #f1f0fa;
  --bg4: #e8e6f8;
  --surface: #ffffff;

  /* Borders */
  --border: rgba(79,70,229,0.15);
  --border2: rgba(0,0,0,0.07);
  --border3: rgba(0,0,0,0.04);

  /* Text */
  --text: #1a1830;
  --text2: #5c5880;
  --text3: #9b97be;

  /* Status */
  --green: #059669;
  --green-bg: rgba(5,150,105,0.08);
  --red: #dc2626;
  --red-bg: rgba(220,38,38,0.08);
  --blue: #2563eb;
  --blue-bg: rgba(37,99,235,0.08);
  --purple: #7c3aed;
  --purple-bg: rgba(124,58,237,0.08);
  --orange: #ea580c;
  --orange-bg: rgba(234,88,12,0.08);

  /* Stat tile text — dark in light mode so it's visible on white cards */
  --stat-text: #1a1830;

  /* Layout */
  --sidebar-w: 248px;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 20px 60px rgba(79,70,229,0.12);
  --card-shadow: 0 2px 12px rgba(79,70,229,0.07);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}
input, textarea, select, button { font-family: inherit; font-size: 1rem; }
a { text-decoration: none; color: inherit; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: transform .28s cubic-bezier(.4,0,.2,1), width .28s;
  box-shadow: 4px 0 24px rgba(79,70,229,0.25);
}
.sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, #4f46e5 0%, #3730a3 60%, #312e81 100%);
  pointer-events: none;
}
/* Decorative dots pattern */
.sidebar::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255,255,255,0.05) 1px, transparent 1px);
  background-size: 20px 20px;
  pointer-events: none;
}

.sidebar.collapsed { width: 58px; overflow: hidden; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .sidebar-footer { display: none; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 16px 0; }
.sidebar.collapsed .brand-icon { margin: 0 auto; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 13px 0; }
.main-wrapper.full { margin-left: 58px; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); z-index: 200; }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0 !important; }
}
#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(79,70,229,0.3); z-index: 150; backdrop-filter: blur(3px); }
#sidebar-overlay.active { display: block; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: relative; z-index: 1;
}
.brand-icon {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.25);
  backdrop-filter: blur(10px);
}
.brand-name { font-size: 1rem; font-weight: 800; color: #fff; line-height: 1.2; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.62rem; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: .1em; margin-top: 2px; }

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  position: relative; z-index: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: rgba(255,255,255,0.6);
  font-weight: 500;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .18s;
}
.nav-item i { width: 16px; text-align: center; font-size: 0.85rem; flex-shrink: 0; transition: transform .2s; }
.nav-item:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.9); }
.nav-item:hover i { transform: scale(1.15); }
.nav-item:active { transform: scale(0.97); }
.nav-item.active {
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-weight: 700;
  border-color: rgba(255,255,255,0.15);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.nav-item.active i { transform: scale(1.1); }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  position: relative; z-index: 1;
}
.sidebar-footer-title { font-size: 0.72rem; color: rgba(255,255,255,0.45); margin-bottom: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer-actions { display: flex; gap: 6px; margin-bottom: 8px; }
.btn-footer {
  flex: 1;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: rgba(255,255,255,0.7);
  padding: 7px 6px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  transition: all .15s;
}
.btn-footer:hover { background: rgba(255,255,255,0.2); color: #fff; }
.btn-reset-soft {
  width: 100%;
  background: rgba(220,38,38,0.15);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #fca5a5;
  padding: 8px;
  font-size: 0.78rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all .15s;
}
.btn-reset-soft:hover { background: rgba(220,38,38,0.3); color: #fff; }

/* ===== MAIN WRAPPER ===== */
#app-screen { display: flex; width: 100%; min-height: 100vh; }
.main-wrapper { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; transition: margin-left .28s; }

/* ===== TOPBAR ===== */
.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border2);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 26px;
  height: 58px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 0 var(--border2), 0 4px 16px rgba(79,70,229,0.05);
}
.hamburger { background: none; border: none; color: var(--text3); font-size: 1.1rem; cursor: pointer; padding: 4px; transition: color .15s; }
.hamburger:hover { color: var(--primary); }
.topbar-title { font-size: 1rem; font-weight: 700; color: var(--text); flex: 1; letter-spacing: -0.01em; }
.today-date { font-size: 0.76rem; color: var(--text3); white-space: nowrap; background: var(--bg3); padding: 4px 12px; border-radius: 20px; border: 1px solid var(--border2); font-weight: 500; }
.back-btn { background: var(--bg3); border: 1px solid var(--border2); border-radius: 8px; color: var(--text2); cursor: pointer; padding: 5px 12px; display: none; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 600; transition: all .15s; white-space: nowrap; }
.back-btn.visible { display: flex; }
.back-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ===== CONTENT ===== */
.content-area { padding: 26px; overflow-y: auto; flex: 1; }

/* ===== PAGES ===== */
.page { display: none; }
.page.active { display: block; animation: pgIn .28s cubic-bezier(.4,0,.2,1); }
@keyframes pgIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 1.65rem; font-weight: 800; color: var(--text); letter-spacing: -0.025em; }
.gold-dot { color: var(--gold); }

/* ===== STAT CARDS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 20px 20px 18px;
  display: flex; flex-direction: column; gap: 4px;
  position: relative; overflow: hidden;
  transition: border-color .2s, transform .18s, box-shadow .2s;
  box-shadow: var(--card-shadow);
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  border-radius: var(--radius) var(--radius) 0 0;
}
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { border-color: var(--border); transform: translateY(-3px); box-shadow: 0 12px 32px rgba(79,70,229,0.12); }
.stat-card.clickable:hover .stat-arrow { opacity: 1; right: 14px; }
.stat-arrow { position: absolute; top: 18px; right: 20px; color: var(--primary); font-size: 0.7rem; opacity: 0; transition: all .2s; }
.stat-icon-wrap { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.stat-icon { font-size: 1.1rem; color: var(--primary); }
.stat-label { font-size: 0.67rem; color: var(--stat-text); text-transform: uppercase; font-weight: 700; letter-spacing: .09em; }
.stat-value { font-size: 1.45rem; font-weight: 800; color: var(--stat-text); line-height: 1.1; letter-spacing: -0.02em; margin-top: 3px; }
.stat-sub { font-size: 0.74rem; color: var(--stat-text); margin-top: 3px; }
.stat-card .stat-label,
.stat-card .stat-sub,
.stat-card [style*="color:var(--text3)"],
.stat-card [style*="color: var(--text3)"] {
  color: var(--stat-text) !important;
}

/* ===== DASHBOARD ===== */
.dashboard-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 4px; }
@media (max-width: 900px) { .dashboard-bottom { grid-template-columns: 1fr; } }
.dash-card { background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius); padding: 22px; box-shadow: var(--card-shadow); }
.dash-card-title { font-size: 0.7rem; font-weight: 700; color: var(--text3); margin-bottom: 18px; text-transform: uppercase; letter-spacing: .09em; display: flex; align-items: center; gap: 7px; }
.dash-card-title i { color: var(--primary); }

.sk-summary-list { display: flex; flex-direction: column; gap: 4px; }
.sk-sum-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 13px; border-radius: 9px; font-size: 0.9rem; background: var(--bg3); }
.sk-sum-row.highlight { background: var(--primary-faint); border: 1px solid var(--border); }

.activity-item { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border3); font-size: 0.9rem; align-items: center; }
.activity-item:last-child { border-bottom: none; }
.activity-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 0.82rem; flex-shrink: 0; }
.activity-icon.loan { background: var(--blue-bg); color: var(--blue); }
.activity-icon.topup { background: var(--green-bg); color: var(--green); }
.activity-icon.interest { background: var(--gold-faint2); color: var(--gold-dark); }
.activity-icon.closure { background: var(--red-bg); color: var(--red); }
.activity-icon.sk_payment { background: var(--purple-bg); color: var(--purple); }
.activity-icon.partial_repayment, .activity-icon.part_payment { background: var(--blue-bg); color: var(--blue); }
.activity-icon.cash_adjustment { background: var(--gold-faint2); color: var(--gold-dark); }
.activity-text { flex: 1; min-width: 0; }
.activity-name { font-weight: 600; color: var(--text); font-size: 0.88rem; }
.activity-meta { color: var(--text3); font-size: 0.75rem; margin-top: 1px; }
.activity-amount { font-weight: 700; color: var(--primary); white-space: nowrap; font-size: 0.92rem; }

/* ===== FORMS ===== */
.form-card { background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius); padding: 26px; box-shadow: var(--card-shadow); }
.form-section-title { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; color: var(--text3); margin: 20px 0 14px; border-bottom: 1px solid var(--border2); padding-bottom: 8px; letter-spacing: .09em; display: flex; align-items: center; gap: 7px; }
.form-section-title:first-child { margin-top: 0; }
.form-section-title i { color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 14px; margin-bottom: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { font-size: 0.77rem; font-weight: 600; color: var(--text2); }
.input-field {
  background: var(--bg);
  border: 1.5px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  color: var(--text);
  font-size: 0.92rem;
  outline: none; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.input-field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-faint); background: #fff; }
.input-field:hover:not(:focus) { border-color: rgba(79,70,229,0.25); }
.input-field[readonly] { opacity: .5; cursor: default; }
select.input-field { cursor: pointer; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.search-existing-row { display: flex; gap: 8px; margin-bottom: 12px; align-items: flex-end; }
.search-existing-row .input-field { flex: 1; }
.field-hint { font-size: 0.76rem; color: var(--text3); margin-top: 4px; line-height: 1.5; }

.customer-results-dropdown { background: var(--surface); border: 1.5px solid var(--border); border-radius: 11px; max-height: 220px; overflow-y: auto; margin-bottom: 14px; box-shadow: 0 8px 32px rgba(79,70,229,0.12); }
.customer-result-item, .dropdown-item, .result-item { padding: 11px 15px; cursor: pointer; border-bottom: 1px solid var(--border3); display: flex; flex-direction: column; gap: 3px; transition: background .12s; }
.customer-result-item:last-child, .dropdown-item:last-child, .result-item:last-child { border-bottom: none; }
.customer-result-item:hover, .dropdown-item:hover, .result-item:hover { background: var(--primary-faint); }
.customer-result-item strong, .dropdown-item strong, .result-item strong { color: var(--text); font-size: 0.92rem; }
.customer-result-item span, .dropdown-item span, .result-item span { color: var(--text3); font-size: 0.78rem; }
.existing-customer-hint { background: var(--green-bg); border: 1px solid rgba(5,150,105,0.2); border-radius: 8px; padding: 9px 14px; font-size: 0.88rem; color: var(--green); margin-bottom: 14px; }

.selected-loan-card { background: var(--primary-faint); border: 1px solid var(--border); border-radius: 11px; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; margin: 12px 0; flex-wrap: wrap; gap: 10px; }
.slc-name { font-weight: 800; color: var(--primary); font-size: 1.05rem; margin-bottom: 3px; }
.slc-meta { font-size: 0.8rem; color: var(--text3); }
.slc-amount { font-weight: 800; color: var(--primary); font-size: 1.4rem; }
.info-banner { background: var(--blue-bg); border: 1px solid rgba(37,99,235,0.15); border-radius: 9px; padding: 11px 15px; font-size: 0.9rem; color: var(--text2); margin-bottom: 16px; line-height: 1.6; }
.info-banner i { color: var(--blue); margin-right: 6px; }

/* ===== BUTTONS ===== */
.btn-primary, .btn-ghost, .btn-danger, .btn-gold, .btn-blue {
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-weight: 600; font-size: 0.88rem;
  cursor: pointer; border: none;
  display: inline-flex; align-items: center; gap: 7px;
  transition: all .18s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 10px rgba(79,70,229,0.3); }
.btn-primary:hover { background: var(--primary-light); box-shadow: 0 4px 18px rgba(79,70,229,0.4); transform: translateY(-1px); }
.btn-ghost { background: var(--bg3); color: var(--text2); border: 1.5px solid var(--border2); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-faint); }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid rgba(220,38,38,0.15); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-gold { background: var(--gold-faint2); color: var(--gold-dark); border: 1px solid rgba(245,158,11,0.25); }
.btn-gold:hover { background: var(--gold); color: #fff; }
.btn-blue { background: var(--blue-bg); color: var(--blue); border: 1px solid rgba(37,99,235,0.15); }
.btn-blue:hover { background: var(--blue); color: #fff; }
.btn-sm { padding: 5px 10px !important; font-size: 0.78rem !important; border-radius: 6px !important; }

/* ===== TOOLBAR ===== */
.toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.search-bar { flex: 1; min-width: 160px; }
.filter-select { min-width: 150px; }

/* ===== SK STATS ROW ===== */
.sk-stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px,1fr)); gap: 14px; margin-bottom: 18px; }

/* ===== INTEREST CALC ===== */
.interest-calc-box { background: var(--bg3); border: 1px solid var(--border2); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.calc-summary { display: flex; gap: 20px; flex-wrap: wrap; align-items: center; }
.calc-item { display: flex; flex-direction: column; gap: 2px; }
.calc-item span { font-size: 0.73rem; color: var(--text3); }
.calc-item strong { font-size: 0.97rem; color: var(--text); }
.calc-item.highlight strong { color: var(--primary); font-size: 1.1rem; font-weight: 800; }
.ir-breakdown { background: var(--bg3); border-radius: 9px; padding: 13px 15px; margin-bottom: 14px; }
.ir-breakdown-title { font-size: 0.73rem; color: var(--text3); text-transform: uppercase; font-weight: 700; margin-bottom: 8px; letter-spacing: .06em; }
.ir-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.ir-table th { color: var(--text3); font-size: 0.7rem; text-transform: uppercase; padding: 5px 8px; text-align: left; letter-spacing: .05em; }
.ir-table td { padding: 6px 8px; border-bottom: 1px solid var(--border2); }
.ir-table tr:last-child td { border-bottom: none; }
.ir-total-row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border2); }
.ir-pending-banner { background: var(--orange-bg); border: 1px solid rgba(234,88,12,0.15); border-radius: 7px; padding: 9px 13px; font-size: 0.84rem; color: var(--orange); margin-bottom: 10px; }

/* ===== GAP CHOICE ===== */
.gap-choice-panel { background: var(--bg3); border: 1px solid var(--border); border-radius: 11px; padding: 14px 16px; margin: 10px 0; }
.gap-choice-title { font-size: 0.9rem; font-weight: 600; color: var(--text2); margin-bottom: 12px; }
.gap-choice-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gap-option { cursor: pointer; }
.gap-option input { display: none; }
.gap-option-box { border: 1.5px solid var(--border2); border-radius: 9px; padding: 12px 14px; transition: all .18s; background: #fff; }
.gap-option input:checked + .gap-option-box { border-color: var(--primary); background: var(--primary-faint); }
.gap-option-box:hover { border-color: var(--border); }
.gap-option-title { font-size: 0.88rem; font-weight: 700; color: var(--text); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.gap-option-desc { font-size: 0.76rem; color: var(--text3); line-height: 1.5; }

/* ===== LOAN CARDS ===== */
.loans-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px,1fr)); gap: 16px; }
.loan-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 18px; cursor: pointer;
  transition: border-color .2s, transform .18s, box-shadow .2s;
  box-shadow: var(--card-shadow);
}
.loan-card:hover { border-color: var(--border); transform: translateY(-2px); box-shadow: 0 10px 28px rgba(79,70,229,0.1); }
.loan-card.via-sk { border-left: 3px solid var(--purple); }
.loan-card.via-other { border-left: 3px solid var(--orange); }
.loan-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; gap: 8px; }
.loan-card-name { font-size: 1.02rem; font-weight: 700; color: var(--text); }
.loan-card-account {
  font-size: 0.9rem;
  color: var(--account-gold);
  margin-top: 4px;
  font-weight: 800;
  display: inline-block;
  padding: 1px 7px 2px;
  margin-left: -7px;
  border-radius: 7px;
  background: var(--account-bg);
  text-shadow: 0 0 7px var(--account-glow);
}
.loan-card-row { display: flex; justify-content: space-between; font-size: 0.87rem; margin-bottom: 5px; gap: 4px; }
.loan-card-row .lbl { color: var(--text3); }
.loan-card-row .val { font-weight: 600; color: var(--text); }
.loan-card-row .val.gold, .val-gold { color: var(--gold-dark) !important; }
.loan-card-row .text-green { color: var(--green) !important; }
.loan-card-row .text-red { color: var(--red) !important; }
.loan-card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border2); }

/* ===== BADGES ===== */
.badge { font-size: 0.62rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; text-transform: uppercase; white-space: nowrap; letter-spacing: .04em; }
.badge-active { background: var(--green-bg); color: var(--green); border: 1px solid rgba(5,150,105,0.15); }
.badge-closed { background: var(--red-bg); color: var(--red); border: 1px solid rgba(220,38,38,0.15); }
.badge-sk { background: var(--purple-bg); color: var(--purple); border: 1px solid rgba(124,58,237,0.15); }
.badge-other { background: var(--orange-bg); color: var(--orange); border: 1px solid rgba(234,88,12,0.15); }

/* ===== INDEX TABLE ===== */
.idx-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; font-size: 0.79rem; color: var(--text3); }
.idx-leg-item { display: flex; align-items: center; gap: 6px; }
.idx-leg-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.idx-leg-dot.sk { background: var(--purple); }
.idx-leg-dot.warn { background: var(--orange); }
.idx-leg-dot.normal { background: var(--border2); }
.idx-pdf-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius); box-shadow: var(--card-shadow); }
.idx-pdf-label { font-size: 0.8rem; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .06em; display: flex; align-items: center; gap: 7px; }
.idx-pdf-count { margin-right: auto; font-size: 0.86rem; font-weight: 800; color: var(--gold); }
.idx-select-th, .idx-select-cell { width: 42px; text-align: center; }
.idx-loan-check { width: 18px; height: 18px; accent-color: var(--gold); cursor: pointer; vertical-align: middle; }
.idx-table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border2); box-shadow: var(--card-shadow); }
.idx-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.idx-table thead th { background: var(--bg3); padding: 12px 14px; text-align: left; font-size: 0.68rem; color: var(--text3); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; border-bottom: 1px solid var(--border2); }
.idx-table tbody tr { border-bottom: 1px solid var(--border3); transition: background .12s; }
.idx-table tbody tr:last-child { border-bottom: none; }
.idx-table tbody tr:hover { background: var(--primary-faint); }
.idx-row-sk { border-left: 3px solid var(--purple); }
.idx-row-sk td:first-child { padding-left: 11px; }
.idx-row-warn { border-left: 3px solid var(--orange); }
.idx-row-warn td:first-child { padding-left: 11px; }
.idx-row-other { border-left: 3px solid var(--orange); }
.idx-row-other td:first-child { padding-left: 11px; }
.idx-table td { padding: 12px 14px; vertical-align: middle; color: var(--text); }
.idx-sr { color: var(--text3); font-size: 0.79rem; width: 36px; text-align: center; }
.idx-acc { font-family: monospace; font-size: 0.85rem; color: var(--primary); font-weight: 700; white-space: nowrap; }
.idx-name-main { font-weight: 700; font-size: 0.92rem; }
.idx-name-sub { font-size: 0.74rem; color: var(--text3); margin-top: 2px; }
.idx-date, .idx-dur { white-space: nowrap; font-size: 0.85rem; color: var(--text2); }
.idx-rate { font-weight: 600; white-space: nowrap; }
.idx-amount { font-weight: 700; color: var(--primary); white-space: nowrap; }
.idx-int { font-weight: 700; white-space: nowrap; }
.idx-int-due { color: var(--orange); }
.idx-pending-label { font-size: 0.7rem; color: var(--text3); font-weight: 400; margin-top: 2px; }
.idx-misc { font-size: 0.8rem; }
.idx-misc-row { display: flex; align-items: center; gap: 5px; margin-bottom: 2px; white-space: nowrap; }
.idx-misc-row:last-child { margin-bottom: 0; }
.topup-row { color: var(--green); }
.repaid-row { color: var(--blue); }

/* ===== MODALS ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(30,27,75,0.55); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(6px); }
.modal-box { background: var(--surface); border: 1px solid var(--border2); border-radius: 18px; padding: 26px; width: 100%; max-width: 660px; max-height: 92vh; overflow-y: auto; box-shadow: 0 24px 64px rgba(79,70,229,0.2); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid var(--border2); padding-bottom: 14px; }
.modal-header h2 { font-size: 1.1rem; color: var(--primary); font-weight: 700; }
.modal-close { background: var(--bg3); border: 1px solid var(--border2); border-radius: 7px; color: var(--text3); font-size: 1rem; cursor: pointer; padding: 5px 9px; transition: all .15s; }
.modal-close:hover { background: var(--red-bg); color: var(--red); border-color: rgba(220,38,38,0.2); }
.modal-actions { display: flex; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.modal-section-title { font-size: 0.69rem; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .08em; margin: 16px 0 10px; }
.modal-profile-block { background: var(--bg3); border-radius: 11px; padding: 18px; margin-bottom: 8px; border: 1px solid var(--border2); }
.mpb-name { font-size: 1.2rem; font-weight: 800; color: var(--text); margin-bottom: 5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mpb-meta { font-size: 0.81rem; color: var(--text3); margin-bottom: 14px; }
.mpb-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 8px; }
.mpb-stat { background: var(--surface); border-radius: 9px; padding: 10px 13px; border: 1px solid var(--border2); }
.mpb-stat span { font-size: 0.7rem; color: var(--text3); display: block; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .05em; }
.mpb-stat strong { font-size: 0.97rem; font-weight: 700; color: var(--text); }

/* ===== TIMELINE ===== */
.timeline { display: flex; flex-direction: column; }
.timeline-item { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border3); align-items: flex-start; }
.timeline-item:last-child { border-bottom: none; }
.tl-body { flex: 1; min-width: 0; }
.tl-title { font-weight: 600; color: var(--text); font-size: 0.88rem; }
.tl-meta { font-size: 0.75rem; color: var(--text3); margin-top: 2px; }
.tl-amount { font-weight: 700; color: var(--primary); font-size: 0.92rem; margin-top: 4px; }
.tl-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.hist-tag { font-size: 0.69rem; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.hist-tag.disc { background: var(--red-bg); color: var(--red); }
.hist-tag.paylater { background: var(--gold-faint); color: var(--gold-dark); border: 1px solid rgba(245,158,11,0.15); }
.hist-tag.period { background: var(--bg3); color: var(--text3); }
.text-red { color: var(--red) !important; }
.text-green { color: var(--green) !important; }
.text-gold { color: var(--gold-dark) !important; }

/* ===== CUSTOMERS ===== */
.customers-list { display: flex; flex-direction: column; gap: 8px; }
.customer-row { background: var(--surface); border: 1px solid var(--border2); border-radius: 11px; padding: 14px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; transition: border-color .15s, box-shadow .15s; box-shadow: var(--card-shadow); }
.customer-row:hover { border-color: var(--border); box-shadow: 0 4px 16px rgba(79,70,229,0.08); }
.cust-info { flex: 1; min-width: 200px; }
.cust-name { font-weight: 700; color: var(--text); font-size: 0.95rem; }
.cust-meta { font-size: 0.77rem; color: var(--text3); margin-top: 2px; }
.cust-stats { display: flex; gap: 20px; flex-wrap: wrap; }
.cust-stat { display: flex; flex-direction: column; gap: 2px; }
.clbl { font-size: 0.67rem; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; }
.cval { font-weight: 700; font-size: 0.9rem; color: var(--text); }

/* ===== CLOSED LOANS ===== */
.closed-loans-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px,1fr)); gap: 14px; }
.closed-loan-card { background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 5px; cursor: pointer; transition: border-color .18s, transform .18s; box-shadow: var(--card-shadow); }
.closed-loan-card:hover { border-color: var(--border); transform: translateY(-2px); }
.clc-name { font-size: 0.97rem; font-weight: 700; color: var(--text2); }
.clc-meta { font-size: 0.75rem; color: var(--text3); }
.clc-row { display: flex; justify-content: space-between; font-size: 0.85rem; margin-top: 3px; }
.clc-row span:first-child { color: var(--text3); }
.clc-row span:last-child { font-weight: 600; }

/* ===== SETTINGS ===== */
.settings-card { background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius); padding: 0; margin-bottom: 16px; overflow: hidden; box-shadow: var(--card-shadow); }
.settings-card.danger-zone { border-color: rgba(220,38,38,0.2); }
.settings-card.danger-zone .settings-card-title { color: var(--red); }
.settings-card-title { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--text3); padding: 13px 18px; border-bottom: 1px solid var(--border2); display: flex; align-items: center; gap: 8px; }
.settings-card-title i { color: var(--primary); }
.settings-card.danger-zone .settings-card-title i { color: var(--red); }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 18px; border-bottom: 1px solid var(--border3); flex-wrap: wrap; }
.settings-row:last-child { border-bottom: none; }
.settings-row-info { flex: 1; min-width: 0; }
.settings-row-label { font-size: 0.92rem; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.settings-row-sub { font-size: 0.79rem; color: var(--text3); line-height: 1.55; }

/* ===== SUCCESS / EMPTY ===== */
.success-msg { margin-top: 14px; padding: 11px 15px; background: var(--green-bg); border: 1px solid rgba(5,150,105,0.2); border-radius: 9px; color: var(--green); font-weight: 600; font-size: 0.88rem; display: flex; align-items: center; gap: 8px; }
.empty-state { text-align: center; padding: 52px 20px; color: var(--text3); }
.empty-state i { font-size: 2.2rem; display: block; margin-bottom: 12px; opacity: .2; }
.empty-state p { font-size: 0.9rem; }

/* ===== FAVOURITE ===== */
.fav-star { background: none; border: none; cursor: pointer; font-size: 1.05rem; color: var(--text3); padding: 2px 5px; transition: color .15s, transform .18s; line-height: 1; }
.fav-star:hover { color: var(--gold); transform: scale(1.22); }
.fav-star.active { color: var(--gold); }

/* ===== LOGIN ===== */
#login-screen { position: fixed; inset: 0; background: linear-gradient(135deg, #eef2ff 0%, #f0fdf4 50%, #fefce8 100%); display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 20px; }
.login-box { background: #fff; border: 1px solid rgba(79,70,229,0.12); border-radius: 20px; padding: 42px 38px; width: 100%; max-width: 395px; box-shadow: 0 20px 60px rgba(79,70,229,0.15), 0 0 0 1px rgba(79,70,229,0.05); }
.login-logo { width: 64px; height: 64px; border-radius: 16px; background: linear-gradient(135deg, var(--primary), var(--gold)); display: flex; align-items: center; justify-content: center; font-size: 26px; color: #fff; margin: 0 auto 20px; box-shadow: 0 4px 20px rgba(79,70,229,0.3); }
.login-title { font-size: 1.5rem; font-weight: 800; color: var(--text); text-align: center; margin-bottom: 4px; letter-spacing: -0.02em; }
.login-sub { font-size: 0.82rem; color: var(--text3); text-align: center; margin-bottom: 30px; }
.login-error { background: var(--red-bg); border: 1px solid rgba(220,38,38,0.2); border-radius: 9px; padding: 10px 14px; font-size: 0.86rem; color: var(--red); margin-bottom: 16px; }

/* ===== SYNC ===== */
#sync-indicator { position: fixed; top: 12px; right: 16px; font-size: 0.75rem; font-weight: 600; z-index: 9999; display: flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 20px; transition: opacity .3s; }

/* ===== UTILS ===== */
.hidden { display: none !important; }

/* ===== IMAGES ===== */
.image-upload-area { background: var(--bg3); border: 2px dashed var(--border2); border-radius: 10px; padding: 14px; transition: border-color .2s; }
.image-upload-area:hover { border-color: var(--primary); }
.image-upload-btn { display: inline-flex; align-items: center; gap: 8px; background: var(--primary-faint); color: var(--primary); border: 1px solid rgba(79,70,229,0.2); border-radius: 8px; padding: 8px 16px; font-size: 0.85rem; font-weight: 600; cursor: pointer; margin-bottom: 12px; transition: all .18s; }
.image-upload-btn:hover { background: var(--primary-faint2); }
.image-preview-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.img-thumb-wrap { position: relative; width: 90px; height: 90px; border-radius: 9px; overflow: hidden; border: 1px solid var(--border2); flex-shrink: 0; }
.img-thumb { width: 100%; height: 100%; object-fit: cover; cursor: pointer; transition: transform .2s; }
.img-thumb:hover { transform: scale(1.05); }
.img-delete-btn { position: absolute; top: 4px; right: 4px; background: rgba(220,38,38,0.9); border: none; color: #fff; width: 22px; height: 22px; border-radius: 50%; font-size: 0.7rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background .15s; }
.img-delete-btn:hover { background: var(--red); }
.img-label { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.6); color: #fff; font-size: 0.6rem; text-align: center; padding: 2px 4px; }
.img-add-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; background: var(--bg3); border: 1.5px dashed var(--border2) !important; transition: border-color .2s; }
.img-add-btn:hover { border-color: var(--primary) !important; }
.loan-images-grid { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 0; }

/* ===== PAYMENT ===== */
.payment-split-toggle { margin-bottom: 10px; }
.split-toggle-label { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text2); cursor: pointer; font-weight: 600; }
.split-toggle-label input { accent-color: var(--primary); width: 16px; height: 16px; }
.split-payment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 10px; }
.payment-split-total { font-size: 0.9rem; font-weight: 700; color: var(--primary); margin-top: 8px; padding: 8px 12px; background: var(--primary-faint); border-radius: 7px; }

/* ===== CLOSE LOAN SUMMARY ===== */
.close-loan-summary { background: linear-gradient(135deg, rgba(79,70,229,0.07), rgba(245,158,11,0.05)); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.cls-title { font-size: 0.85rem; color: var(--text2); margin-bottom: 12px; }
.cls-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 8px; }
.cls-item { background: var(--surface); border-radius: 8px; padding: 10px 12px; border: 1px solid var(--border2); }
.cls-item span { font-size: 0.72rem; color: var(--text3); display: block; margin-bottom: 3px; text-transform: uppercase; font-weight: 600; letter-spacing: .05em; }
.cls-item strong { font-size: 1rem; font-weight: 700; }
.cls-item.highlight { background: var(--primary-faint); border-color: var(--border); }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .content-area { padding: 16px; }
  .loans-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .sk-stats-row { grid-template-columns: 1fr 1fr; }
}

/* ===== DARK MODE ===== */
body.dark {
  --primary: #818cf8;
  --primary-light: #a5b4fc;
  --primary-faint: rgba(129,140,248,0.08);
  --primary-faint2: rgba(129,140,248,0.15);

  --gold: #fbbf24;
  --gold-light: #fcd34d;
  --gold-dark: #f59e0b;
  --gold-faint: rgba(251,191,36,0.08);
  --gold-faint2: rgba(251,191,36,0.14);
  --account-gold: #ffe7a3;
  --account-glow: rgba(255,205,94,0.58);
  --account-bg: transparent;

  --bg: #0f0f13;
  --bg2: #141418;
  --bg3: #1a1a20;
  --bg4: #1f1f28;
  --surface: #141418;

  --border: rgba(129,140,248,0.2);
  --border2: rgba(255,255,255,0.07);
  --border3: rgba(255,255,255,0.035);

  --text: #e8e8f0;
  --text2: #9090b0;
  --text3: #55556a;

  --green: #34d399;
  --green-bg: rgba(52,211,153,0.1);
  --red: #f87171;
  --red-bg: rgba(248,113,113,0.1);
  --blue: #60a5fa;
  --blue-bg: rgba(96,165,250,0.1);
  --purple: #a78bfa;
  --purple-bg: rgba(167,139,250,0.1);
  --orange: #fb923c;
  --orange-bg: rgba(251,146,60,0.1);

  /* Stat tile text — white in dark mode */
  --stat-text: #ffffff;
}

/* Dark mode sidebar overrides */
body.dark .sidebar {
  background: linear-gradient(160deg, #1e1b4b 0%, #1a1730 60%, #141230 100%);
  box-shadow: 4px 0 24px rgba(0,0,0,0.5);
}
body.dark .sidebar::before {
  background: linear-gradient(160deg, #2d2a6e 0%, #1e1b4b 60%, #141230 100%);
}
body.dark .sidebar::after {
  background-image: radial-gradient(rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* Dark mode input */
body.dark .input-field { background: var(--bg3); }
body.dark .input-field:focus { background: var(--bg4); }

/* Dark mode gap option */
body.dark .gap-option-box { background: var(--bg3); }

/* Dark mode login */
body.dark #login-screen {
  background: linear-gradient(135deg, #0f0f1a 0%, #111118 50%, #14101a 100%);
}
body.dark .login-box {
  background: var(--bg2);
  border-color: rgba(129,140,248,0.15);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

/* Dark mode modal */
body.dark .modal-overlay { background: rgba(0,0,0,0.8); }
body.dark .modal-box { box-shadow: 0 24px 64px rgba(0,0,0,0.7); }

/* Dark mode topbar */
body.dark .topbar { background: rgba(20,20,24,0.97); backdrop-filter: blur(16px); }

/* Smooth transition for theme switch */
body, .sidebar, .topbar, .form-card, .stat-card, .dash-card,
.loan-card, .modal-box, .customer-row, .settings-card,
.closed-loan-card, .input-field, #login-screen, .login-box {
  transition: background-color .25s, border-color .25s, color .2s, box-shadow .25s;
}

/* =====================================================
   RESPONSIVE — FULL MOBILE/TABLET/DESKTOP OVERHAUL
   Breakpoints:
     xs: <480px  (small phones)
     sm: <640px  (phones)
     md: <768px  (large phones / small tablets)
     lg: <1024px (tablets)
   ===================================================== */

/* ===== GLOBAL MOBILE FIXES ===== */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  /* Prevent horizontal scroll on mobile */
  overflow-x: hidden;
  /* Improve tap responsiveness */
  -webkit-tap-highlight-color: transparent;
}
/* Bigger tap targets on touch devices */
@media (hover: none) {
  .nav-item { padding: 12px 14px; }
  .btn-primary, .btn-ghost, .btn-danger, .btn-gold, .btn-blue { padding: 11px 18px; }
  .btn-sm { padding: 8px 12px !important; font-size: 0.82rem !important; }
  input, select, textarea { font-size: 16px !important; } /* Prevent iOS zoom on focus */
}

/* ===== TOPBAR MOBILE ===== */
@media (max-width: 640px) {
  .topbar {
    padding: 0 14px;
    height: 52px;
    gap: 8px;
  }
  .topbar-title { font-size: 0.9rem; }
  .today-date { display: none; } /* Hide date on small screens */
  #theme-toggle span { display: none; } /* Show only icon on mobile */
  #theme-toggle { padding: 6px 9px; }
  .back-btn { padding: 5px 9px; font-size: 0.78rem; gap: 4px; }
  .back-btn span { display: none; } /* Hide "Back" text, keep icon */
}

/* ===== CONTENT AREA ===== */
@media (max-width: 768px) {
  .content-area { padding: 16px; }
}
@media (max-width: 480px) {
  .content-area { padding: 12px; }
  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: 1.3rem; }
}

/* ===== STATS GRID ===== */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat-value { font-size: 1.2rem; }
  .stat-card { padding: 14px 14px 12px; }
}
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 1.05rem; }
  .stat-card { padding: 12px; }
}

/* ===== DASHBOARD ===== */
@media (max-width: 900px) {
  .dashboard-bottom { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .dash-card { padding: 16px; }
  .sk-sum-row { font-size: 0.82rem; padding: 8px 10px; }
}

/* ===== LOAN CARDS ===== */
@media (max-width: 768px) {
  .loans-grid { grid-template-columns: 1fr; gap: 12px; }
}
@media (max-width: 480px) {
  .loan-card { padding: 14px; }
  .loan-card-name { font-size: 0.95rem; }
  .loan-card-row { font-size: 0.83rem; }
  .loan-card-actions {
    gap: 5px;
    flex-wrap: wrap;
  }
  /* Make action buttons full-width rows on very small screens */
  .loan-card-actions .btn-primary { flex: 1; justify-content: center; }
  .loan-card-actions .btn-sm { padding: 7px 10px !important; font-size: 0.79rem !important; }
}

/* ===== SK / OTHER STATS ROW ===== */
@media (max-width: 768px) {
  .sk-stats-row { grid-template-columns: 1fr 1fr; gap: 10px; }
}
@media (max-width: 400px) {
  .sk-stats-row { grid-template-columns: 1fr; }
}

/* ===== FORMS ===== */
@media (max-width: 768px) {
  .form-card { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .form-group.full-width { grid-column: 1; }
}
@media (max-width: 480px) {
  .form-card { padding: 14px; }
  .form-actions { flex-direction: column; }
  .form-actions button { width: 100%; justify-content: center; }
}

/* ===== TOOLBAR ===== */
@media (max-width: 640px) {
  .toolbar { gap: 8px; }
  .filter-select { min-width: 0; flex: 1; }
  .search-bar { min-width: 0; }
}
@media (max-width: 480px) {
  .toolbar { flex-wrap: wrap; }
  .toolbar .search-bar { width: 100%; flex: none; }
  .toolbar .filter-select { flex: 1; }
}

/* ===== INDEX TABLE ===== */
@media (max-width: 768px) {
  .idx-table-wrap {
    /* Allow horizontal scroll with snap */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .idx-table { min-width: 600px; }
  /* Hide less important columns on mobile */
  .idx-table th:nth-child(5),
  .idx-table td:nth-child(5) { display: none; } /* Hide Duration */
  .idx-table th:nth-child(10),
  .idx-table td:nth-child(10) { display: none; } /* Hide Top-Up/Repaid */
}
@media (max-width: 480px) {
  .idx-table { min-width: 500px; font-size: 0.82rem; }
  .idx-table td, .idx-table th { padding: 9px 8px; }
  .idx-table th:nth-child(4),
  .idx-table td:nth-child(4) { display: none; } /* Also hide Date column */
}

/* ===== MODALS ===== */
@media (max-width: 768px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box {
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    padding: 20px;
    /* Pull-up sheet style on mobile */
    width: 100%;
    max-width: 100%;
  }
}
@media (max-width: 480px) {
  .modal-box { padding: 16px; max-height: 95vh; }
  .modal-actions { flex-direction: column; }
  .modal-actions button { width: 100%; justify-content: center; }
  .mpb-stats { grid-template-columns: 1fr 1fr; }
  .mpb-stat { padding: 8px 10px; }
  .mpb-name { font-size: 1rem; }
  .cls-grid { grid-template-columns: 1fr 1fr; }
}

/* ===== CLOSED LOANS GRID ===== */
@media (max-width: 768px) {
  .closed-loans-grid { grid-template-columns: 1fr; }
}

/* ===== CUSTOMERS ===== */
@media (max-width: 640px) {
  .customer-row { flex-direction: column; align-items: flex-start; gap: 10px; }
  .cust-info { width: 100%; }
  .cust-stats { width: 100%; justify-content: space-between; }
}

/* ===== ACTIVITY / TIMELINE ===== */
@media (max-width: 480px) {
  .activity-item { gap: 9px; }
  .activity-name { font-size: 0.83rem; }
  .activity-amount { font-size: 0.85rem; }
  .timeline-item { gap: 9px; }
}

/* ===== GAP CHOICE (interest form) ===== */
@media (max-width: 480px) {
  .gap-choice-options { grid-template-columns: 1fr; }
}

/* ===== PAYMENT SPLIT GRID ===== */
@media (max-width: 640px) {
  .split-payment-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 400px) {
  .split-payment-grid { grid-template-columns: 1fr; }
}

/* ===== CLOSE LOAN SUMMARY ===== */
@media (max-width: 480px) {
  .cls-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
}

/* ===== SIDEBAR FOOTER ===== */
@media (max-width: 768px) {
  .sidebar-footer-actions { flex-wrap: wrap; }
}

/* ===== LOGIN ===== */
@media (max-width: 480px) {
  .login-box { padding: 28px 20px; border-radius: 16px; }
  .login-title { font-size: 1.3rem; }
  .login-logo { width: 54px; height: 54px; font-size: 22px; }
}

/* ===== SYNC INDICATOR ===== */
@media (max-width: 640px) {
  #sync-indicator { top: auto; bottom: 72px; right: 12px; font-size: 0.7rem; }
}

/* ===== STOP INTEREST POPUP ===== */
@media (max-width: 480px) {
  #stop-interest-popup {
    width: calc(100vw - 32px) !important;
    left: 16px !important;
    transform: translateY(-50%) !important;
  }
}

/* ===== TABLET (768px – 1024px) ===== */
@media (min-width: 768px) and (max-width: 1024px) {
  :root { --sidebar-w: 220px; }
  .loans-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .content-area { padding: 20px; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .sk-stats-row { grid-template-columns: repeat(3, 1fr); }
  .closed-loans-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== LARGE DESKTOP (>1400px) ===== */
@media (min-width: 1400px) {
  .content-area { padding: 30px 36px; }
  .loans-grid { grid-template-columns: repeat(auto-fill, minmax(320px,1fr)); }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); }
}

/* ===== SAFE AREA (iPhone notch / home bar) ===== */
@supports (padding: max(0px)) {
  .topbar {
    padding-left: max(26px, env(safe-area-inset-left));
    padding-right: max(26px, env(safe-area-inset-right));
  }
  @media (max-width: 640px) {
    .topbar {
      padding-left: max(14px, env(safe-area-inset-left));
      padding-right: max(14px, env(safe-area-inset-right));
    }
  }
  .content-area {
    padding-bottom: max(26px, env(safe-area-inset-bottom));
  }
  @media (max-width: 768px) {
    .content-area {
      padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    .sidebar {
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}

/* ===== PREVENT TEXT OVERFLOW EVERYWHERE ===== */
.loan-card-name, .cust-name, .mpb-name, .activity-name,
.tl-title, .clc-name, .idx-name-main {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* But allow wrapping in modal where space is tight */
.mpb-name { white-space: normal; }

/* ===== IMAGE GRID MOBILE ===== */
@media (max-width: 480px) {
  .img-thumb-wrap { width: 75px; height: 75px; }
  .loan-images-grid { gap: 7px; }
}

/* ===== MODAL BOTTOM SHEET DRAG HANDLE ===== */
@media (max-width: 768px) {
  .modal-box::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border2);
    border-radius: 2px;
    margin: 0 auto 16px;
  }
}

/* ===== LOADING SCREEN ===== */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg, #0f0f13);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  transition: opacity .3s ease;
}
#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
#loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
#loading-logo img {
  box-shadow: 0 4px 24px rgba(79,70,229,0.3);
  animation: loadPulse 1.8s ease-in-out infinite;
}
@keyframes loadPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.04); opacity: .85; }
}
#loading-name {
  font-family: 'Inter', sans-serif;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text, #e8e8f0);
  letter-spacing: -0.02em;
}
#loading-spinner {
  display: flex;
  gap: 7px;
  margin-top: 4px;
}
#loading-spinner span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary, #818cf8);
  animation: loadDot .9s ease-in-out infinite;
}
#loading-spinner span:nth-child(2) { animation-delay: .15s; }
#loading-spinner span:nth-child(3) { animation-delay: .30s; }
@keyframes loadDot {
  0%, 80%, 100% { transform: scale(.6); opacity: .3; }
  40%           { transform: scale(1);  opacity: 1; }
}
#loading-text {
  font-size: 0.8rem;
  color: var(--text3, #55556a);
  font-weight: 500;
}
