/* Personal Finance OS — design tokens and shared components.
   Type: a serif for figures and headings (engraved-ledger authority),
   system sans for interface text. No external fonts, so it works offline. */

:root {
  --ink: #14201d;
  --ink-soft: #3d4f49;
  --slate: #5f716b;
  --slate-light: #8b9a95;
  --paper: #eef1ec;
  --paper-deep: #e4e9e3;
  --surface: #ffffff;
  --line: #d3dbd5;
  --line-strong: #b9c5be;

  --ledger: #17604a;
  --ledger-deep: #0e4433;
  --ledger-wash: #e3ede8;
  --positive: #1f7a56;
  --negative: #a8372c;
  --caution: #8f6414;
  --info: #3a5f8a;

  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 14px;

  --shadow-card: 0 1px 2px rgba(20, 32, 29, 0.06);
  --shadow-pop: 0 12px 34px rgba(20, 32, 29, 0.16);

  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.0625rem;
  --step-2: 1.375rem;
  --step-3: 1.875rem;
  --step-4: 2.5rem;
  --step-5: 3.375rem;

  --sidebar: 236px;
  --maxw: 1180px;
}

[data-theme="dark"] {
  --ink: #e8efea;
  --ink-soft: #c3d0ca;
  --slate: #9aaaa4;
  --slate-light: #75857f;
  --paper: #101815;
  --paper-deep: #0b120f;
  --surface: #17211e;
  --line: #2a3733;
  --line-strong: #3a4944;
  --ledger: #58b894;
  --ledger-deep: #7fd0b0;
  --ledger-wash: #1b2a25;
  --positive: #5cba90;
  --negative: #e58074;
  --caution: #d2a34d;
  --info: #7ba5d8;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 14px 40px rgba(0, 0, 0, 0.55);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: var(--step-0);
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 0.4em;
  color: var(--ink);
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); letter-spacing: 0; }

p { margin: 0 0 1em; max-width: 68ch; }

a { color: var(--ledger); text-decoration: none; }
a:hover { text-decoration: underline; }

small { font-size: var(--step--1); }

:focus-visible {
  outline: 2px solid var(--ledger);
  outline-offset: 2px;
  border-radius: 3px;
}

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

/* ---------- numbers ---------- */

.num {
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.num-lg { font-size: var(--step-3); }
.num-xl { font-size: var(--step-4); }
.pos { color: var(--positive); }
.neg { color: var(--negative); }
.muted { color: var(--slate); }
.dim { color: var(--slate-light); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  font: inherit;
  font-weight: 500;
  padding: 0.55em 1.05em;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--paper-deep); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--ledger);
  border-color: var(--ledger);
  color: #fff;
}
.btn-primary:hover { background: var(--ledger-deep); border-color: var(--ledger-deep); }
[data-theme="dark"] .btn-primary { color: #0b120f; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--slate); }
.btn-ghost:hover { background: var(--paper-deep); color: var(--ink); }

.btn-danger { border-color: var(--negative); color: var(--negative); background: transparent; }
.btn-danger:hover { background: var(--negative); color: #fff; }

.btn-sm { padding: 0.35em 0.7em; font-size: var(--step--1); }
.btn-lg { padding: 0.7em 1.4em; font-size: var(--step-1); }
.btn-block { width: 100%; }

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

label { display: block; font-size: var(--step--1); color: var(--slate); margin-bottom: 0.3em; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 0.55em 0.7em;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
input[type="checkbox"], input[type="radio"] { width: auto; }
textarea { min-height: 72px; resize: vertical; }

.field { margin-bottom: 0.9rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.checkbox { display: flex; align-items: center; gap: 0.5em; font-size: var(--step-0); color: var(--ink); }
.checkbox input { margin: 0; }

/* ---------- surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow-card);
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}
.card-head h3, .card-head h4 { margin: 0; }
.card-title { font-family: var(--serif); font-size: var(--step-1); }

.stack { display: grid; gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.spacer { flex: 1; }

@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}

/* ---------- ledger tables ---------- */

.ledger { width: 100%; border-collapse: collapse; font-size: var(--step-0); }
.ledger th {
  text-align: left;
  font-weight: 500;
  font-size: var(--step--1);
  color: var(--slate);
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
.ledger td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.ledger tbody tr:last-child td { border-bottom: none; }
.ledger .amount { text-align: right; font-family: var(--serif); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ledger .actions { text-align: right; white-space: nowrap; }
.ledger-scroll { overflow-x: auto; }

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--slate-light);
  flex: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-size: var(--step--1);
  padding: 0.15em 0.55em;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--slate);
  background: var(--surface);
}
.pill-pos { color: var(--positive); border-color: color-mix(in srgb, var(--positive) 40%, transparent); }
.pill-neg { color: var(--negative); border-color: color-mix(in srgb, var(--negative) 40%, transparent); }
.pill-caution { color: var(--caution); border-color: color-mix(in srgb, var(--caution) 40%, transparent); }
.pill-plan { color: var(--ledger); border-color: var(--ledger); font-weight: 500; }

/* ---------- progress ---------- */

.bar { height: 7px; border-radius: 999px; background: var(--paper-deep); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--ledger); transition: width 0.3s ease; }
.bar.over > span { background: var(--negative); }
.bar.tight > span { background: var(--caution); }

/* ---------- messages ---------- */

.note {
  border-left: 3px solid var(--line-strong);
  padding: 0.6rem 0.9rem;
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: var(--step-0);
}
.note-good { border-color: var(--positive); }
.note-warn { border-color: var(--caution); }
.note-alert { border-color: var(--negative); }
.note-info { border-color: var(--info); }
.note h4 { margin: 0 0 0.15em; font-family: var(--sans); font-size: var(--step-0); font-weight: 600; }
.note p { margin: 0; color: var(--slate); font-size: var(--step--1); }

.empty {
  text-align: center;
  padding: 2.2rem 1rem;
  color: var(--slate);
}
.empty h4 { font-family: var(--serif); font-size: var(--step-2); color: var(--ink); margin-bottom: 0.3em; }
.empty p { margin: 0 auto 1rem; max-width: 44ch; }

.form-error {
  color: var(--negative);
  font-size: var(--step--1);
  margin-bottom: 0.7rem;
  min-height: 1.2em;
}

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 32, 29, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 60;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-pop);
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.35rem;
}
.modal h3 { margin-bottom: 0.2em; }
.modal-sub { color: var(--slate); font-size: var(--step--1); margin-bottom: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.1rem; }

/* ---------- toast ---------- */

.toasts {
  position: fixed;
  bottom: 1.1rem;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 0.5rem;
  z-index: 80;
  width: min(420px, calc(100vw - 2rem));
}
.toast {
  background: var(--ink);
  color: var(--paper);
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: var(--step-0);
  box-shadow: var(--shadow-pop);
}
.toast-error { background: var(--negative); color: #fff; }
.toast-success { background: var(--ledger-deep); color: #fff; }

/* ---------- misc ---------- */

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skeleton {
  background: linear-gradient(90deg, var(--paper-deep) 25%, var(--line) 50%, var(--paper-deep) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
  height: 1em;
}
@keyframes shimmer { to { background-position: -200% 0; } }
