/*
 * Faturas, portal dos pais.
 *
 * Written for two people in their seventies reading a phone at arm's length: nothing below
 * 17px, nothing that needs a steady finger, and no meaning carried by colour alone. Every
 * choice here has a reason, and where the reason is not obvious it is written down.
 *
 * Self-hosted by construction: the font is whatever the phone already has, and this file
 * fetches nothing. No web font, no icon set, no background image, no import. A page showing a
 * family's finances should make exactly zero requests to anybody else, and a test asserts it.
 */

/* ------------------------------------------------------------------ tokens */

:root {
  --bg: #ffffff;
  --surface: #f5f7f9;
  --ink: #14161a;
  --ink-2: #565c63;
  --pay: #0a5c33;
  --pay-ink: #ffffff;
  --accent: #0b5490;
  --accent-soft: #e8f0f8;
  --alert: #a81414;
  --alert-soft: #fdecec;
  --rule: #d9dde1;
  --filet: #1ea0fa;

  --hero: clamp(40px, 12vw, 72px);
  --title: 30px;
  --row: 22px;
  --body: 19px;
  --meta: 17px;

  --gutter: 20px;
  --radius-card: 12px;
  --radius-btn: 16px;
  --tap: 64px;
  --tap-primary: 72px;
  --paybar: 76px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2026;
    --ink: #f2f4f7;
    --ink-2: #a8b0b8;
    --pay: #2e9e63;
    --pay-ink: #04140b;
    --accent: #7fc4ff;
    --accent-soft: #1d2a35;
    --alert: #ff8a8a;
    --alert-soft: #2c1a1a;
    --rule: #2a2f36;
  }
}

/* ------------------------------------------------------------------ base */

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

html {
  /* text-size-adjust is deliberately not set: the phone's own font scaling must win. */
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--body);
  line-height: 1.5;
  overflow-wrap: break-word;
}

.wrap {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

main {
  display: block;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
  font-weight: 700;
}

h1 {
  font-size: var(--title);
}

h2 {
  font-size: var(--row);
}

p {
  margin: 0 0 12px;
}

p:last-child {
  margin-bottom: 0;
}

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

/* Never removed, on anything. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  position: static;
  display: block;
  padding: 12px var(--gutter);
  background: var(--accent-soft);
  color: var(--ink);
}

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

.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ------------------------------------------------------------------ chrome */

.masthead {
  border-top: 6px solid var(--filet);
  padding: 16px 0 8px;
}

.masthead-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
}

.brand {
  font-size: var(--row);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}

.who {
  font-size: var(--meta);
  color: var(--ink-2);
}

/*
 * Adjacent-sibling rather than :first-of-type. The bands are a mix of <div> and <section>
 * depending on whether they have a heading, and :first-of-type counts per element name, so it
 * silently swallowed the divider above the first <section>.
 */
.band {
  padding: 24px 0;
}

.band + .band {
  border-top: 1px solid var(--rule);
}

.band[hidden] + .band {
  border-top: 0;
}

.band-title {
  font-size: var(--row);
  font-weight: 700;
  margin: 0 0 12px;
}

.lede {
  font-size: var(--body);
  color: var(--ink-2);
}

.meta {
  font-size: var(--meta);
  line-height: 1.4;
  color: var(--ink-2);
}

/* ------------------------------------------------------------------ hero */

.hero {
  font-size: var(--hero);
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.hero-note {
  font-size: var(--body);
  color: var(--ink-2);
  margin-top: 8px;
}

.status {
  display: inline-block;
  margin-top: 12px;
  padding: 4px 16px;
  border-radius: 999px;
  font-size: var(--meta);
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--rule);
}

.status.is-paid {
  background: var(--pay);
  color: var(--pay-ink);
  border-color: var(--pay);
}

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

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 20px;
  border: 2px solid var(--rule);
  border-radius: var(--radius-btn);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: var(--row);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn + .btn {
  margin-top: 12px;
}

.btn-primary {
  min-height: var(--tap-primary);
  background: var(--pay);
  border-color: var(--pay);
  color: var(--pay-ink);
}

.btn-quiet {
  border-color: var(--rule);
  color: var(--accent);
}

.btn[disabled] {
  opacity: 1;
  color: var(--ink-2);
  background: var(--surface);
  border-color: var(--rule);
  cursor: default;
}

.btn-group {
  margin-top: 24px;
}

/* ------------------------------------------------------------------ forms */

.field {
  margin: 0 0 24px;
}

.label {
  display: block;
  font-size: var(--body);
  font-weight: 600;
  margin-bottom: 8px;
}

.hint {
  font-size: var(--meta);
  color: var(--ink-2);
  margin-bottom: 8px;
}

.input {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 16px;
  border: 2px solid var(--ink-2);
  border-radius: var(--radius-btn);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: var(--row);
}

.input-phone {
  font-variant-numeric: tabular-nums;
}

