:root {
  color-scheme: light;
  font: 16px/1.5 system-ui, "Segoe UI", sans-serif;
  color: #1d3028;
  background: #f5f7f5;
  --green: #165a45;
  --line: #d7dfd8;
}

* { box-sizing: border-box; }

body { margin: 0; }
.app { width: min(1120px, 100% - 32px); margin: 32px auto; }
header { margin-bottom: 20px; }
h1 { margin: 0; font-size: clamp(1.7rem, 3vw, 2.2rem); color: var(--green); }
h2 { font-size: 1.15rem; }
.muted, .empty, footer { color: #53645a; }
.muted { margin: 4px 0 0; }

.budget-card, .list-section, footer {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 18px;
}
.budget-card { display: grid; grid-template-columns: 1fr minmax(190px, 280px); align-items: center; gap: 8px 18px; }
.budget-card > label { font-weight: 650; }
.budget-card input { grid-column: 2; grid-row: 1; }
.summary { display: flex; flex-wrap: wrap; gap: 22px; grid-column: 1 / -1; }
.status { grid-column: 1 / -1; margin: 0; font-weight: 650; }
.status.over { color: #a62922; }
.status.under { color: #165a45; }
.list-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.list-heading h2 { margin: 0 0 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { padding: 9px 7px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .85rem; background: #edf3ee; white-space: nowrap; }
td input { width: 100%; min-width: 75px; }
td .store-input { min-width: 105px; }
td .name-input { min-width: 130px; }
td .amount-input { min-width: 65px; }
td .price-input { min-width: 90px; }
.row-total { white-space: nowrap; font-variant-numeric: tabular-nums; }
.remove { padding: 5px 9px; color: #922b24; }
.empty { text-align: center; padding: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }
button, input, select { font: inherit; }
button, input, select { border: 1px solid #aebcb1; border-radius: 7px; padding: 9px 11px; }
button { cursor: pointer; background: #fff; }
button:hover { background: #edf3ee; }
button.primary { background: var(--green); color: #fff; border-color: var(--green); }
button.primary:hover { background: #104632; }
button.quiet { color: #53645a; }
footer h2 { margin: 0 0 8px; color: var(--green); }
footer p { margin: 6px 0; font-size: .92rem; }
.notice { min-height: 1.5em; color: var(--green); }
dialog { width: min(480px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / 35%); }
dialog h2 { margin-top: 0; }
dialog label { display: block; font-size: .9rem; font-weight: 600; margin: 12px 0; }
dialog label input, dialog label select { display: block; width: 100%; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid label:last-child { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.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; }

@media (max-width: 600px) {
  .app { width: min(100% - 20px, 1120px); margin: 18px auto; }
  .budget-card { grid-template-columns: 1fr; }
  .budget-card input { grid-column: 1; grid-row: auto; }
  .actions button { flex: 1 1 40%; }
}

@media print {
  @page { size: A4 portrait; margin: 10mm; }
  body { background: #fff; font-size: 10pt; }
  .app { width: 100%; margin: 0; }
  header, .budget-card, .list-section, footer { padding: 8px; margin-bottom: 8px; }
  .actions, .list-heading button, .remove, .notice { display: none !important; }
  .table-wrap { overflow: visible; }
  table { min-width: 0; font-size: 8.5pt; }
  th, td { padding: 5px 4px; }
  td input, td select { border: 0; padding: 0; background: transparent; appearance: none; }
  td input[type="number"] { text-align: left; }
  .budget-card { grid-template-columns: 1fr 220px; }
  .budget-card input { border: 0; }
  footer p { font-size: 8pt; }
  tr, footer, .budget-card { break-inside: avoid; }
}
