:root {
  --dark: #1a1a2e;
  --primary: #16213e;
  --accent: #0f3460;
  --green: #27ae60;
  --red: #e74c3c;
  --white: #ffffff;
  --gray: #f5f5f5;
  --text: #333333;
  --text-light: #888888;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* Layout */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--dark);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 24px 20px 16px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--white);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo span {
  font-size: 0.85rem;
  font-weight: 400;
  display: block;
  color: rgba(255,255,255,0.5);
  letter-spacing: 1px;
  margin-top: 2px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 0.92rem;
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: var(--white);
}

.nav-item.active {
  background: rgba(255,255,255,0.12);
  color: var(--white);
  border-left-color: #4a9eff;
}

.nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.85rem;
  color: rgba(255,255,255,0.5);
}

.sidebar-footer #username-display { color: var(--white); font-weight: 600; }

/* Main content */
.main-content {
  margin-left: 240px;
  padding: 28px 32px;
  flex: 1;
  min-height: 100vh;
}

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

.page-title { font-size: 1.5rem; font-weight: 700; color: var(--dark); }

/* Card */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

/* Dashboard grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  border-left: 4px solid var(--accent);
}

.stat-card.green { border-left-color: var(--green); }
.stat-card.red { border-left-color: var(--red); }
.stat-card.blue { border-left-color: #4a9eff; }

.stat-label { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-light); margin-bottom: 8px; }
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--dark); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:hover { opacity: 0.88; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--white); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-secondary { background: var(--gray); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--green); color: var(--white); }
.btn-sm { padding: 5px 12px; font-size: 0.82rem; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 0.88rem; font-weight: 500; color: var(--text); }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.92rem;
  background: var(--white);
  color: var(--text);
  transition: border-color 0.2s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
select.form-control { cursor: pointer; }

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

/* Table */
.table-wrapper { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-light);
  border-bottom: 2px solid var(--border);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f9f9f9; }

/* Amounts */
.amount-positive { color: var(--green); font-weight: 600; }
.amount-negative { color: var(--red); font-weight: 600; }

/* Badge */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-recurring { background: #e3f2fd; color: #1565c0; }
.badge-variable { background: #f3e5f5; color: #6a1b9a; }
.badge-active { background: #e8f5e9; color: #2e7d32; }
.badge-inactive { background: #ffebee; color: #c62828; }

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #ccc;
  border-radius: 22px;
  transition: 0.3s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
input:checked + .toggle-slider { background: var(--green); }
input:checked + .toggle-slider:before { transform: translateX(20px); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  z-index: 9999;
  max-width: 320px;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--green); color: white; }
.toast-error { background: var(--red); color: white; }
.toast-info { background: var(--accent); color: white; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--dark);
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--dark) 0%, var(--accent) 100%);
}
.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.login-logo {
  text-align: center;
  margin-bottom: 8px;
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--dark);
}
.login-tagline {
  text-align: center;
  color: var(--text-light);
  margin-bottom: 28px;
  font-size: 0.9rem;
}
.error-msg { color: var(--red); font-size: 0.88rem; margin-top: 10px; text-align: center; }

/* Chart containers */
.chart-container {
  position: relative;
  height: 280px;
}
.chart-container-wide {
  position: relative;
  height: 320px;
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 20px;
}
.filter-bar .form-group { margin-bottom: 0; }

/* Import drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--gray);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: #e8eaf6;
}
.drop-zone-icon { font-size: 2.5rem; margin-bottom: 12px; }
.drop-zone-text { color: var(--text-light); margin-bottom: 8px; }

/* Import results */
.import-results {
  display: none;
  padding: 16px;
  border-radius: var(--radius);
  background: #e8f5e9;
  border-left: 4px solid var(--green);
  margin-top: 16px;
}
.import-results.error { background: #ffebee; border-left-color: var(--red); }

/* Mobile bottom nav */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--dark);
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 200;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.bottom-nav-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 12px;
  color: rgba(255,255,255,0.6);
  font-size: 0.7rem;
  cursor: pointer;
  transition: color 0.2s;
  min-width: 56px;
}
.bottom-nav-item.active { color: #4a9eff; }
.bottom-nav-icon { font-size: 1.2rem; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-nav { display: block; }
  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-bottom: 80px;
  }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }

/* Action buttons */
.actions { display: flex; gap: 6px; }
