/* =========================================================
   Budget Ledger — design tokens
   Concept: a personal "passbook" — the paper ledger a bank
   used to stamp your balance into. Ink navy + parchment paper,
   with a gold stamp accent and monospace figures, like amounts
   printed by a receipt machine.
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=IBM+Plex+Mono:wght@400;500;600&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ink: #1c2b3a;
  --ink-soft: #2c3f52;
  --paper: #fdfbf6;
  --page-bg: #e9e3d4;
  --line: #d8cfb8;
  --green: #2f6f4e;
  --green-soft: #e4efe6;
  --rust: #a83c2c;
  --rust-soft: #f5e4e0;
  --gold: #b8862f;
  --gold-soft: #f3e6c8;
  --text: #26241f;
  --muted: #756e5e;

  --font-display: "Fraunces", serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 43, 58, 0.06), 0 8px 24px rgba(28, 43, 58, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--page-bg);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(28,43,58,0.06) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  min-height: 100vh;
}

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

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
  color: var(--ink);
}

.mono { font-family: var(--font-mono); }

/* ---------- Top bar ---------- */

.topbar {
  background: var(--ink);
  color: #f2ede0;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand .stamp {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transform: rotate(-6deg);
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.topbar nav a {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.92rem;
  color: #e6e0d0;
  transition: background 0.15s ease, color 0.15s ease;
}

.topbar nav a:hover { background: rgba(255,255,255,0.08); }
.topbar nav a.active { background: var(--gold); color: var(--ink); font-weight: 600; }

.topbar .user-chip {
  font-size: 0.85rem;
  color: #cfc7b2;
  margin-right: 4px;
}

/* ---------- Layout ---------- */

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ---------- Cards (passbook stub) ---------- */

.card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  border: 1px solid var(--line);
  position: relative;
}

.card + .card { margin-top: 20px; }

/* torn/perforated edge signature detail on the ledger stub */
.stub {
  background-image: radial-gradient(circle, var(--page-bg) 6px, transparent 6.5px);
  background-position: top left;
  background-size: 18px 18px;
  background-repeat: repeat-x;
  padding-top: 22px;
  margin-top: -1px;
  border-top: 1px dashed var(--line);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
  display: block;
}

/* ---------- Auth forms ---------- */

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 30px;
  border: 1px solid var(--line);
}

.auth-card .stamp-big {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 1.3rem;
  margin: 0 auto 14px;
  transform: rotate(-6deg);
}

.auth-card h1 {
  text-align: center;
  font-size: 1.5rem;
}

.auth-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 22px;
}

.auth-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 0.88rem;
  color: var(--muted);
}

.auth-switch a { color: var(--green); font-weight: 600; }

/* ---------- Form elements ---------- */

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 18px;
  border-radius: 8px;
  border: none;
  background: var(--ink);
  color: #f5f1e6;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.btn:hover { background: var(--ink-soft); }
.btn:active { transform: scale(0.98); }

.btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold:hover { background: #a5761f; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn-outline:hover { background: var(--page-bg); }

.btn-small { width: auto; padding: 8px 14px; font-size: 0.85rem; }
.btn-danger { background: var(--rust); color: #fff; }
.btn-danger:hover { background: #8c3123; }

/* ---------- Alerts ---------- */

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 18px;
  border: 1px solid transparent;
}
.alert-error { background: var(--rust-soft); color: var(--rust); border-color: #e7c3ba; }
.alert-success { background: var(--green-soft); color: var(--green); border-color: #c3ddc9; }

/* ---------- Dashboard summary ---------- */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat .eyebrow { margin-bottom: 8px; }

.stat .value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
}

.stat.positive .value { color: var(--green); }
.stat.negative .value { color: var(--rust); }
.stat.gold .value { color: var(--gold); }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 32px 0 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.section-title h2 { font-size: 1.2rem; }

/* ---------- Budget progress rows ---------- */

.budget-row {
  padding: 16px 0;
  border-bottom: 1px dashed var(--line);
}
.budget-row:last-child { border-bottom: none; }

.budget-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.budget-row-head .category {
  font-weight: 600;
  color: var(--ink);
}

.budget-row-head .figures {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--muted);
}

.budget-row-head .figures strong { color: var(--ink); }

.bar-track {
  width: 100%;
  height: 10px;
  background: var(--page-bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.bar-fill.over { background: var(--rust); }
.bar-fill.warn { background: var(--gold); }

.row-actions {
  margin-top: 8px;
  display: flex;
  gap: 14px;
}

.row-actions a {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
.row-actions a:hover { color: var(--rust); }
.row-actions a.add-expense-link { color: var(--green); }

/* ---------- Tables (expense list) ---------- */

.table-wrap { overflow-x: auto; }

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

thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 12px;
  border-bottom: 1px dashed var(--line);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

.amount-cell { font-family: var(--font-mono); font-weight: 600; }

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.empty-state .glyph {
  font-family: var(--font-display);
  font-size: 2.2rem;
  color: var(--gold);
  margin-bottom: 8px;
}

/* ---------- Footer note ---------- */

.ledger-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 40px;
  font-family: var(--font-mono);
}

/* ---------- Responsive ---------- */

@media (max-width: 780px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .summary-grid { grid-template-columns: 1fr; }
  .topbar { padding: 14px 16px; }
  .page { padding: 22px 14px 50px; }
  .card { padding: 20px; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 8px 4px;
    background: #fff;
  }
  tbody td {
    display: flex;
    justify-content: space-between;
    border-bottom: none;
    padding: 6px 12px;
  }
  tbody td::before {
    content: attr(data-label);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--muted);
  }
}