.input-code {
  font-size: 32px;
  letter-spacing: 8px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.prefix-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.prefix {
  display: flex;
  align-items: center;
  padding: 0 16px;
  border: 2px solid var(--rule);
  border-radius: var(--radius-btn);
  background: var(--surface);
  font-size: var(--row);
  font-weight: 600;
  white-space: nowrap;
}

.checkbox {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-height: var(--tap);
  padding: 12px 0;
  font-size: var(--body);
  cursor: pointer;
}

.checkbox input {
  width: 28px;
  height: 28px;
  margin: 2px 0 0;
  accent-color: var(--pay);
  flex: 0 0 auto;
}

.notice,
.error {
  margin: 0 0 24px;
  padding: 16px;
  border-radius: var(--radius-card);
  font-size: var(--body);
  border: 2px solid;
}

.notice {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}

.error {
  background: var(--alert-soft);
  border-color: var(--alert);
  color: var(--ink);
}

.error strong,
.notice strong {
  display: block;
}

/* ------------------------------------------------------------------ bands: onde foi */

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

.band-row {
  display: block;
  min-height: var(--tap);
  padding: 12px 0;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}

.bands li:last-child .band-row {
  border-bottom: 0;
}

.band-head {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  align-items: baseline;
  margin-bottom: 8px;
}

.band-label {
  font-size: var(--row);
  font-weight: 600;
}

/*
 * No nowrap here: this is "R$ 2.680,85 · 80%", two values with a separator, and at 200% zoom
 * it has to be allowed to break at the middle dot rather than push the page sideways.
 */
.band-value {
  margin-left: auto;
  font-size: var(--body);
  color: var(--ink-2);
}

.bar {
  display: block;
  height: 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--rule);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  min-width: 4px;
  background: var(--accent);
  border-radius: 999px;
}

.band-row[aria-current="true"] .bar-fill {
  background: var(--pay);
}

.band-row[aria-current="true"] .band-label::after {
  content: " (filtrando)";
  font-size: var(--meta);
  font-weight: 400;
  color: var(--ink-2);
}

.filter-note {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  font-size: var(--body);
}

/* ------------------------------------------------------------------ lists */

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

.rows > li {
  border-bottom: 1px solid var(--rule);
}

.rows > li:last-child {
  border-bottom: 0;
}

.entry {
  display: block;
}

.entry > summary {
  display: block;
  list-style: none;
  min-height: var(--tap);
  padding: 12px 0;
  cursor: pointer;
}

.entry > summary::-webkit-details-marker {
  display: none;
}

.row-main {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  align-items: baseline;
}

.row-desc {
  font-size: var(--row);
  font-weight: 600;
  line-height: 1.35;
}

.row-value {
  margin-left: auto;
  font-size: var(--row);
  font-weight: 600;
  white-space: nowrap;
}

.row-value.is-credit {
  color: var(--pay);
}

.row-meta {
  display: block;
  margin-top: 2px;
  font-size: var(--meta);
  line-height: 1.4;
  color: var(--ink-2);
}

.more {
  margin: 0 0 16px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-card);
  font-size: var(--meta);
}

/*
 * Stacked by default and only two columns once there is room. A label-and-value grid is nicer
 * to read, but at 200% zoom on a 360px phone the value column drops below the width of the
 * word "sexta-feira" and the text walks off the right edge, unreachable because the page
 * itself must never scroll sideways.
 */
.more dl {
  margin: 0;
}

.more dt {
  color: var(--ink-2);
}

.more dd {
  margin: 0 0 12px;
  overflow-wrap: anywhere;
}

.more dd:last-child {
  margin-bottom: 0;
}

@media (min-width: 420px) {
  .more dl {
    display: grid;
    grid-template-columns: minmax(9ch, max-content) 1fr;
    gap: 4px 16px;
  }

  .more dd {
    margin: 0;
  }
}

.group > summary {
  display: block;
  list-style: none;
  min-height: var(--tap);
  padding: 12px 0;
  cursor: pointer;
}

.group > summary::-webkit-details-marker {
  display: none;
}

.disclosure {
  font-size: var(--meta);
  color: var(--accent);
  text-decoration: underline;
}

/* ------------------------------------------------------------------ extras */

.extra-kind {
  display: inline-block;
  margin-left: 8px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: var(--meta);
  font-weight: 600;
  background: var(--pay);
  color: var(--pay-ink);
}

/* ------------------------------------------------------------------ tables */

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  /* Monthly totals, top merchants and toll passages are primary content, not metadata:
     they read at body size like every other figure on the page. */
  font-size: var(--body);
}

caption {
  text-align: left;
  font-size: var(--meta);
  color: var(--ink-2);
  padding-bottom: 8px;
}

