/* Jo Budget: visual language from DESIGN.md (colors, radii, shadows, type). */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/inter/inter-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
    U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/inter/inter-latin-ext-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Greens, each with its role */
  --green-brand: #006241;    /* headings, wordmark, active nav */
  --green-accent: #00754A;   /* primary buttons, Frap, income */
  --green-house: #1E3932;    /* feature band, toast */
  --green-uplift: #2b5148;   /* decorative accents on the band */
  --green-light: #d4e9e2;    /* light tints */

  --red: #c82014;            /* expenses, destructive actions */
  --red-tint: hsl(4 82% 43% / 5%);
  --red-tint-strong: hsl(4 82% 43% / 12%);
  --yellow: #fbbc05;        /* warning (DESIGN.md semantic yellow) */
  --yellow-tint: hsl(45 97% 50% / 22%);
  --yellow-text: #6b4e00;   /* readable dark amber text on the yellow tint */

  --canvas: #f2f0eb;         /* neutral warm page canvas */
  --ceramic: #edebe9;
  --white: #ffffff;
  --neutral-cool: #f9f9f9;
  --input-border: #d6dbde;
  --hairline: #e7e7e7;

  --text: rgba(0, 0, 0, 0.87);
  --text-soft: rgba(0, 0, 0, 0.58);
  --text-white-soft: rgba(255, 255, 255, 0.70);

  --font: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --tracking: -0.01em;

  --space-1: 4px; --space-2: 8px; --space-3: 16px; --space-4: 24px;
  --space-5: 32px; --space-6: 40px; --space-7: 48px; --space-8: 56px;
  --gutter: 16px;

  --radius-card: 12px;
  --radius-pill: 50px;
  --shadow-card: 0 0 0.5px 0 rgba(0, 0, 0, 0.14), 0 1px 1px 0 rgba(0, 0, 0, 0.24);
  --shadow-nav: 0 1px 3px rgba(0, 0, 0, 0.1), 0 2px 2px rgba(0, 0, 0, 0.06), 0 0 2px rgba(0, 0, 0, 0.07);
  --shadow-frap: 0 0 6px rgba(0, 0, 0, 0.24), 0 8px 12px rgba(0, 0, 0, 0.14);
  --nav-height: 64px;
}

@media (min-width: 768px) {
  :root { --gutter: 24px; --nav-height: 72px; }
}
@media (min-width: 1024px) {
  :root { --gutter: 40px; }
}

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

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

body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: var(--tracking);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; letter-spacing: var(--tracking); }
/* Hierarchy by weight and color, not size (DESIGN.md) */
h1 { font-size: 24px; line-height: 36px; font-weight: 600; color: var(--green-brand); }
h2 { font-size: 24px; line-height: 36px; font-weight: 400; color: var(--text); }
h3 { font-size: 16px; line-height: 1.5; font-weight: 600; color: var(--text); }

p { margin: 0; }
a { color: var(--green-accent); }

.muted { color: var(--text-soft); }
.small { font-size: 14px; }
.micro { font-size: 13px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Buttons: 50px pills, scale(0.95) on press ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: 7px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: var(--tracking);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.95); }
.btn:focus-visible, .frap:focus-visible, .tabs a:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--green-accent);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }

.btn-primary { background: var(--green-accent); border-color: var(--green-accent); color: var(--white); }
.btn-primary:hover { background: var(--green-brand); border-color: var(--green-brand); }
.btn-outline { border-color: var(--green-accent); color: var(--green-accent); }
.btn-outline:hover { background: rgba(0, 117, 74, 0.06); }
.btn-dark-outline { border-color: var(--text); color: var(--text); }
.btn-dark-outline:hover { background: rgba(0, 0, 0, 0.06); }
.btn-danger { background: var(--red); border-color: var(--red); color: var(--white); }
.btn-danger-outline { border-color: var(--red); color: var(--red); }
.btn-danger-outline:hover { background: var(--red-tint); }
.btn-on-dark { border-color: var(--white); color: var(--white); }
.btn-on-dark:hover { background: rgba(255, 255, 255, 0.10); }
.btn-small { font-size: 14px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 40px; height: 40px; padding: 0;
  border-radius: 50%;
  border: 1px solid var(--input-border);
  background: var(--white);
  color: var(--text);
}
.icon-btn svg { width: 20px; height: 20px; }

