/* ==========================================================================
   Our Family Budget — styles
   Palette: warm neutrals, high contrast, large touch targets.
   No external fonts/icons — system font stack + emoji only.
   ========================================================================== */

:root {
  --color-bg: #faf8f5;
  --color-surface: #ffffff;
  --color-surface-alt: #f2efe9;
  --color-border: #e3ded3;
  --color-field-border: #8a8274;
  --color-text: #2b2926;
  --color-text-muted: #6e675c;
  --color-primary: #3f6b58;
  --color-primary-dark: #2f5244;
  --color-primary-tint: #e7efe9;
  --color-on-primary: #ffffff;
  --color-warning: #8f6410;
  --color-warning-tint: #faf1de;
  --color-danger: #a63a32;
  --color-danger-tint: #fbeae8;
  --color-income: #3f6b58;

  --cat-food: #c98a4b;
  --cat-bills: #5b7c99;
  --cat-debt: #a6564c;
  --cat-transportation: #7a8b6f;
  --cat-healthcare: #7c6a8e;
  --cat-savings: #4f8a78;
  --cat-personal: #b8963f;
  --cat-other: #9c9488;
  --cat-income: #3f6b58;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(43, 41, 38, 0.08), 0 1px 2px rgba(43, 41, 38, 0.06);
  --touch-min: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #22201d;
    --color-surface: #2c2a26;
    --color-surface-alt: #33312c;
    --color-border: #47433c;
    --color-field-border: #8f887b;
    --color-text: #f3f0ea;
    --color-text-muted: #b8b1a4;
    --color-primary: #6fa78e;
    --color-primary-dark: #8bc0a7;
    --color-primary-tint: #2a3a32;
    --color-on-primary: #10160b;
    --color-income: #8bc0a7;
    --color-warning: #d9ab52;
    --color-warning-tint: #3a3122;
    --color-danger: #e08277;
    --color-danger-tint: #3d2624;
  }
}

:root { color-scheme: light dark; }

* { box-sizing: border-box; }

::placeholder { color: var(--color-text-muted); opacity: 1; }
:focus-visible { outline: 3px solid var(--color-primary); outline-offset: 2px; }

html { font-size: 18px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html[data-text-size="large"] { font-size: 21px; }
html[data-text-size="xlarge"] { font-size: 24px; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}
body {
  font-size: 1rem;
  /* A long unbroken word (a pasted web address, a very long name) wraps instead of
     stretching the page, which on a phone would zoom the whole app out sideways. */
  overflow-wrap: anywhere;
}
/* ...but buttons and badges keep their words whole. */
.btn, button, .tab, .bill-paid-badge, .focus-badge, .toast-btn { overflow-wrap: normal; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.75em; }

button {
  font: inherit;
  cursor: pointer;
}
button, select, input, label, summary { touch-action: manipulation; }

input, select, textarea {
  font: inherit;
  color: inherit;
}

.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch-min);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-field-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.05s ease;
}
a.btn { text-decoration: none; }
.btn:where(:hover:not(:disabled)) { background: var(--color-surface-alt); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:active { transform: none; }
.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-danger {
  background: var(--color-danger-tint);
  border-color: var(--color-danger);
  color: var(--color-danger);
}
.btn-large { min-height: 56px; font-size: 1.1rem; width: 100%; }
.btn-icon {
  min-width: var(--touch-min);
  padding: 10px;
}
.help-text .btn-link { min-height: 0; padding: 2px 4px; display: inline; } /* a link inside a sentence stays in the line */
.lock-card summary { padding: 12px 0; min-height: 44px; cursor: pointer; }
.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  text-decoration: underline;
  min-height: 44px;
  padding: 8px 6px;
}

