/* ============================================================
   Finance Tracker — Main Stylesheet
   ============================================================ */

:root {
  --primary:       #4f46e5;
  --primary-dark:  #3730a3;
  --primary-light: #e0e7ff;
  --success:       #10b981;
  --danger:        #ef4444;
  --warning:       #f59e0b;
  --info:          #3b82f6;
  --bg:            #f8fafc;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --sidebar-w:     260px;
  --radius:        12px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --transition:    .2s ease;
}

[data-theme="dark"] {
  --bg:         #0f172a;
  --surface:    #1e293b;
  --border:     #334155;
  --text:       #f1f5f9;
  --text-muted: #94a3b8;
  --primary-light: #312e81;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}

.sidebar-brand .brand-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand .brand-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.sidebar-nav { padding: .75rem 0; flex: 1; }

.nav-section-label {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding: .75rem 1.25rem .25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  border-radius: 0;
  transition: all var(--transition);
  position: relative;
}

.nav-link:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.nav-link.active {
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 600;
}

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.nav-link .nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .75rem;
}

.user-avatar {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: .875rem;
  flex-shrink: 0;
}

.user-name { font-size: .875rem; font-weight: 600; }
.user-role { font-size: .75rem; color: var(--text-muted); }

/* ── Main Content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title { font-size: 1.125rem; font-weight: 700; }

.topbar-actions { display: flex; align-items: center; gap: .75rem; }

.page-content { padding: 1.5rem; flex: 1; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-title { font-size: .9375rem; font-weight: 700; }
.card-body  { padding: 1.25rem; }

/* ── Stat Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-icon.green  { background: #d1fae5; color: var(--success); }
.stat-icon.red    { background: #fee2e2; color: var(--danger); }
.stat-icon.blue   { background: #dbeafe; color: var(--info); }
.stat-icon.purple { background: #ede9fe; color: var(--primary); }
.stat-icon.yellow { background: #fef3c7; color: var(--warning); }

.stat-label { font-size: .75rem; color: var(--text-muted); font-weight: 500; margin-bottom: .25rem; }
.stat-value { font-size: 1.25rem; font-weight: 700; }
.stat-sub   { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-sm { padding: .35rem .75rem; font-size: .8125rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }

.btn-primary   { background: var(--primary);  color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-success   { background: var(--success);  color: #fff; }
.btn-success:hover { filter: brightness(.9); }

.btn-danger    { background: var(--danger);   color: #fff; }
.btn-danger:hover  { filter: brightness(.9); }

.btn-warning   { background: var(--warning);  color: #fff; }
.btn-warning:hover { filter: brightness(.9); }

.btn-outline   { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }

.btn-ghost     { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .375rem; }

.form-control {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}

.form-control::placeholder { color: var(--text-muted); }

select.form-control { cursor: pointer; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

/* ── Tables ── */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

thead th {
  background: var(--bg);
  padding: .75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: .8125rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-income  { background: #d1fae5; color: #065f46; }
.badge-expense { background: #fee2e2; color: #991b1b; }
.badge-transfer{ background: #dbeafe; color: #1e40af; }
.badge-admin   { background: #ede9fe; color: #5b21b6; }
.badge-user    { background: #e0f2fe; color: #0369a1; }

/* ── Alerts / Flash ── */
.alert {
  padding: .875rem 1rem;
  border-radius: 8px;
  font-size: .875rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.25rem; color: var(--text-muted); padding: .25rem; }
.modal-close:hover { color: var(--text); }
.modal-body   { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .75rem; }

/* ── Progress Bar ── */
.progress {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: .5rem;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  transition: width .4s ease;
}

/* ── Account Type Colors ── */
.account-type-cash       { background: #d1fae5; color: #065f46; }
.account-type-bank       { background: #dbeafe; color: #1e40af; }
.account-type-ewallet    { background: #fef3c7; color: #92400e; }
.account-type-investment { background: #ede9fe; color: #5b21b6; }
.account-type-other      { background: #f1f5f9; color: #475569; }

/* ── Chart Container ── */
.chart-container { position: relative; }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; color: var(--text); }
.empty-state p  { font-size: .875rem; }

/* ── Login Page ── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1rem;
}

.auth-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo .logo-icon {
  width: 64px; height: 64px;
  background: var(--primary);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem;
  color: #fff;
  margin: 0 auto 1rem;
}

.auth-logo h1 { font-size: 1.5rem; font-weight: 800; }
.auth-logo p  { color: var(--text-muted); font-size: .875rem; }

/* ── Hamburger (mobile) ── */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: .25rem;
  color: var(--text);
  font-size: 1.25rem;
}

/* ── Dark mode toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .4rem .6rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .875rem;
  transition: all var(--transition);
}

.theme-toggle:hover { background: var(--bg); color: var(--text); }

/* ── Utilities ── */
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger)  !important; }
.text-muted   { color: var(--text-muted) !important; }
.text-primary { color: var(--primary) !important; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.fw-bold      { font-weight: 700; }
.d-flex       { display: flex; }
.align-center { align-items: center; }
.gap-1        { gap: .5rem; }
.gap-2        { gap: 1rem; }
.mb-1         { margin-bottom: .5rem; }
.mb-2         { margin-bottom: 1rem; }
.mb-3         { margin-bottom: 1.5rem; }
.mt-1         { margin-top: .5rem; }
.mt-2         { margin-top: 1rem; }
.w-100        { width: 100%; }
.flex-1       { flex: 1; }
.justify-between { justify-content: space-between; }
.flex-wrap    { flex-wrap: wrap; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .hamburger { display: block; }

  .form-row, .form-row-3 {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-content { padding: 1rem; }

  .topbar { padding: .75rem 1rem; }

  .modal { max-width: 100%; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}

.sidebar-overlay.open { display: block; }

/* ── Color dot ── */
.color-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ── Amount display ── */
.amount-income  { color: var(--success); font-weight: 600; }
.amount-expense { color: var(--danger);  font-weight: 600; }
.amount-transfer{ color: var(--info);    font-weight: 600; }

/* ── 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: var(--text-muted); }
