/* Sized for a 65-year-old holding a phone in a shop, not for a designer's
   screenshot. Body text is 18px, buttons are 20px and at least 60px tall,
   contrast is near-maximum, and nothing important is conveyed by colour
   alone — every red line also carries a symbol and a word. */

:root {
  --ink: #111418;
  --ink-soft: #4a5560;
  --line: #d4dae0;
  /* --bg is the card, --bg-soft the page behind it. The card is the lighter
     of the two, and stays the lighter of the two in dark mode as well — the
     relationship is what people read, not the absolute value. */
  --bg: #ffffff;
  --bg-soft: #f4f6f8;
  --brand: #14532d;
  --brand-ink: #ffffff;
  --danger: #a8121b;
  --danger-bg: #fdeced;
  --warn: #8a5300;
  --warn-bg: #fdf3e2;
  --ok: #14532d;
  --ok-bg: #e8f3ec;
  --on-brand-wash: rgba(255, 255, 255, 0.14);
  --on-brand-wash-active: rgba(255, 255, 255, 0.3);
  --on-danger: #ffffff;
  --toast-bg: #1d2733;
  --toast-ink: #ffffff;
  --radius: 12px;
  --tap: 60px;
}

/* ── Dark ─────────────────────────────────────────────────────────────────
   Chosen, not inverted. Three things drove it:

   * The page is a very dark blue-grey rather than black, and the text a soft
     white rather than pure. Pure white on pure black smears for older eyes —
     the effect gets worse with age, and this app is for two people in their
     sixties reading it at 5am before a delivery run.
   * The top bar and primary buttons stay *dark* green. Lifting the brand to
     a pale green would put a glaring band across the top of every screen,
     which is the opposite of why anyone turns dark mode on.
   * --ok diverges from --brand here. They share a value in light mode by
     coincidence: one is a background, one is text on a dark green wash, and
     in dark mode those need to go opposite ways.

   The viewer has three states, not two. A bare `prefers-color-scheme` block
   would be overridden by nothing when someone picks light explicitly, so the
   media query is guarded and the explicit choice is repeated below. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e8ecf1;
    --ink-soft: #a3aeba;
    --line: #333b45;
    --bg: #1b212a;
    --bg-soft: #12161b;
    --brand: #1d6b3c;
    --brand-ink: #ffffff;
    --danger: #ff9aa2;
    --danger-bg: #2c1417;
    --warn: #f0c07a;
    --warn-bg: #2b2114;
    --ok: #74c98f;
    --ok-bg: #16281d;
    --on-brand-wash: rgba(255, 255, 255, 0.16);
    --on-brand-wash-active: rgba(255, 255, 255, 0.32);
    --on-danger: #2c1417;
    --toast-bg: #eef2f6;
    --toast-ink: #12161b;
  }
}

/* The explicit choice, which must beat the phone's setting in both
   directions. */
:root[data-theme="dark"] {
  --ink: #e8ecf1;
  --ink-soft: #a3aeba;
  --line: #333b45;
  --bg: #1b212a;
  --bg-soft: #12161b;
  --brand: #1d6b3c;
  --brand-ink: #ffffff;
  --danger: #ff9aa2;
  --danger-bg: #2c1417;
  --warn: #f0c07a;
  --warn-bg: #2b2114;
  --ok: #74c98f;
  --ok-bg: #16281d;
  --on-brand-wash: rgba(255, 255, 255, 0.16);
  --on-brand-wash-active: rgba(255, 255, 255, 0.32);
  --on-danger: #2c1417;
  --toast-bg: #eef2f6;
  --toast-ink: #12161b;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 18px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg-soft);
  /* Room for the phone's home indicator so the last button is never cut off. */
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Chrome ──────────────────────────────────────────────────────────── */

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--brand);
  color: var(--brand-ink);
}

#title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  min-width: 48px;
  min-height: 48px;
  font-size: 24px;
  border: 0;
  border-radius: var(--radius);
  background: var(--on-brand-wash);
  color: inherit;
  cursor: pointer;
}
.icon-btn:active { background: var(--on-brand-wash-active); }
.icon-btn[hidden] { display: none; }