/* ---------- Lock screen ---------- */
.lock-screen {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  overflow-y: auto;
  padding: 40px 20px;
  z-index: 100;
}
.lock-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
  text-align: center;
}
.lock-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 8px;
  display: block;
}
.lock-card input {
  width: 100%;
  min-height: var(--touch-min);
  font-size: 1.2rem;
  text-align: center;
  padding: 10px;
  border: 2px solid var(--color-field-border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  background: var(--color-surface);
  color: var(--color-text);
}
.error-text { color: var(--color-danger); font-weight: 600; }
.help-text { color: var(--color-text-muted); font-size: 0.95rem; }

/* ---------- App shell ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.app-header h1 { font-size: 1.3rem; margin: 0; }
.app-header { flex-wrap: wrap; gap: 4px 12px; }
.app-header .brand { display: flex; align-items: center; gap: 10px; flex: none; }
.app-logo { width: 34px; height: 34px; flex: none; }
.sync-status {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-align: right;
  flex: 1 1 auto;
  min-width: 0;
}
.sync-status.syncing { color: var(--color-warning); }
.sync-status.error { color: var(--color-danger); }

.tabs {
  display: flex;
  overflow-x: auto;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tab {
  flex: 1 1 auto;
  min-height: var(--touch-min);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--color-text-muted);
  font-weight: 600;
  padding: 10px 8px;
  white-space: nowrap;
}
.tab { display: flex; align-items: center; justify-content: center; gap: 6px; }
.tab:focus-visible { outline-offset: -4px; }
.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

@media (max-width: 520px) {
  .tab { flex-direction: column; gap: 0; min-width: 0; padding: 6px 2px; font-size: 0.8rem; }
  .tab-icon { font-size: 1.3rem; line-height: 1.2; }
}

main#view-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

/* ---------- Dashboard ---------- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(max(140px, 8.7rem), 1fr)); /* grows with the text size, so bigger text means one wide card per row */
  gap: 12px;
  margin-bottom: 20px;
}
.summary-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.summary-card .label { color: var(--color-text-muted); font-size: 0.9rem; }
.summary-card { container-type: inline-size; }
.summary-card .value { font-size: 1.25rem; font-weight: 700; margin-top: 4px; white-space: nowrap; overflow-wrap: normal; }
@supports (font-size: 1cqi) { .summary-card .value { font-size: min(1.5rem, 16cqi); } } /* shrinks only if a long amount wouldn't fit the card */
.bar-row .bar-amount, .budget-row .actual-amount, .budget-total-row span:last-child, .history-spent,
.flow-row span:last-child, .debt-stats strong, .history-detail strong { white-space: nowrap; overflow-wrap: normal; }
.value.positive { color: var(--color-primary); }
.value.negative { color: var(--color-danger); }

.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.bar-row .bar-label { flex: 0 0 7.2rem; font-size: 0.95rem; }
.bar-track {
  flex: 1;
  background: var(--color-surface-alt);
  border-radius: 6px;
  height: 16px;
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 6px; }
.bar-row .bar-amount { flex: 0 0 auto; min-width: 5rem; text-align: right; font-variant-numeric: tabular-nums; }
.bar-row { flex-wrap: wrap; }
.bar-row .bar-change { flex: 0 0 100%; margin-top: -6px; font-size: 0.85rem; color: var(--color-text-muted); }