/* Bigger touch targets on phones */
@media (max-width: 767px) {
  .btn { min-height: 44px; }
}

/* ---------- Frap: floating circular add button ---------- */

.frap {
  position: fixed;
  right: max(var(--gutter), env(safe-area-inset-right));
  bottom: max(var(--space-4), env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--green-accent);
  color: var(--white);
  box-shadow: var(--shadow-frap);
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.frap::before { content: ""; position: absolute; inset: -8px; border-radius: 50%; } /* touch offset */
.frap:hover { background: var(--green-brand); }
.frap:active { transform: scale(0.95); box-shadow: 0 0 6px rgba(0, 0, 0, 0.24), 0 8px 12px rgba(0, 0, 0, 0); }

/* ---------- Top bar & tabs ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--white);
  box-shadow: var(--shadow-nav);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  max-width: 1120px;
  height: var(--nav-height);
  margin: 0 auto;
  padding: 0 var(--gutter);
}
.wordmark {
  font-size: 20px;
  font-weight: 700;
  color: var(--green-brand);
  text-decoration: none;
  white-space: nowrap;
}
.tabs { display: flex; gap: var(--space-1); flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; white-space: nowrap; }
.tabs a {
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  color: var(--text);
  font-size: 16px;
  font-weight: 400;
  text-decoration: none;
  transition: all 0.2s ease;
}
.tabs a:hover { background: var(--ceramic); }
.tabs a[aria-current="page"] { color: var(--green-brand); font-weight: 600; background: var(--green-light); }

@media (max-width: 767px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding-top: 12px; padding-bottom: 8px; row-gap: 8px; }
  .topbar-inner .wordmark { flex: 1; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs a { flex: none; text-align: center; padding: 8px 10px; font-size: 14px; letter-spacing: -0.02em; }
}

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

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: var(--space-4) var(--gutter) calc(var(--space-8) + var(--space-7));
}
.stack > * + * { margin-top: var(--space-4); }
.grid-2 { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.card {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
}
@media (max-width: 479px) { .card { padding: var(--space-3); } }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }

.head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }

/* ---------- Month switcher ---------- */

.month-switcher { display: inline-flex; align-items: center; gap: var(--space-2); }
.month-switcher .month-name { min-width: 150px; text-align: center; font-weight: 600; font-size: 18px; }

/* ---------- Feature band: monthly balance (House Green) ---------- */

.band {
  background: var(--green-house);
  color: var(--white);
  border-radius: var(--radius-card);
  padding: var(--space-5) var(--space-4);
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}
@media (min-width: 768px) {
  .band { grid-template-columns: 1.2fr 1fr; align-items: center; padding: var(--space-6); }
}
.band-label { color: var(--text-white-soft); font-size: 14px; }
.band-balance { font-size: 40px; line-height: 1.2; font-weight: 600; word-break: break-word; }
@media (min-width: 768px) { .band-balance { font-size: 45px; } }
.band-stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.band-stat {
  border-left: 3px solid var(--green-uplift);
  padding-left: var(--space-3);
}
.band-stat .value { font-size: 19px; font-weight: 600; word-break: break-word; }
@media (max-width: 479px) { .band-stat .value { font-size: 16px; } }

/* ---------- Amounts: sign + color (never color alone) ---------- */

.amount { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.amount.expense { color: var(--red); }
.amount.income { color: var(--green-accent); }

/* ---------- Category breakdown ---------- */

.breakdown { list-style: none; margin: 0; padding: 0; }
.breakdown li + li { margin-top: var(--space-3); }
.breakdown .row { display: flex; justify-content: space-between; gap: var(--space-3); font-size: 15px; }
.breakdown .name { font-weight: 600; }
.bar { height: 8px; margin-top: 6px; border-radius: var(--radius-pill); background: var(--ceramic); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: var(--radius-pill); }
.bar.expense > span { background: var(--red); }
.bar.income > span { background: var(--green-accent); }

.chart-box { position: relative; height: 260px; }

.empty { color: var(--text-soft); font-size: 15px; padding: var(--space-2) 0; }

/* ---------- Filters ---------- */

.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--ceramic);
}
.seg button {
  min-height: 34px;
  padding: 6px 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: var(--tracking);
  cursor: pointer;
  transition: all 0.2s ease;
}
.seg button:active { transform: scale(0.95); }
.seg button[aria-pressed="true"] { background: var(--white); color: var(--green-brand); box-shadow: var(--shadow-card); }
.seg.block { display: flex; }
.seg.block button { flex: 1; }