main { padding: 12px; max-width: 720px; margin: 0 auto; }

.pad { padding: 16px; }

/* ── Type ────────────────────────────────────────────────────────────── */

h2 { font-size: 22px; margin: 4px 0 12px; }
h3 { font-size: 19px; margin: 18px 0 8px; }

.cn { display: block; }
.en { display: block; font-size: 0.78em; opacity: 0.75; font-weight: 400; }

.muted { color: var(--ink-soft); }
.small { font-size: 15px; }
.right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }
/* Shrinks rather than wrapping. At a flat 30px, "RM 1,231.60" beside its
   label breaks after "RM" on a 320px screen, and a money figure split across
   two lines is briefly unreadable as a number — which is the one thing this
   style exists to prevent. */
.big-money {
  font-size: clamp(22px, 7.2vw, 30px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── Home grid ───────────────────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.tile {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  min-height: 104px;
  padding: 12px 8px;
  font-size: 19px;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.tile:active { background: var(--bg-soft); }
.tile .emoji { font-size: 30px; line-height: 1; }

/* Count of things that need attention, on the tile itself. Sized to be
   readable at arm's length by someone who is not looking for it — this is a
   number that has to be noticed without being sought. `position: relative`
   goes on the tile so the badge hangs off its own corner. */
.tile { position: relative; }
.tile .badge {
  position: absolute;
  top: -10px;
  right: -6px;
  min-width: 34px;
  padding: 4px 9px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--on-danger);
  background: var(--danger);
  border: 2px solid var(--bg);
  border-radius: 999px;
}
.tile .badge[hidden] { display: none; }

/* ── Cards and lists ─────────────────────────────────────────────────── */

.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
}
.row + .row { border-top: 1px solid var(--line); }

.list { list-style: none; margin: 0; padding: 0; }

.list-item {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 18px;
  text-align: left;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.list-item:active { background: var(--bg-soft); }
.list-item strong { display: block; font-size: 19px; }

/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 14px;
  margin-top: 12px;
  font-size: 20px;
  font-weight: 600;
  font-family: inherit;
  color: var(--brand-ink);
  background: var(--brand);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn:active { filter: brightness(1.2); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.btn.secondary { color: var(--ink); background: var(--bg); border: 2px solid var(--line); }
.btn.danger { background: var(--danger); }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }

.chip {
  min-width: 62px;
  min-height: 52px;
  padding: 8px 14px;
  font-size: 19px;
  font-family: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.chip[aria-pressed="true"] { color: var(--brand-ink); background: var(--brand); border-color: var(--brand); }

/* ── Forms ───────────────────────────────────────────────────────────── */

label { display: block; margin: 14px 0 6px; font-weight: 600; }

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px;
  font-size: 19px;
  font-family: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}
/* A password box and the button that reveals it. The button sits inside the
   box's right edge, and the box is padded so the text never runs under it —
   a password that disappears behind the very control meant to show it is a
   particular kind of insult. */
.reveal-wrap { position: relative; display: block; }
.reveal-wrap input { padding-right: calc(var(--tap) + 4px); }
.reveal {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  /* Full-height tap target: this is pressed by people who find small keys
     hard, which is the whole reason it exists. */
  width: var(--tap);
  height: calc(var(--tap) - 12px);
  padding: 0;
  font-size: 24px;
  line-height: 1;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.reveal:active { background: var(--bg-soft); }

input:focus, select:focus, textarea:focus {
  outline: 3px solid var(--brand);
  outline-offset: 1px;
}

/* ── Status lines ────────────────────────────────────────────────────── */

.note {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  padding: 12px;
  margin: 8px 0;
  border-radius: var(--radius);
  border-left: 6px solid;
}

/* The mark is a label, not prose. As a plain flex child it shrank below its
   own content and broke mid-word: on a 320px phone "🟠 注意 CHECK" came out
   as "🟠 注" above "意 CHECK", which is exactly the line a founder is meant
   to read fastest. */
.note > :first-child { flex: 0 0 auto; }

/* And once the mark holds its width there may be too little left for the
   message, so rather than squeezing it into a column a few characters wide,
   it drops to its own full-width line. Side by side when there is room,
   stacked when there is not. */
.note > :last-child { flex: 1 1 11rem; }
.note.blocker { color: var(--danger); background: var(--danger-bg); border-color: var(--danger); }
.note.warning { color: var(--warn);   background: var(--warn-bg);   border-color: var(--warn); }
.note.info    { color: var(--ink);    background: var(--bg-soft);   border-color: var(--ink-soft); }
.note.ok      { color: var(--ok);     background: var(--ok-bg);     border-color: var(--ok); }
/* An author `display` beats the browser's own `[hidden] { display: none }`,
   so a hidden note kept rendering as an empty coloured bar. On the sign-in
   screen that was a red stripe under the password box announcing an error
   that had not happened. */
.note[hidden] { display: none; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}
.pill.bad { color: var(--danger); background: var(--danger-bg); border-color: var(--danger); }
.pill.good { color: var(--ok); background: var(--ok-bg); border-color: var(--ok); }

/* Section headings inside a long list — "Overdue", "Today", "Tomorrow".
   The rule above the heading is what stops one pile running into the next
   on a phone, where the whole list is one narrow column. */
.group-heading {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 2px solid var(--line);
  align-items: center;
}
.group-heading h3 { margin: 0; }

/* ── Toast ───────────────────────────────────────────────────────────── */

#toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 50;
  padding: 16px;
  font-size: 18px;
  color: var(--toast-ink);
  background: var(--toast-bg);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}
#toast[hidden] { display: none; }
#toast.bad { color: var(--on-danger); background: var(--danger); }

.spinner { padding: 30px; text-align: center; color: var(--ink-soft); }

@media (prefers-reduced-motion: no-preference) {
  .list-item, .tile, .btn { transition: background 90ms linear; }
}

/* ── Charts ──────────────────────────────────────────────────────────────
   Hand-drawn inline SVG; see js/charts.js for why there is no library. The
   rule these all follow: the shape is a summary, never the only place a
   number appears, because a bar on a 320px screen cannot be read to the
   ringgit and nobody should have to try. */

.chart { margin: 6px 0 2px; }
.chart svg { display: block; width: 100%; }
.chart-scale {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 2px;
}

.ranked { display: flex; flex-direction: column; gap: 12px; }
.ranked-row { display: flex; flex-direction: column; gap: 4px; }
.ranked-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
/* The name gives way before the number does: a truncated customer name is
   still recognisable, a truncated amount is misinformation. */
.ranked-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
}
.ranked-value { flex: 0 0 auto; font-size: 17px; font-weight: 700; }
.ranked-track {
  height: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.ranked-fill { height: 100%; background: var(--brand); border-radius: 999px; }
.ranked-fill.bad { background: var(--danger); }
.ranked-sub { margin-top: 1px; }

.progress-wrap { margin: 10px 0 4px; display: flex; flex-direction: column; gap: 6px; }
.progress-track {
  height: 18px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--brand); border-radius: 999px; }

.big-money.bad { color: var(--danger); }

/* Inline danger text, for the auditor's screens where a count being non-zero
   is itself the finding — a failed sign-in tally, a refused request. Distinct
   from `.note.blocker`, which is a whole box and would drown a list. */
.small.danger { color: var(--danger); }

/* Long unbroken tokens must wrap rather than widen the page. API paths like
   `/api/customers/{id}/migration-card` have no spaces, and a browser will
   happily push the viewport out to fit one — which on a 320px screen means
   every other screen scrolls sideways too. `anywhere` rather than
   `break-word` because the latter still refuses to split a single long
   token when it is the only thing on the line. */
.list-item strong,
.list-item span,
.ranked-name,
.ranked-sub {
  overflow-wrap: anywhere;
}

/* Short explanatory lists on the auditor screens. */
ul.plain { margin: 6px 0 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 8px; }
ul.plain li { line-height: 1.45; }
