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

:root {
  --sidebar-w:   240px;
  --bg:          #f1f5f9;
  --sidebar-bg:  #0f172a;
  --sidebar-txt: #94a3b8;
  --sidebar-act: #6366f1;
  --card:        #ffffff;
  --primary:     #6366f1;
  --primary-dk:  #4f46e5;
  --success:     #10b981;
  --danger:      #ef4444;
  --warn:        #f59e0b;
  --info:        #3b82f6;
  --txt:         #1e293b;
  --txt-muted:   #64748b;
  --border:      #e2e8f0;
  --radius:      10px;
  --shadow:      0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
}

html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--txt);
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Layout ─────────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand .brand-icon { font-size: 22px; }
.sidebar-brand .brand-name {
  font-size: 16px; font-weight: 700;
  color: #fff; letter-spacing: -.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: var(--sidebar-txt);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 0;
  cursor: pointer;
  transition: background .15s, color .15s;
  user-select: none;
}
.sidebar-nav a:hover  { background: rgba(255,255,255,.05); color: #fff; }
.sidebar-nav a.active { background: rgba(99,102,241,.2); color: #a5b4fc; }
.sidebar-nav a .nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.user-pill {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.user-name  { font-size: 13px; font-weight: 600; color: #fff; }
.user-role  { font-size: 11px; color: var(--sidebar-txt); }
.btn-logout {
  width: 100%; padding: 8px;
  background: rgba(255,255,255,.06);
  color: var(--sidebar-txt);
  border: none; border-radius: 6px;
  font-size: 13px; cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-logout:hover { background: rgba(239,68,68,.15); color: #fca5a5; }

/* ─── Main content ───────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.page-header {
  padding: 24px 28px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-title { font-size: 20px; font-weight: 700; }
.page-body  { padding: 20px 28px 32px; }

/* ─── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-title {
  font-size: 13px; font-weight: 600;
  color: var(--txt-muted); text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 6px;
}

/* ─── Stat cards ─────────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 16px; }
.stat-card  { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--txt-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 26px; font-weight: 700; margin: 4px 0; }
.stat-sub   { font-size: 12px; color: var(--txt-muted); }
.stat-green { color: var(--success); }
.stat-red   { color: var(--danger); }
.stat-blue  { color: var(--info); }

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

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 7px;
  font-size: 13.5px; font-weight: 500;
  border: none; cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-dk); }
.btn-success  { background: var(--success);  color: #fff; }
.btn-success:hover  { opacity: .9; }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-danger:hover   { opacity: .9; }
.btn-outline  { background: transparent; color: var(--txt); border: 1px solid var(--border); }
.btn-outline:hover  { background: var(--bg); }
.btn-ghost    { background: transparent; color: var(--txt-muted); border: none; }
.btn-ghost:hover    { color: var(--txt); background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; }
/* ─── SVG icon sizing ──────────────────────────────────────────────────────────── */
.logo-icon svg  { width: 44px; height: 44px; }
.brand-icon svg { width: 22px; height: 22px; }
.nav-icon svg   { width: 18px; height: 18px; }
.empty-icon svg { width: 48px; height: 48px; opacity: 0.35; }

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form-row   { display: grid; gap: 14px; }
.form-cols  { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-cols3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--txt); }
.form-label .req { color: var(--danger); }
.form-input, .form-select, .form-textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--txt);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.form-textarea { min-height: 80px; resize: vertical; }
.form-hint  { font-size: 12px; color: var(--txt-muted); }
.form-error { font-size: 12px; color: var(--danger); }

/* ─── Table ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
}
.table th {
  text-align: left; padding: 10px 14px;
  font-size: 11.5px; font-weight: 600;
  color: var(--txt-muted); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fafafa; }

/* ─── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600;
}
.badge-income  { background: #d1fae5; color: #065f46; }
.badge-expense { background: #fee2e2; color: #991b1b; }
.badge-active  { background: #dbeafe; color: #1e40af; }
.badge-paid    { background: #d1fae5; color: #065f46; }
.badge-warn    { background: #fef3c7; color: #92400e; }

/* ─── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: 14px;
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-header {
  padding: 20px 24px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--txt-muted); line-height: 1; }
.modal-body   { padding: 16px 24px; }
.modal-footer { padding: 0 24px 20px; display: flex; gap: 10px; justify-content: flex-end; }

/* ─── Loading spinner ────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  display: flex; align-items: center; justify-content: center;
  padding: 48px; gap: 12px;
  color: var(--txt-muted);
}

/* ─── Toast ──────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 2000;
}
.toast {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--txt); color: #fff;
  padding: 14px 18px; border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  min-width: 280px; max-width: 380px;
  font-size: 13.5px;
  animation: slideUp .25s ease;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warn    { background: var(--warn); color: #1e293b; }
@keyframes slideUp { from { opacity:0; transform: translateY(16px); } to { opacity:1; transform: translateY(0); } }

/* ─── Progress bar ───────────────────────────────────────────────────────────── */
.progress { background: var(--border); border-radius: 20px; height: 7px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 20px; transition: width .4s; }

/* ─── Notification bell ──────────────────────────────────────────────────────── */
.notif-bell {
  position: relative; cursor: pointer;
  background: none; border: none; font-size: 20px;
  color: var(--sidebar-txt); padding: 4px;
}
.notif-badge {
  position: absolute; top: -2px; right: -4px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
}

/* ─── Chart container ────────────────────────────────────────────────────────── */
.chart-container { position: relative; height: 240px; }
.chart-container-sm { position: relative; height: 160px; }

/* ─── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--txt-muted);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 10px; }
.empty-state .empty-title { font-size: 15px; font-weight: 600; color: var(--txt); }
.empty-state .empty-sub   { font-size: 13px; margin-top: 4px; }

/* ─── Filter bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  align-items: center; margin-bottom: 16px;
}
.filter-bar .form-input,
.filter-bar .form-select { max-width: 160px; }

/* ─── Amount display ─────────────────────────────────────────────────────────── */
.amount-income  { color: var(--success); font-weight: 600; }
.amount-expense { color: var(--danger);  font-weight: 600; }

/* ─── Debt progress card ─────────────────────────────────────────────────────── */
.debt-card      { margin-bottom: 12px; }
.debt-meta      { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.debt-name      { font-weight: 600; }
.debt-amounts   { font-size: 13px; color: var(--txt-muted); }

/* ─── Pagination ─────────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 16px; }

/* ─── Login page ─────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; background: var(--sidebar-bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 16px; padding: 40px;
  width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-icon  { font-size: 40px; }
.login-logo .logo-title { font-size: 22px; font-weight: 800; color: var(--txt); margin-top: 6px; }
.login-logo .logo-sub   { font-size: 13px; color: var(--txt-muted); margin-top: 2px; }

/* ─── Mobile bottom nav ───────────────────────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--sidebar-bg);
  border-top: 1px solid rgba(255,255,255,.08);
  height: 60px;
  justify-content: space-around; align-items: stretch;
  z-index: 500;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mobile-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--sidebar-txt); cursor: pointer; text-decoration: none;
  flex: 1; font-size: 10px; font-weight: 500;
  transition: color .15s; position: relative;
}
.mobile-nav a.active { color: #a5b4fc; }
.mobile-nav svg { width: 22px; height: 22px; }
.mn-dot {
  position: absolute; top: 8px; right: calc(50% - 18px);
  width: 7px; height: 7px;
  background: var(--danger); border-radius: 50%;
}

/* ─── FAB ─────────────────────────────────────────────────────────────────────── */
.fab {
  display: none;
  position: fixed; bottom: 76px; right: 20px;
  width: 52px; height: 52px;
  background: var(--primary); color: #fff;
  border-radius: 50%; border: none; cursor: pointer;
  box-shadow: 0 4px 20px rgba(99,102,241,.5);
  align-items: center; justify-content: center;
  z-index: 400; transition: transform .15s;
}
.fab:active { transform: scale(.92); }
.fab svg { width: 26px; height: 26px; }

/* ─── Transaction mobile cards ────────────────────────────────────────────────── */
.tx-card-list { display: none; }
.tx-card-item {
  padding: 13px 14px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card);
}
.tx-card-row  { display: flex; align-items: center; gap: 10px; }
.tx-card-meta { margin-top: 5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tx-card-acts { margin-top: 8px; display: flex; gap: 6px; justify-content: flex-end; border-top: 1px solid var(--border); padding-top: 8px; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar    { width: 56px; }
  .sidebar-brand .brand-name,
  .sidebar-nav a span:not(.nav-icon),
  .sidebar-footer .user-name,
  .sidebar-footer .user-role,
  .btn-logout { display: none; }
  .sidebar-nav a { justify-content: center; padding: 12px; }
  .page-body  { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-cols, .form-cols3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar      { display: none; }
  .mobile-nav   { display: flex; }
  .fab          { display: flex; }
  .main-content { padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  .page-header  { flex-direction: column; align-items: flex-start; gap: 10px; padding-top: 16px; }
  .tx-table-wrap { display: none; }
  .tx-card-list  { display: block; }
  .toast-container { bottom: calc(70px + env(safe-area-inset-bottom, 0px)); left: 12px; right: 12px; }
  .toast { min-width: unset; max-width: 100%; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { padding: 14px 14px 0; }
  .page-body   { padding: 10px 14px 24px; }
  .modal       { border-radius: 16px 16px 0 0; max-width: 100%; max-height: 95dvh; }
  .modal-overlay { align-items: flex-end; padding: 0; }
}

/* ─── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ─── Utilities ──────────────────────────────────────────────────────────────── */
.mt-1 { margin-top: 4px; }  .mt-2 { margin-top: 8px; }  .mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; } .mt-5 { margin-top: 20px; } .mt-6 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.flex { display: flex; } .flex-1 { flex: 1; } .items-center { align-items: center; }
.justify-between { justify-content: space-between; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.text-right { text-align: right; } .text-center { text-align: center; }
.font-bold { font-weight: 700; } .font-semibold { font-weight: 600; }
.text-sm { font-size: 12px; } .text-muted { color: var(--txt-muted); }
.text-danger { color: var(--danger); } .text-success { color: var(--success); }
.w-full { width: 100%; } .truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
[x-cloak] { display: none !important; }
