/* Modern SaaS UI Design System (Linear / Stripe / Vercel Inspired) */

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

:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Color Palette - Modern Dark Slate & Crisp Light Mode */
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-surface: #1f293d;
  --bg-surface-hover: #2d3748;
  --navbar-bg: rgba(17, 24, 39, 0.85);

  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #6366f1;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --brand-primary: #6366f1;
  --brand-hover: #4f46e5;
  --brand-light: rgba(99, 102, 241, 0.15);

  --income-green: #10b981;
  --income-bg: rgba(16, 185, 129, 0.12);
  --expense-red: #f43f5e;
  --expense-bg: rgba(244, 63, 94, 0.12);

  --warning-amber: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --info-blue: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.2);

  --sidebar-width: 260px;
  --header-height: 68px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: var(--brand-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--brand-hover);
}

/* App Layout Grid */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.brand-logo-img {
  height: 36px;
  width: auto;
  max-width: 170px;
  object-fit: contain;
  display: block;
}

/* Default to dark-logo if data-theme is not set */
.dark-logo { display: block; }
.light-logo { display: none; }

[data-theme="dark"] .dark-logo { display: block !important; }
[data-theme="dark"] .light-logo { display: none !important; }

[data-theme="light"] .dark-logo { display: none !important; }
[data-theme="light"] .light-logo { display: block !important; }

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  background: var(--brand-light);
  color: var(--brand-primary);
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-nav {
  padding: 1.25rem 0.75rem;
  flex: 1;
  overflow-y: auto;
}

.nav-group-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.nav-link:hover {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.nav-link.active {
  background-color: var(--brand-light);
  color: var(--brand-primary);
  font-weight: 600;
}

.nav-link svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  font-size: 0.9rem;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Layout */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left var(--transition-normal);
}

.top-navbar {
  height: var(--header-height);
  background-color: var(--navbar-bg, rgba(17, 24, 39, 0.85));
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 30;
}

.top-navbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
}

.page-header-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.top-navbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.main-content {
  padding: 1.75rem 2rem;
  flex: 1;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

/* KPI Summary Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1.25rem;
  margin-bottom: 2rem;
}

@media (max-width: 1200px) {
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

.kpi-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.kpi-card:hover {
  border-color: rgba(255, 255, 255, 0.18);
  transform: translateY(-2px);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.kpi-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-icon.income { background: var(--income-bg); color: var(--income-green); }
.kpi-icon.expense { background: var(--expense-bg); color: var(--expense-red); }
.kpi-icon.balance { background: var(--brand-light); color: var(--brand-primary); }
.kpi-icon.cxc { background: var(--info-bg); color: var(--info-blue); }
.kpi-icon.cxp { background: var(--warning-bg); color: var(--warning-amber); }

.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

/* UI Cards */
.card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--brand-primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
  background-color: var(--brand-hover);
  color: #ffffff;
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background-color: var(--bg-surface-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
  background-color: var(--expense-bg);
  color: var(--expense-red);
  border-color: rgba(244, 63, 94, 0.3);
}
.btn-danger:hover {
  background-color: var(--expense-red);
  color: #ffffff;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 0.8rem 1.5rem;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

/* Form Controls */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.9rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

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

.form-control::placeholder {
  color: var(--text-muted);
}

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

/* Table Styles */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

[data-theme="light"] {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-surface: #f8fafc;
  --bg-surface-hover: #e2e8f0;
  --navbar-bg: rgba(255, 255, 255, 0.85);

  --border-color: #e2e8f0;
  --border-focus: #4f46e5;

  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;

  --brand-primary: #4f46e5;
  --brand-hover: #4338ca;
  --brand-light: rgba(79, 70, 229, 0.08);

  --income-green: #059669;
  --income-bg: #d1fae5;
  --expense-red: #e11d48;
  --expense-bg: #ffe4e6;

  --warning-amber: #d97706;
  --warning-bg: #fef3c7;
  --info-blue: #2563eb;
  --info-bg: #dbeafe;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.08);
  --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.1);
}

.table th {
  padding: 0.75rem 1rem;
  background-color: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
}

.table td {
  padding: 0.9rem 1rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.table tbody tr {
  transition: background-color var(--transition-fast);
}

.table tbody tr:hover {
  background-color: var(--bg-surface-hover);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  line-height: 1;
}

.badge-income { background: var(--income-bg); color: var(--income-green); }
.badge-expense { background: var(--expense-bg); color: var(--expense-red); }
.badge-warning { background: var(--warning-bg); color: var(--warning-amber); }
.badge-info { background: var(--info-bg); color: var(--info-blue); }
.badge-neutral { background: var(--bg-surface); color: var(--text-secondary); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform var(--transition-fast);
}

.modal-backdrop.active .modal-content {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
}
.modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Upload Dropzone */
.dropzone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  background-color: var(--bg-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--brand-primary);
  background-color: var(--brand-light);
}

.dropzone-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  color: var(--brand-primary);
}

.dropzone-title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

.dropzone-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 60;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  font-size: 0.875rem;
  min-width: 280px;
  animation: slideIn 0.3s ease forwards;
}

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

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
}

.empty-icon {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin: 0 auto 1rem;
}

.empty-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.empty-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 360px;
  margin: 0 auto 1.25rem;
}

/* Responsive Breakpoints */
@media (max-width: 992px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .mobile-toggle {
    display: block;
  }
}
