:root {
  --text: #1a1a1a;
  --muted: #3b3b3b;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --border: #595959;
  --accent: #0b3d91;
  --accent-contrast: #ffffff;
  --banner-bg: #fff4d6;
  --intro-bg: #e8f1fb;
  --focus: #0b3d91;
  --error: #a4000f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header, #notices, main, .site-footer { padding: 0.5rem 1rem; }

h1 { margin: 0.25rem 0; font-size: 1.5rem; }

nav { display: flex; flex-wrap: wrap; gap: 0.5rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

button, select, input, .target { min-height: 44px; }

button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.25rem 1rem;
  font: inherit;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
  margin: 0.5rem 0;
}

.banner { background: var(--banner-bg); border: 1px solid var(--border); padding: 0.5rem 1rem; }
.intro { background: var(--intro-bg); border: 1px solid var(--border); padding: 0.5rem 1rem; }
.muted { color: var(--muted); }

.bar { display: block; height: 1rem; background: var(--accent); }

nav button[aria-current="page"] {
  background: var(--surface);
  color: var(--accent);
  font-weight: bold;
  text-decoration: underline;
}

h2 { margin: 0.5rem 0; font-size: 1.25rem; }
h3 { margin: 1rem 0 0.25rem; font-size: 1.1rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }

button.secondary { background: var(--surface); color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
.field { margin: 0.75rem 0; }
.field > label { display: block; font-weight: 600; }
.hint { margin: 0.25rem 0 0; }
input[type="text"], input[type="search"], input[type="date"], select {
  font: inherit;
  max-width: 100%;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}
input[type="text"], input[type="search"] { width: 20rem; }
input.short, input.date { width: 9rem; }
input[type="file"] { max-width: 100%; }
input[aria-invalid="true"] { border: 2px solid var(--error); }
.choice { display: flex; align-items: center; gap: 0.5rem; min-height: 44px; }
.choice input { width: 1.5rem; height: 1.5rem; min-height: 0; margin: 0; flex: none; }
fieldset { border: 1px solid var(--border); border-radius: 4px; margin: 0.75rem 0; padding: 0.5rem 1rem; min-width: 0; }
legend { font-weight: 600; padding: 0 0.25rem; overflow-wrap: anywhere; }
.row { display: flex; flex-wrap: wrap; gap: 0 1rem; }
/* A field alone on a line may shrink to the line, so a 20rem input fits a 320px screen. */
.row > .field { min-width: 0; }
.error { color: var(--error); font-weight: 600; margin: 0.25rem 0 0; }
.dropzone { border: 2px dashed var(--border); border-radius: 4px; padding: 1rem; margin: 0.5rem 0; text-align: center; }
.dropzone.over { background: var(--intro-bg); }

/* Tables */
table { border-collapse: collapse; margin: 0.5rem 0; }
caption { text-align: left; font-weight: 600; }
th, td { border-bottom: 1px solid var(--border); padding: 0.25rem 0.5rem; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.num { text-align: right; }
.raw { white-space: pre-wrap; overflow-wrap: anywhere; }
.scroll { overflow-x: auto; max-width: 100%; position: relative; }
.scroll th, .scroll td { white-space: nowrap; overflow-wrap: normal; }

/* Categories */
.row-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.inline-form .name-input { width: 14rem; }
.inline-form .error { white-space: normal; }

/* Categorise card */
.category-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.category-buttons .key { font-weight: bold; }
.plain-list { list-style: none; padding: 0; margin: 0.25rem 0; }
.plain-list > li { padding: 0.25rem 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.plain-list > li p { margin: 0.25rem 0; }
.plain-list .row-actions { margin-top: 0.25rem; }
.card-form { margin: 0.5rem 0; }

/* Transactions */
.filters { align-items: flex-start; }
.counts-as { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.5rem; }
dialog {
  max-width: min(40rem, calc(100vw - 2rem));
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h3 { margin-top: 0; }

/* Buckets */
.field.toggle { padding-top: 1.5em; }
.field.toggle > label.choice { display: flex; font-weight: normal; }
table.buckets td, table.buckets th { vertical-align: middle; }
table.buckets input.select { width: 1.5rem; height: 1.5rem; min-height: 0; margin: 0; }

/* Typical month */
hgroup p { margin: 0 0 0.5rem; }
dl.summary { display: grid; grid-template-columns: auto auto; justify-content: start; gap: 0.25rem 1.5rem; margin: 1rem 0; }
dl.summary dt { font-weight: 600; }
dl.summary dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
dl.summary .sub { font-weight: normal; padding-left: 1rem; }
.uncategorised { align-items: center; }
.uncategorised p { margin: 0; }
table.typical td.num { font-variant-numeric: tabular-nums; }
table.typical td.bar-cell { width: 8rem; min-width: 8rem; vertical-align: middle; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* Footer */
.site-footer { font-size: 0.875rem; color: var(--muted); overflow-wrap: anywhere; }
.site-footer p { margin: 0.5rem 0; }
.site-footer a { color: var(--accent); }
