/* Bookkeeping — phone-first, light. Big targets because this gets used standing
   in a driveway holding a receipt, not sitting at a desk.

   The palette is warm paper rather than pure white: a full-brightness #fff phone
   screen is what you are holding outdoors, and the off-white takes the glare off
   without costing any contrast. Deposits are green, expenses are rust, and the
   two are never distinguished by colour ALONE — every amount carries a + or −
   and the row says which it is. */

:root {
  --bg:        #f6f4ef;   /* warm paper */
  --card:      #ffffff;
  --card-2:    #faf8f4;   /* input fill */
  --line:      #e3ddd2;
  --line-firm: #cec7b9;
  --ink:       #23272c;
  --ink-dim:   #6f6960;
  --accent:    #1f6f6b;   /* deep teal — reads as "ledger", not "startup" */
  --accent-in: #ffffff;
  --in:        #1a7f4f;   /* money in  */
  --out:       #b0492e;   /* money out */
  --danger:    #b0492e;
  --moongate:  #3f6fb0;
  --lpre:      #2f8f63;
  --escrow:    #7a5aa8;
  --trust:     #a8791f;
  --radius:    14px;
  --shadow:    0 1px 2px rgba(35, 39, 44, .05), 0 4px 14px rgba(35, 39, 44, .05);
}

* { box-sizing: border-box; }

/* ⚠️ KEEP THIS. The browser hides `[hidden]` with a UA-stylesheet rule of
   `display: none`, and ANY author rule that sets `display` beats it regardless
   of specificity. So the moment an element gets `display: flex` or
   `display: inline-block` in this file, its `hidden` attribute silently stops
   working — and JS setting `el.hidden = true` does nothing.
   It had already bitten twice: the full-screen picture viewer rendered on load
   as an undismissable dark overlay, and the Cancel button sat under Save from
   the very first version. Neither is visible to a test that only asserts the
   markup exists. One global rule beats remembering per element. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  background: rgba(246, 244, 239, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: .01em; }
.brand.big { font-size: 26px; margin-bottom: 4px; }
.signout { color: var(--ink-dim); text-decoration: none; font-size: 15px; }

main { max-width: 620px; margin: 0 auto; padding: 16px 14px 60px; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin-bottom: 18px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 15px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-dim);
}

/* ------------------------------------------------- expense / deposit toggle */

.kind-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: 5px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 18px;
}
.kind-option {
  position: relative;
  display: block; text-align: center;
  padding: 12px 8px;
  border-radius: 8px;
  font-size: 16px; font-weight: 600;
  color: var(--ink-dim);
  cursor: pointer;
}
.kind-option input { position: absolute; opacity: 0; pointer-events: none; }
.kind-option.out:has(input:checked) { background: var(--out); color: #fff; }
.kind-option.in:has(input:checked)  { background: var(--in);  color: #fff; }

/* ----------------------------------------------------------------- fields */

.field { margin-bottom: 14px; }
.field label {
  display: block; margin-bottom: 6px;
  font-size: 14px; color: var(--ink-dim);
}
/* The entity question, which is the one people get wrong -- and the one that is
   unrecoverable if they do, since nothing else in the row identifies the book. */
.field label.big-label {
  font-size: 19px; font-weight: 600; color: var(--ink);
  margin-bottom: 10px;
}
.opt { opacity: .7; }

input[type=text], input[type=date], input[type=password],
input[type=search], select {
  width: 100%;
  padding: 13px 12px;
  font-size: 17px;                 /* 17px+ stops iOS zooming the page on focus */
  color: var(--ink);
  background: var(--card-2);
  border: 1px solid var(--line-firm);
  border-radius: 10px;
  appearance: none;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 107, .15);
}
::placeholder { color: #a49d92; }

.row { display: flex; gap: 12px; }
.row .field { flex: 1; }
.amount-field { flex: 1.3; }

.amount-wrap { position: relative; }
.amount-wrap .dollar {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--ink-dim); font-size: 22px;
}
.amount-wrap input {
  padding-left: 30px;
  font-size: 26px; font-weight: 600;
  letter-spacing: .01em;
}

select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' stroke='%236f6960' stroke-width='1.8' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}

/* --------------------------------------------------------- entity picker */

.entity-picker { display: grid; gap: 8px; }
.entity-option {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 14px;
  background: var(--card-2);
  border: 1px solid var(--line-firm);
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
}
.entity-option input { accent-color: var(--accent); width: 20px; height: 20px; margin: 0; }
.entity-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(31, 111, 107, .08);
}

