@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Cormorant:ital,wght@0,500;0,600;0,700;1,500;1,600;1,700&display=swap');

:root {
  /* "Almanac" — bottle green & gold ink on parchment, not cream-and-terracotta. */
  --bg: #EFE7D8;
  --surface: #FFFFFF;
  --surface-2: #E7DEC9;
  --ink: #1F3A34;
  --text: #2A2A20;
  --text-muted: #706B54;
  --border: #DED2B4;
  --brand: #2B4A3E;
  --brand-ink: #1F3A34;
  --brand-light: #E3E7DD;
  --accent: #A88A4A;
  --accent-light: #F1E6C9;
  --danger: #B14834;
  --danger-light: #F7E4DD;
  --gold: #A88A4A;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(31,58,52,.08);
  --shadow-md: 0 8px 24px rgba(31,58,52,.10);
  --shadow-lg: 0 20px 48px rgba(31,58,52,.16);
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, Segoe UI, sans-serif;
  --font-display: 'Cormorant', Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12201C;
    --surface: #182A24;
    --surface-2: #1E332A;
    --ink: #EDE7D5;
    --text: #E0D8C0;
    --text-muted: #9CA192;
    --border: #2A3A30;
    --brand: #4A7862;
    --brand-ink: #8FBBA3;
    --brand-light: #24402F;
    --accent: #C9A96B;
    --accent-light: #2E2818;
    --danger: #E0846F;
    --danger-light: #33201A;
    --gold: #C9A96B;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 8px 24px rgba(0,0,0,.35);
    --shadow-lg: 0 20px 48px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12201C;
  --surface: #182A24;
  --surface-2: #1E332A;
  --ink: #EDE7D5;
  --text: #E0D8C0;
  --text-muted: #9CA192;
  --border: #2A3A30;
  --brand: #4A7862;
  --brand-ink: #8FBBA3;
  --brand-light: #24402F;
  --accent: #C9A96B;
  --accent-light: #2E2818;
  --danger: #E0846F;
  --danger-light: #33201A;
  --gold: #C9A96B;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* The hidden attribute must always win over a component's own `display`
   rule (e.g. .modal-overlay{display:flex}) — same specificity, so without
   !important the later class rule would silently keep "hidden" elements shown. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 500; color: var(--ink); margin: 0 0 .4em; line-height: 1.15; }
p { margin: 0 0 1em; color: var(--text); }
.muted { color: var(--text-muted); }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

.container { max-width: 1180px; margin: 0 auto; padding-inline: 24px; }
.container-narrow { max-width: 760px; margin: 0 auto; padding-inline: 24px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-ink); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(.95); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- Nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-inner { display: flex; align-items: center; gap: 24px; padding-block: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-style: italic; font-weight: 600; font-size: 23px; color: var(--ink); letter-spacing: -.005em; }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.nav-links { display: flex; align-items: center; gap: 4px; margin-left: 8px; overflow-x: auto; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a { padding: 8px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; flex-shrink: 0; }
@media (max-width: 900px) { .nav-links a span { display: none; } .nav-links a { padding: 8px 10px; } }
.nav-links a:hover { color: var(--text); background: var(--surface-2); }
.nav-links a.active { color: var(--brand-ink); background: var(--brand-light); }
.nav-spacer { flex: 1; }
.nav-right { display: flex; align-items: center; gap: 10px; }
.badge-dot { display: inline-flex; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; align-items: center; justify-content: center; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.icon { display: block; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card-hover { transition: transform .15s ease, box-shadow .15s ease; }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.section-title h2 { margin: 0; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--text); }
.field .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], textarea, select {
  width: 100%; padding: 10px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); outline: none; transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- Toast / alerts ---------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; }
.alert-error { background: var(--danger-light); color: var(--danger); }
.alert-info { background: var(--brand-light); color: var(--brand-ink); }
.alert-warn { background: var(--accent-light); color: var(--accent); }

#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; animation: toast-in .18s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: none; } }

/* ---------- Chips / tags ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text-muted); }
.chip-brand { background: var(--brand-light); color: var(--brand-ink); }
.chip-accent { background: var(--accent-light); color: var(--accent); }
.pill-tabs { display: inline-flex; background: var(--surface-2); padding: 4px; border-radius: 999px; gap: 2px; }
.pill-tabs button { border: none; background: transparent; padding: 7px 15px; border-radius: 999px; font-weight: 600; font-size: 13px; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; gap: 6px; }
.pill-tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty .icon { margin: 0 auto 12px; color: var(--text-muted); opacity: .6; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,21,18,.5); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 80; padding: 20px; }
.modal { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; padding: 26px; }
.modal-wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { margin: 0; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 64px; padding-block: 36px; color: var(--text-muted); font-size: 13px; }
.site-footer .container { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.site-footer a:hover { color: var(--text); }

/* ---------- Table ---------- */
table.plain { width: 100%; border-collapse: collapse; }
table.plain th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.plain td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.plain tr:last-child td { border-bottom: none; }

/* ---------- Utility ---------- */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2,1fr); } .grid-3 { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.mt-8{margin-top:8px}.mt-16{margin-top:16px}.mt-24{margin-top:24px}.mt-32{margin-top:32px}
.mb-0{margin-bottom:0}

/* ---------- Charts (shared by budget/mortgage/salary) ---------- */
.chart-box { position: relative; height: 220px; }
.chart-box.short { height: 180px; }
.chart-box.tall { height: 240px; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-row .label { flex: 1; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .amt { font-weight: 600; }

/* ---------- Loading skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Page shell (logged-in area) ---------- */
.page-head { padding-block: 28px 8px; }
.page-head .eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.page-head h1 { font-size: 30px; margin-bottom: 4px; }

@media print {
  .nav, .site-footer, .no-print { display: none !important; }
  body { background: #fff; }
  .container { max-width: none; padding: 0; }
}
