/* === CSS Variables === */
:root {
  --bg-dark: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #252836;
  --bg-hover: #2a2d3a;
  --border: #333648;
  --text: #e4e4e7;
  --text-muted: #9ca3af;
  --text-heading: #f4f4f5;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --success-bg: rgba(34,197,94,0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239,68,68,0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245,158,11,0.1);
  --income: #22c55e;
  --expense: #ef4444;
  --radius: 8px;
  --shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 70px;
}

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

/* === Typography === */
h1 { font-size: 1.75rem; color: var(--text-heading); margin-bottom: 1rem; }
h2 { font-size: 1.375rem; color: var(--text-heading); margin-bottom: 0.75rem; }
h3 { font-size: 1.125rem; color: var(--text-heading); margin-bottom: 0.5rem; }

/* === Layout === */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }

/* === Top Nav === */
.top-nav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 2rem;
}
.nav-brand a { font-weight: 700; font-size: 1.125rem; color: var(--text-heading); }
.nav-links { display: flex; gap: 0.25rem; flex: 1; }
.nav-links a {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover, .nav-links a.active { background: var(--bg-hover); color: var(--text); }
.nav-actions { display: flex; gap: 0.5rem; align-items: center; }

/* Nav dropdown */
.nav-dropdown { position: relative; }
.nav-dropdown-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 0.5rem 0.75rem; border-radius: var(--radius); font-size: 0.875rem;
  font-family: inherit;
}
.nav-dropdown-btn:hover { background: var(--bg-hover); color: var(--text); }
.nav-dropdown-content {
  display: none; position: absolute; top: 100%; left: 0; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius); min-width: 150px;
  box-shadow: var(--shadow); z-index: 100; padding: 0.25rem;
}
.nav-dropdown:hover .nav-dropdown-content { display: block; }
.nav-dropdown-content a { display: block; padding: 0.5rem 0.75rem; border-radius: 4px; color: var(--text); font-size: 0.875rem; }
.nav-dropdown-content a:hover { background: var(--bg-hover); }

/* === Bottom Nav (mobile) === */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  justify-content: space-around;
  padding: 0.5rem 0;
  z-index: 100;
}
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.625rem; color: var(--text-muted); padding: 0.25rem 0.5rem;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-icon { font-size: 1.25rem; line-height: 1; }
.bottom-nav-add .bottom-nav-icon {
  background: var(--primary); color: white; width: 40px; height: 40px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; margin-top: -12px;
}

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem; border-radius: var(--radius); font-size: 0.875rem;
  font-weight: 500; border: none; cursor: pointer; transition: background 0.15s;
  font-family: inherit; text-decoration: none; line-height: 1.25;
}
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); color: white; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; color: white; }
.btn-success { background: var(--success); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg-hover); }
.btn-full { width: 100%; }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.375rem; font-size: 0.875rem; color: var(--text-muted); font-weight: 500; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="email"], input[type="file"], select, textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9375rem;
  font-family: inherit;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { min-height: 80px; resize: vertical; }
select { cursor: pointer; }

/* === Cards === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { text-align: center; }
.stat-value { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.25rem; }
.stat-label { font-size: 0.8125rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-income { color: var(--income); }
.stat-expense { color: var(--expense); }

/* === Tables === */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; padding: 0.75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.5px; border-bottom: 2px solid var(--border); }
td { padding: 0.75rem; border-bottom: 1px solid var(--border); }
tr:hover { background: var(--bg-hover); }
.amount-positive { color: var(--income); font-weight: 600; }
.amount-negative { color: var(--expense); font-weight: 600; }

/* === Alerts === */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.875rem; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }

/* === Modal === */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  z-index: 200; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border-radius: 12px; padding: 1.5rem;
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; padding: 0.25rem; }

/* === Filters === */
.filters {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.filters-toggle { display: none; }
.filter-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: end; }
.filter-row .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }

/* === Pagination === */
.pagination { display: flex; gap: 0.25rem; justify-content: center; margin-top: 1rem; }
.pagination a, .pagination span {
  padding: 0.5rem 0.75rem; border-radius: var(--radius); font-size: 0.875rem;
  border: 1px solid var(--border); color: var(--text);
}
.pagination a:hover { background: var(--bg-hover); }
.pagination .active { background: var(--primary); border-color: var(--primary); color: white; }

/* === Tags / Badges === */
.badge {
  display: inline-flex; padding: 0.125rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 500;
}
.badge-income { background: var(--success-bg); color: var(--income); }
.badge-expense { background: var(--danger-bg); color: var(--expense); }
.badge-tax { background: var(--warning-bg); color: var(--warning); }

/* === Toggle === */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--bg-input); border-radius: 24px;
  cursor: pointer; transition: background 0.2s; border: 1px solid var(--border);
}
.toggle-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px; left: 2px; bottom: 2px;
  background: white; border-radius: 50%; transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--primary); border-color: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* === Attachment indicator === */
.attachment-icon { color: var(--text-muted); font-size: 0.875rem; cursor: pointer; }
.attachment-icon:hover { color: var(--primary); }

/* === Responsive === */
@media (max-width: 768px) {
  .top-nav { display: none; }
  .bottom-nav { display: flex; }
  body { padding-top: 0; padding-bottom: 80px; }
  .container { padding: 1rem 0.75rem; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .filter-row { flex-direction: column; }
  .filters { display: none; }
  .filters.open { display: block; }
  .filters-toggle { display: inline-flex; margin-bottom: 0.75rem; }

  /* Card-based transaction list on mobile */
  .mobile-cards .table-wrap { display: none; }
  .mobile-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem; margin-bottom: 0.5rem;
  }
  .mobile-card-header { display: flex; justify-content: space-between; margin-bottom: 0.5rem; }
  .mobile-card-desc { font-weight: 500; }
  .mobile-card-date { font-size: 0.8125rem; color: var(--text-muted); }
  .mobile-card-details { display: flex; justify-content: space-between; align-items: center; font-size: 0.8125rem; color: var(--text-muted); }
}

@media (min-width: 769px) {
  .mobile-card { display: none; }
}

/* === Quick Entry === */
.quick-entry { max-width: 480px; margin: 0 auto; }
.quick-entry .form-group input,
.quick-entry .form-group select {
  padding: 0.875rem 1rem;
  font-size: 1.125rem;
}
.quick-entry .amount-input { font-size: 2rem; text-align: center; font-weight: 700; }
.quick-entry .btn { padding: 1rem; font-size: 1.125rem; }
.camera-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.75rem; border: 2px dashed var(--border); border-radius: var(--radius);
  color: var(--text-muted); cursor: pointer; width: 100%; background: none;
  font-family: inherit; font-size: 0.9375rem; transition: border-color 0.15s;
}
.camera-btn:hover { border-color: var(--primary); color: var(--primary); }
.receipt-preview { max-width: 100%; max-height: 200px; border-radius: var(--radius); margin-top: 0.5rem; }
