/* ══════════════════════════════════════════════════════════════════════════
   Mobile ledger — the Modernist system from the desktop dashboard, rebuilt
   for a thumb. Same tokens: square corners, 2px rules, Archivo 800, teal
   accent, warm red for the opposite pole.

   Two rules drive everything below:
     * nothing interactive is under 48px tall, because this is used one-handed
       and often outdoors;
     * the page never scrolls sideways, whatever the content.
   ══════════════════════════════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@400;600;800&display=swap');

:root {
  --bg: #f3f2f2;
  --surface: #ffffff;
  --surface-2: #eae9e9;
  --text: #201e1d;
  --muted: #605d5d;
  --line: #d7d3d3;
  --line-strong: #201e1d;

  --accent: #0d8fa8;
  --accent-700: #0a7189;
  --accent-100: #eaf8fb;
  --warm: #c94b39;
  --warm-100: #fff2ef;

  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s6: 24px; --s8: 32px;
  --tap: 48px;                       /* the floor for anything touchable */

  /* Kept clear of the home indicator and the notch. */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabbar-h: calc(58px + var(--safe-b));
}

/* Dark tokens live in one place and are applied from two selectors.
 *
 *   - the media query, guarded so an explicit "light" choice still wins;
 *   - the [data-theme="dark"] attribute, so the in-app switch wins in the
 *     other direction, on a phone whose system is set to light.
 *
 * Every colour is defined on bare :root above; nothing has its only definition
 * inside a media query, or the theme would break wherever that query is false. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1918; --surface: #262423; --surface-2: #2f2d2c;
    --text: #f3f2f2; --muted: #a5a1a1; --line: #423f3f; --line-strong: #f3f2f2;
    --accent: #5fc6da; --accent-700: #9fdfeb; --accent-100: #10333c;
    --warm: #e88a78; --warm-100: #3a1c16;
  }
}

:root[data-theme="dark"] {
  --bg: #1a1918; --surface: #262423; --surface-2: #2f2d2c;
  --text: #f3f2f2; --muted: #a5a1a1; --line: #423f3f; --line-strong: #f3f2f2;
  --accent: #5fc6da; --accent-700: #9fdfeb; --accent-100: #10333c;
  --warm: #e88a78; --warm-100: #3a1c16;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Any class that sets `display` outranks the browser's own [hidden] rule, so
   an element hidden in markup would still be painted. Several components here
   set display (.viewer is grid, .screen--login is grid), and the app toggles
   exactly those with .hidden = true. This puts the attribute back in charge. */
[hidden] { display: none !important; }

html, body {
  /* Kills double-tap-to-zoom, which fires on ordinary taps and makes the whole
     app feel like it is fighting you. Deliberately NOT `user-scalable=no` or
     `touch-action: none`: pinch-zoom survives, and it has to -- reading
     someone's handwriting off a photographed page depends on it. */
  touch-action: manipulation;
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.45;
  overflow-x: hidden;                /* the no-sideways-scroll rule */
  -webkit-text-size-adjust: 100%;
}

body { padding-top: var(--safe-t); }

h1, h2, h3 { font-weight: 800; letter-spacing: -0.01em; margin: 0; }

/* ── screens ─────────────────────────────────────────────────────────── */
.screen { padding: 0 var(--s4) calc(var(--tabbar-h) + var(--s8)); }
.screen--login {
  min-height: 100dvh; display: grid; place-items: center; padding-bottom: var(--s8);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); padding: var(--s6) 0 var(--s4);
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 78%, transparent);
}
.topbar__title { font-size: 26px; }
.topbar__action {
  border: 0; background: none; color: var(--accent);
  font: inherit; font-weight: 600; min-height: var(--tap); padding: 0 var(--s2);
  /* Three things share this row now. Without nowrap "Sign out" breaks across
     two lines and drags the header's height with it. */
  white-space: nowrap; flex: 0 0 auto;
}
/* The title is the only flexible item, so it yields first. */
.topbar__title { flex: 1 1 auto; min-width: 0; }

.section-head {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: var(--s8) 0 var(--s3);
}
.lede { color: var(--muted); font-size: 15px; margin: 0 0 var(--s6); }

/* ── sign in ─────────────────────────────────────────────────────────── */
.login { width: 100%; max-width: 380px; padding: var(--s6) var(--s4); }
/* The same lettermark as the app icon, set in type rather than shipped as a
   second image -- so the two cannot drift apart. */
.login__mark {
  width: 64px; height: 64px; background: var(--accent);
  display: grid; place-items: center; margin-bottom: var(--s6);
  color: #fff; font-family: var(--font); font-weight: 800;
  font-size: 30px; letter-spacing: -0.02em;
}
.login__title { font-size: 30px; }
.login__sub { color: var(--muted); margin: var(--s1) 0 var(--s8); }

