/* ─────────────────────────────────────────────────────────────────────────
   Base + components. Everything derives from tokens.css — no raw hex here.

   Cascade discipline: element rules first, then layout, then components,
   then state. Nothing uses !important; if two rules fight, the structure is
   wrong rather than the specificity.
   ───────────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

/* 112.5% of the browser's 16px default = 18px base (plan §5.3, older readers).
   Set as a percentage rather than a fixed px so a resident who has raised their
   browser's font size still gets the increase — the whole rem scale follows. */
html {
  font-size: 112.5%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-ui);
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
}
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-md); }

p { margin: 0; max-width: var(--measure); }

a { color: var(--accent); }

/* Focus is never removed — only restyled. */
:focus-visible {
  outline: var(--focus-ring) solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.ml { font-family: var(--font-ml); }

/* Digits that line up in columns must not jitter. */
.num, table td, table th, .amount, .money {
  font-variant-numeric: tabular-nums;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── layout ────────────────────────────────────────────────────────────── */

.page  { max-width: var(--page-max); margin: 0 auto; padding: var(--s-5) var(--s-4) var(--s-8); }
.page--wide { max-width: var(--wide-max); }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack--lg { gap: var(--s-6); }
.row   { display: flex; align-items: center; gap: var(--s-3); }
.row--between { justify-content: space-between; }
.spacer { flex: 1; }

.rule { border: none; border-top: 1px solid var(--border); margin: 0; }

/* Wide content scrolls inside itself; the body never scrolls sideways. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Inside a scroller, cells must NOT wrap — otherwise a five-column table
   squashes into two-line rows ("July / 2026") instead of scrolling, which is
   both uglier and harder to read than the scroll it was trying to avoid. */
.scroll-x .table th, .scroll-x .table td { white-space: nowrap; }

/* ── app shell ─────────────────────────────────────────────────────────── */

.appbar {
  background: var(--ink);
  color: var(--surface);
  padding: var(--s-3) var(--s-4);
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.appbar__who { font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 500; }
.appbar__who span { opacity: 0.65; font-weight: 400; }
.appbar__action {
  margin-left: auto;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--surface);
  background: none;
  border: 1px solid rgb(255 255 255 / 0.3);
  border-radius: var(--radius);
  padding: var(--s-2) var(--s-3);
  min-height: 36px;
  cursor: pointer;
}
.appbar__action:hover { border-color: rgb(255 255 255 / 0.6); }

/* God-mode banner. Functional, not decorative: it must be impossible to
   forget you are impersonating (plan §5.5). Never dismissible. */
.godbar {
  background: var(--awaiting-wash);
  border-bottom: 2px solid var(--awaiting);
  color: #6B4708;
  padding: var(--s-3) var(--s-4);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}
.godbar__text { font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 600; }
.godbar__actions { margin-left: auto; display: flex; gap: var(--s-2); }
.godbar[hidden] { display: none; }

/* ── type helpers ──────────────────────────────────────────────────────── */

.label {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--ink-muted);
}
.label .ml { font-size: var(--text-sm); letter-spacing: 0; text-transform: none; }

.muted { color: var(--ink-muted); }
.small { font-size: var(--text-sm); }

.amount {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: var(--text-3xl);
  line-height: 1;
  letter-spacing: -0.03em;
}

/* ── buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--touch);
  padding: var(--s-3) var(--s-5);
  border: 1.5px solid transparent;
  border-radius: var(--radius-btn);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  /* Pay is an <a> (it navigates to a upi:// URI), so kill the link underline. */
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition);
}
.btn:hover { text-decoration: none; }
.btn:hover { background: #085839; }
.btn--block { display: flex; width: 100%; }
.btn--lg { min-height: 56px; font-size: var(--text-md); }

.btn--ghost { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn--ghost:hover { background: var(--accent-wash); }

.btn--quiet {
  background: transparent; color: var(--ink-muted); border-color: var(--border-strong);
}
.btn--quiet:hover { background: var(--surface); color: var(--ink); }

.btn--danger { background: var(--overdue); }
.btn--danger:hover { background: #991B1B; }

.btn[disabled], .btn[aria-disabled='true'] {
  background: #EFEEE9; color: var(--ink-muted); border-color: var(--border);
  cursor: not-allowed;
}

.btn--sm { min-height: 40px; padding: var(--s-2) var(--s-4); font-size: var(--text-sm); }

.linkish {
  color: var(--accent); font-weight: 600; text-decoration: none;
  border-bottom: 1px solid var(--accent-line); padding-bottom: 1px; background: none;
  border-left: 0; border-right: 0; border-top: 0; font-family: var(--font-body);
  font-size: inherit; cursor: pointer;
}

/* ── status ────────────────────────────────────────────────────────────── */

/* Colour is never the only signal — every chip carries a dot and a word. */
.chip {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase;
  padding: var(--s-1) var(--s-2); border-radius: var(--radius); border: 1px solid;
}
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip--paid     { color: var(--paid);     background: var(--accent-wash);   border-color: var(--accent-line); }
.chip--awaiting { color: var(--awaiting); background: var(--awaiting-wash); border-color: var(--awaiting-line); }
.chip--overdue  { color: var(--overdue);  background: var(--overdue-wash);  border-color: var(--overdue-line); }
.chip--neutral  { color: var(--ink-muted); background: var(--surface);      border-color: var(--border); }

/* ── surfaces ──────────────────────────────────────────────────────────── */

/* Borders, never shadows. */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-4);
}
.note {
  border-radius: var(--radius); padding: var(--s-3) var(--s-4);
  font-size: var(--text-sm); border: 1px solid;
}
.note--good { background: var(--accent-wash);   border-color: var(--accent-line);   color: #0A4F38; }
.note--warn { background: var(--awaiting-wash); border-color: var(--awaiting-line); color: #6B4708; }
.note--bad  { background: var(--overdue-wash);  border-color: var(--overdue-line);  color: #7F1D1D; }

/* ── tables — the bill breakdown is a ruled document, not a card grid ──── */

.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
/* Horizontal padding matters: without it multi-column headers collide into
   one unreadable word ("USEDRATEAMOUNT"). First and last cells stay flush so
   the table still aligns to the page edge. */
.table th, .table td {
  padding: var(--s-3) var(--s-3);
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child,  .table td:last-child  { padding-right: 0; }
.table th {
  font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.11em; text-transform: uppercase; color: var(--ink-muted);
}
.table .r { text-align: right; font-family: var(--font-ui); }
.table tr.total td {
  border-top: 2px solid var(--ink); border-bottom: none;
  padding-top: var(--s-3); font-family: var(--font-ui); font-weight: 700; font-size: var(--text-md);
}

/* ── forms ─────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field > label { font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 500; }
.field > label .ml { font-weight: 400; color: var(--ink-muted); }

.input {
  width: 100%;
  min-height: var(--touch);
  padding: var(--s-3);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);   /* >=16px, or iOS zooms on focus */
}
.input:focus-visible { border-color: var(--accent); outline-offset: 0; }
.input[readonly], .input[disabled] { background: #F2F1EC; color: var(--ink-muted); }
.input--error { border-color: var(--overdue); background: var(--overdue-wash); }
.input--warn  { border-color: var(--awaiting); background: var(--awaiting-wash); }

/* Errors sit beside their field, and say how to fix it. */
.field__hint { font-size: var(--text-xs); color: var(--ink-muted); }
.field__error { font-size: var(--text-xs); color: var(--overdue); font-weight: 600; }

/* ── bottom navigation ─────────────────────────────────────────────────── */

/* Fixed, thumb-reachable, and role-driven (see js/nav.js). The portal shipped
   without any navigation at all; this is the way between the screens. */
.bottomnav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 90;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  /* Clears the iPhone home indicator. */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottomnav__item {
  flex: 1;
  min-height: var(--touch);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--s-2) var(--s-1);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-muted);
  text-decoration: none;
  /* Reserve the indicator's space in both states so nothing shifts on nav. */
  border-top: 2px solid transparent;
}
.bottomnav__item:hover { color: var(--ink); }

/* Current location carries a label, a colour AND a rule — never colour alone. */
.bottomnav__item.is-current {
  color: var(--accent);
  border-top-color: var(--accent);
  font-weight: 600;
}

/* Fixed bars hide content underneath unless the page reserves room. */
.has-bottomnav .page { padding-bottom: calc(var(--s-8) + 56px); }
.has-bottomnav .footbar { bottom: calc(56px + env(safe-area-inset-bottom, 0)); }

@media (min-width: 900px) {
  /* On a desktop the bar sits at the top, where a menu is expected. */
  .bottomnav { position: sticky; inset: 0 0 auto 0; border-top: none; border-bottom: 1px solid var(--border); }
  .bottomnav__item { flex: 0 0 auto; flex-direction: row; gap: var(--s-2); padding: var(--s-3) var(--s-4);
                     border-top: none; border-bottom: 2px solid transparent; }
  .bottomnav__item.is-current { border-bottom-color: var(--accent); }
  .has-bottomnav .page { padding-bottom: var(--s-8); }
  .has-bottomnav .footbar { bottom: 0; }
}