/* ------------------------------------------------------------------ photo */

.photo-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%;
  padding: 18px 15px;
  background: var(--card-2);
  border: 1px dashed var(--line-firm);
  border-radius: 10px;
  color: var(--ink);
  cursor: pointer;
  font-size: 17px; font-weight: 600;
  font-family: inherit;
}
.photo-btn:active { border-color: var(--accent); background: #f2efe8; }
.photo-btn .photo-icon { font-size: 22px; line-height: 1; }

/* The quieter second option — a receipt photographed earlier still needs a way
   in, but the camera is the common case and gets the big button. */
.photo-alt {
  display: block; width: 100%;
  margin-top: 8px; padding: 10px;
  background: none; border: 0;
  color: var(--accent); font-size: 15px; font-family: inherit;
  cursor: pointer; text-align: center;
}

/* Two quiet options side by side. The camera is the common case and keeps the
   big button; these are for a photo taken earlier and for an emailed invoice. */
.photo-alts { display: flex; gap: 8px; }
.photo-alts .photo-alt { flex: 1; }

/* An attachment with no thumbnail — a spreadsheet, or a PDF poppler could not
   render. Same size and shape as a picture so the strip stays one row of
   equal tiles rather than two kinds of thing. */
.file-tile {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px;
  width: 96px; height: 96px; padding: 6px;
  border: 1px solid var(--line-firm); border-radius: 10px;
  background: var(--card-2); cursor: pointer;
}
.file-tile .file-icon { font-size: 26px; line-height: 1; }
.file-tile .file-name {
  font-size: 11px; color: var(--ink-dim); text-align: center;
  line-height: 1.2; word-break: break-word;
}

/* A tile that opens the file itself rather than the picture viewer. The corner
   badge says so before it is tapped -- without it a rendered PDF first page is
   indistinguishable from a photograph. */
.doc-link { display: block; position: relative; text-decoration: none; }
.doc-link::after {
  content: '📄';
  position: absolute; right: 3px; bottom: 3px;
  font-size: 13px; line-height: 1;
  background: rgba(255, 255, 255, .92);
  border-radius: 4px; padding: 1px 3px;
}

/* The same thing inside a ledger row. */
.file-pill {
  display: inline-flex; align-items: center;
  padding: 6px 10px;
  border: 1px solid var(--line-firm); border-radius: 7px;
  background: var(--card-2); color: var(--ink-dim);
  font-size: 13px; text-decoration: none;
}
/* Attached pictures. Big enough to recognise at arm's length -- these are read
   by someone checking they photographed the right slip, not browsed. */
.photo-strip { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.photo-strip:empty { display: none; }

.photo-chip { position: relative; }
.photo-chip img {
  display: block; width: 96px; height: 96px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--line-firm);
  background: var(--card-2);
  cursor: pointer;
}
.photo-chip .drop {
  position: absolute; top: -8px; right: -8px;
  width: 30px; height: 30px;           /* a comfortable tap target, not 16px */
  display: grid; place-items: center;
  background: var(--card); color: var(--danger);
  border: 1px solid var(--line-firm); border-radius: 50%;
  font-size: 16px; line-height: 1; cursor: pointer;
  box-shadow: var(--shadow);
}

.scan-hint {
  margin-top: 8px;
  font-size: 14px; color: var(--ink-dim);
}

/* ----------------------------------------------------------------- viewer */

.viewer {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 22, 26, .94);
  padding: 16px;
}
.viewer img {
  max-width: 100%; max-height: 100%;
  border-radius: 8px;
}
.viewer-close {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 16px;
  width: 46px; height: 46px;
  background: rgba(255, 255, 255, .12); color: #fff;
  border: 0; border-radius: 50%;
  font-size: 22px; cursor: pointer;
}
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 72px;
  background: rgba(255, 255, 255, .12); color: #fff;
  border: 0; border-radius: 10px;
  font-size: 34px; line-height: 1; cursor: pointer;
}
.viewer-nav.prev { left: 10px; }
.viewer-nav.next { right: 10px; }
.viewer-count {
  position: absolute; bottom: calc(18px + env(safe-area-inset-bottom));
  color: #fff; font-size: 15px; opacity: .85;
}

/* Thumbnails inside a ledger row. */
.item .shots { display: flex; gap: 6px; margin-top: 8px; }
.item .shots img {
  width: 52px; height: 52px; object-fit: cover;
  border-radius: 7px; border: 1px solid var(--line-firm); cursor: pointer;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-block;
  padding: 14px 18px;
  font-size: 17px; font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-in); }
