/* AA Treasury — system fonts, light & dark, phone first. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16191d;
  --muted: #545b66;
  --border: #d3d8df;
  --accent: #1d4e89;
  --accent-text: #ffffff;
  --in: #0b6b3a;
  --out: #a02121;
  --collection: #0b6b3a;
  --spend: #a3401a;
  --move: #1d4e89;
  --flash-bg: #e3f3e9;
  --error-bg: #fbe5e5;
  --notice-bg: #fff6d9;
  --warning-bg: #fde8cf;
  --warning-border: #b54708;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1b2027;
    --text: #eef1f4;
    --muted: #a9b1bc;
    --border: #353d47;
    --accent: #7fb2f0;
    --accent-text: #0b1a2c;
    --in: #6fd39b;
    --out: #ff9a9a;
    --collection: #1f7a4a;
    --spend: #a8481f;
    --move: #2a5f9e;
    --flash-bg: #173826;
    --error-bg: #4a1c1c;
    --notice-bg: #3d3414;
    --warning-bg: #45290f;
    --warning-border: #f5a25d;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--surface); padding: .6rem; border-radius: 8px; border: 1px solid var(--border); }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem 1rem;
  padding: calc(.6rem + env(safe-area-inset-top)) 1rem .6rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.brand span { color: var(--muted); font-weight: 400; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .2rem .9rem; align-items: center; }
.topbar nav a, .linkish { font-size: .95rem; padding: .35rem 0; }
.linkish { background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }
form.inline { display: inline; }

.page { max-width: 640px; margin: 0 auto; padding: 1rem 1rem 3rem; }
.page.narrow { max-width: 420px; }
.page.wide { max-width: 900px; }

.flash, .error, .notice { padding: .75rem 1rem; border-radius: var(--radius); margin: 0 0 1rem; }
.flash { background: var(--flash-bg); }
.error { background: var(--error-bg); }
.notice { background: var(--notice-bg); }
.warning { background: var(--warning-bg); border: 2px solid var(--warning-border); border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 1rem; }
.warning ul { margin: .4rem 0; padding-left: 1.2rem; }
.warning p { margin: .3rem 0 0; font-size: .9rem; }
.notice h2 { margin-top: 0; }
.lede { color: var(--muted); margin-top: -.5rem; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: 1.2rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .8rem; display: flex; flex-direction: column; }
.tile-label { font-size: .85rem; color: var(--muted); }
.tile-value { font-size: 1.3rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile.negative .tile-value { color: var(--out); }
.tile.total, .tile.available { grid-column: span 1; border-width: 2px; border-color: var(--accent); }
.tile small { font-size: .75rem; }

/* Big buttons */
.actions { display: grid; gap: .7rem; margin: 1rem 0 1.4rem; }
.big-button {
  display: flex; align-items: center; justify-content: center; min-height: 72px;
  border-radius: var(--radius); color: #fff; font-size: 1.3rem; font-weight: 650; text-decoration: none;
}
.big-button.collection { background: var(--collection); }
.big-button.spend { background: var(--spend); }
.big-button.move { background: var(--move); }
.big-button.prepare { background: var(--move); filter: saturate(.6); }
.links-heading { color: var(--muted); padding: .5rem 0; }
textarea {
  width: 100%; padding: .55rem .7rem; font-size: 1rem; font-family: ui-monospace, Menlo, monospace;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.preview { margin-top: 1rem; }
.preview tr.bad td { background: var(--error-bg); }
.line-error { color: var(--out); display: block; }
.line-warning { display: block; }
.small-links { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.small-links a { padding: .5rem 0; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: .35rem; }
.stack label { font-weight: 600; margin-top: .6rem; }
.stack label.check { font-weight: 400; display: flex; align-items: center; gap: .6rem; min-height: 44px; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], select {
  width: 100%; min-height: 48px; padding: .55rem .7rem; font-size: 1.1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
input[type=date], input[type=time] { -webkit-appearance: none; appearance: none; }
input[type=file] { max-width: 100%; font-size: 1rem; }
input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); }
input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.money { display: flex; align-items: center; gap: .4rem; }
.money span { font-size: 1.2rem; color: var(--muted); }
.hint { font-size: .85rem; color: var(--muted); margin: .1rem 0 0; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin-top: 1rem; padding: .5rem 1rem 1rem; }
legend { font-weight: 600; padding: 0 .3rem; }
.settings-section { margin-top: 2rem; }
.rule-time { display: flex; align-items: center; gap: .6rem; }
.rule-time input { max-width: 9rem; }
.devices { padding-left: 1.2rem; }
.devices li { margin: .3rem 0; }

.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: .6rem 1.2rem;
  border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer; margin-top: .8rem;
}
.button.secondary { background: transparent; color: var(--accent); }
.button.danger { background: var(--out); border-color: var(--out); color: #fff; }
.button.small { min-height: 40px; padding: .3rem .9rem; margin-top: 0; font-size: .95rem; }
.button:disabled { opacity: .6; }

.presets { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: .55rem .9rem; text-decoration: none; color: var(--text); font-size: .95rem; }
.chip.active { border-color: var(--accent); border-width: 2px; }

/* Ledger */
.filters { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem .8rem; margin-bottom: 1rem; }
.filters label { font-size: .85rem; font-weight: 600; }
.filter-buttons { display: flex; gap: .5rem; align-items: end; }
.entries { list-style: none; padding: 0; margin: 0; }
.entry { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: .6rem; }
.entry-head { display: flex; gap: .7rem; align-items: baseline; flex-wrap: wrap; }
.entry-date { font-weight: 650; font-variant-numeric: tabular-nums; }
.entry-id { margin-left: auto; color: var(--muted); font-size: .85rem; }
.entry-summary, .entry-note { margin: .3rem 0; }
.entry-meta { color: var(--muted); font-size: .8rem; margin: .3rem 0 0; }
.lines { width: 100%; border-collapse: collapse; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.lines th { text-align: left; font-size: .75rem; color: var(--muted); font-weight: 600; }
.lines td, .lines th { padding: .2rem .3rem .2rem 0; }
.num { text-align: right; }
td.in { color: var(--in); }
td.out { color: var(--out); }
.entry.voided .entry-head, .entry.voided .lines, .entry.voided .entry-summary, .entry.voided .entry-note { text-decoration: line-through; opacity: .65; }
.void-info { color: var(--out); font-weight: 600; margin: .3rem 0 0; font-size: .9rem; }
.void-link { font-size: .9rem; }
.entry-evidence { margin: .3rem 0; font-size: .9rem; overflow-wrap: anywhere; }
.evidence-link { font-size: .9rem; }
.evidence-voided { color: var(--out); font-size: .85rem; }
.evidence-list { list-style: none; padding: 0; }
.evidence-list li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; margin-bottom: .5rem; overflow-wrap: anywhere; }
.evidence-list .entry-meta { display: block; }
.evidence-remove { display: flex; gap: .4rem; margin-top: .4rem; }
.evidence-remove input { flex: 1; min-width: 0; }
.report .evidence-note { font-size: .9em; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.report-list { padding-left: 1.2rem; }
.report-list li { margin-bottom: .5rem; }
.report-list li.voided a { text-decoration: line-through; }

/* Report */
.report-tools { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.report { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; }
.report h1 { font-size: 1.35rem; }
.report h2 { font-size: 1rem; text-decoration: underline; margin: 1.2rem 0 .3rem; }
.report h3 { font-size: .9rem; margin: 1rem 0 .3rem; }
.report p { margin: .15rem 0; font-variant-numeric: tabular-nums; }
.report .period { color: var(--muted); font-size: .9rem; }
.report .adjustments { font-size: .85rem; }

@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .actions { grid-template-columns: repeat(4, 1fr); }
  .filters { grid-template-columns: repeat(5, auto); }
}

@media print {
  @page { size: A4; margin: 18mm; }
  :root { color-scheme: light; }
  body { background: #fff !important; color: #000 !important; font-size: 12pt; }
  .no-print, .topbar, .flash, .error { display: none !important; }
  .page { max-width: none; padding: 0; }
  .report { border: 0; padding: 0; background: #fff; color: #000; }
  .report * { color: #000 !important; }
  .report section { break-inside: avoid; }
  a { color: #000; text-decoration: none; }
}