/* ---------- Forms ---------- */

.field { display: block; }
.field + .field { margin-top: var(--space-3); }
.field-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 700; color: var(--text); }
.field-hint { display: block; margin-top: 4px; font-size: 13px; color: var(--text-soft); }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  background: var(--white);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iOS from zooming in */
  letter-spacing: var(--tracking);
  transition: border-color 0.2s ease, background 0.2s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green-accent); box-shadow: 0 0 0 1px var(--green-accent); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--red); background: var(--red-tint); }
.filters select { width: auto; min-width: 180px; }
.inline-form { display: flex; gap: var(--space-2); }
.inline-form input { flex: 1; min-width: 0; }

.form-error {
  margin-top: var(--space-3);
  padding: 10px 12px;
  border-radius: 4px;
  background: var(--red-tint);
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
}

/* ---------- Transactions list ---------- */

.tx-day { margin: var(--space-4) 0 var(--space-2); font-size: 13px; font-weight: 700; color: var(--text-soft); letter-spacing: 0.1em; text-transform: uppercase; }
.tx-day:first-child { margin-top: 0; }
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px var(--space-3);
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--hairline);
}
.tx:last-child { border-bottom: 0; }
.tx-main { min-width: 0; }
.tx-cat { font-weight: 600; }
.tx-meta { color: var(--text-soft); font-size: 14px; overflow-wrap: anywhere; }
.tx-actions { display: flex; gap: var(--space-2); grid-column: 1 / -1; justify-content: flex-end; }
@media (min-width: 768px) {
  .tx { grid-template-columns: 1fr auto auto; }
  .tx-actions { grid-column: auto; }
}

.totals-line { margin-top: var(--space-3); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); font-size: 15px; }

/* ---------- Budgets ---------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
@media (max-width: 599px) { .stats { grid-template-columns: 1fr; } }
.stat-label { color: var(--text-soft); font-size: 14px; }
.stat-value { font-size: 20px; font-weight: 600; word-break: break-word; }
.stat-value.over { color: var(--red); }

.budget-list { list-style: none; margin: 0; padding: 0; }
.budget { padding: var(--space-3) 0; border-bottom: 1px solid var(--hairline); }
.budget:first-child { padding-top: 0; }
.budget:last-child { border-bottom: 0; padding-bottom: 0; }
.budget-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px var(--space-3); }
.budget-name { font-weight: 600; overflow-wrap: anywhere; }
.budget-amounts { font-variant-numeric: tabular-nums; }
.budget-meta, .budget-foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-2) var(--space-3); margin-top: var(--space-2); font-size: 14px;
}
.budget-actions { display: inline-flex; gap: var(--space-2); }
.budget-none { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.budget-from { font-weight: 600; color: var(--green-accent); margin-bottom: var(--space-2); }
.button-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }

/* Progress bar: color plus the status text next to it (never color alone) */
.meter { height: 10px; margin-top: var(--space-2); border-radius: var(--radius-pill); background: var(--ceramic); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: var(--radius-pill); }
.meter.on_track > span { background: var(--green-accent); }
.meter.close > span { background: var(--yellow); }
.meter.over > span { background: var(--red); }

.chip { display: inline-block; padding: 2px 10px; border-radius: var(--radius-pill); font-weight: 600; }
.chip.on_track { background: var(--green-light); color: var(--green-brand); }
.chip.close { background: var(--yellow-tint); color: var(--yellow-text); }
.chip.over { background: var(--red-tint-strong); color: var(--red); }

/* ---------- Loans ---------- */

