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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22252f;
  --border: #2a2d3a;
  --text: #e4e4e7;
  --text-muted: #9ca3af;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --orange: #f97316;
}

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

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-hover); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1.1rem;
  transition: color 0.15s;
}
.btn-icon:hover { color: var(--danger); }

/* Tab Navigation */
.tab-nav {
  display: flex;
  gap: 0;
  max-width: 1200px;
  margin: 0 auto 1.5rem;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
  max-width: 1200px;
  margin: 0 auto;
}

.tab-content.active {
  display: block;
}

/* Dashboard */
.dashboard {
  max-width: 1200px;
  margin: 0 auto;
}

.dashboard-stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-card.stat-total {
  border-color: var(--primary);
  border-width: 2px;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 800;
}

.stat-top-cat {
  font-size: 1rem;
  color: var(--orange);
}

.dashboard-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  position: relative;
}

.chart-container h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}

.chart-container canvas {
  max-height: 220px;
}

.chart-small {
  max-width: 400px;
}

.chart-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 2rem 0;
}
.chart-empty.hidden { display: none; }

/* View Container (week/month/all) */
.view-container {
  max-width: 1200px;
  margin: 0 auto;
}

/* Navigation Bar (week/month) */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.nav-label {
  font-size: 1.1rem;
  font-weight: 700;
  min-width: 220px;
  text-align: center;
}

/* Week View */
.week-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.week-total-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.week-total-value {
  font-size: 1.5rem;
  font-weight: 800;
}

.week-charts {
  margin-bottom: 1.5rem;
}

.week-days {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.day-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.day-header:hover {
  background: var(--surface-hover);
}

.day-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.day-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

.day-total {
  font-weight: 700;
  font-size: 0.9rem;
}

.day-expenses {
  display: none;
  padding: 0 1rem 0.75rem;
  border-top: 1px solid var(--border);
}

.day-expenses.open {
  display: block;
}

.day-expense-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.day-expense-item:last-child { border-bottom: none; }

.category-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
}

/* Month View */
.month-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.month-total-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.month-total-value {
  font-size: 1.5rem;
  font-weight: 800;
}

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

.month-charts {
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: center;
}

.month-charts .chart-container {
  max-width: 450px;
  width: 100%;
}

/* Category Table */
.category-table {
  margin-bottom: 1.5rem;
}

.cat-row {
  display: flex;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.4rem;
  gap: 0.75rem;
}

.cat-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.cat-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.cat-name {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 120px;
}

.cat-amount {
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 80px;
  text-align: right;
}

.cat-pct {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 45px;
  text-align: right;
}

/* Month Week Subtotals */
.month-weeks {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.week-subtotal {
  flex: 1;
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  text-align: center;
}

.week-subtotal-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.week-subtotal-value {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

/* Filter Bar (All Expenses) */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.filter-select, .filter-input {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}
.filter-select:focus, .filter-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Expenses Table */
.expenses-table-wrap {
  overflow-x: auto;
}

.expenses-table {
  width: 100%;
  border-collapse: collapse;
}

.expenses-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

.expenses-table td {
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.expenses-table tr:hover td {
  background: var(--surface-hover);
}

.expense-actions {
  display: flex;
  gap: 0.25rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 90%;
  max-width: 400px;
}

.modal-wide {
  max-width: 500px;
}

.modal-content h2 {
  margin-bottom: 1rem;
  font-size: 1.25rem;
}

.modal-content label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.modal-content input,
.modal-content select {
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
}
.modal-content input:focus,
.modal-content select:focus {
  outline: none;
  border-color: var(--primary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Category Manager */
.category-list {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.category-item:last-child { border-bottom: none; }

.category-item-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.add-category-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.add-category-form input[type="text"] {
  flex: 1;
  padding: 0.4rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
}
.add-category-form input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}

.add-category-form input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
}

.form-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state p {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
  .dashboard-charts { grid-template-columns: 1fr; }
  .dashboard-stats { flex-direction: column; }
  .tab-nav { overflow-x: auto; }
  .filter-bar { flex-direction: column; }
}

@media (max-width: 600px) {
  body { padding: 1rem; }
  header { flex-direction: column; gap: 1rem; align-items: flex-start; }
  .tab-btn { padding: 0.6rem 0.75rem; font-size: 0.8rem; }
  .nav-label { font-size: 0.9rem; min-width: auto; }
}
