/* ========================================================
   Mon Foyer - CSS Application
   ======================================================== */

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --sidebar-width: 260px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #6366f1;
  --header-height: 64px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.05);
  --shadow-lg: 0 4px 6px rgba(0,0,0,.05), 0 20px 40px rgba(0,0,0,.1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f8fafc;
  color: #1e293b;
  line-height: 1.5;
}

/* ---- Sidebar ---- */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .3s ease;
  overflow-y: auto;
}

#sidebar .logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

#sidebar .logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}

#sidebar .logo .logo-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

#sidebar .logo p {
  font-size: .75rem;
  color: var(--sidebar-text);
  margin-top: 2px;
}

#sidebar nav {
  flex: 1;
  padding: 16px 12px;
}

#sidebar nav .nav-section {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #475569;
  padding: 16px 8px 6px;
}

#sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: all .15s;
  margin-bottom: 2px;
}

#sidebar nav a:hover {
  background: rgba(255,255,255,.06);
  color: #e2e8f0;
}

#sidebar nav a.active {
  background: rgba(99,102,241,.15);
  color: #818cf8;
}

#sidebar nav a .nav-icon {
  width: 20px;
  font-size: 1rem;
  flex-shrink: 0;
}

#sidebar nav a .nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: .65rem;
  padding: 2px 6px;
  border-radius: 99px;
}

/* Sidebar user */
#sidebar .sidebar-user {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  color: white;
  flex-shrink: 0;
}

.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name { font-size: .85rem; color: #e2e8f0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { font-size: .7rem; color: var(--sidebar-text); }

/* ---- Main content ---- */
#main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#topbar {
  background: white;
  height: var(--header-height);
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

#topbar .page-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: #0f172a;
}

#topbar .topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

#content {
  flex: 1;
  padding: 28px 28px;
}

/* ---- Cards ---- */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid #f1f5f9;
}

.card-header {
  padding: 20px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: .9375rem;
  font-weight: 700;
  color: #0f172a;
}

.card-body { padding: 20px 24px; }
.card-footer { padding: 12px 24px; border-top: 1px solid #f1f5f9; }

/* ---- Stat cards ---- */
.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  border: 1px solid #f1f5f9;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

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

.stat-card .stat-label {
  font-size: .8rem;
  color: #64748b;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
  margin: 4px 0;
}

.stat-card .stat-change {
  font-size: .8rem;
  font-weight: 500;
}

.stat-card .stat-change.up { color: var(--success); }
.stat-card .stat-change.down { color: var(--danger); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
}

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

.btn-ghost {
  background: transparent;
  color: #64748b;
  border: 1px solid #e2e8f0;
}
.btn-ghost:hover { background: #f8fafc; color: #0f172a; }

.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 8px; }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-income { background: #dcfce7; color: #16a34a; }
.badge-expense { background: #fee2e2; color: #dc2626; }
.badge-transfer { background: #dbeafe; color: #2563eb; }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: .9rem;
  color: #0f172a;
  background: white;
  transition: border-color .15s;
  outline: none;
}

.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.form-control::placeholder { color: #94a3b8; }

select.form-control { cursor: pointer; }

.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ---- Tables ---- */
.table-wrapper { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

table.data-table th {
  text-align: left;
  padding: 10px 16px;
  background: #f8fafc;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
}

table.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  color: #1e293b;
  vertical-align: middle;
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: #fafafa; }

/* ---- Amount colors ---- */
.amount-positive { color: var(--success); font-weight: 700; }
.amount-negative { color: var(--danger); font-weight: 700; }
.amount-neutral { color: #64748b; }

/* ---- Progress bars ---- */
.progress {
  background: #f1f5f9;
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 99px;
  transition: width .4s ease;
}

/* ---- Modals ---- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { transform: scale(.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: #94a3b8; padding: 4px; }
.modal-close:hover { color: #0f172a; }
.modal-body { padding: 20px 24px; overflow-y: auto; }
.modal-footer { padding: 16px 24px; border-top: 1px solid #f1f5f9; display: flex; gap: 10px; justify-content: flex-end; }

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

/* ---- Account card ---- */
.account-card {
  border-radius: var(--radius);
  padding: 20px;
  color: white;
  position: relative;
  overflow: hidden;
}

.account-card::after {
  content: '';
  position: absolute;
  top: -20px; right: -20px;
  width: 100px; height: 100px;
  background: rgba(255,255,255,.08);
  border-radius: 50%;
}

.account-card .account-label { font-size: .75rem; opacity: .8; text-transform: uppercase; letter-spacing: .06em; }
.account-card .account-balance { font-size: 1.8rem; font-weight: 800; margin: 8px 0 4px; }
.account-card .account-type { font-size: .75rem; opacity: .7; }
.account-card .account-actions { position: absolute; top: 16px; right: 16px; display: flex; gap: 6px; }
.account-card .account-actions button { background: rgba(255,255,255,.2); border: none; color: white; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-size: .9rem; display: flex; align-items: center; justify-content: center; }
.account-card .account-actions button:hover { background: rgba(255,255,255,.35); }

/* ---- Category dot ---- */
.cat-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- Toast notifications ---- */
#toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #0f172a;
  color: white;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: .875rem;
  font-weight: 500;
  max-width: 320px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn .2s ease;
}

@keyframes toastIn { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error { border-left: 4px solid var(--danger); }
.toast.toast-info { border-left: 4px solid var(--info); }

/* ---- Skeleton loading ---- */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}

@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #94a3b8;
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 { font-size: 1.1rem; color: #64748b; margin-bottom: 8px; }
.empty-state p { font-size: .9rem; }

/* ---- Wealth bars ---- */
.wealth-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.wealth-bar .wb-icon { font-size: 1.3rem; width: 32px; text-align: center; }
.wealth-bar .wb-info { flex: 1; }
.wealth-bar .wb-name { font-size: .85rem; font-weight: 600; color: #1e293b; }
.wealth-bar .wb-amount { font-size .8rem; color: #64748b; }

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
  background: white;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-box .login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-box .login-logo h1 { font-size: 1.75rem; font-weight: 800; color: #0f172a; }
.login-box .login-logo p { color: #64748b; font-size: .9rem; margin-top: 4px; }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .grid-5 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #main { margin-left: 0; }
  .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
  #content { padding: 16px; }
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
}

/* ---- Misc ---- */
.text-muted { color: #64748b; }
.text-sm { font-size: .85rem; }
.text-xs { font-size: .75rem; }
.fw-bold { font-weight: 700; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; } .items-center { align-items: center; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* Upload zone */
.upload-zone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-zone .upload-icon { font-size: 2rem; color: #94a3b8; margin-bottom: 8px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1.5px solid #e2e8f0; margin-bottom: 20px; }
.tab-btn { padding: 8px 16px; border: none; background: none; cursor: pointer; font-size: .875rem; font-weight: 500; color: #64748b; border-bottom: 2px solid transparent; margin-bottom: -1.5px; }
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }
