/* Components of the "Planta" identity. Every colour comes from tokens.css. */

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

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

body {
  --ctx: var(--brand);
  --ctx-fill: var(--brand-fill);
  /* Fainter than a border: the grid stays behind the text, never competes with it. */
  --sheet-line: color-mix(in srgb, var(--line) 40%, transparent);
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  /* The sheet: a fine blueprint grid behind every screen, lines only, no image. */
  background-image:
    linear-gradient(var(--sheet-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--sheet-line) 1px, transparent 1px);
  background-size: var(--grid-sheet) var(--grid-sheet);
  background-position: -1px -1px;
  color: var(--ink);
  font: 0.9375rem/1.45 var(--f-body);
}
body[data-context="construction"] { --ctx: var(--ctx-construction); --ctx-fill: var(--ctx-fill-construction); }
body[data-context="personal"] { --ctx: var(--ctx-personal); --ctx-fill: var(--ctx-fill-personal); }
body[data-context="company"] { --ctx: var(--ctx-company); --ctx-fill: var(--ctx-fill-company); }

a { color: var(--brand); }
p { margin: 0 0 var(--s-3); }

h1 {
  margin: 0 0 var(--s-3);
  font: 700 1.875rem/1.02 var(--f-display);
  letter-spacing: -0.025em;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.ic {
  width: 14px;
  height: 14px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The name, drawn. The check takes the brand colour unless told otherwise. */
.wordmark { display: block; width: 58px; height: auto; aspect-ratio: 860 / 330; color: var(--ink); }
.wordmark-check { stroke: var(--check, var(--brand)); }

/* ---------- shell ---------- */

.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  max-width: 44rem;
  margin: 0 auto;
  padding: calc(var(--s-1) + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) var(--s-1) calc(18px + env(safe-area-inset-left));
}
.appbar-home { display: inline-flex; align-items: center; min-height: var(--tap); }
.appbar-ctx { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 0.75rem var(--f-mono); color: var(--ctx); text-transform: lowercase; }
.appbar form { margin: 0; }
.appbar .btn-quiet { color: var(--muted); }

/* Sections of a context and views of a list: one small segmented control. */
.sections, .views {
  display: flex;
  width: fit-content;
  max-width: 100%;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
}
.sections { margin-bottom: var(--s-3); }
.views { margin-bottom: var(--s-2); }
.sections a, .views a {
  min-height: 38px; /* 44px with the frame around it */
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  font: 500 0.75rem var(--f-mono);
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  border-radius: var(--r-pill);
}
.sections a[aria-current="true"], .views a[aria-current="true"] { color: var(--bg); background: var(--ink); }

.content {
  padding: var(--s-1) calc(14px + env(safe-area-inset-right)) calc(var(--tabbar-h) + 88px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  max-width: 44rem;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: var(--s-2) calc(10px + env(safe-area-inset-right)) calc(var(--s-2) + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font: 500 0.75rem var(--f-body);
  color: var(--muted);
  text-decoration: none;
  border-radius: 14px;
}
.tabbar a .ic { width: 20px; height: 20px; }
.tabbar a[aria-current="page"] { color: var(--on-fill); background: var(--ctx-fill); }

.fab {
  position: fixed;
  right: calc(var(--s-4) + env(safe-area-inset-right));
  bottom: calc(var(--tabbar-h) + var(--s-4) + env(safe-area-inset-bottom));
  z-index: 3;
  height: 52px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font: 600 0.9375rem var(--f-body);
  color: var(--on-brand);
  background: var(--brand-fill);
  border-radius: var(--r-pill);
  text-decoration: none;
  box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--brand-fill) 60%, transparent);
}
.fab .ic { width: 18px; height: 18px; stroke-width: 2.2; }
.fab:focus-visible { outline-color: var(--ink); }

/* ---------- text pieces ---------- */

.label {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  margin: 14px 2px var(--s-2);
  font: 500 0.6875rem var(--f-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint { margin: var(--s-2) 0 0; color: var(--muted); font-size: 0.8125rem; line-height: 1.4; }
.mono { font-family: var(--f-mono); }
.optional { color: var(--muted); font-weight: 400; }

.back { margin: 0; }
.back a, .pages a {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  font: 500 0.75rem var(--f-mono);
  text-decoration: none;
}

.notice {
  margin: 0 0 var(--s-3);
  padding: var(--s-3);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow-wrap: anywhere;
}
.notice[role="alert"] { border-color: var(--danger); }

/* Blueprint grid behind empty states: lines of the drawing, no image. */
.empty {
  margin: var(--s-2) 0;
  padding: var(--s-8) var(--s-4);
  color: var(--muted);
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background-color: var(--surface);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: var(--grid) var(--grid);
  background-position: -1px -1px;
}
.empty p { margin: 0; display: inline; padding: 2px var(--s-2); background: var(--surface); box-decoration-break: clone; -webkit-box-decoration-break: clone; }

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

.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: var(--s-3) var(--s-3) 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  min-width: 0;
}
.card form { margin: 0; }
.item { display: block; color: var(--ink); font: 600 1rem/1.25 var(--f-body); text-wrap: balance; text-decoration: none; overflow-wrap: anywhere; }
.item-text { font: 400 0.9375rem/1.4 var(--f-body); text-wrap: wrap; }
.row { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--muted); }

/* Where it came from: channel, sender, date. On every item and subject. */
.src {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 6px;
  font: 0.71875rem/1.5 var(--f-mono);
  color: var(--muted);
  min-width: 0;
}
.src i { width: 8px; height: 8px; flex: none; background: var(--ctx-fill); outline: 1px solid color-mix(in srgb, var(--ink) 25%, transparent); }
.src span, .src time { overflow-wrap: anywhere; }
.src-channel { text-transform: lowercase; }
.src-channel::before { content: "// "; }
.src span + span::before, .src span + time::before { content: "· "; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font: 500 0.71875rem var(--f-mono);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
}

.due {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px var(--s-2);
  font: 500 0.71875rem var(--f-mono);
  color: var(--muted);
  border-radius: var(--r-sm);
}
/* Overdue: inverted, with a clock and words. Never colour alone, never red. */
.due.late { color: var(--bg); background: var(--ink); }

.hero { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); margin-bottom: 14px; }
.stat {
  display: block;
  padding: var(--s-3);
  color: var(--ink);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.stat b { display: block; font: 800 2.5rem/1 var(--f-display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat span { font: 0.75rem var(--f-mono); color: var(--muted); }
.stat.inv { color: var(--bg); background: var(--ink); border-color: var(--ink); }
.stat.inv span { color: var(--bg); opacity: 0.75; }

/* ---------- forms and buttons ---------- */

.stack { display: flex; flex-direction: column; gap: var(--s-2); }
.stack label, .filters label { margin-top: var(--s-2); font: 500 0.6875rem var(--f-mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

input, textarea, select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  font: 1rem var(--f-body); /* 16px: below that iOS zooms on focus */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
textarea { padding: var(--s-3) 14px; line-height: 1.45; resize: vertical; }
input[type="file"] { padding: var(--s-2); }
input[type="radio"], input[type="checkbox"] { width: 1.3rem; min-height: 1.3rem; flex: none; margin: 0 var(--s-2) 0 0; accent-color: var(--brand); }

/* Native selects ignore height on iOS; draw our own box and arrow. */
.select { position: relative; }
.select select { -webkit-appearance: none; appearance: none; padding-right: 2.5rem; }
.select::after { content: "▾"; position: absolute; right: var(--s-4); top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

.choices { display: flex; gap: var(--s-2); margin: var(--s-2) 0 0; padding: 0; border: 0; }
.choices legend { padding: 0; margin-bottom: var(--s-2); font: 500 0.6875rem var(--f-mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.choices label {
  flex: 1;
  min-height: 48px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 500 0.875rem var(--f-body);
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.check { display: flex; align-items: flex-start; min-height: var(--tap); margin: 0; overflow-wrap: anywhere; }

.btn {
  min-height: var(--tap);
  padding: 0 var(--s-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font: 600 0.875rem var(--f-body);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { min-height: 48px; margin-top: var(--s-3); color: var(--on-brand); background: var(--brand-fill); border-color: var(--brand-fill); }
.btn-quiet { padding: 0 var(--s-2); color: var(--brand); background: none; border-color: transparent; font: 500 0.75rem var(--f-mono); }
.btn-primary:focus-visible { outline-color: var(--ink); }

.search { display: flex; gap: var(--s-2); margin-bottom: var(--s-3); }
.search input { flex: 1; min-width: 0; }
.search .btn { min-height: 48px; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s-2); align-items: end; margin-bottom: var(--s-3); }
.filters .field { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.filters .wide { grid-column: 1 / -1; }
.filters .search { margin: var(--s-2) 0 0; }

.pages { display: flex; justify-content: space-between; gap: var(--s-4); margin-top: var(--s-4); }
.actions { margin-top: var(--s-5); display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }
.actions form { margin: 0; }
.actions .btn { width: 100%; height: 100%; padding: 6px 10px; text-align: center; }
.actions .hint { grid-column: 1 / -1; margin: 0; }

/* ---------- item and subject pages ---------- */

.original, .annotation, .text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.original { padding: var(--s-3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }

.attachments, .annotations, .history { list-style: none; margin: 0; padding: 0; }
.attachments li, .annotations li { padding: var(--s-3) 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.attachments img { display: block; max-width: 100%; height: auto; margin-bottom: var(--s-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.attachments a { margin-right: var(--s-2); font: 0.75rem var(--f-mono); }

.history li { display: flex; justify-content: space-between; gap: var(--s-4); padding: var(--s-2) 0; border-bottom: 1px solid var(--line); font-size: 0.84375rem; }
.history .line { display: block; overflow-wrap: anywhere; }
.history time { flex: none; font: 0.6875rem/1.9 var(--f-mono); color: var(--muted); text-align: right; }

.facts { display: grid; grid-template-columns: fit-content(7.5rem) 1fr; gap: 6px 14px; margin: 0 0 var(--s-2); padding: 10px 0; font-size: 0.84375rem; border-block: 1px solid var(--line); }
/* A subject with nothing filled in shows no empty frame. */
.facts:not(:has(dt)) { display: none; }
.facts dt { padding-top: 2px; font: 0.6875rem var(--f-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }

/* Timeline: a thin dashed line with square markers, like dimension lines. */
.timeline { list-style: none; margin: 0; padding: 0 0 0 var(--s-5); position: relative; display: flex; flex-direction: column; gap: var(--s-2); }
.timeline::before { content: ""; position: absolute; left: 4px; top: var(--s-2); bottom: var(--s-2); border-left: 1px dashed var(--muted); }
.timeline > li { position: relative; }
.row + h1 { margin-top: 10px; }
.timeline .item-text { font-size: 0.84375rem; color: var(--muted); }
.timeline > li::before { content: ""; position: absolute; left: calc(-1 * var(--s-5)); top: 14px; width: 9px; height: 9px; background: var(--bg); border: 1.5px solid var(--ctx); }

/* Title block of a drawing sheet: the name on the left, the fields beside it. */
.seal { display: grid; grid-template-columns: auto 1fr; max-width: 32.5rem; font: 0.71875rem/1.4 var(--f-mono); border: 2px solid currentColor; }
.seal-mark { display: flex; align-items: center; justify-content: center; padding: var(--s-3) var(--s-4); border-right: 2px solid currentColor; }
.seal-mark .wordmark { width: 72px; color: inherit; }
.seal dl { display: grid; grid-template-columns: repeat(2, 1fr); margin: 0; }
.seal dl div { padding: var(--s-2) 10px; border: 0 solid currentColor; border-width: 0 1px 1px 0; min-width: 0; }
.seal dl div:nth-child(2n) { border-right-width: 0; }
.seal dl div:nth-last-child(-n+2) { border-bottom-width: 0; }
.seal dt { font-size: 0.59375rem; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.7; }
.seal dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- login: the signature screen ---------- */

.login-page { background: var(--brand-fill); color: var(--on-brand); }
.login {
  min-height: 100dvh;
  max-width: 26rem;
  margin: 0 auto;
  padding: calc(76px + env(safe-area-inset-top)) 22px calc(36px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--s-8);
}
.login-page {
  background-position: 0 0;
  background-image:
    linear-gradient(color-mix(in srgb, var(--on-brand) 13%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--on-brand) 13%, transparent) 1px, transparent 1px);
  background-size: var(--grid) var(--grid);
}
.login h1 { margin: 0; }
.login .wordmark { width: 190px; color: var(--on-brand); --check: var(--on-brand); }
.login-tag { margin: 14px 0 0; font: 0.8125rem/1.5 var(--f-mono); opacity: 0.85; }
.login .stack { gap: 10px; }
.login .stack label { margin: 0; color: var(--on-brand); opacity: 0.85; }
.login input { color: var(--on-fill); background: var(--on-brand); border-color: var(--on-brand); }
.login input.mono { letter-spacing: 0.3em; }
.login .hint { margin: 0; font: 0.6875rem/1.5 var(--f-mono); color: var(--on-brand); opacity: 0.7; }
.login .btn-primary { min-height: 50px; margin-top: 6px; font-size: 1rem; background: transparent; border: 1.5px solid var(--on-brand); }
.login .seal-mark .wordmark { width: 64px; }
.login :focus-visible { outline-color: var(--on-brand); }
.login .notice { color: var(--on-fill); background: var(--on-brand); border-color: var(--on-brand); }

/* ---------- styleguide (dev only) ---------- */

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--s-2); margin: 0; padding: 0; list-style: none; }
.swatches li { font: 0.68rem var(--f-mono); color: var(--muted); }
.swatch { display: block; height: 40px; margin-bottom: var(--s-1); border: 1px solid var(--line); border-radius: var(--r-sm); }
.swatch-bg { background: var(--bg); }
.swatch-surface { background: var(--surface); }
.swatch-line { background: var(--line); }
.swatch-ink { background: var(--ink); }
.swatch-muted { background: var(--muted); }
.swatch-brand { background: var(--brand); }
.swatch-brand-fill { background: var(--brand-fill); }
.swatch-danger { background: var(--danger); }
.swatch-ctx { background: var(--ctx); }
.swatch-ctx-fill { background: var(--ctx-fill); }
.specimen-display { margin: 0; font: 800 2.2rem/1 var(--f-display); letter-spacing: -0.03em; }
.specimen-mono { margin: 0; font: 0.75rem var(--f-mono); color: var(--muted); }
.theme-light, .theme-dark { margin: 0 0 var(--s-4); padding: var(--s-4); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); }

/* ---------- motion: CSS only, and only if the user accepts it ---------- */

@view-transition { navigation: auto; }
.htmx-added { opacity: 0; translate: 0 8px; }
.htmx-settling { transition: opacity 180ms ease, translate 180ms ease; }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Extra facts appended to a source line (attachments, state). */
.src time + span::before { content: "· "; }

/* A checkbox row inside a form reads as text, not as a field label. */
.stack label.check { margin: 0; font: inherit; letter-spacing: 0; text-transform: none; color: var(--ink); }

/* ---------- construction schedule ---------- */

/* The line at the top: what is happening, in mono, one fact per span. */
.summary { margin: 0 0 var(--s-3); display: flex; flex-wrap: wrap; gap: 2px 0; font: 0.75rem/1.5 var(--f-mono); color: var(--muted); }
.summary span + span::before { content: "·"; margin: 0 6px; }

/* Planned against actual, aligned like the columns of a drawing schedule. */
.dates { display: grid; grid-template-columns: max-content 1fr; gap: 2px var(--s-3); margin: 0; font: 0.75rem/1.5 var(--f-mono); color: var(--muted); }
.dates dt { letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.6875rem; }
.dates dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }

.milestones { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.milestones li { padding: var(--s-2) 0; display: flex; flex-direction: column; gap: var(--s-1); border-top: 1px dashed var(--line); overflow-wrap: anywhere; }
.card > .milestones:first-child li:first-child { padding-top: 0; border-top: 0; }
.milestones a { min-height: var(--tap); display: flex; align-items: center; color: var(--ink); font: 500 0.9375rem/1.3 var(--f-body); text-decoration: none; }

.move { display: flex; justify-content: flex-end; gap: var(--s-2); }
.move .btn { min-width: var(--tap); }

/* The suggested stages: a tick and a name that can be rewritten. */
.template { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.template li { display: flex; align-items: center; gap: var(--s-2); }
.template input[type="text"] { flex: 1; min-width: 0; }
/* ---------- interaction patterns (docs/design/patterns.md) ---------- */

/* Every tap target is at least 44x44. Links inside text grow a box around them. */
.back a, .pages a, .row a, .facts a, .notice a, .hint a, .attachments a, .history a, .content > p > a, .content section > p > a {
  display: inline-flex;
  align-items: center;
  min-width: var(--tap);
  min-height: var(--tap);
}
.appbar-action { min-width: var(--tap); min-height: var(--tap); }
.appbar-action .ic { width: 20px; height: 20px; }

/* A thin bar at the top after a short wait: the tap was heard. */
.progress { position: fixed; inset: 0 0 auto; z-index: 6; height: 3px; background: var(--brand); transform-origin: left; scale: 0 1; opacity: 0; pointer-events: none; }
body.busy .progress { opacity: 1; animation: progress 1.6s ease-out infinite; }
@keyframes progress {
  from { scale: 0 1; }
  to { scale: 1 1; }
}

.offline { position: sticky; top: 0; z-index: 5; margin: 0; padding: calc(var(--s-2) + env(safe-area-inset-top)) var(--s-4) var(--s-2); font: 0.75rem/1.4 var(--f-mono); text-align: center; color: var(--bg); background: var(--ink); }
.offline[hidden] { display: none; }

/* The notice of the last action, above the capture button. Inverted like the late badge; never red. */
.toast {
  position: fixed;
  left: calc(var(--s-3) + env(safe-area-inset-left));
  right: calc(var(--s-3) + env(safe-area-inset-right));
  bottom: calc(var(--tabbar-h) + 76px + env(safe-area-inset-bottom));
  z-index: 4;
  max-width: 42rem;
  min-height: 52px;
  margin: 0 auto;
  padding: var(--s-1) var(--s-2) var(--s-1) var(--s-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  font: 500 0.875rem/1.3 var(--f-body);
  color: var(--bg);
  background: var(--ink);
  border-radius: var(--r-md);
}
.toast form { margin: 0; }
.toast .btn-quiet { min-width: var(--tap); min-height: var(--tap); color: var(--bg); text-decoration: underline; font-size: 0.8125rem; }
.toast.leaving { opacity: 0; translate: 0 8px; transition: opacity 200ms ease, translate 200ms ease; }

/* A sheet rises from the bottom for a short task. */
.sheet {
  width: 100%;
  max-width: 44rem;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0 calc(var(--s-4) + env(safe-area-inset-right)) calc(var(--s-4) + env(safe-area-inset-bottom)) calc(var(--s-4) + env(safe-area-inset-left));
  color: var(--ink);
  background: var(--bg);
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: var(--r-md) var(--r-md) 0 0;
  overflow-y: auto;
}
.sheet::backdrop { background: color-mix(in srgb, var(--ink) 45%, transparent); }
.sheet[open] { animation: sheet-in 220ms ease; }
@keyframes sheet-in {
  from { translate: 0 24px; opacity: 0; }
}
.sheet-bar { position: sticky; top: 0; z-index: 1; margin: 0; min-height: 52px; display: flex; align-items: center; justify-content: space-between; font: 500 0.6875rem var(--f-mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); background: var(--bg); }
.sheet-bar .btn-quiet { min-width: var(--tap); min-height: var(--tap); }

/* Optional fields of a form, folded away. */
.more { margin-top: var(--s-2); border-top: 1px solid var(--line); }
.more summary { min-height: var(--tap); display: flex; align-items: center; font: 500 0.75rem var(--f-mono); color: var(--brand); cursor: pointer; }

/* The main button of a form stays within reach, above the tab bar or the keyboard. */
.stack > .btn-primary { position: sticky; bottom: calc(var(--tabbar-h) + var(--s-2) + env(safe-area-inset-bottom)); z-index: 2; }
.sheet .stack > .btn-primary { bottom: var(--s-2); }
.login .stack > .btn-primary { position: static; }

/* A missing page or a failure: calm, with a way forward. */
.error { max-width: 44rem; margin: 0 auto; padding-top: calc(var(--s-8) + env(safe-area-inset-top)); }
.error h1 { margin-top: var(--s-6); }
.sections a, .views a { min-height: var(--tap); }
.item { min-height: var(--tap); display: flex; align-items: center; }
.template .check { min-width: var(--tap); justify-content: center; align-items: center; }
.template .check input { margin: 0; }

/* ---------- suppliers and budget ---------- */

/* More sections than fit in a phone: the strip scrolls sideways, the page does not. */
.sections { overflow-x: auto; scrollbar-width: none; }
.sections::-webkit-scrollbar { display: none; }

.amount { font-family: var(--f-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat .stat-money { font: 700 1.125rem/1.3 var(--f-mono); letter-spacing: -0.02em; overflow-wrap: anywhere; }
.origin { margin: var(--s-3) 0 0; padding: var(--s-3); display: flex; flex-direction: column; gap: var(--s-2); border: 1px dashed var(--line); border-radius: var(--r-md); }
.origin legend { padding: 0 var(--s-2); font: 500 0.6875rem var(--f-mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
/* A fieldset grows to its widest option by default; keep it inside the page. */
.origin { min-width: 0; }
.origin .select, .origin select, .origin input { min-width: 0; max-width: 100%; }

/* The summary for strategy: plain text she copies, with what EVA swapped highlighted. */
.strategy-text { margin: 0; padding: var(--s-4); white-space: pre-wrap; overflow-wrap: anywhere; font: 0.84375rem/1.6 var(--f-mono); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.strategy-text mark { background: var(--ctx-fill); color: var(--on-fill); border-radius: var(--r-sm); padding: 0 var(--s-1); }

/* ---------- usage guide (/guide) ----------
   A set of drawing sheets: each section is a "prancha" with a mono title, and the
   figures are phone captures with a legend, like the details of a drawing. */
.guide-page { font-size: 1rem; line-height: 1.6; }
.guide-page h2, .guide-page h3 { margin: 0; font-family: var(--f-display); text-wrap: balance; line-height: 1.12; }
.guide-page p { margin: 0; }
.guide-page figure { margin: 0; display: grid; gap: 10px; min-width: 0; }
.guide-page figcaption { font: 0.75rem/1.45 var(--f-mono); color: var(--muted); }
.guide-page figcaption b { color: var(--ink); font-weight: 500; }
.guide-wrap {
  max-width: 70rem;
  margin: 0 auto;
  padding-left: max(var(--s-4), env(safe-area-inset-left, 0px));
  padding-right: max(var(--s-4), env(safe-area-inset-right, 0px));
}
.guide-label { font: 500 0.75rem/1.4 var(--f-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.guide-label b { color: var(--ink); font-weight: 500; }
.guide-light { display: block; }
.guide-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .guide-light { display: none; }
  .guide-dark { display: block; }
}

/* top bar */
.guide-top {
  position: sticky;
  top: 0;
  z-index: 5;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.guide-top .guide-wrap { display: flex; align-items: center; gap: var(--s-4); }
.guide-home { display: inline-flex; align-items: center; min-width: var(--tap); min-height: var(--tap); flex: none; }
.guide-home .wordmark { width: 54px; }
.guide-top nav { display: flex; gap: var(--s-1); overflow-x: auto; scrollbar-width: none; min-width: 0; }
.guide-top nav::-webkit-scrollbar { display: none; }
.guide-top nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--s-3);
  border-radius: var(--r-pill);
  font: 0.78rem var(--f-mono);
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.guide-top nav a:hover { color: var(--ink); background: var(--surface); }

/* hero: the one large area of ultramarine, as on the login */
.guide-hero {
  background-color: var(--brand-fill);
  background-image:
    linear-gradient(color-mix(in srgb, var(--on-brand) 13%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--on-brand) 13%, transparent) 1px, transparent 1px);
  background-size: var(--grid) var(--grid);
  color: var(--on-brand);
}
.guide-hero .guide-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr);
  gap: 48px;
  align-items: end;
  padding-block: 56px 0;
}
.guide-hero-copy { display: grid; gap: var(--s-6); padding-bottom: 56px; min-width: 0; }
.guide-hero-copy > .wordmark { width: min(240px, 60vw); color: var(--on-brand); --check: var(--on-brand); }
.guide-hero h1 { margin: 0; font-size: clamp(2.1rem, 5.4vw, 3.75rem); font-weight: 750; letter-spacing: -0.02em; max-width: 15ch; }
.guide-lede { font-size: 1.125rem; max-width: 46ch; opacity: 0.92; }
.guide-cta { display: flex; flex-wrap: wrap; gap: var(--s-3); }
.guide-cta .btn { min-height: 48px; font-size: 0.95rem; }
.guide-btn-light { color: var(--on-fill); background: var(--on-brand); border-color: var(--on-brand); }
.guide-btn-ghost { color: var(--on-brand); background: transparent; border-color: var(--on-brand); }
.guide-hero .seal { color: var(--on-brand); }
.guide-hero .seal-mark .wordmark { color: var(--on-brand); --check: var(--on-brand); }
.guide-hero :focus-visible { outline-color: var(--on-brand); }
.guide-hero-phone { align-self: end; justify-self: center; width: min(320px, 100%); }
.guide-hero-phone .guide-phone { border-bottom: 0; border-radius: 28px 28px 0 0; border-color: var(--on-brand); }

/* sheets */
.guide-sheet { padding-block: 72px; border-bottom: 1px solid var(--line); }
.guide-head { display: grid; gap: 14px; margin-bottom: 40px; max-width: 70ch; }
.guide-head h2 { font-size: clamp(1.75rem, 4vw, 2.6rem); font-weight: 720; letter-spacing: -0.015em; }
.guide-head p { color: var(--muted); font-size: 1.06rem; }

/* a phone capture */
.guide-phone {
  display: block;
  max-width: 100%;
  aspect-ratio: 390 / 844;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
}
.guide-phone img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top; }

/* start: a real sequence, so the steps are numbered */
.guide-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-4); counter-reset: step; }
.guide-steps li {
  counter-increment: step;
  display: grid;
  gap: var(--s-2);
  align-content: start;
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.guide-steps li::before { content: "passo " counter(step); font: 0.75rem var(--f-mono); color: var(--brand); letter-spacing: 0.06em; }
.guide-steps h3 { font-size: 1.2rem; font-weight: 680; }
.guide-steps p { color: var(--muted); font-size: 0.94rem; }

.guide-loop { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-5); }

/* features */
.guide-feature {
  display: grid;
  grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
  gap: 48px;
  align-items: start;
  padding-block: 48px;
  border-top: 1px dashed var(--line);
}
.guide-feature:first-of-type { border-top: 0; padding-top: 0; }
.guide-feature-body { display: grid; gap: 18px; min-width: 0; }
.guide-feature h3 { font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 720; }
.guide-feature ul { margin: 0; padding-left: var(--s-5); display: grid; gap: var(--s-2); max-width: 62ch; }
.guide-feature li::marker, .guide-rules li::marker { color: var(--brand); }
.guide-where { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.guide-ctx { font: 500 0.75rem var(--f-mono); padding: 3px 10px; border-radius: var(--r-pill); color: var(--on-fill); }
.guide-ctx-construction { background: var(--ctx-fill-construction); }
.guide-ctx-personal { background: var(--ctx-fill-personal); }
.guide-ctx-company { background: var(--ctx-fill-company); }
.guide-path { font: 0.75rem var(--f-mono); color: var(--muted); overflow-wrap: anywhere; }
.guide-tip {
  max-width: 62ch;
  padding: 14px var(--s-4);
  font-size: 0.94rem;
  background: var(--surface);
  border-left: 3px solid var(--brand);
  border-radius: 0 var(--r-md) var(--r-md) 0;
}
.guide-tip .guide-label { display: block; margin-bottom: var(--s-1); color: var(--brand); }
.guide-strip { display: flex; gap: var(--s-4); overflow-x: auto; padding-bottom: 6px; }
.guide-thumb { flex: 0 0 168px; }
.guide-thumb .guide-phone { border-radius: 18px; }

/* good practices */
.guide-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); }
.guide-card, .guide-panel {
  display: grid;
  gap: var(--s-2);
  align-content: start;
  min-width: 0;
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.guide-card h3 { font-size: 1.12rem; font-weight: 680; }
.guide-card p, .guide-panel p { color: var(--muted); font-size: 0.94rem; }

/* brand */
.guide-brand { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5); }
.guide-panel { gap: var(--s-4); padding: var(--s-6); }
.guide-panel h3 { font-size: 1.25rem; font-weight: 680; }
.guide-plate {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-8);
  align-items: center;
  justify-content: center;
  padding: 36px var(--s-6);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: var(--grid) var(--grid);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.guide-plate .wordmark { width: 200px; }
.guide-icon { width: 88px; height: 88px; border-radius: 20px; }
.guide-rules { margin: 0; padding-left: var(--s-5); display: grid; gap: 6px; font-size: 0.94rem; }
.guide-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.guide-swatch { overflow: hidden; font: 0.72rem/1.4 var(--f-mono); color: var(--muted); border: 1px solid var(--line); border-radius: var(--r-sm); }
.guide-swatch i { display: block; height: 52px; }
.guide-swatch span { display: block; padding: 6px var(--s-2); }
.guide-swatch b { display: block; font-weight: 500; color: var(--ink); }
.guide-sw-brand { background: var(--brand-fill); }
.guide-sw-paper, .guide-sw-night { background: var(--bg); }
.guide-sw-construction { background: var(--ctx-fill-construction); }
.guide-sw-personal { background: var(--ctx-fill-personal); }
.guide-sw-company { background: var(--ctx-fill-company); }
.guide-badges { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.guide-late { font: 0.78rem var(--f-mono); padding: 4px 10px; color: var(--bg); background: var(--ink); border-radius: var(--r-pill); }
.guide-source { display: flex; gap: var(--s-2); align-items: center; font: 0.78rem var(--f-mono); color: var(--muted); }
.guide-source i { width: 9px; height: 9px; flex: none; background: var(--ctx-fill-construction); }
.guide-type { display: grid; gap: var(--s-1); padding-top: 10px; border-top: 1px solid var(--line); }
.guide-type:first-of-type { padding-top: 0; border-top: 0; }
.guide-type-d { font: 750 2.1rem/1.1 var(--f-display); letter-spacing: -0.01em; }
.guide-type-b { font: 1.12rem var(--f-body); }
.guide-type-m { font: 0.94rem var(--f-mono); }
.guide-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }

/* the last sheet leaves room for the home indicator */
.guide-page main { padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px)); }

@media (max-width: 900px) {
  .guide-hero .guide-wrap { grid-template-columns: 1fr; gap: 0; padding-top: 40px; }
  .guide-hero-copy { padding-bottom: 36px; }
  .guide-steps, .guide-loop { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guide-feature { grid-template-columns: 1fr; gap: var(--s-6); }
  .guide-feature > figure { max-width: 300px; }
  .guide-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guide-brand { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .guide-steps, .guide-cards { grid-template-columns: 1fr; }
  .guide-loop { gap: 14px; }
  .guide-sheet { padding-block: 52px; }
  .guide-hero-phone { width: min(260px, 80%); }
}
@media (prefers-reduced-motion: no-preference) {
  html:has(.guide-page) { scroll-behavior: smooth; }
}

/* ---------- pages outside the contexts: the way back, and the account ---------- */
.guide-back { flex: none; margin-left: auto; gap: 6px; font-size: 0.8125rem; }
.account-title { min-width: 0; }
.account { display: grid; gap: var(--s-6); max-width: 36rem; padding-block: var(--s-8) 64px; }
.account h1 { margin: 0; }
.account-email { display: grid; gap: var(--s-1); }
.account-card {
  display: grid;
  gap: var(--s-3);
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.account-card h2 { margin: 0; font: 680 1.2rem/1.2 var(--f-display); }
.account-card form { margin: 0; }
.account .stack > .btn-primary { position: static; }
.account-logout { width: 100%; }
.account-card > .btn { width: 100%; }