/* ---------- Month by month ---------- */
.history-row {
  overflow-wrap: anywhere;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  width: 100%;
  min-height: var(--touch-min);
  margin-bottom: 8px;
  padding: 10px 14px;
  text-align: left;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.history-row.selected { border-color: var(--color-primary); border-width: 2px; }
.history-month { font-weight: 700; }
.history-spent { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.history-bar { grid-column: 1 / -1; height: 10px; background: var(--color-surface-alt); border-radius: 5px; overflow: hidden; }
.history-bar span { display: block; height: 100%; background: var(--cat-bills); border-radius: 5px; }
.history-detail { grid-column: 1 / -1; font-size: 0.9rem; color: var(--color-text-muted); }
.history-detail strong.positive { color: var(--color-primary); }
.history-detail strong.negative { color: var(--color-danger); }

/* ---------- Month nav ---------- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}
.month-nav .month-label { font-weight: 700; font-size: 1.1rem; min-width: 160px; text-align: center; }

/* ---------- Budget grid ---------- */
.budget-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6.5rem 6rem;
  align-items: center;
  gap: 10px;
  padding: 12px 0 4px;
  border-bottom: 1px solid var(--color-border);
}
.budget-row:last-child { border-bottom: none; }
.budget-total-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 2px solid var(--color-border);
  font-weight: 700;
}
.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  min-width: 0;
}
.cat-pill span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cat-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; vertical-align: middle; margin-bottom: 2px; }
.budget-row .planned-input {
  width: 100%;
  min-height: var(--touch-min);
  padding: 6px 8px;
  border: 1px solid var(--color-field-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  text-align: right;
}
.budget-row .actual-amount { text-align: right; font-variant-numeric: tabular-nums; }
.budget-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6.5rem 6rem;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-weight: 600;
}
.budget-head span:not(:first-child) { text-align: right; }
.budget-track-row { grid-column: 1 / -1; margin-bottom: 8px; }

/* ---------- Transactions ---------- */
.txn-item {
  display: flex;
  flex-wrap: wrap; /* a very long amount drops to its own line instead of squeezing the description to nothing */
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}
.txn-item:last-child { border-bottom: none; }
.txn-main { flex: 1 1 8rem; min-width: 0; }
.txn-desc { font-weight: 600; }
.txn-meta { color: var(--color-text-muted); font-size: 0.9rem; }
.txn-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.txn-amount.income { color: var(--color-income); }
.txn-actions { display: flex; gap: 4px; }

