/* ============================================================
   LoanPro — Design System & Stylesheet
   Aesthetic: Refined Financial / Dark-Accent SaaS
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── Variables ──────────────────────────────────────────── */
:root {
  --bg:           #0f1117;
  --bg-2:         #161b27;
  --bg-3:         #1e2535;
  --bg-4:         #252d3f;
  --border:       rgba(255,255,255,.08);
  --border-light: rgba(255,255,255,.05);

  --text:         #e8edf5;
  --text-2:       #8b97b4;
  --text-3:       #5c6880;

  --accent:       #4f6ef7;
  --accent-soft:  rgba(79,110,247,.15);
  --accent-glow:  rgba(79,110,247,.3);

  --green:        #22c55e;
  --green-soft:   rgba(34,197,94,.15);
  --red:          #f43f5e;
  --red-soft:     rgba(244,63,94,.15);
  --yellow:       #f59e0b;
  --yellow-soft:  rgba(245,158,11,.15);
  --blue:         #38bdf8;
  --blue-soft:    rgba(56,189,248,.15);

  --sidebar-w:    240px;
  --topbar-h:     60px;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    16px;

  --shadow:       0 4px 24px rgba(0,0,0,.4);
  --shadow-sm:    0 2px 8px rgba(0,0,0,.3);

  --font:         'DM Sans', sans-serif;
  --font-mono:    'DM Mono', monospace;

  --transition:   .2s cubic-bezier(.4,0,.2,1);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: opacity var(--transition); }
a:hover { opacity: .8; }

/* ── Layout ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  transition: transform var(--transition);
}

.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Sidebar Brand ──────────────────────────────────────── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
}

/* ── Sidebar Nav ────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-3);
  padding: 14px 16px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 0;
  transition: all var(--transition);
  position: relative;
  text-decoration: none;
}

.nav-item:hover {
  color: var(--text);
  background: var(--bg-3);
  opacity: 1;
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: .75;
}
.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

/* ── Sidebar Footer ─────────────────────────────────────── */
.sidebar-footer {
  padding: 12px 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.user-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--text-3);
}

.sidebar-action-btn {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  transition: all var(--transition);
  flex-shrink: 0;
  text-decoration: none;
}
.sidebar-action-btn:hover { background: var(--bg-3); color: var(--text); opacity: 1; }
.logout-btn:hover { background: var(--red-soft); color: var(--red); }

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  padding: 4px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-date {
  font-size: 12.5px;
  color: var(--text-3);
  font-family: var(--font-mono);
}

/* ── Page Content ───────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 28px 28px 40px;
  max-width: 1400px;
  width: 100%;
}

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

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.3px;
}

.page-header p {
  color: var(--text-2);
  font-size: 13.5px;
  margin-top: 2px;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

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

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

.card-subtitle {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 2px;
}

/* ── Stat Cards ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition);
}

.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.stat-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  background: var(--stat-color, var(--accent-soft));
  border-radius: 0 var(--radius-lg) 0 80px;
  opacity: .5;
}

.stat-card.green  { --stat-color: var(--green-soft); }
.stat-card.red    { --stat-color: var(--red-soft); }
.stat-card.yellow { --stat-color: var(--yellow-soft); }
.stat-card.blue   { --stat-color: var(--blue-soft); }

.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  background: var(--stat-icon-bg, var(--accent-soft));
}
.stat-card.green  .stat-icon { background: var(--green-soft); color: var(--green); }
.stat-card.red    .stat-icon { background: var(--red-soft);   color: var(--red); }
.stat-card.yellow .stat-icon { background: var(--yellow-soft);color: var(--yellow); }
.stat-card.blue   .stat-icon { background: var(--blue-soft);  color: var(--blue); }
.stat-card:not([class*="green"]):not([class*="red"]):not([class*="yellow"]):not([class*="blue"]) .stat-icon {
  background: var(--accent-soft); color: var(--accent);
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.5px;
  line-height: 1.2;
}

.stat-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 6px;
}

/* ── Grids ──────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-2);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
}

th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-3);
  white-space: nowrap;
}

td {
  padding: 13px 16px;
  font-size: 13.5px;
  color: var(--text-2);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background var(--transition);
}
tbody tr:hover { background: var(--bg-3); }

.td-strong { color: var(--text); font-weight: 500; }
.td-mono   { font-family: var(--font-mono); font-size: 12.5px; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
}
.badge-active  { background: var(--green-soft);  color: var(--green); }
.badge-paid    { background: var(--blue-soft);   color: var(--blue); }
.badge-overdue { background: var(--red-soft);    color: var(--red); }
.badge-default { background: var(--bg-4);        color: var(--text-2); }
.badge-admin   { background: var(--accent-soft); color: var(--accent); }
.badge-super   { background: var(--yellow-soft); color: var(--yellow); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: #3d5ae0; opacity: 1; color: white; transform: translateY(-1px); box-shadow: 0 4px 14px var(--accent-glow); }

.btn-secondary {
  background: var(--bg-4);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-3); border-color: var(--text-3); opacity: 1; }

.btn-success {
  background: var(--green);
  color: white;
}
.btn-success:hover { background: #16a34a; opacity: 1; }

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid rgba(244,63,94,.3);
}
.btn-danger:hover { background: var(--red); color: white; opacity: 1; }

.btn-warning {
  background: var(--yellow-soft);
  color: var(--yellow);
  border: 1px solid rgba(245,158,11,.3);
}
.btn-warning:hover { background: var(--yellow); color: white; opacity: 1; }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 7px; }

.btn-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ── Forms ──────────────────────────────────────────────── */
.form-grid { display: grid; gap: 18px; }
.form-row  { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .2px;
}

