/* Dark and light both, from the viewer's own setting. Nothing here assumes one. */
:root {
  color-scheme: light dark;
  --ink: #16181d;
  --paper: #ffffff;
  --sunken: #f3f4f6;
  --line: #d8dbe0;
  --quiet: #5c6370;
  --jason: #1f6feb;
  --andria: #a2469c;
  --flag: #b4530a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6e8eb;
    --paper: #14161a;
    --sunken: #1d2026;
    --line: #2c3038;
    --quiet: #9aa1ac;
    --jason: #6ea8fe;
    --andria: #d79ad3;
    --flag: #e8a562;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  justify-content: center;
}
main { width: min(60rem, 100% - 2rem); padding: 1.5rem 0 4rem; }
a { color: inherit; }
h1 { font-size: 1.4rem; margin: 0 0 0.25rem; }
.page { margin-bottom: 1.25rem; }
.crumb { margin: 0 0 0.5rem; font-size: 0.85rem; }
.crumb a, .ledger thead a { color: var(--quiet); text-decoration: none; }
.ledger thead a:hover { color: var(--ink); }
.tally { margin: 0; color: var(--quiet); }
.tally strong { color: var(--ink); }
.note {
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--flag);
  border-radius: 0.4rem;
  background: var(--sunken);
}

/* Months ------------------------------------------------------------------ */
.months { list-style: none; margin: 0; padding: 0; }
.months a {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: baseline;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  text-decoration: none;
  min-height: 44px;
}
.months a:hover { background: var(--sunken); }
.month-key { font-weight: 600; font-variant-numeric: tabular-nums; }
.month-meta { color: var(--quiet); font-size: 0.9rem; flex: 1; }
.status {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--quiet);
}
.status-reconciled, .status-locked { color: var(--jason); }

/* Tally ------------------------------------------------------------------- */
.headline { margin: 0; font-size: 1.1rem; color: var(--quiet); }
.headline strong { color: var(--ink); font-variant-numeric: tabular-nums; }
h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--quiet); margin: 2rem 0 0.5rem; }
.hint { margin: 0 0 0.75rem; color: var(--quiet); font-size: 0.9rem; }

.history { width: 100%; border-collapse: collapse; }
.history th, .history td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.history th { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.period, .balance { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Which way the balance ran at that point. Quiet, because the amount is the
   figure being read and this only says who it belongs to. */
.owed { color: var(--quiet); font-size: 0.85rem; }
.why { display: block; color: var(--quiet); font-size: 0.85rem; }

.settle { display: grid; gap: 0.75rem; max-width: 26rem; }
.settle .field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--quiet); }
.settle input[type="text"], .settle input:not([type]), .settle input[type="date"] {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  padding: 0.6rem 0.75rem;
  min-height: 44px;
}
.who-paid { border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.5rem 0.9rem 0.75rem; }
.who-paid legend { font-size: 0.85rem; color: var(--quiet); padding: 0 0.3rem; }
.who-paid label { display: flex; align-items: center; gap: 0.5rem; min-height: 44px; }
.settle button {
  font: inherit;
  padding: 0.6rem 0.75rem;
  min-height: 44px;
  border: 1px solid var(--ink);
  border-radius: 0.4rem;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
}

/* Tiles ------------------------------------------------------------------- */
.tiles {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
}
.tiles li {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.75rem 0.9rem;
  background: var(--sunken);
}
.tile-label { display: block; font-size: 0.8rem; color: var(--quiet); }
.tile-value { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* Filters ----------------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.9rem;
}
/* Selected filters are filled, not tinted: at a glance you can always tell
   which card you are looking at. */
.chip-on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip-count { color: var(--quiet); font-variant-numeric: tabular-nums; }
.chip-on .chip-count { color: inherit; opacity: 0.75; }

/* The same sorting the table header offers, for screens where the header is
   not shown. Hidden on wide screens, where the header is the control. */
.sorts { display: none; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }
.sorts-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--quiet); }

/* Ledger ------------------------------------------------------------------ */
.ledger { width: 100%; border-collapse: collapse; }
.ledger th, .ledger td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
/* The sorted column is marked by an arrow alone - no shaded header. */
.ledger th { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.arrow { color: var(--ink); }
.right { text-align: right; }
.date, .amount, .card { font-variant-numeric: tabular-nums; white-space: nowrap; }
.flagged { background: color-mix(in srgb, var(--flag) 8%, transparent); }
.tag {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 0.4rem;
}
.tag-flag { color: var(--flag); border-color: currentColor; }

/* Rows the script has filtered out. Stated explicitly because the narrow
   layout gives table rows a display of their own, which would otherwise win. */
[hidden] { display: none !important; }

/* A change that did not reach the ledger. Shown for a few seconds, because
   silently keeping one is the outcome nobody could recover from. */
.failed { outline: 2px solid var(--flag); outline-offset: -2px; }
.failed .whose::after { content: " not saved"; color: var(--flag); font-size: 0.8rem; }

/* Attribution ------------------------------------------------------------- */
.whose form { display: flex; gap: 0.35rem; }
.who {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.6rem;
  min-height: 44px;
  border-radius: 0.4rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--quiet);
  cursor: pointer;
}
.who:hover { color: var(--ink); }
/* The chosen one takes that person's colour with a matching outline. An
   unmarked row shows neither, because shared is the absence of a mark. */