.bill-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}
.bill-item:last-child { border-bottom: none; }
.bill-main { flex: 1; min-width: 140px; }
.bill-name { font-weight: 600; }
.bill-meta { color: var(--color-text-muted); font-size: 0.9rem; }
.bill-meta .cat-dot { margin-right: 6px; }
.token-banner {
  padding: 12px 20px;
  font-weight: 600;
  background: var(--color-warning-tint);
  color: var(--color-warning);
  border-bottom: 1px solid var(--color-warning);
}
.token-banner.expired { background: var(--color-danger-tint); color: var(--color-danger); border-bottom-color: var(--color-danger); }
.repo-warning {
  padding: 12px 14px;
  margin-bottom: 14px;
  font-weight: 600;
  background: var(--color-danger-tint);
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius-sm);
}
.bill-sort { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; }
.bill-sort label { font-weight: 600; }
.bill-sort select {
  min-height: 44px;
  padding: 4px 8px;
  border: 1px solid var(--color-field-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
.text-size-options { display: flex; gap: 8px; flex-wrap: wrap; }
.text-size-options .btn { flex: 1 1 0; }
.text-size-options .btn.active { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary); }
.bill-cat { display: flex; align-items: center; gap: 8px; margin-top: 6px; min-width: 0; }
.bill-cat-select {
  min-height: 44px;
  min-width: 0;
  flex: 0 1 auto;
  text-overflow: ellipsis;
  max-width: 100%;
  padding: 4px 8px;
  font-size: 0.9rem;
  border: 1px solid var(--color-field-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
.bill-next { flex: 1 1 auto; color: var(--color-text-muted); font-size: 0.95rem; }
.bill-paid-badge {
  display: inline-block;
  color: var(--color-primary-dark);
  background: var(--color-primary-tint);
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.9rem;
  white-space: nowrap;
}

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

/* ---------- Debts ---------- */
.debt-card { position: relative; }
.debt-card.focus { border-color: var(--color-primary); border-width: 2px; }
.focus-badge {
  display: inline-block;
  background: var(--color-primary-tint);
  color: var(--color-primary-dark);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 8px;
}
.debt-progress-track {
  background: var(--color-surface-alt);
  border-radius: 8px;
  height: 20px;
  overflow: hidden;
  margin: 10px 0;
}
.debt-progress-fill { height: 100%; background: var(--cat-debt); border-radius: 8px; }
.debt-stats { display: flex; flex-wrap: wrap; gap: 16px; color: var(--color-text-muted); font-size: 0.95rem; margin-bottom: 12px; }
.debt-stats strong { color: var(--color-text); display: block; font-size: 1.05rem; }
.debt-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.strategy-toggle { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.strategy-toggle .btn { flex: 1 1 9rem; min-width: 0; padding-left: 12px; padding-right: 12px; }
.strategy-toggle .btn.active { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary); }

/* ---------- Forms / modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43, 41, 38, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
@media (min-width: 600px) {
  .modal { border-radius: var(--radius); }
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  min-height: var(--touch-min);
  padding: 8px 12px;
  border: 1px solid var(--color-field-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
.type-toggle { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.type-toggle .btn { flex: 1 1 6rem; min-width: 0; padding-left: 12px; padding-right: 12px; }
.type-toggle .btn.active-income { background: var(--color-primary-tint); border-color: var(--color-primary); color: var(--color-primary-dark); }
.type-toggle .btn.active-expense { background: var(--color-danger-tint); border-color: var(--color-danger); color: var(--color-danger); }

/* ---------- Settings ---------- */
.settings-section {
  margin-bottom: 16px;
  padding: 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.settings-section h2 { display: flex; align-items: center; gap: 8px; }
.category-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}
.category-list-item:last-child { border-bottom: none; }
.category-list-item .cat-name { flex: 1; }
.color-swatch { width: 22px; height: 22px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,0.1); }
.swatch-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch-picker .color-swatch {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 3px solid transparent;
  background-clip: padding-box;
  cursor: pointer;
}
.swatch-picker .color-swatch.selected { border-color: var(--color-text); box-shadow: inset 0 0 0 3px var(--color-surface); background-clip: border-box; }
.status-line { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; color: var(--color-text-muted); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--color-text-muted); }
.status-dot.ok { background: var(--color-primary); }
.status-dot.error { background: var(--color-danger); }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: var(--color-bg);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  z-index: 300;
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* ---------- Undo toast, search, coming up, debt-free ---------- */
.toast-undo { display: flex; align-items: center; gap: 14px; padding: 6px 8px 6px 20px; }
.toast-btn {
  min-height: var(--touch-min);
  padding: 8px 16px;
  background: none;
  border: 2px solid currentColor;
  border-radius: var(--radius-sm);
  color: inherit;
  font-weight: 700;
}
.search-box { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; margin-bottom: 14px; }
.search-label { flex: 0 0 100%; font-weight: 600; }
.search-box input {
  flex: 1;
  min-width: 0;
  min-height: var(--touch-min);
  padding: 8px 12px;
  border: 1px solid var(--color-field-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
.search-summary { text-align: center; margin: 4px 0 14px; }
.coming-up { border-color: var(--color-primary); border-width: 2px; }
.coming-up h2 { margin-bottom: 0.3em; }
.debt-free-date { font-size: 1.8rem; font-weight: 700; color: var(--color-primary); margin-bottom: 6px; }
#extra-debt-select { width: 100%; }

.overdue-title { color: var(--color-warning); margin: 4px 0 2px; }
.upcoming-title { margin: 16px 0 2px; }
.carry-note { margin-top: -4px; }
.cash-flow { margin-top: 14px; padding-top: 6px; border-top: 2px solid var(--color-border); }
.flow-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-variant-numeric: tabular-nums; }
.flow-row.flow-left { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--color-border); margin-top: 4px; padding-top: 10px; }
.flow-row .positive { color: var(--color-primary); }
.flow-row .negative { color: var(--color-danger); }
.flow-names { color: var(--color-text-muted); font-size: 0.9rem; margin: -2px 0 4px; }
.goal-item { padding: 12px 0; border-bottom: 1px solid var(--color-border); }
.goal-item:last-of-type { border-bottom: none; }
.goal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.goal-fill { height: 100%; background: var(--cat-savings); border-radius: 8px; }
.goal-meta { color: var(--color-text-muted); font-size: 0.95rem; margin-bottom: 10px; }

/* ---------- Large-print bills list ---------- */
.print-modes { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.print-modes .btn { flex: 1 1 0; }
.print-modes .btn.active { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary); }
.print-sheet { overflow-x: auto; background: #ffffff; color: #000000; padding: 16px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); }
.print-sheet h2 { font-size: 1.5rem; margin-bottom: 0.2em; }
.print-sheet .print-sub { color: #333333; font-size: 1rem; }
.print-sheet table { width: 100%; border-collapse: collapse; font-size: 1.05rem; }
.print-sheet th { text-align: left; border-bottom: 3px solid #000000; padding: 6px 4px; }
.print-sheet td { padding: 8px 4px; border-bottom: 1px solid #888888; }
.print-sheet th.num, .print-sheet td.num { text-align: right; font-variant-numeric: tabular-nums; }
.print-sheet th:nth-child(2), .print-sheet td:nth-child(2) { width: 100%; overflow-wrap: anywhere; }
.print-sheet th, .print-sheet td:first-child, .print-sheet td.num, .print-sheet td.paid-box { white-space: nowrap; }
.print-sheet td.paid-box { width: 2.2em; text-align: center; font-weight: 700; border-left: 1px solid #888888; }
.print-sheet tfoot td { font-weight: 700; border-top: 3px solid #000000; border-bottom: none; }

/* ---------- User preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .btn:active { transform: none; }
}
@media (forced-colors: active) {
  .bar-fill, .debt-progress-fill, .goal-fill, .history-bar span, .cat-dot, .color-swatch { forced-color-adjust: none; }
  .btn { border: 2px solid ButtonText; }
}

/* ---------- Small screens (kept last so they override the rules above) ---------- */
@media (max-width: 520px) {
  .app-header { padding: 12px 16px; }
  .app-header h1 { font-size: 1.15rem; }

  /* Spending bars: name and amount on one line, the bar full width underneath. */
  .bar-row { row-gap: 4px; }
  .bar-row .bar-label { flex: 1 1 0; min-width: 0; order: 1; }
  .bar-row .bar-amount { flex: 0 0 auto; order: 2; font-weight: 600; }
  .bar-row .bar-track { flex: 0 0 100%; order: 3; }
  .bar-row .bar-change { order: 4; margin-top: 0; }

  /* Budget grid: category name on its own line so it is never cut short. */
  .budget-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .budget-row .cat-pill { grid-column: 1 / -1; }
  .budget-head { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .budget-head span:first-child { display: none; }

  /* Bills list: details on top, the big buttons in a row underneath. */
  .bill-item-list .bill-main { flex: 1 1 100%; }
  .bill-item-list > .btn-primary, .bill-item-list > .bill-paid-badge { flex: 1 1 auto; justify-content: center; text-align: center; }
  .bill-item-list > .bill-next { text-align: left; }

  .print-sheet { padding: 8px; }
  .print-sheet table { font-size: 0.9rem; }
  .print-sheet td { padding: 6px 3px; }
}

@media print {
  @page { margin: 0.6in; }
  body > *:not(#modal-root) { display: none !important; }
  .no-print { display: none !important; }
  .modal-backdrop { position: static; background: none; display: block; }
  .modal { max-width: none; max-height: none; overflow: visible; padding: 0; border-radius: 0; background: #ffffff; }
  .print-sheet { border: none; padding: 0; overflow: visible; }
  .print-sheet h2 { font-size: 30pt; }
  .print-sheet .print-sub { font-size: 16pt; }
  .print-sheet table { font-size: 22pt; }
  .print-sheet td { padding: 10px 6px; border-bottom: 1.5px solid #000000; }
  .print-sheet td.paid-box { border: 1.5px solid #000000; font-size: 26pt; }
  .print-sheet tr { break-inside: avoid; }
}
