/* ============================================
   MONEY MANAGER - MAIN CSS
   Design System Tokens + Layout + Base
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* ============ CSS VARIABLES ============ */
:root {
  /* Brand Colors */
  --primary: #6366F1;
  --primary-light: #818CF8;
  --primary-dark: #4F46E5;
  --primary-bg: #EEF2FF;

  /* Semantic Colors */
  --success: #22C55E;
  --success-light: #86EFAC;
  --success-bg: #F0FDF4;
  --danger: #EF4444;
  --danger-light: #FCA5A5;
  --danger-bg: #FEF2F2;
  --warning: #F59E0B;
  --warning-light: #FCD34D;
  --warning-bg: #FFFBEB;
  --info: #3B82F6;
  --info-light: #93C5FD;
  --info-bg: #EFF6FF;

  /* Neutral Colors */
  --gray-50: #F8FAFC;
  --gray-100: #F1F5F9;
  --gray-200: #E2E8F0;
  --gray-300: #CBD5E1;
  --gray-400: #94A3B8;
  --gray-500: #64748B;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1E293B;
  --gray-900: #0F172A;

  /* Layout */
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --border: #E2E8F0;
  --border-light: #F1F5F9;

  /* Text */
  --text-primary: #1E293B;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --text-inverse: #FFFFFF;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px -1px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
  --shadow-card: 0 2px 8px rgba(99,102,241,0.06), 0 1px 3px rgba(0,0,0,0.08);

  /* Spacing */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --transition: all 0.2s ease;
  --transition-slow: all 0.3s ease;

  /* Sidebar */
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --bottom-nav-height: 64px;
}

/* ============ DARK MODE ============ */
[data-theme="dark"] {
  --bg: #0F172A;
  --surface: #1E293B;
  --surface-2: #263548;
  --border: #334155;
  --border-light: #1E293B;
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --shadow-card: 0 2px 8px rgba(0,0,0,0.3), 0 1px 3px rgba(0,0,0,0.2);
  --primary-bg: #1E1B4B;
  --success-bg: #052e16;
  --danger-bg: #450a0a;
  --warning-bg: #422006;
  --info-bg: #0c1a2e;
}

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

html { font-size: 16px; scroll-behavior: smooth; height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }
img { max-width: 100%; }
ul, ol { list-style: none; }

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--gray-600); }

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  transition: var(--transition-slow);
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-logo-text h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.sidebar-logo-text span {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 20px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-radius: 0;
  transition: var(--transition);
  cursor: pointer;
  position: relative;
  margin: 1px 8px;
  border-radius: var(--radius-sm);
}

.nav-item:hover {
  background: var(--primary-bg);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.nav-item i {
  width: 20px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}

.sidebar-bottom {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

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

/* Top bar */
.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  flex: 1;
}

.topbar-title h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.topbar-title p {
  font-size: 12px;
  color: var(--text-muted);
}

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

/* Page content area */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* Pages */
.page {
  display: none;
  animation: fadeIn 0.2s ease;
}

.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Bottom Nav (Mobile) */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 200;
  padding: 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
}

.bottom-nav-items {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  min-width: 0;
}

.bottom-nav-item i {
  font-size: 18px;
  transition: var(--transition);
}

.bottom-nav-item.active {
  color: var(--primary);
}

.bottom-nav-item.active i {
  transform: scale(1.1);
}

/* Mobile top bar */
.mobile-topbar {
  display: none;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.mobile-topbar h2 {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============ GRID UTILITIES ============ */
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); gap: 12px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4 { gap: 16px; }
.gap-3 { gap: 12px; }
.gap-2 { gap: 8px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar { display: none; }
  .bottom-nav { display: flex; }
  .mobile-topbar { display: flex; }
  .page-content {
    padding: 12px 12px calc(var(--bottom-nav-height) + 12px);
  }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .grid-2 { grid-template-columns: 1fr; }
  .page-content { padding: 10px 10px calc(var(--bottom-nav-height) + 10px); }
}

/* ============ FAB BUTTON ============ */
.fab {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + 16px);
  right: 16px;
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  border-radius: var(--radius-full);
  font-size: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-xl), 0 0 0 4px rgba(99,102,241,0.2);
  transition: var(--transition);
  z-index: 150;
}

.fab:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-xl), 0 0 0 6px rgba(99,102,241,0.2);
}

@media (max-width: 768px) {
  .fab { display: flex; }
}

/* ============ TYPOGRAPHY ============ */
h1 { font-size: 24px; font-weight: 800; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 14px; font-weight: 600; }

.text-xs { font-size: 11px; }
.text-sm { font-size: 13px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.text-2xl { font-size: 22px; }
.text-3xl { font-size: 28px; }

.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-extrabold { font-weight: 800; }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info { color: var(--info); }
.text-brand { color: var(--primary); }

/* ============ SPACING ============ */
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.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; }
.section-gap { margin-bottom: 24px; }

/* ============ TOAST NOTIFICATIONS ============ */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: slideInRight 0.3s ease;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.info { border-left: 4px solid var(--primary); }

.toast i { font-size: 16px; }
.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.warning i { color: var(--warning); }
.toast.info i { color: var(--primary); }

.toast-close {
  margin-left: auto;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
}

.toast.removing {
  animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOutRight {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(100%); }
}

@media (max-width: 768px) {
  .toast-container { top: auto; bottom: calc(var(--bottom-nav-height) + 16px); left: 12px; right: 12px; }
  .toast { min-width: unset; }
}

/* ============ PAGE HEADER ============ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-header-left h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

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

/* ============ SECTION HEADER ============ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ============ LOADING ============ */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

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

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