th,
td {
  text-align: left;
  padding: 12px 8px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

th {
  font-weight: 600;
}

td.amount,
th.amount {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ chart */

.spark {
  display: block;
  width: 100%;
  height: 96px;
  margin: 8px 0 16px;
}

.spark-line {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.spark-area {
  fill: var(--accent-soft);
  stroke: none;
}

.spark-dot {
  fill: var(--accent);
}

/* ------------------------------------------------------------------ history */

.year > summary {
  display: block;
  list-style: none;
  min-height: var(--tap);
  padding: 16px 0;
  font-size: var(--row);
  font-weight: 700;
  cursor: pointer;
  border-bottom: 1px solid var(--rule);
}

.year > summary::-webkit-details-marker {
  display: none;
}

.month-link {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  align-items: baseline;
  min-height: var(--tap);
  padding: 12px 0;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}

.month-link .name {
  font-size: var(--row);
  font-weight: 600;
  text-decoration: underline;
}

.month-link .amount {
  margin-left: auto;
  font-size: var(--row);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.month-link .state {
  flex: 1 1 100%;
  font-size: var(--meta);
  color: var(--ink-2);
}

.window-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 24px;
}

.window-form .field {
  flex: 1 1 140px;
  margin: 0;
}

.window-form .btn {
  flex: 1 1 100%;
}

select.input {
  appearance: none;
  background: var(--bg);
}

/* ------------------------------------------------------------------ pix */

.pix-amount {
  font-size: 44px;
  line-height: 1.1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 0;
}

/*
 * The three offers. Cards rather than rows of a chooser: each one carries an amount, a QR and a
 * code, and the only way to be sure nobody pays the wrong one is to never let two of them share
 * a control. The whole bill is emphasised by weight and colour, and the shares are the same size
 * and the same distance away, so "only my part" costs one tap like everything else.
 */
.pay-choices {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pay-choice {
  margin-bottom: 24px;
  padding: 20px 16px;
  border: 2px solid var(--rule);
  border-radius: var(--radius-card);
}

.pay-choice:last-child {
  margin-bottom: 0;
}

.pay-choice.is-whole {
  border-color: var(--pay);
  background: var(--surface);
}

.pay-choice-title {
  font-size: var(--row);
  font-weight: 700;
  margin: 0;
}

.pay-choice-amount {
  margin: 4px 0 0;
  font-size: 36px;
  line-height: 1.1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pay-choice.is-whole .pay-choice-amount {
  font-size: 44px;
}

/* Not colour alone: the word is the marker, the tint only follows it. */
.pay-choice-badge {
  display: inline-block;
  margin: 8px 0 0;
  padding: 2px 16px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  font-size: var(--body);
  font-weight: 600;
}

.pay-choice-covers,
.pay-choice-confirm {
  margin: 8px 0 0;
  font-size: var(--body);
  color: var(--ink-2);
}

.pay-choice-confirm {
  margin-top: 16px;
}

.pix-qr-frame {
  width: 280px;
  max-width: 100%;
  margin: 24px auto;
  padding: 8px;
  background: #ffffff;
  border: 1px solid var(--rule);
  border-radius: var(--radius-card);
}

.pix-qr {
  display: block;
  width: 100%;
  height: auto;
}

.pix-payload {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
  font-size: var(--meta);
  line-height: 1.4;
  overflow-wrap: anywhere;
  resize: vertical;
}

.steps {
  margin: 24px 0 0;
  padding-left: 24px;
  font-size: var(--body);
}

.steps li {
  margin-bottom: 8px;
}

/* ------------------------------------------------------------------ pay bar */

.has-paybar main {
  padding-bottom: calc(var(--paybar) + 48px + env(safe-area-inset-bottom, 0px));
}

.paybar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  min-height: var(--paybar);
  background: var(--bg);
  border-top: 1px solid var(--rule);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}

/*
 * At 360px there are 320 usable pixels for a label and a 56px-tall button. The label lands at
 * about 125 and the button at about 180, which fits with room to spare; anything wider wraps
 * the button onto its own full-width row rather than shrinking a tap target.
 */
.paybar-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  padding: 5px var(--gutter) calc(5px + env(safe-area-inset-bottom, 0px));
}

.paybar-label {
  flex: 1 1 auto;
  min-width: 0;
}

.paybar-label .k {
  display: block;
  font-size: var(--meta);
  line-height: 1.2;
  color: var(--ink-2);
}

.paybar-label .v {
  display: block;
  font-size: var(--body);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.paybar .btn {
  width: auto;
  flex: 0 1 auto;
  min-height: var(--tap);
  padding: 8px 16px;
  font-size: var(--body);
}

/* ------------------------------------------------------------------ footer */

.foot {
  padding: 32px 0 48px;
  border-top: 1px solid var(--rule);
}

.foot-note {
  margin-top: 24px;
  font-size: var(--meta);
  color: var(--ink-2);
}

/* ------------------------------------------------------------------ motion */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  details > summary {
    transition: none;
  }
}