.form-control {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
  outline: none;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-control::placeholder { color: var(--text-3); }

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235c6880' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

textarea.form-control { resize: vertical; min-height: 90px; }

.form-hint { font-size: 11.5px; color: var(--text-3); }
.form-error { font-size: 12px; color: var(--red); margin-top: 2px; }

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ── Search Bar ─────────────────────────────────────────── */
.search-bar {
  position: relative;
  flex: 1;
  max-width: 360px;
}
.search-bar .search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.search-bar input {
  padding-left: 36px;
}

/* ── Toolbar (above tables) ─────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13.5px;
  border: 1px solid transparent;
}

.alert-icon {
  font-size: 16px;
  line-height: 1.4;
  flex-shrink: 0;
}

.alert-success { background: var(--green-soft); color: var(--green); border-color: rgba(34,197,94,.2); }
.alert-error   { background: var(--red-soft);   color: var(--red);   border-color: rgba(244,63,94,.2); }
.alert-warning { background: var(--yellow-soft);color: var(--yellow);border-color: rgba(245,158,11,.2); }
.alert-info    { background: var(--blue-soft);  color: var(--blue);  border-color: rgba(56,189,248,.2); }

/* ── Pagination ─────────────────────────────────────────── */
.pagination-nav { padding: 16px; display: flex; justify-content: center; }
.pagination { display: flex; gap: 4px; list-style: none; }
.page-item.disabled .page-link { opacity: .4; pointer-events: none; }
.page-item.active   .page-link { background: var(--accent); color: white; border-color: var(--accent); }
.page-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
}
.page-link:hover { background: var(--bg-3); color: var(--text); opacity: 1; }

/* ── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 560px;
  transform: translateY(20px) scale(.97);
  transition: transform var(--transition);
  box-shadow: var(--shadow);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close {
  background: none; border: none;
  color: var(--text-3); cursor: pointer;
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-3); color: var(--text); }

/* ── Detail Row ─────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
}

.detail-item { }
.detail-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-3);
  font-weight: 600;
  margin-bottom: 3px;
}
.detail-value {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

/* ── Empty State ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-3);
}
.empty-state svg { margin-bottom: 12px; opacity: .3; }
.empty-state h3  { font-size: 15px; color: var(--text-2); margin-bottom: 6px; }
.empty-state p   { font-size: 13px; }

/* ── Section divider ────────────────────────────────────── */
.section-divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}

/* ── Charts ─────────────────────────────────────────────── */
.chart-container {
  position: relative;
  height: 280px;
}

/* ── Login Page ─────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

body.login-page::before {
  content: '';
  position: fixed;
  top: -40%;
  left: -20%;
  width: 70%;
  height: 80%;
  background: radial-gradient(ellipse, rgba(79,110,247,.12) 0%, transparent 70%);
  pointer-events: none;
}

.login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.login-brand .brand-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
}
.login-subtitle {
  font-size: 13.5px;
  color: var(--text-2);
  margin-bottom: 28px;
}

.login-divider {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-3);
  margin: 20px 0;
}

/* ── Responsive ─────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 99;
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.visible { display: block; }
  .main-wrapper { margin-left: 0; }
  .menu-toggle { display: flex; }
  .grid-2, .form-row { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  .page-content { padding: 16px 14px 32px; }
  .stats-grid { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }
  .toolbar { gap: 8px; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ── Utilities ──────────────────────────────────────────── */
.text-green  { color: var(--green) !important; }
.text-red    { color: var(--red)   !important; }
.text-yellow { color: var(--yellow)!important; }
.text-blue   { color: var(--blue)  !important; }
.text-accent { color: var(--accent)!important; }
.text-muted  { color: var(--text-2)!important; }
.text-sm     { font-size: 12px !important; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.mono { font-family: var(--font-mono); }

/* ── Skeleton Loader ────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-3) 25%, var(--bg-4) 50%, var(--bg-3) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Calc Preview ───────────────────────────────────────── */
.calc-preview {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
.calc-item .calc-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); margin-bottom: 3px; }
.calc-item .calc-value { font-size: 16px; font-weight: 700; color: var(--text); font-family: var(--font-mono); }
.calc-item .calc-value.highlight { color: var(--green); }