.people { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.people button {
  min-height: 56px; width: 100%; text-align: left; padding: 0 var(--s4);
  background: var(--surface); color: var(--text);
  border: 2px solid var(--line); font: inherit; font-weight: 600; font-size: 17px;
}
.people button:active { border-color: var(--accent); background: var(--accent-100); }

/* ── forms ───────────────────────────────────────────────────────────── */
.field { display: block; margin-bottom: var(--s6); }
.field__label {
  display: block; font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-bottom: var(--s2);
}
.field__label em { font-style: normal; text-transform: none; letter-spacing: 0;
  font-weight: 400; opacity: 0.75; }

/* Every text-ish input, by exclusion rather than by listing types -- listing
   them meant a new type="tel" field silently rendered unstyled. */
input:not([type="file"]):not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
textarea {
  width: 100%; min-height: var(--tap);
  padding: var(--s3) var(--s4);
  background: var(--surface); color: var(--text);
  border: 2px solid var(--line); border-radius: 0;
  font: inherit; font-size: 17px;          /* 17px: iOS zooms in under 16 */
  appearance: none;
}
input:focus { outline: none; border-color: var(--accent); }
input::placeholder { color: var(--muted); opacity: 0.7; }

.row { display: flex; gap: var(--s3); }
.field--half { flex: 1 1 0; min-width: 0; }

.money { display: flex; align-items: stretch; border: 2px solid var(--line);
         background: var(--surface); }
.money:focus-within { border-color: var(--accent); }
.money input { border: 0; flex: 1 1 auto; min-width: 0; font-size: 22px;
               font-weight: 600; }
.money input:focus { outline: none; }
.money__sym {
  display: grid; place-items: center; padding: 0 var(--s3);
  background: var(--surface-2); color: var(--muted);
  font-size: 18px; font-weight: 600; min-width: 46px;
}

.hint { display: block; font-size: 13px; color: var(--muted); margin-top: var(--s2);
        min-height: 1.2em; }
.hint--centre { text-align: center; }
.error {
  background: var(--warm-100); color: var(--warm); border-left: 4px solid var(--warm);
  padding: var(--s3) var(--s4); font-size: 15px; margin: 0 0 var(--s4);
}

/* ── buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: block; width: 100%; min-height: var(--tap);
  border: 2px solid var(--line-strong); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 700; font-size: 17px;
  padding: var(--s3) var(--s4);
}
.btn--lg { min-height: 56px; font-size: 18px; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:active { background: var(--accent-700); border-color: var(--accent-700); }
.btn--primary[disabled] { opacity: 0.55; }
.btn--quiet { border: 0; background: none; color: var(--accent); font-weight: 600; }
.btn--sm { min-height: 44px; font-size: 15px; width: auto; padding: 0 var(--s4); }

/* ── the book ────────────────────────────────────────────────────────── */
.kpi {
  border: 2px solid var(--line-strong); background: var(--surface);
  padding: var(--s6) var(--s4); margin-bottom: var(--s3);
}
.kpi__label { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em;
              color: var(--muted); }
.kpi__value { font-size: 34px; font-weight: 800; letter-spacing: -0.02em;
              margin-top: var(--s1); overflow-wrap: anywhere; }
.kpi__note { font-size: 14px; color: var(--muted); margin-top: var(--s1); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.tile { background: var(--surface); border: 2px solid var(--line); padding: var(--s3); }
.tile__label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
               color: var(--muted); }
.tile__value { font-size: 19px; font-weight: 700; margin-top: 2px;
               overflow-wrap: anywhere; }

.seg { display: flex; gap: 0; border: 2px solid var(--line); background: var(--surface);
       margin-bottom: var(--s3); }
.seg--wide .seg__btn { flex-direction: column; gap: 0; padding: var(--s2); }
.seg__btn {
  flex: 1 1 0; min-height: var(--tap); border: 0; background: none;
  color: var(--muted); font: inherit; font-weight: 600; font-size: 15px;
  display: flex; align-items: center; justify-content: center; min-width: 0;
}
.seg__btn small { display: block; font-size: 11px; font-weight: 400; opacity: 0.8; }
.seg__btn.is-on { background: var(--accent); color: #fff; }

.search { margin-bottom: var(--s3); }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 60px; padding: var(--s3) 0;
  border-bottom: 2px solid var(--line);
}
/* An expanding counterparty: the <li> becomes the container, and the tappable
   part is the row inside it. */
.list li.party { display: block; padding: 0; }
.list__main { flex: 1 1 auto; min-width: 0; }
.list__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis;
              white-space: nowrap; }
