/* ==========================================================================
   Ledger — design tokens
   A personal expense tracker styled like a bank passbook: ruled ledger
   lines, a brass stamp accent, and monospaced figures that line up like
   real account entries.
   ========================================================================== */

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

:root {
  /* Palette */
  --ink: #10231F;          /* cover / app shell background */
  --ink-soft: #16302A;     /* raised panels on the ink shell */
  --paper: #FBF7EC;        /* ledger page */
  --paper-line: #D8CBAE;   /* ruled line on the ledger */
  --paper-dim: #EFE8D6;    /* subtle stripe / hover */
  --brass: #C9A227;        /* stamp / accent / focus */
  --income: #1C6E4A;       /* currency green */
  --expense: #B23A2E;      /* rust red */
  --text-on-ink: #F4EFDF;
  --text-muted-on-ink: #9FB3AC;
  --text-on-paper: #21201C;
  --text-muted-on-paper: #6B6355;

  --font-display: 'Zilla Slab', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  --radius: 10px;
  --shadow-lift: 0 8px 24px rgba(16, 35, 31, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text-on-paper);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

a { color: inherit; }

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background: var(--ink);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* -------------------- Header -------------------- */
.app-header {
  padding: 28px 20px 16px;
  color: var(--text-on-ink);
}

.app-header .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0 0 4px;
}

.app-header h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  margin: 0;
}

/* -------------------- Ledger page (paper panel) -------------------- */
.ledger-page {
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  flex: 1;
  padding: 24px 20px 100px;
  box-shadow: var(--shadow-lift);
}

/* -------------------- Balance stamp card -------------------- */
.stamp-card {
  background: var(--ink-soft);
  color: var(--text-on-ink);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(201, 162, 39, 0.25);
}

.stamp-card::after {
  content: '';
  position: absolute;
  right: -30px;
  top: -30px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px dashed rgba(201, 162, 39, 0.35);
}

.stamp-card .label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted-on-ink);
  margin: 0 0 6px;
}

.stamp-card .balance {
  font-family: var(--font-mono);
  font-size: 34px;
  font-weight: 600;
  margin: 0 0 18px;
  letter-spacing: -0.01em;
}

.stamp-card .split {
  display: flex;
  gap: 12px;
}

.stamp-card .split div { flex: 1; }

.stamp-card .split .k {
  font-size: 11px;
  color: var(--text-muted-on-ink);
  margin: 0 0 2px;
}

.stamp-card .split .v {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
}

.stamp-card .split .income .v { color: #8FD3AE; }
.stamp-card .split .expense .v { color: #E39A8F; }

/* -------------------- Section headings -------------------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 0 8px;
}

.section-head h2 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted-on-paper);
  margin: 0;
}

.section-head a {
  font-size: 13px;
  font-weight: 500;
  color: var(--income);
  text-decoration: none;
}

/* -------------------- Ledger rows (ruled lines) -------------------- */
.ledger-rows {
  border-top: 1px solid var(--paper-line);
}

.ledger-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--paper-line);
  background: transparent;
}

.ledger-row .icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--paper-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.ledger-row .meta { flex: 1; min-width: 0; }

.ledger-row .title {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text-on-paper);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ledger-row .sub {
  font-size: 12px;
  color: var(--text-muted-on-paper);
  margin-top: 1px;
}

.ledger-row .amount {
  font-family: var(--font-mono);
  font-size: 14.5px;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.ledger-row .amount.income { color: var(--income); }
.ledger-row .amount.expense { color: var(--expense); }

.ledger-row .running {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted-on-paper);
  text-align: right;
  margin-top: 2px;
}

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

.empty-state .glyph { font-size: 30px; margin-bottom: 8px; }
.empty-state p { margin: 0; font-size: 13.5px; }

/* -------------------- Bottom nav -------------------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  width: 100%;
  max-width: 480px;
  background: var(--paper);
  border-top: 1px solid var(--paper-line);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
  z-index: 20;
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-muted-on-paper);
  font-size: 10px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 8px;
}

.bottom-nav a.active { color: var(--income); }

.bottom-nav .fab {
  background: var(--income);
  color: #fff;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-top: -26px;
  box-shadow: 0 6px 14px rgba(28, 110, 74, 0.4);
}

.bottom-nav svg { width: 20px; height: 20px; }

/* -------------------- Forms -------------------- */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted-on-paper);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--paper-line);
  background: #fff;
  color: var(--text-on-paper);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--brass);
  outline-offset: 1px;
  border-color: var(--brass);
}

.field textarea { resize: vertical; min-height: 70px; }

.type-toggle {
  display: flex;
  gap: 8px;
}

.type-toggle button {
  flex: 1;
  padding: 11px;
  border-radius: 8px;
  border: 1px solid var(--paper-line);
  background: #fff;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted-on-paper);
  cursor: pointer;
}

.type-toggle button.selected.expense {
  background: var(--expense);
  border-color: var(--expense);
  color: #fff;
}

.type-toggle button.selected.income {
  background: var(--income);
  border-color: var(--income);
  color: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px;
  border-radius: 8px;
  border: none;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}

.btn-primary { background: var(--income); color: #fff; }
.btn-danger { background: var(--expense); color: #fff; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--paper-line);
  color: var(--text-on-paper);
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* -------------------- Category chips -------------------- */
.chip-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 12px 4px;
  border-radius: 8px;
  border: 1.5px solid var(--paper-line);
  background: #fff;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-on-paper);
  cursor: pointer;
}

.chip.selected {
  border-color: var(--brass);
  background: #FBF3D9;
}

.chip .glyph { font-size: 19px; }

/* -------------------- Toast -------------------- */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--text-on-ink);
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* -------------------- Modal sheet -------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 35, 31, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
  transform: translateY(24px);
  transition: transform 0.22s ease;
}

.sheet-backdrop.open .sheet { transform: translateY(0); }

.sheet-grip {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--paper-line);
  margin: 0 auto 16px;
}

.sheet h2 {
  font-family: var(--font-display);
  font-size: 19px;
  margin: 0 0 18px;
}

/* -------------------- Filters row -------------------- */
.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 4px;
}

.filter-row::-webkit-scrollbar { display: none; }

.filter-pill {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--paper-line);
  background: #fff;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted-on-paper);
  cursor: pointer;
  white-space: nowrap;
}

.filter-pill.selected {
  background: var(--ink);
  color: var(--text-on-ink);
  border-color: var(--ink);
}

/* -------------------- Auth pages -------------------- */
.auth-wrap {
  width: 100%;
  max-width: 400px;
  padding: 60px 24px;
  color: var(--text-on-ink);
}

.auth-wrap .mark {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  margin-bottom: 10px;
}

.auth-wrap h1 {
  font-family: var(--font-display);
  font-size: 30px;
  margin: 0 0 6px;
}

.auth-wrap p.sub {
  color: var(--text-muted-on-ink);
  font-size: 14px;
  margin: 0 0 28px;
}

.auth-card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 22px;
}

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

.auth-switch button {
  background: none;
  border: none;
  color: var(--brass);
  font-weight: 600;
  cursor: pointer;
  font-size: 13.5px;
  padding: 0;
}

.form-error {
  background: #FBE4E1;
  color: var(--expense);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}

.form-error.show { display: block; }

/* -------------------- Utility -------------------- */
.hidden { display: none !important; }

::selection { background: var(--brass); color: #10231F; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
