:root {
  /* Ledger palette: warm charcoal ink, parchment card, brass accent */
  --ink: #15181C;
  --paper: #1F242B;
  --paper-raised: #262C34;
  --rule: #383F49;
  --rule-strong: #4A5361;

  --brass: #C9A227;
  --brass-dim: #8E7220;
  --text: #ECE7DA;
  --text-dim: #A8A296;
  --text-faint: #6E695F;

  --debit: #B5533F;
  --debit-dim: #7A3A2C;
  --credit: #5C8F72;
  --credit-dim: #3E624D;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

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

.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.hidden { display: none !important; }

.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.card h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}
.card input {
  width: 100%;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 1.2rem;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--ink);
  color: var(--text);
  margin: 14px 0;
  text-align: center;
  letter-spacing: 6px;
}
.card input:focus { outline: none; border-color: var(--brass); }
.card button {
  width: 100%;
  padding: 14px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  background: var(--brass);
  color: var(--ink);
  letter-spacing: 0.02em;
}
.error { color: var(--debit); font-size: 0.85rem; }
.muted { color: var(--text-dim); font-size: 0.85rem; }

#app { display: block; min-height: 100vh; padding-bottom: 40px; }

header {
  position: sticky;
  top: 0;
  background: var(--ink);
  z-index: 10;
  padding: env(safe-area-inset-top) 12px 0 12px;
  border-bottom: 1px solid var(--rule);
}

.tabs { display: flex; overflow-x: auto; gap: 4px; padding: 14px 4px 0; }
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-faint);
  padding: 8px 12px 12px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  position: relative;
}
.tab.active { color: var(--brass); border-bottom-color: var(--brass); }
.badge {
  background: var(--debit);
  color: var(--ink);
  border-radius: 8px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  margin-left: 4px;
}

main { padding: 18px 16px; max-width: 640px; margin: 0 auto; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.month-picker { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.month-picker button {
  background: var(--paper);
  border: 1px solid var(--rule);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 1.1rem;
}
#month-label { font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; letter-spacing: 0.01em; }

.summary-grid { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.summary-row { display: flex; gap: 10px; }
.summary-card {
  flex: 1;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px;
}
.summary-card .label { color: var(--text-dim); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
.summary-card .amount { font-family: var(--font-mono); font-size: 1.15rem; font-weight: 600; margin-top: 5px; font-variant-numeric: tabular-nums; }
.summary-card.spent { border-left: 3px solid var(--debit); }
.summary-card.spent .amount { color: var(--debit); }
.summary-card.income { border-left: 3px solid var(--credit); }
.summary-card.income .amount { color: var(--credit); }

.segmented { display: flex; background: var(--paper); border-radius: 8px; padding: 4px; margin-bottom: 18px; border: 1px solid var(--rule); }
.segmented button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}
.segmented button.active { background: var(--brass); color: var(--ink); font-weight: 600; }

h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
  margin: 24px 0 12px;
  letter-spacing: 0.005em;
}

.list { display: flex; flex-direction: column; margin-top: 10px; }
.list-item {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 14px 14px;
  position: relative;
}
.list-item:not(:last-child) { border-bottom: none; }
.list-item:first-child { border-radius: 10px 10px 0 0; }
.list-item:last-child { border-radius: 0 0 10px 10px; }
.list-item:only-child { border-radius: 10px; }
.list-item:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  border-bottom: 1px dashed var(--rule-strong);
}
.list-row { display: flex; justify-content: space-between; align-items: center; }
.list-row .name { font-weight: 500; }
.list-row .amount { font-family: var(--font-mono); font-weight: 600; font-variant-numeric: tabular-nums; }
.list-row .amount.credit { color: var(--credit); }
.list-row .amount.debit { color: var(--debit); }
.sub { color: var(--text-faint); font-size: 0.76rem; margin-top: 3px; font-family: var(--font-mono); }

.category-chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.category-chip {
  border: 1px solid;
  background: transparent !important;
  padding: 5px 11px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.export-btn {
  width: 100%;
  padding: 14px;
  margin-top: 22px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--brass);
  font-weight: 600;
  font-size: 0.9rem;
}

#settings-search {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  margin: 14px 0;
}
#settings-search::placeholder { color: var(--text-faint); }
