/* ============================================
   FINANCE SUITE — Design Tokens
   Light + Dark Mode | Apple System | Animations
   ============================================ */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  /* ---- Colors: Backgrounds (Apple Neutral) ---- */
  --bg-app: #F5F5F7;
  --bg-surface: rgba(255, 255, 255, 0.72);
  --bg-surface-hover: rgba(255, 255, 255, 0.85);
  --bg-elevated: rgba(255, 255, 255, 0.9);
  --bg-overlay: rgba(0, 0, 0, 0.3);
  --bg-secondary: #EFEFF1;

  /* ---- Apple Glass Effect ---- */
  --glass-blur: 40px;
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-shadow: 0 2px 20px rgba(0, 0, 0, 0.06);
  --glass-inset: inset 0 0.5px 0 rgba(255, 255, 255, 0.8);

  /* ---- Colors: Borders ---- */
  --border-primary: rgba(0, 0, 0, 0.08);
  --border-subtle: rgba(0, 0, 0, 0.04);
  --border-hover: rgba(0, 0, 0, 0.12);
  --border-focus: #007AFF;

  /* ---- Colors: Text ---- */
  --text-primary: #1D1D1F;
  --text-secondary: #6E6E73;
  --text-muted: #86868B;
  --text-inverse: #FFFFFF;

  /* ---- Colors: Brand / Accent (Apple Blue) ---- */
  --accent: #007AFF;
  --accent-hover: #0063D1;
  --accent-muted: rgba(0, 122, 255, 0.1);

  /* ---- Colors: Semantic (Apple System) ---- */
  --success: #34C759;
  --color-success: #34C759;
  --color-success-muted: rgba(52, 199, 89, 0.12);
  --warning: #FF9F0A;
  --color-warning: #FF9F0A;
  --color-warning-muted: rgba(255, 159, 10, 0.12);
  --danger: #FF3B30;
  --color-danger: #FF3B30;
  --color-danger-muted: rgba(255, 59, 48, 0.1);
  --color-info: #5AC8FA;
  --color-info-muted: rgba(90, 200, 250, 0.12);

  /* ---- Typography (Apple System) ---- */
  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Inter', 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --text-xs: 0.6875rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;

  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  --leading-tight: 1.2;
  --leading-normal: 1.47;

  /* ---- Spacing ---- */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* ---- Border Radius (Apple Generoso) ---- */
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-2xl: 26px;
  --radius-pill: 999px;

  /* ---- Shadows (Apple Diffuse) ---- */
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08);
  --shadow-glow: 0 0 0 3px rgba(0, 122, 255, 0.25);

  /* ---- Transitions (Apple Spring) ---- */
  --transition-fast: 150ms ease;
  --transition-base: 250ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --transition-slow: 350ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* ---- Layout ---- */
  --sidebar-width: 260px;
  --header-height: 56px;

  /* ---- Z-index ---- */
  --z-sticky: 200;
  --z-sidebar: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-toast: 600;
}

/* ============================================
   DARK MODE
   ============================================ */
