/* Tally: one stylesheet, light and dark, phone first. Colors are tokens: change them here. */
:root {
  --bg: #f7f7f5; --surface: #ffffff; --text: #1d1d1f; --muted: #6b6b70; --line: #e3e3e0;
  --accent: #2357c6; --ok: #11845b; --ok-bg: #e3f4ec; --bad: #c2352b; --bad-bg: #fbe7e5;
  --warn: #8a5a00; --warn-bg: #fff4d6; --neutral-bg: #ececec; --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214; --surface: #1c1c1f; --text: #ececee; --muted: #9a9aa2; --line: #2e2e33;
    --accent: #7ea6ff; --ok: #4cc690; --ok-bg: #12342a; --bad: #ff7b70; --bad-bg: #3d1c1a;
    --warn: #f0c35a; --warn-bg: #3a2e10; --neutral-bg: #2b2b30;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0.4rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 0.6rem; }
.card h2 { margin-top: 0; }
main { max-width: 1100px; margin: 0 auto; padding: 0 16px 32px; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.num { text-align: right; }

/* header */
.top {
  display: flex; align-items: center; gap: 18px; padding: 10px 16px; margin-bottom: 8px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; gap: 14px; }
.top nav a { color: var(--muted); }
.top nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.menu { position: relative; }
.menu summary { cursor: pointer; list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: " ▾"; color: var(--muted); }
.menu-items {
  position: absolute; right: 0; top: 1.8rem; z-index: 10; min-width: 170px; padding: 8px 12px;
  display: grid; gap: 6px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
}

/* bits */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.narrow { max-width: 380px; margin: 24px auto; }
.messages { list-style: none; padding: 0; margin: 0 0 12px; }
.msg { padding: 8px 12px; border-radius: 8px; background: var(--neutral-bg); margin: 8px 0; }
.msg.success { background: var(--ok-bg); }
.msg.error { background: var(--bad-bg); }
.msg.warning { background: var(--warn-bg); color: var(--warn); }
.empty { padding: 24px 0; }
.name { color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
tr.rough td { opacity: 0.62; }
table.compact td, table.compact th { padding: 5px 6px; font-size: 0.88rem; }
.actions { text-align: right; white-space: nowrap; }
.actions form { display: inline; }

/* forms */
input, button, select, textarea { font: inherit; }
input:not([type="checkbox"]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
button {
  padding: 8px 14px; border: 0; border-radius: 8px; background: var(--accent); color: #fff;
  cursor: pointer; font-weight: 600; justify-self: start;
}
button.link { background: none; color: var(--accent); padding: 0 4px; font-weight: 400; }
button.link.danger { color: var(--bad); }
.stack { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 0.85rem; font-weight: 600; }
.has-error input, .has-error textarea { border-color: var(--bad); }
.errorlist { list-style: none; padding: 0; margin: 0; color: var(--bad); font-size: 0.85rem; }
.check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 600; border: 1px solid var(--line); }
.status { font-size: 0.82rem; font-weight: 600; }
.status.done { color: var(--ok); }
.status.queued, .status.running { color: var(--warn); }
.status.failed { color: var(--bad); }

/* Tally pages */
:root { --chart-this: var(--accent); --chart-last: #9a9aa2; --bar-track: var(--neutral-bg); }
.nowrap { white-space: nowrap; }
.good { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.tag {
  display: inline-block; padding: 0 6px; border-radius: 6px; font-size: 0.72rem; font-weight: 600;
  background: var(--neutral-bg); color: var(--muted); vertical-align: middle;
}
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.button, label.button {
  display: inline-block; padding: 8px 14px; border-radius: 8px; background: var(--accent); color: #fff;
  font-weight: 600; cursor: pointer; text-decoration: none; justify-self: start;
}
.button:hover { text-decoration: none; filter: brightness(1.08); }
label.button input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
form.busy label.button { opacity: 0.6; pointer-events: none; }
form.busy label.button::after { content: " … uploading"; }

.month-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }
.month-head h1 { margin: 0; }
.month-head .step { font-size: 1.5rem; line-height: 1; padding: 0 6px; color: var(--muted); }
.month-head .snap, .month-head .button { margin-left: auto; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.tile .value { font-size: 1.5rem; font-weight: 700; margin: 2px 0; }
.intro ol { padding-left: 1.2rem; margin: 0 0 8px; }
.intro li { margin-bottom: 6px; }

svg.pace { width: 100%; height: auto; display: block; }
svg.pace polyline { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
svg.pace polyline.this { stroke: var(--chart-this); }
svg.pace polyline.last { stroke: var(--chart-last); stroke-dasharray: 5 4; stroke-width: 2; }
svg.pace .budget-line { stroke: var(--bad); stroke-width: 1; stroke-dasharray: 2 4; }
.legend { color: var(--muted); margin: 6px 0 0; }
.legend .key { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin: 0 4px 0 8px; }
.legend .key.this { background: var(--chart-this); }
.legend .key.last { background: var(--chart-last); }
.legend .key.budget { background: var(--bad); }

.trend { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; align-items: end; }
.trend .col { display: grid; justify-items: center; gap: 4px; color: var(--text); }
.trend .col:hover { text-decoration: none; }
.trend svg { width: 100%; height: 120px; }
.trend rect { fill: var(--chart-last); opacity: 0.55; }
.trend .current rect { fill: var(--chart-this); opacity: 1; }
.trend .current .muted { color: var(--text); font-weight: 600; }

table.cats td { padding: 6px 6px; }
table.cats .cat { width: 30%; }
table.cats .barcell { width: 40%; }
svg.bar { width: 100%; height: 12px; display: block; background: var(--bar-track); border-radius: 3px; }
svg.bar .fill { fill: var(--chart-this); }
svg.bar .fill.over { fill: var(--bad); }
svg.bar .avg { stroke: var(--text); stroke-width: 0.8; }
.note ul, .note p { margin: 0 0 6px; }

.receipts { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.receipt { display: grid; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; color: var(--text); }
.receipt:hover { text-decoration: none; border-color: var(--accent); }
.receipt img, .receipt .noimg { width: 100%; height: 150px; object-fit: cover; object-position: top;
  background: var(--neutral-bg); display: grid; place-items: center; color: var(--muted); }
.receipt .info { display: grid; gap: 1px; padding: 8px 10px; }
.receipt .total { font-weight: 700; }

.receipt-layout { display: grid; grid-template-columns: minmax(240px, 2fr) 3fr; gap: 16px; align-items: start; }
.receipt-layout .photo img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.fields .field:first-child { grid-column: 1 / -1; }
table.items td { padding: 4px 4px; }
table.items .qty input { width: 5rem; }
table.items .amt input { width: 6.5rem; }
.row-actions { display: flex; gap: 18px; margin-top: 16px; }
.items-line { color: var(--muted); margin-top: 2px; }
.link-charge { margin-top: 12px; }
.link-charge summary { cursor: pointer; font-weight: 600; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.filters input[type="search"] { flex: 1 1 200px; width: auto; }
.filters select { width: auto; }
.narrowish { max-width: 560px; }
.budget-grid { display: grid; grid-template-columns: auto 10rem; gap: 8px 14px; align-items: center; }

@media (max-width: 720px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .receipt-layout { grid-template-columns: 1fr; }
  .month-head .snap, .month-head .button { margin-left: 0; width: 100%; }
  .month-head label.button { width: 100%; text-align: center; padding: 12px; }
  table.cats .cat { width: 38%; }
  table.items thead { display: none; }
  table.items tr { display: grid; grid-template-columns: 1fr auto auto; gap: 4px; padding: 6px 0; border-bottom: 1px solid var(--line); }
  table.items td { border: 0; }
  table.items td:first-child { grid-column: 1 / -1; }
}

/* phones: tables become cards */
@media (max-width: 720px) {
  .top { flex-wrap: wrap; gap: 10px; }
  table.manage thead { display: none; }
  table.manage tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; padding: 10px 0;
    border-bottom: 1px solid var(--line);
  }
  table.manage td { border: 0; padding: 2px 0; text-align: left; }
  table.manage td:first-child { grid-column: 1 / -1; }
  table.manage td[data-label]::before {
    content: attr(data-label); display: block; font-size: 0.7rem; color: var(--muted);
  }
  table.manage td:first-child::before { display: none; }
  .actions { text-align: left; }
  .grid { grid-template-columns: 1fr; }
}