.stats-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 899px) { .stats-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 479px) { .stats-4 { grid-template-columns: 1fr; } }
.loans-note { margin-top: var(--space-3); }
.loan .card-head { align-items: flex-start; margin-bottom: var(--space-2); }
.loan-name { font-weight: 600; overflow-wrap: anywhere; }
.loan-progress { margin-top: var(--space-2); font-weight: 600; }
.chip.done { background: var(--ceramic); color: var(--text); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--space-3); margin: var(--space-3) 0 0; font-size: 15px; }
.facts dt { color: var(--text-soft); }
.facts dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.loan-preview { margin-top: var(--space-3); padding: 10px 12px; border-radius: 4px; background: var(--green-light);
  color: var(--green-brand); font-weight: 600; font-size: 15px; }
.loan-preview.invalid { background: var(--red-tint); color: var(--red); }
.debt { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-5); }

.schedule { max-height: min(60vh, 480px); overflow: auto; border: 1px solid var(--hairline); border-radius: 4px; }
.schedule:focus-visible { outline: 2px solid var(--green-accent); outline-offset: 2px; }
.schedule-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.schedule-table th { position: sticky; top: 0; background: var(--ceramic); text-align: left; padding: 8px 10px; }
.schedule-table td { padding: 8px 10px; border-top: 1px solid var(--hairline); }
.schedule-table .nowrap { white-space: nowrap; }
.schedule-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.schedule-table .pay-recorded td, .schedule-table .pay-counted td { color: var(--green-brand); font-weight: 600; }
.schedule-table .pay-not_needed td { color: var(--text-soft); }


/* ---------- Savings ---------- */

.stat-value.big { font-size: 28px; }
.savings-split { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
@media (max-width: 599px) { .savings-split { grid-template-columns: 1fr; } }
.savings-split .this-month { border-left: 3px solid var(--ceramic); padding-left: var(--space-4); }
@media (max-width: 599px) {
  .savings-split .this-month { border-left: 0; padding-left: 0; border-top: 1px solid var(--hairline); padding-top: var(--space-3); }
}
.setup-card { max-width: 560px; }
.table-scroll { overflow-x: auto; }
.table-scroll:focus-visible { outline: 2px solid var(--green-accent); outline-offset: 2px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; padding: 8px 10px; background: var(--ceramic); white-space: nowrap; }
.data-table td { padding: 8px 10px; border-top: 1px solid var(--hairline); }
.data-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.data-table .nowrap { white-space: nowrap; }

/* ---------- Categories ---------- */

.cat-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; }
.cat {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}
.cat:last-child { border-bottom: 0; }
.cat-name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.cat-count { color: var(--text-soft); font-size: 14px; white-space: nowrap; }

/* ---------- Login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: var(--gutter); }
.login-card { width: 100%; max-width: 380px; padding: var(--space-5) var(--space-4); }
.login-card .wordmark { display: block; font-size: 28px; line-height: 1.2; margin-bottom: var(--space-2); }
.login-card .muted { margin-bottom: var(--space-4); }
.login-card .btn { margin-top: var(--space-4); }

/* ---------- Dialog ---------- */

.dialog {
  width: min(480px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100vh - 2 * var(--gutter));
  padding: var(--space-4);
  border: 0;
  border-radius: var(--radius-card);
  background: var(--white);
  color: var(--text);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.24), 0 8px 24px rgba(0, 0, 0, 0.14);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog h2 { font-weight: 600; color: var(--green-brand); margin-bottom: var(--space-3); }
.dialog .seg.block { margin-bottom: var(--space-3); }
.dialog .dialog-intro { margin-bottom: var(--space-3); }
.dialog .actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }
.dialog .actions .spacer { flex: 1; }
@media (max-width: 479px) {
  .dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--radius-card) var(--radius-card) 0 0; padding-bottom: max(var(--space-4), env(safe-area-inset-bottom)); }
  .dialog .actions .btn { flex: 1; }
  .dialog .actions .spacer { display: none; }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(var(--space-4), env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  max-width: calc(100vw - 2 * var(--gutter) - 72px);
  padding: 12px 20px;
  border-radius: var(--radius-card);
  background: var(--green-house);
  color: var(--white);
  font-size: 15px;
  box-shadow: var(--shadow-frap);
}
.toast.error { background: var(--red); }