[data-theme="dark"] {
  --bg-app: #000000;
  --bg-surface: rgba(28, 28, 30, 0.8);
  --bg-surface-hover: rgba(44, 44, 46, 0.9);
  --bg-elevated: rgba(44, 44, 46, 0.95);
  --bg-overlay: rgba(0, 0, 0, 0.6);
  --bg-secondary: #1C1C1E;

  --glass-blur: 40px;
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-shadow: 0 2px 20px rgba(0, 0, 0, 0.4);
  --glass-inset: inset 0 0.5px 0 rgba(255, 255, 255, 0.04);

  --border-primary: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --border-hover: rgba(255, 255, 255, 0.14);
  --border-focus: #0A84FF;

  --text-primary: #F5F5F7;
  --text-secondary: #A1A1A6;
  --text-muted: #6E6E73;
  --text-inverse: #000000;

  --accent: #0A84FF;
  --accent-hover: #409CFF;
  --accent-muted: rgba(10, 132, 255, 0.18);
  --accent-subtle: rgba(10, 132, 255, 0.08);

  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ============================================
   MICRO-ANIMATIONS (GPU-accelerated)
   ============================================ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes progressFill {
  from { width: 0; }
  to { width: var(--progress, 0%); }
}

/* Staggered card animations */
.card, .stat-card { animation: fadeInUp 0.4s ease both; }
.grid-stats > :nth-child(1) { animation-delay: 0s; }
.grid-stats > :nth-child(2) { animation-delay: 0.05s; }
.grid-stats > :nth-child(3) { animation-delay: 0.1s; }
.grid-stats > :nth-child(4) { animation-delay: 0.15s; }
.grid-2 > :nth-child(1), .grid-3 > :nth-child(1) { animation-delay: 0.05s; }
.grid-2 > :nth-child(2), .grid-3 > :nth-child(2) { animation-delay: 0.1s; }
.grid-3 > :nth-child(3) { animation-delay: 0.15s; }

/* Hover lift */
.card { transition: transform var(--transition-base), box-shadow var(--transition-base); }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

/* Sidebar link hover */
.sidebar-link { transition: all var(--transition-base); }
.sidebar-link:hover { background: var(--bg-surface-hover); }

/* Quick list item stagger */
.quick-list-item { animation: slideInRight 0.3s ease both; }
.quick-list-item:nth-child(1) { animation-delay: 0s; }
.quick-list-item:nth-child(2) { animation-delay: 0.04s; }
.quick-list-item:nth-child(3) { animation-delay: 0.04s; }
.quick-list-item:nth-child(4) { animation-delay: 0.12s; }
.quick-list-item:nth-child(5) { animation-delay: 0.16s; }

/* ============================================
   DARK MODE — Component Overrides
   Fixes all text/background visibility issues
   ============================================ */
[data-theme="dark"] .card {
  background: var(--bg-surface);
  border-color: var(--border-primary);
}

[data-theme="dark"] .stat-card {
  background: var(--bg-surface);
  border-color: var(--border-primary);
  color: var(--text-primary);
}
[data-theme="dark"] .stat-card .stat-card-label {
  color: var(--text-muted);
}
[data-theme="dark"] .stat-card .stat-card-value {
  color: var(--text-primary);
}
/* Colored stat cards keep their gradient — text is already white */

/* Sidebar */
[data-theme="dark"] .sidebar {
  background: var(--bg-surface);
  border-right-color: var(--border-primary);
}
[data-theme="dark"] .sidebar-brand {
  border-bottom-color: var(--border-primary);
}
[data-theme="dark"] .sidebar-user {
  border-top-color: var(--border-primary);
}

/* Page header */
[data-theme="dark"] .page-header {
  border-bottom-color: var(--border-primary);
}
[data-theme="dark"] .page-title {
  color: var(--text-primary);
}

/* Data tables */
[data-theme="dark"] .table-container {
  background: var(--bg-surface);
  border-color: var(--border-primary);
}
[data-theme="dark"] .data-table th {
  background: var(--bg-secondary);
  color: var(--text-muted);
  border-bottom-color: var(--border-primary);
}
[data-theme="dark"] .data-table td {
  color: var(--text-secondary);
  border-bottom-color: var(--border-subtle);
}
[data-theme="dark"] .data-table tbody tr:hover {
  background: var(--bg-surface-hover);
}

/* Forms & Inputs */
[data-theme="dark"] .form-input,
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-textarea {
  background: var(--bg-secondary);
  border-color: var(--border-primary);
  color: var(--text-primary);
}
[data-theme="dark"] .form-input::placeholder {
  color: var(--text-muted);
}

/* Modal */
[data-theme="dark"] .modal-content {
  background: var(--bg-elevated);
  border-color: var(--border-primary);
}
[data-theme="dark"] .modal-header {
  border-bottom-color: var(--border-primary);
  color: var(--text-primary);
}
[data-theme="dark"] .modal-footer {
  border-top-color: var(--border-primary);
}

[data-theme="dark"] .tabs {
  background: rgba(255, 255, 255, 0.04);
}
[data-theme="dark"] .tab.active {
  color: var(--text-primary);
  background: var(--bg-elevated);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] .tab:hover {
  color: var(--text-primary);
}

/* Badges */
[data-theme="dark"] .badge-neutral {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-color: var(--border-primary);
}

/* Quick list items */
[data-theme="dark"] .quick-list-item {
  background: var(--bg-elevated);
}
[data-theme="dark"] .quick-list-item:hover {
  background: var(--bg-surface-hover);
}

/* Buttons */
[data-theme="dark"] .btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border-primary);
}
[data-theme="dark"] .btn-ghost {
  color: var(--text-secondary);
}
[data-theme="dark"] .btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* Toast */
[data-theme="dark"] .toast {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-primary);
}

/* Empty state */
[data-theme="dark"] .empty-state-title {
  color: var(--text-primary);
}
[data-theme="dark"] .empty-state-text {
  color: var(--text-muted);
}
[data-theme="dark"] .empty-state-icon {
  color: var(--text-muted);
}

/* Card title & headers */
[data-theme="dark"] .card-title,
[data-theme="dark"] .card-header h3 {
  color: var(--text-primary);
}

/* Text utility overrides */
[data-theme="dark"] .text-muted {
  color: var(--text-muted) !important;
}

/* Item info text */
[data-theme="dark"] .item-title {
  color: var(--text-primary);
}
[data-theme="dark"] .item-subtitle {
  color: var(--text-muted);
}

/* Item icons */
[data-theme="dark"] .item-icon {
  background: var(--bg-secondary);
}
[data-theme="dark"] .item-icon.income { background: rgba(52, 199, 89, 0.15); }
[data-theme="dark"] .item-icon.expense { background: rgba(255, 59, 48, 0.15); }
[data-theme="dark"] .item-icon.project { background: rgba(0, 122, 255, 0.15); }

/* Auth screen — now dark-native, no theme override needed */

/* Chart backgrounds */
[data-theme="dark"] .chart-container {
  background: transparent;
}

/* Scrollbar */
[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--bg-app);
}
[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--border-hover);
}

/* Selection */
[data-theme="dark"] ::selection {
  background: var(--accent-muted);
  color: var(--text-primary);
}

/* Link colors in dark */
[data-theme="dark"] a {
  color: var(--accent);
}
[data-theme="dark"] a.sidebar-link {
  color: var(--text-secondary);
}
[data-theme="dark"] a.sidebar-link.active {
  color: var(--accent);
}

/* Cell actions */
[data-theme="dark"] .cell-actions button {
  color: var(--text-muted);
}
[data-theme="dark"] .cell-actions button:hover {
  color: var(--text-primary);
}

/* Dividers */
[data-theme="dark"] .divider {
  border-color: var(--border-primary);
}

/* Mono text */
[data-theme="dark"] .mono {
  color: var(--text-primary);
}
