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

:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --green-light: #dcfce7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --yellow: #d97706;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-900: #111827;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.6;
}

/* ── Navbar ─────────────────────────────────────────────────────────────── */

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--green);
}

.nav-links { display: flex; gap: 1rem; align-items: center; }
.user-email { font-size: 0.9rem; color: var(--gray-600); }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.container { max-width: 960px; margin: 0 auto; padding: 2rem 1.5rem; }

.section { margin-bottom: 2.5rem; }
.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--gray-900);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-900); }
.btn-secondary:hover { background: #d1d5db; }
.btn-large { font-size: 1.05rem; padding: 0.75rem 1.75rem; margin-bottom: 1rem; }

/* ── Landing page ────────────────────────────────────────────────────────── */

.hero { text-align: center; }
.hero h1 { font-size: 2.2rem; font-weight: 800; margin-bottom: 1rem; }
.subtitle { font-size: 1.1rem; color: var(--gray-600); max-width: 600px; margin: 0 auto 2rem; }
.features {
  list-style: none;
  display: inline-flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
  margin-bottom: 2rem;
}
.features li::before { content: "✓ "; color: var(--green); font-weight: 700; }
.pricing { font-size: 0.9rem; color: var(--gray-600); margin-top: 0.5rem; }

/* ── Cards row ───────────────────────────────────────────────────────────── */

.cards-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 540px) {
  .cards-row { grid-template-columns: 1fr; }
}

.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

/* ── Budget cards ────────────────────────────────────────────────────────── */

.budget-card { display: flex; flex-direction: column; gap: 0.4rem; padding: 1rem 1.25rem; }
.budget-label { font-weight: 700; font-size: 0.95rem; margin-bottom: 0.2rem; }

.budget-period-row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.85rem;
}
.budget-period-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: 3.5rem;
  flex-shrink: 0;
}
.budget-inline { color: var(--gray-900); flex: 1; }
.budget-pct-inline { font-size: 0.78rem; color: var(--gray-400); white-space: nowrap; }

.progress-track {
  height: 6px;
  background: var(--gray-100);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transition: width 0.4s ease;
}
.progress-fill.warn { background: var(--yellow); }
.progress-fill.over { background: var(--red); }

.week-label {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--gray-400);
}

/* ── Transaction table ───────────────────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
}

.tx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.tx-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  font-weight: 600;
  color: var(--gray-600);
  white-space: nowrap;
}

.tx-table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.tx-table tr:last-child td { border-bottom: none; }
.tx-table tr:hover td { background: var(--gray-50); }

.loading-cell {
  text-align: center;
  color: var(--gray-400);
  padding: 2rem !important;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-out      { background: var(--red-light);   color: var(--red); }
.badge-in       { background: var(--green-light); color: var(--green-dark); }
.badge-fixed    { background: #e0e7ff; color: #3730a3; }
.badge-variable { background: #f0fdf4; color: #166534; }

/* ── Overview grid (budget left + categories right) ─────────────────────── */

.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

.overview-left  { display: flex; flex-direction: column; }
.overview-right { display: flex; flex-direction: column; }

@media (max-width: 640px) {
  .overview-grid { grid-template-columns: 1fr; }
}

/* ── Monthly summary table ───────────────────────────────────────────────── */

.tx-table-compact th,
.tx-table-compact td {
  padding: 0.5rem 0.85rem;
  font-size: 0.87rem;
}

.monthly-total-row td {
  background: var(--gray-50);
  border-top: 2px solid var(--gray-200);
}

/* ── Pagination ──────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.pagination button {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
}
.pagination button:hover { background: var(--gray-100); }
.pagination button.active {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* ── Settings form ───────────────────────────────────────────────────────── */

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.75rem;
}

.settings-group-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.field-label {
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 0.5rem;
}

.field-input {
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 0.95rem;
  width: 100%;
  background: #fff;
  transition: border-color 0.15s;
}
.field-input:focus {
  outline: none;
  border-color: var(--green);
}

.field-hint {
  font-size: 0.82rem;
  color: var(--gray-600);
  line-height: 1.5;
  margin-top: 0.25rem;
}

/* ── Inline edit selects (transaction table) ─────────────────────────────── */

.tx-table td select {
  padding: 0.15rem 0.35rem;
  font-size: 0.82rem;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  color: var(--gray-900);
}
.tx-table td select:focus {
  outline: none;
  border-color: var(--green);
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */

.alert-success {
  background: var(--green-light);
  color: var(--green-dark);
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--red-light);
  color: var(--red);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
