/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-hover: #334155;
  --sidebar-active: #6366f1;
  --sidebar-w: 220px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ============================================================
   LAYOUT
   ============================================================ */
#app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  transition: transform .25s ease;
  z-index: 100;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar-brand svg { flex-shrink: 0; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item svg { flex-shrink: 0; opacity: .85; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 12px 16px;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-chip span {
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
}

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

.menu-toggle { display: none; }

.month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border-radius: 8px;
  padding: 4px 8px;
}

.month-label {
  font-size: 13px;
  font-weight: 600;
  min-width: 120px;
  text-align: center;
  color: var(--text);
}

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

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

.page-title { font-size: 20px; font-weight: 700; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background .15s, opacity .15s, transform .1s;
  cursor: pointer;
  border: none;
  white-space: nowrap;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

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

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: 8px; color: var(--text-muted); transition: background .15s, color .15s; }
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card-body { padding: 20px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 14px; font-weight: 700; color: var(--text); }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stat-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1.1; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; margin-bottom: 12px; }

/* ============================================================
   CHARTS
   ============================================================ */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.chart-container { position: relative; height: 240px; }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg); }
th { padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); white-space: nowrap; }
td { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tr:hover td { background: var(--bg); }

.td-amount { font-weight: 700; font-size: 14px; }
.td-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ============================================================
   FILTERS
   ============================================================ */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filters input, .filters select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}

.filters input:focus, .filters select:focus { border-color: var(--primary); }
.filters input { flex: 1; min-width: 180px; }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

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

.form-control.error { border-color: var(--danger); }

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

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type="color"] { width: 40px; height: 36px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; padding: 2px; }

/* ============================================================
   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: 16px;
  opacity: 0;
  transition: opacity .2s;
}

.modal-overlay.open { opacity: 1; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(12px);
  transition: transform .2s;
}

.modal-overlay.open .modal { transform: translateY(0); }
.modal-sm { max-width: 360px; }

.modal-header {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-header h3 { font-size: 15px; font-weight: 700; }

.modal-body { padding: 20px; overflow-y: auto; }

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

/* ============================================================
   TOAST
   ============================================================ */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: #fff;
  max-width: 320px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}

.toast.visible { opacity: 1; transform: translateX(0); }
.toast-success { background: #166534; }
.toast-error { background: #991b1b; }
.toast-info { background: #1e40af; }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  padding: 16px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 400px;
  padding: 36px 32px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo-icon {
  width: 52px;
  height: 52px;
  background: var(--primary);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  margin-bottom: 12px;
}

.auth-logo h1 { font-size: 22px; font-weight: 800; color: var(--text); }
.auth-logo p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.auth-footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-muted); }
.auth-footer a { color: var(--primary); font-weight: 600; }

/* ============================================================
   CATEGORY CHIPS & TAGS
   ============================================================ */
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  gap: 4px;
}

.tags-row { display: flex; flex-wrap: wrap; gap: 4px; }

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--primary);
  transition: width .4s ease;
}

.progress-fill.over { background: var(--danger); }
.progress-fill.warn { background: var(--warning); }

/* ============================================================
   BUDGET CARDS GRID
   ============================================================ */
.budget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.budget-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
}

.budget-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.budget-cat { display: flex; align-items: center; gap: 8px; }
.budget-cat-icon { font-size: 20px; }
.budget-cat-name { font-size: 14px; font-weight: 700; }
.budget-amounts { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.budget-amounts strong { color: var(--text); }

/* ============================================================
   CATEGORY CARDS GRID
   ============================================================ */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cat-card-header { display: flex; align-items: center; justify-content: space-between; }
.cat-card-info { display: flex; align-items: center; gap: 10px; }
.cat-card-icon { font-size: 26px; }
.cat-card-name { font-size: 14px; font-weight: 700; }
.cat-swatch { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: .5; }
.empty h3 { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 13px; }

/* ============================================================
   LOADING
   ============================================================ */
.full-center { height: 100vh; display: flex; align-items: center; justify-content: center; }

.loading { display: flex; align-items: center; justify-content: center; padding: 60px; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   RECENT LIST
   ============================================================ */
.recent-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.recent-item:last-child { border-bottom: none; }
.recent-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.recent-desc { flex: 1; min-width: 0; }
.recent-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-date { font-size: 12px; color: var(--text-muted); }
.recent-amount { font-size: 14px; font-weight: 700; flex-shrink: 0; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); }

  .menu-toggle { display: flex; }

  .content { padding: 16px; }

  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }

  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
  }

  .sidebar-overlay.open { display: block; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