.btn.primary:disabled { opacity: .55; }
/* The save button takes the colour of the direction being saved, so the last
   thing under your thumb still says which way the money went. */
.btn.primary.is-deposit { background: var(--in); }
.btn.ghost { background: transparent; color: var(--ink-dim); border-color: var(--line-firm); }
.btn.export { background: var(--card-2); color: var(--ink); border-color: var(--line-firm); }
.btn.wide, .form-actions .primary { width: 100%; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.form-actions .ghost { flex: 0 0 auto; }

.form-error {
  padding: 11px 13px; margin-bottom: 12px;
  background: #fdf0ec;
  border: 1px solid #edc4b8;
  border-radius: 9px;
  color: #8f3722; font-size: 15px;
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 50;
  padding: 12px 18px;
  background: var(--ink); color: #fff;
  border-radius: 999px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(35, 39, 44, .25);
}

/* ---------------------------------------------------------------- filters */

.filters { display: grid; gap: 10px; margin-bottom: 16px; }
.filters .field { margin: 0; }
.filter-actions { display: flex; gap: 10px; }
.filter-actions .btn { flex: 1; padding: 12px; font-size: 15px; }

/* ----------------------------------------------------------------- totals */

.totals {
  display: grid; gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 16px;
}
.total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 13px;
  background: var(--card);
  font-size: 15px;
}
.total-row .label { color: var(--ink-dim); display: flex; align-items: center; gap: 8px; }
.total-row .value { font-variant-numeric: tabular-nums; font-weight: 600; }
.total-row .sub { color: var(--ink-dim); font-weight: 500; font-size: 13px; margin-left: 8px; }
.total-row.summary { background: var(--card-2); }
.total-row.grand { background: #eef1ec; }
.total-row.grand .label, .total-row.grand .value { color: var(--ink); font-size: 17px; font-weight: 700; }
.value.pos { color: var(--in); }
.value.neg { color: var(--out); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
/* Index order follows store.ENTITIES. */
.dot.e0 { background: var(--moongate); }
.dot.e1 { background: var(--lpre); }
.dot.e2 { background: var(--escrow); }
.dot.e3 { background: var(--trust); }

/* ------------------------------------------------------------------- list */

.list { display: grid; gap: 1px; background: var(--line);
        border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.list:empty { display: none; }

.item {
  display: grid;
  grid-template-columns: 9px 1fr auto;
  gap: 11px; align-items: start;
  padding: 13px;
  background: var(--card);
}
.item .stripe { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; }
.item .what { font-weight: 600; }
.item .meta { color: var(--ink-dim); font-size: 14px; margin-top: 3px; }
.item .amt {
  font-variant-numeric: tabular-nums; font-weight: 650; font-size: 17px;
  white-space: nowrap;
}
.item .amt.pos { color: var(--in); }
.item .amt.neg { color: var(--out); }
.item .actions { display: flex; gap: 14px; margin-top: 8px; font-size: 14px; }
.item .actions a, .item .actions button {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent); font-size: 14px; text-decoration: none;
}
.item .actions .del { color: var(--danger); }

.empty { padding: 22px 14px; text-align: center; color: var(--ink-dim); background: var(--card); }

/* ------------------------------------------------------------------ login */

.login-wrap { min-height: 100svh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.tagline { color: var(--ink-dim); font-size: 14px; margin: 0 0 20px; }

/* --- Transfers in the phone list -------------------------------------------
   A transfer is money moving between two accounts we own. It is shown so the
   ledger is complete, but it is NEUTRAL: it is neither income nor an expense,
   and colouring it green or rust would put it in a category it does not belong
   to. Editing happens on the Ledger page, where both legs move together. */

.item.is-transfer { background: var(--card-2); }

.amt.neutral { color: var(--ink-dim); }

.tag {
  display: inline-block;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  padding: .1rem .4rem;
  border-radius: 999px;
  background: #ece7dd;
  color: var(--ink-dim);
  margin-left: .35rem;
  vertical-align: middle;
}

/* The one link off the entry screen. Deliberately quiet and in the top bar,
   not in the form: the form itself gains nothing — no field, no button, no
   decision — from the desk pages existing. */
.topbar .deskline {
  margin-left: auto;
  margin-right: .9rem;
  color: var(--ink-dim);
  text-decoration: none;
  font-weight: 600;
  font-size: .95rem;
}