.list__sub { font-size: 13px; color: var(--muted); }
.list__amt { font-weight: 700; font-variant-numeric: tabular-nums;
             text-align: right; white-space: nowrap; }
.pos { color: var(--accent); }    /* you owe them  */
.neg { color: var(--warm); }      /* they owe you  */

.empty { color: var(--muted); text-align: center; padding: var(--s8) var(--s4);
         border: 2px dashed var(--line); }

/* ── uploads ─────────────────────────────────────────────────────────── */
.drop {
  display: grid; place-items: center; min-height: 64px; padding: var(--s4);
  border: 2px dashed var(--line); background: var(--surface);
  color: var(--muted); font-weight: 600; text-align: center;
}
.drop--lg { min-height: 128px; }
.drop:active { border-color: var(--accent); color: var(--accent); }

.thumbs { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }
.thumbs figure { margin: 0; position: relative; }
.thumbs img { width: 76px; height: 76px; object-fit: cover; border: 2px solid var(--line);
              display: block; }
.thumbs button {
  position: absolute; top: -8px; right: -8px; width: 28px; height: 28px;
  border: 2px solid var(--line-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 700; line-height: 1; padding: 0;
}

/* ── review ──────────────────────────────────────────────────────────── */
.card {
  border: 2px solid var(--line); background: var(--surface);
  padding: var(--s4); margin-bottom: var(--s3);
}
.card__head { display: flex; justify-content: space-between; gap: var(--s3);
              align-items: baseline; }
.card__who { font-size: 13px; color: var(--muted); }
.card__amt { font-size: 22px; font-weight: 800; }
.card__meta { font-size: 14px; color: var(--muted); margin-top: var(--s1); }
.card__actions { display: flex; gap: var(--s2); margin-top: var(--s4); }
.card__actions .btn { flex: 1 1 0; }
.pill {
  display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 3px var(--s2); border: 2px solid currentColor;
}
.pill--pending { color: var(--accent); }
.pill--approved { color: var(--accent); background: var(--accent-100); }
.pill--rejected { color: var(--warm); background: var(--warm-100); }

/* ── chrome ──────────────────────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--surface); border-top: 2px solid var(--line-strong);
  padding-bottom: var(--safe-b);
}
.tabbar__btn {
  position: relative; min-height: 58px; border: 0; background: none;
  color: var(--muted); font: inherit; font-size: 10.5px; font-weight: 600;
  padding: 0 2px; overflow: hidden; white-space: nowrap;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
}
.tabbar__ico { font-size: 19px; line-height: 1; }
.tabbar__btn.is-on { color: var(--accent); }
.badge {
  position: absolute; top: 8px; right: 50%; transform: translateX(18px);
  min-width: 19px; height: 19px; padding: 0 5px;
  background: var(--warm); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}

.banner {
  position: fixed; left: 0; right: 0; top: 0; z-index: 30;
  padding: calc(var(--safe-t) + var(--s3)) var(--s4) var(--s3);
  background: var(--line-strong); color: var(--bg);
  font-size: 14px; font-weight: 600; text-align: center;
}
.banner--warn { background: var(--warm); color: #fff; }
.banner--ok { background: var(--accent); color: #fff; }

.stale {
  background: var(--surface-2); border-left: 4px solid var(--muted);
  padding: var(--s2) var(--s3); font-size: 14px; color: var(--muted);
  margin-bottom: var(--s3);
}

.viewer {
  position: fixed; inset: 0; z-index: 40; background: #000;
  display: grid; place-items: center;
}
.viewer img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  /* Explicit here: this is the screen where zooming is the whole point. */
  touch-action: pinch-zoom;
}
.viewer__close {
  position: absolute; top: calc(var(--safe-t) + var(--s3)); right: var(--s4);
  min-height: 44px; padding: 0 var(--s4); background: rgba(255,255,255,0.15);
  color: #fff; border: 2px solid rgba(255,255,255,0.5); font: inherit; font-weight: 700;
}

.spin { opacity: 0.55; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}


/* ── customers ───────────────────────────────────────────────────────── */
.panel {
  border: 2px solid var(--line-strong); background: var(--surface);
  padding: var(--s4); margin-bottom: var(--s6);
}
.panel__title { font-size: 18px; margin-bottom: var(--s4); }

/* The table is wide by nature. It scrolls inside this box so the page itself
   never scrolls sideways, which is the one thing that makes a phone layout
   feel broken. */
.tablewrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 2px solid var(--line); background: var(--surface);
}
.table { border-collapse: collapse; width: 100%; min-width: 620px; font-size: 14px; }
.table th, .table td {
  text-align: left; padding: var(--s3); border-bottom: 2px solid var(--line);
  white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis;
}
.table th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); background: var(--surface-2);
  position: sticky; top: 0; z-index: 1;
}
.table tbody tr:active { background: var(--accent-100); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.name { font-weight: 600; }
.table .dim { color: var(--muted); }
.table tbody tr.is-open { background: var(--accent-100); }


/* ── an expanded counterparty ─────────────────────────────────────────── */
.party__row {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 60px; padding: var(--s3) 0;
}
.party__chev {
  color: var(--muted); font-size: 20px; line-height: 1;
  transition: transform 0.15s ease; flex: 0 0 auto;
}
.party.is-open .party__chev { transform: rotate(90deg); }
.party.is-open .party__row { border-bottom: 2px solid var(--line); }

.party__detail { padding: var(--s3) 0 var(--s4); }
.party__sum {
  font-size: 13px; color: var(--muted); padding: var(--s2) var(--s3);
  background: var(--surface-2); margin-bottom: var(--s2);
}
.party__loading { font-size: 14px; color: var(--muted); padding: var(--s3); }

.entry {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3); background: var(--surface);
  border-left: 2px solid var(--line); margin-bottom: var(--s2);
}
.entry__main { flex: 1 1 auto; min-width: 0; }
.entry__top { display: flex; align-items: baseline; gap: var(--s2); }
.entry__top b { font-size: 16px; font-variant-numeric: tabular-nums; }
.entry__date { font-size: 12px; color: var(--muted); }
.entry__meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.entry__net {
  font-weight: 700; font-variant-numeric: tabular-nums;
  text-align: right; white-space: nowrap; font-size: 14px;
}


/* ── insights ────────────────────────────────────────────────────────── */
.tiles--3 { grid-template-columns: repeat(3, 1fr); }
.tile__note { font-size: 11px; color: var(--muted); margin-top: 1px; }

.chart {
  margin: var(--s8) 0 0; padding: var(--s4);
  border: 2px solid var(--line); background: var(--surface);
}
.chart__t {
  font-family: var(--font); font-weight: 800; font-size: 15px;
  color: var(--text); margin-bottom: var(--s1);
}
.chart__d { font-size: 12.5px; color: var(--muted); margin: 0 0 var(--s4); }
/* Charts are drawn to a 340-unit viewBox and scale to the card; the card, not
   the page, absorbs anything that overflows. */
.chart__c { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.legend {
  display: flex; flex-wrap: wrap; gap: var(--s4);
  font-size: 12px; color: var(--muted); margin-top: var(--s3);
}
.legend i {
  display: inline-block; width: 10px; height: 10px;
  margin-right: 6px; vertical-align: baseline;
}


/* ── theme switch ────────────────────────────────────────────────────── */
/* One control, in the header. The button carries the 48px touch target; the
   track inside it is the part you see, so the switch reads small without
   being small to hit. */
.tgl {
  border: 0; background: none; padding: 0 var(--s1);
  min-height: var(--tap); min-width: 52px;
  display: grid; place-items: center; flex: 0 0 auto;
}
.tgl__track {
  position: relative; display: block; width: 46px; height: 26px;
  background: var(--surface-2); border: 2px solid var(--line);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.tgl__knob {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: var(--muted); transition: transform 0.15s ease, background 0.15s ease;
}
.tgl[aria-checked="true"] .tgl__track {
  background: var(--accent-100); border-color: var(--accent);
}
.tgl[aria-checked="true"] .tgl__knob {
  transform: translateX(20px); background: var(--accent);
}
@media (prefers-reduced-motion: reduce) {
  .tgl__track, .tgl__knob { transition: none; }
}

/* ── name picker on the entry form ───────────────────────────────────── */
.combo { display: flex; align-items: stretch; }
.combo input { flex: 1 1 auto; min-width: 0; }
.combo__btn {
  flex: 0 0 auto; min-width: var(--tap); min-height: var(--tap);
  border: 2px solid var(--line); border-left: 0;
  background: var(--surface-2); color: var(--muted);
  font: inherit; font-size: 18px; line-height: 1;
}
.combo:focus-within .combo__btn { border-color: var(--accent); }

.combo__list {
  list-style: none; margin: 0; padding: 0;
  border: 2px solid var(--accent); border-top: 0;
  background: var(--surface);
  /* Capped so the list never pushes the rest of the form off the screen; it
     scrolls inside itself instead. */
  max-height: 244px; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.combo__list li {
  display: block; min-height: var(--tap); padding: var(--s3) var(--s4);
  border-bottom: 2px solid var(--line); font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.combo__list li:last-child { border-bottom: 0; }
.combo__list li:active,
.combo__list li.is-active { background: var(--accent-100); }
.combo__list .combo__none { color: var(--muted); font-size: 14px; }
.combo__list .combo__new { color: var(--accent); font-weight: 600; }
