: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; }
input[aria-invalid="true"] { border-color: #a62922; outline: 1px solid #a62922; }
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; }
.print-sheet { display: none; }

@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: 9mm; }
  body { background: #fff; color: #14251e; font: 8.5pt/1.12 Arial, sans-serif; }
  .app { width: 100%; margin: 0; }
  header, .budget-card, .list-section, .actions, .starter-help, .app > footer, .notice { display: none !important; }
  .print-sheet { display: block; }
  .print-sheet h1 { margin: 0 0 2mm; color: #14251e; font-size: 18pt; }
  .print-sheet h2 { margin: 0 0 1.5mm; font-size: 10pt; }
  .print-subtitle, .print-sheet p { margin: 1mm 0; }
  .print-budget { margin: 2mm 0; padding: 2mm; border: 1.5pt solid #244c3a; }
  .print-columns { display: grid; grid-template-columns: minmax(0, 130mm) minmax(0, 59mm); gap: 3mm; }
  .print-table { width: 100%; min-width: 0; border-collapse: collapse; font-size: 7.7pt; }
  .print-table th, .print-table td { padding: 1mm .45mm; border-bottom: .3pt solid #aeb9b1; text-align: left; vertical-align: top; }
  .print-table th { background: #edf1ed !important; print-color-adjust: exact; }
  .print-table td:first-child { width: 4mm; }
  .print-table td:last-child, .print-table th:last-child { white-space: nowrap; text-align: right; }
  .print-checkbox { display: inline-block; width: 2.6mm; height: 2.6mm; border: .7pt solid #222; }
  .print-box { margin-bottom: 1.5mm; padding: 1.5mm; border: 1pt solid #7d8e82; break-inside: avoid; }
  .print-box ul { margin: .7mm 0; padding-left: 3.5mm; }
  .print-box li { margin: .7mm 0; }
  .print-no { font-weight: bold; }
  .print-small { font-size: 8pt; }
  .print-footer { margin-top: 2mm; padding-top: 1.5mm; border-top: 1pt solid #244c3a; font-size: 8pt; }
  .print-sheet tr { break-inside: avoid; }
}