.who-on.who-jason { background: var(--jason); border-color: var(--jason); color: var(--paper); }
.who-on.who-andria { background: var(--andria); border-color: var(--andria); color: var(--paper); }

/* Import ------------------------------------------------------------------ */
.counts { margin: 0.5rem 0 0; color: var(--quiet); font-variant-numeric: tabular-nums; }
.upload { margin: 1.5rem 0; }
.upload h2 { font-size: 1rem; margin: 0 0 0.5rem; }
.hint { margin: 0 0 0.75rem; color: var(--quiet); font-size: 0.9rem; }
.hint strong { color: var(--ink); }
/* Wraps on a phone, so the file control is never pushed off the edge. */
.pick, .drop { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.pick { margin-bottom: 1.5rem; }
.drop { margin-bottom: 0.75rem; }
.pick label, .drop label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--quiet); }
.pick select, .drop input, .pick button, .drop button {
  font: inherit;
  padding: 0.45rem 0.7rem;
  min-height: 44px;
  border-radius: 0.4rem;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}
.pick button, .drop button { background: var(--ink); color: var(--paper); cursor: pointer; }
.problems { margin: 0 0 1rem; padding-left: 1.2rem; color: var(--flag); }
.files { list-style: none; margin: 0; padding: 0; }
.files li { padding: 0.35rem 0; border-bottom: 1px solid var(--line); }
/* Exceptions -------------------------------------------------------------- */
/* Whose a standing rule is, shown rather than chosen. A month is where a row
   gets attributed; by the time a rule exists, that is already decided. */
.person { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 0.4rem; font-size: 0.85rem; }
.person-jason { background: var(--jason); color: var(--paper); }
.person-andria { background: var(--andria); color: var(--paper); }
.switch, .danger {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.6rem;
  min-height: 44px;
  border-radius: 0.4rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--quiet);
  cursor: pointer;
}
/* A rule that is running is filled, not tinted: the value of this column is
   telling at a glance which rules will produce a row next month. */
.switch-on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.danger { color: var(--flag); }
.waiting {
  border: 1px solid var(--line);
  border-left: 3px solid var(--flag);
  border-radius: 0.4rem;
  background: var(--sunken);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}
.waiting h2 { font-size: 1rem; margin: 0 0 0.5rem; }
.waiting-month { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; }
.waiting-month p { margin: 0.25rem 0; flex: 1; min-width: 14rem; }
.rule-form {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  align-items: end;
  margin-top: 1rem;
}
.rule-form label { display: block; font-size: 0.8rem; color: var(--quiet); }
.rule-form input, .rule-form select, .rule-form button {
  font: inherit;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 0.4rem;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  min-height: 44px;
}
.rule-form button { background: var(--ink); color: var(--paper); cursor: pointer; }
/* A statement of fact rather than a warning, so it does not borrow the flag. */
.quiet { border-left-color: var(--line); }
.remove { font-size: 0.75rem; color: var(--quiet); white-space: nowrap; }

/* Sign-in ----------------------------------------------------------------- */
form.signin { display: flex; flex-direction: column; gap: 1rem; max-width: 22rem; }
form.signin input, form.signin button {
  font: inherit;
  padding: 0.6rem 0.75rem;
  border-radius: 0.4rem;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  min-height: 44px;
}
form.signin button { background: var(--ink); color: var(--paper); cursor: pointer; }

@media (max-width: 40rem) {
  .sorts { display: flex; }
  /* One card per row, so a thumb has something to aim at. */
  .ledger, .ledger tbody, .ledger tr, .ledger td { display: block; width: 100%; }
  .ledger thead { display: none; }
  .ledger tr {
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.6rem;
  }
  .ledger td { border: 0; padding: 0.15rem 0; }
  .ledger td.right { text-align: left; font-size: 1.1rem; }
  .whose form { padding-top: 0.4rem; }

  /* Same collapse for the history, so a phone reads one entry per card
     instead of four columns squeezed into a thumb's width. */
  .history, .history tbody, .history tr, .history td { display: block; width: 100%; }
  .history thead { display: none; }
  .history tr {
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.6rem;
  }
  .history td { border: 0; padding: 0.15rem 0; }
  .history td.right { text-align: left; }
  /* The header is gone here, so each balance says which one it is. */
  .history td.balance::before { content: attr(data-label) " "; color: var(--quiet); font-size: 0.85rem; }
}
