/*
 * app.css - how every page is laid out (ADR-0032).
 *
 * Every colour, font, size, and shadow comes from a variable theme.css
 * defines. Nothing here names a colour: to change the look, change
 * theme.css, not this file. internal/web/theme_test.go holds both rules.
 *
 * Class names say what a thing is for ("primary", "danger", "notice"), never
 * what it looks like, so a new theme never needs a template changed.
 * Elements are styled before classes, so plain markup is already consistent.
 */

/* ---- Base --------------------------------------------------------------- */

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-2xl);
}

h2 {
  font-size: var(--text-xl);
}

h3 {
  font-size: var(--text-lg);
}

p {
  margin: 0 0 var(--space-4);
}

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

a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--font-mono);
}

svg {
  flex-shrink: 0;
}

/* The classes below set display, which would otherwise show an element marked
 * hidden, such as a button only its script can make work. */
[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.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;
}

/* ---- Header and navigation --------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-header);
  -webkit-backdrop-filter: var(--header-blur);
  backdrop-filter: var(--header-blur);
  border-bottom: 1px solid var(--color-separator);
}

.site-header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  max-width: var(--width-content);
  height: var(--height-header);
  margin: 0 auto;
  padding: 0 var(--space-5);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 22px;
  height: 22px;
  color: var(--color-brand);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-size: var(--text-sm);
}

.site-nav a {
  color: var(--color-text-secondary);
  transition: color var(--transition);
}

.site-nav a:hover {
  color: var(--color-text);
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  color: var(--color-text);
  font-weight: var(--weight-medium);
}

.account {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
  min-width: 0;
}

.account-email {
  max-width: 240px;
  overflow: hidden;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account form {
  margin: 0;
}

.account-link {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.account-link[aria-current="page"] {
  color: var(--color-text);
  font-weight: var(--weight-medium);
}

/* ---- Page structure ----------------------------------------------------- */

.content {
  max-width: var(--width-content);
  margin: 0 auto;
  padding: var(--space-7) var(--space-5) var(--space-8);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-head .actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  flex-shrink: 0;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}

.back svg {
  width: 14px;
  height: 14px;
}

.lead {
  max-width: 62ch;
  margin-top: var(--space-3);
  color: var(--color-text-secondary);
  font-size: var(--text-base);
}

.section {
  margin-top: var(--space-7);
}

.section:first-child {
  margin-top: 0;
}

.section > h2 {
  margin-bottom: var(--space-4);
}

/* A section title with something beside it, such as the filter bar. */
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.section > h3 {
  margin: var(--space-6) 0 var(--space-3);
}

.section-foot {
  margin-top: var(--space-3);
}

.section > .lead {
  margin: calc(-1 * var(--space-2)) 0 var(--space-4);
  font-size: var(--text-sm);
}

.subtle {
  color: var(--color-text-secondary);
}

.fineprint {
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
}

/* ---- Cards --------------------------------------------------------------- */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
}

.card.flush {
  padding: 0;
  overflow: hidden;
}

.card + .card {
  margin-top: var(--space-4);
}

.card > h2,
.card > h3,
.card form > h2 {
  margin-bottom: var(--space-4);
}

.card h3 {
  font-size: var(--text-base);
}

/* A form after a card's facts, or after another form, keeps its distance. */
.card .facts + form,
.card .status-line + form {
  margin-top: var(--space-4);
}

.card form + form.inline {
  margin-top: var(--space-3);
}

.card ul.bullets {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-5);
  font-size: var(--text-sm);
}

.card-head {
  padding: var(--space-4) var(--space-5) 0;
}

.empty {
  padding: var(--space-7) var(--space-5);
  color: var(--color-text-secondary);
  text-align: center;
}

/* ---- Lists (folders) ----------------------------------------------------- */

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

.list li + li {
  border-top: 1px solid var(--color-separator);
}

.list a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  min-height: 52px;
  color: var(--color-text);
  transition: background var(--transition);
}

.list a:hover {
  background: var(--color-surface-hover);
  text-decoration: none;
}

.list .icon {
  width: 24px;
  height: 24px;
  color: var(--color-brand);
}

.list .chevron {
  width: 14px;
  height: 14px;
  margin-left: auto;
  color: var(--color-text-tertiary);
}

/* ---- Tables -------------------------------------------------------------- */

.table-wrap {
  position: relative;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

th {
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-align: left;
  white-space: nowrap;
}

td {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-separator);
  vertical-align: middle;
}

/* The card's own inset at either edge, tighter between columns. */
th:first-child,
td:first-child {
  padding-left: var(--space-5);
}

th:last-child,
td:last-child {
  padding-right: var(--space-5);
}

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

td.name {
  min-width: 14rem;
  font-size: var(--text-base);
}

/* A second line under a name stays small. */
td.name .subtle {
  font-size: var(--text-sm);
}

.nowrap,
td.name.nowrap {
  min-width: 0;
  white-space: nowrap;
}

/* A bill's lines: what, its period, and its amount, one line each. */
td.lines {
  min-width: 14rem;
}

.line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
}

.line + .line {
  margin-top: var(--space-1);
}

td.lines > .button {
  margin-top: var(--space-2);
}

.name-cell {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.name-cell .icon {
  width: 22px;
  height: 22px;
  color: var(--color-text-tertiary);
}

td.year {
  white-space: nowrap;
}

.name-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

td.actions {
  text-align: right;
  white-space: nowrap;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* Seven columns still fit the page: less room between them than elsewhere. */
@media screen and (min-width: 861px) {
  table.stack th:not(:first-child):not(:last-child),
  table.stack td:not(:first-child):not(:last-child) {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
}

/* Just wider than a stacked table: let names and years wrap sooner. */
@media screen and (min-width: 861px) and (max-width: 1040px) {
  table.stack td.name,
  table.stack td.lines {
    min-width: 8rem;
  }

  table.stack td.year {
    white-space: normal;
  }
}

/* ---- Buttons ------------------------------------------------------------- */

/* A plain <button> is the secondary style; a page's main action adds
 * "primary", and there should be one of those per form. */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--size-control);
  padding: 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-secondary-fill);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-base);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

button:hover,
.button:hover {
  background: var(--color-secondary-fill-hover);
  text-decoration: none;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

.primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.primary:hover {
  background: var(--color-primary-hover);
}

.primary:active {
  background: var(--color-primary-active);
}

.primary:disabled:hover {
  background: var(--color-primary);
}

/* For an action repeated on every row of a list: present, not loud. */
.tinted {
  background: var(--color-primary-tint);
  color: var(--color-link);
}

.tinted:hover {
  background: var(--color-primary-tint-hover);
}

/* Text only, for actions that should not draw the eye. */
.plain {
  background: transparent;
  color: var(--color-link);
  padding: 0 var(--space-2);
}

.plain:hover {
  background: transparent;
  text-decoration: underline;
}

.danger {
  color: var(--color-danger);
}

/* Its own tint under the pointer: the grey one is too close to the red. */
button.danger:hover,
.button.danger:hover {
  background: var(--color-danger-tint);
}

.small {
  min-height: var(--size-control-small);
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
}

.plain.small {
  padding: 0 var(--space-2);
}

.block {
  width: 100%;
}

/* ---- Forms --------------------------------------------------------------- */

form.inline {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
}

.field {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

label,
legend {
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="search"],
input[type="number"],
select {
  width: 100%;
  min-height: var(--size-control);
  padding: 0 var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-base);
  transition: border-color var(--transition), box-shadow var(--transition);
}

::placeholder {
  color: var(--color-text-tertiary);
  opacity: 1;
}

input:focus,
select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-primary-tint);
  outline: none;
}

form.inline input[type="date"] {
  width: auto;
  min-height: var(--size-control-small);
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
}

/* The same height and frame as the other fields, so a row of them lines up. */
input[type="file"] {
  width: 100%;
  min-height: var(--size-control);
  padding: calc((var(--size-control) - var(--size-control-small)) / 2 - 1px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font: inherit;
  font-size: var(--text-sm);
}

input[type="file"]::file-selector-button {
  min-height: var(--size-control-small);
  margin-right: var(--space-3);
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-secondary-fill);
  color: var(--color-text);
  font: inherit;
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: var(--color-secondary-fill-hover);
}

input[type="radio"],
input[type="checkbox"] {
  accent-color: var(--color-primary);
  width: 18px;
  height: 18px;
  margin: 0;
}

fieldset {
  margin: 0 0 var(--space-4);
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: var(--space-2);
  padding: 0;
}

.choices {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* On its own, a choice lines up with the fields around it; inside a
 * bordered group it is inset from the border. */
.choice {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-weight: var(--weight-regular);
  cursor: pointer;
}

.choice input {
  flex-shrink: 0;
}

.choices .choice {
  padding: var(--space-3) var(--space-4);
}

.choice + .choice {
  border-top: 1px solid var(--color-separator);
}

.hint {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

/* "Remember me on this device" on the sign-in form (ADR-0053). The warning
 * against shared and public computers is in the text colour and weight
 * rather than the hint's quieter grey, so it is read with the box. */
.remember {
  gap: var(--space-1);
}

.remember .hint {
  margin: 0;
}

.remember-warning {
  color: var(--color-text);
  font-weight: var(--weight-semibold);
}

.form-actions a {
  font-size: var(--text-sm);
}

.form-actions a.hint {
  color: var(--color-link);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

/* A choice and the number that goes with it, on one line at any width. */
.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7rem;
  align-items: end;
  gap: var(--space-3);
}

.form-row .field {
  margin-bottom: 0;
}

/* Rows of fields stacked in one form, such as the reminder schedule. */
.form-row + .form-row {
  margin-top: var(--space-3);
}

/* Fields side by side, as many as fit. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.form-grid .field {
  margin-bottom: 0;
}

.field.narrow {
  max-width: 320px;
}

form + .hint {
  margin-top: var(--space-4);
}

/* One invoice that can be voided: why, and the button, on one line. */
.void-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.void-row + .void-row {
  margin-top: var(--space-3);
}

.void-row input[type="text"] {
  flex: 1 1 14rem;
  width: auto;
  min-height: var(--size-control-small);
  font-size: var(--text-sm);
}

/* The new-folder form, one line under the folder list. */
.add-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-separator);
}

.add-row input[type="text"] {
  min-height: var(--size-control-small);
  border-color: transparent;
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
}

.add-row .icon {
  width: 24px;
  height: 24px;
  color: var(--color-text-tertiary);
}

/* ---- Labels (ADR-0033) --------------------------------------------------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.chip {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-secondary-fill);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.6;
  white-space: nowrap;
}

/* Labels to tick, drawn as chips. The checkbox stays in the page, and in
 * the tab order, but out of sight; its chip shows whether it is ticked. */
.chip-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip-toggle {
  position: relative;
  font-weight: var(--weight-regular);
}

.chip-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.chip-toggle span {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  color: var(--color-text);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.chip-toggle span:hover {
  border-color: var(--color-text-tertiary);
}

.chip-toggle input:checked + span {
  border-color: var(--color-primary);
  background: var(--color-primary-tint);
  color: var(--color-link);
}

.chip-toggle input:focus-visible + span {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.chip-toggle input:disabled + span {
  opacity: 0.5;
  cursor: default;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
}

.filter-bar select {
  width: auto;
  min-height: var(--size-control-small);
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
}

/* The search box (ADR-0044): the input takes the row, the button sits beside
   it, and on a narrow screen the two stay on one line. */
.search-bar {
  display: flex;
  gap: var(--space-2);
  margin: 0;
}

.search-bar input {
  flex: 1;
  min-width: 0;
}

/* The facts about one document: a row of label and value pairs. */
.facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5) var(--space-7);
  margin: 0;
}

.facts > div {
  min-width: 90px;
  max-width: 100%;
}

.facts dt {
  margin-bottom: var(--space-1);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.facts dd {
  margin: 0;
}

/* The settings page's list of labels. */
.label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
}

.label-row .chip {
  font-size: var(--text-sm);
}

/* A dashed outline, not a fade: its name still has to be read. */
.label-list li.retired .chip {
  border: 1px dashed var(--color-text-tertiary);
  background: transparent;
}

.label-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

details.rename {
  display: inline-block;
}

details.rename summary {
  list-style: none;
}

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

details.rename[open] summary {
  display: none;
}

details.rename input[type="text"],
details.rename input[type="email"] {
  width: 14rem;
  min-height: var(--size-control-small);
  font-size: var(--text-sm);
}

/* A customer's people, under its name on the customers page (ADR-0047). */
.people-list {
  margin: var(--space-1) 0;
  padding: 0;
  list-style: none;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
}

td.name details.rename {
  display: block;
}

/* ---- Notices and badges -------------------------------------------------- */

.notice {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-primary-tint);
  color: var(--color-text);
  font-size: var(--text-sm);
}

.notice.error {
  background: var(--color-danger-tint);
  color: var(--color-danger);
  font-weight: var(--weight-medium);
}

.status-line {
  margin: var(--space-3) 0 0;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.status-line:empty {
  display: none;
}

.badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.badge {
  display: inline-block;
  padding: 2px var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-secondary-fill);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

/* States arrive as stored ("clean"); only the first letter is raised, so a
 * longer label keeps its own case. */
.badge::first-letter {
  text-transform: uppercase;
}

.badge.success {
  background: var(--color-success-tint);
  color: var(--color-success);
}

.badge.warning {
  background: var(--color-warning-tint);
  color: var(--color-warning);
}

.badge.danger {
  background: var(--color-danger-tint);
  color: var(--color-danger);
}

/* ---- Home ---------------------------------------------------------------- */

.hero {
  margin-bottom: var(--space-7);
}

.hero h1 {
  font-size: var(--text-hero);
  margin-bottom: var(--space-3);
}

.hero p {
  margin: 0;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-5);
}

.tiles + .status-line {
  margin-top: var(--space-5);
}

.tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-6);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  color: var(--color-text);
  transition: box-shadow var(--transition), transform var(--transition);
}

.tile:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
  text-decoration: none;
}

.tile .icon {
  width: 36px;
  height: 36px;
  margin-bottom: var(--space-3);
  color: var(--color-brand);
}

.tile-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
}

.tile-text {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.tile-go {
  margin-top: auto;
  padding-top: var(--space-3);
  color: var(--color-link);
  font-size: var(--text-sm);
}

/* ---- Sign-in and single-message pages ----------------------------------- */

.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10vh var(--space-4) var(--space-8);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  font-size: var(--text-lg);
}

.auth-brand .brand-mark {
  width: 44px;
  height: 44px;
}

.auth-card {
  width: 100%;
  max-width: var(--width-auth);
  padding: var(--space-6);
}

.auth-card.wide {
  max-width: var(--width-auth-wide);
}

.auth-card > h1 {
  margin-bottom: var(--space-2);
  font-size: var(--text-xl);
  text-align: center;
}

.auth-card > .subtle {
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  text-align: center;
}

.auth-card .primary.block {
  margin-top: var(--space-2);
}

.auth-links {
  margin-top: var(--space-5);
  font-size: var(--text-sm);
  text-align: center;
}

.choice-buttons {
  display: grid;
  gap: var(--space-3);
}

.choice-buttons form {
  margin: 0;
}

.message {
  max-width: var(--width-message);
  margin: 0 auto;
  padding: var(--space-7) var(--space-6);
  text-align: center;
}

.message .icon {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-4);
  color: var(--color-brand);
}

.message .icon.success {
  color: var(--color-success);
}

.message .icon.danger {
  color: var(--color-danger);
}

.message h1 {
  margin-bottom: var(--space-3);
  font-size: var(--text-xl);
  overflow-wrap: anywhere;
}

.message .eyebrow {
  margin-bottom: var(--space-2);
  color: var(--color-text-tertiary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.message .form-actions {
  justify-content: center;
}

/* ---- Authenticator enrolment -------------------------------------------- */

.steps {
  margin: 0 0 var(--space-5);
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps > li {
  position: relative;
  padding-left: var(--space-7);
  counter-increment: step;
}

.steps > li + li {
  margin-top: var(--space-4);
}

.steps > li::before {
  content: counter(step);
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: var(--color-primary-tint);
  color: var(--color-link);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.qr {
  width: fit-content;
  margin: var(--space-4) 0;
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-md);
  overflow: hidden;
  line-height: 0;
}

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

.secret {
  display: block;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-secondary-fill);
  font-size: var(--text-sm);
  letter-spacing: 0.04em;
  text-align: center;
  user-select: all;
  overflow-wrap: anywhere;
}

/* ---- Small screens ------------------------------------------------------- */

@media (max-width: 680px) {
  .site-header-inner {
    gap: var(--space-4);
    padding: 0 var(--space-4);
  }

  /* The header keeps only the mark on a phone; the sign-in pages keep the
   * name, since there it is the page's only introduction. */
  .site-header .brand-name {
    display: none;
  }

  /* More sections than fit a phone's width scroll sideways in their own
   * strip, so Sign out is never pushed off the edge. */
  .site-nav {
    flex: 1 1 auto;
    gap: var(--space-4);
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    white-space: nowrap;
  }

  .site-nav a {
    flex: none;
  }

  .account {
    flex: none;
  }

  .account-email {
    display: none;
  }

  .label-actions {
    margin-left: 0;
  }

  .content {
    padding: var(--space-6) var(--space-4) var(--space-7);
  }

  h1 {
    font-size: var(--text-xl);
  }

  .hero h1 {
    font-size: var(--text-2xl);
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
  }

  /* Every tab stays in view, so the current one is never off screen. */
  .tabs {
    flex-wrap: wrap;
  }

  .tabs a {
    padding: var(--space-2) var(--space-3);
  }

  .form-row {
    grid-template-columns: minmax(0, 1fr) 5rem;
  }

  .form-row select,
  .form-row input[type="number"] {
    padding: 0 var(--space-2);
    font-size: var(--text-sm);
  }

  .timeline li {
    flex-direction: column;
    gap: var(--space-1);
  }

  th,
  td {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  .auth-card {
    padding: var(--space-5);
  }
}

/* ---- Tables on narrow screens ------------------------------------------- */

/* Each row of a stacked table is a block, so the name, its details, and its
 * buttons stay on screen rather than scrolling off it. Every table is one:
 * a cell after the first is "meta", with data-label where its value needs
 * the column's name, or "actions". */
@media screen and (max-width: 860px) {
  table.stack,
  table.stack tbody,
  table.stack tr,
  table.stack td {
    display: block;
    width: 100%;
  }

  table.stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  table.stack tr {
    padding: var(--space-3) var(--space-4);
  }

  table.stack tr + tr {
    border-top: 1px solid var(--color-separator);
  }

  table.stack td {
    min-width: 0;
    padding: 0;
    border: 0;
    overflow-wrap: anywhere;
    text-align: left;
  }

  table.stack td.meta {
    display: inline-block;
    width: auto;
    margin: var(--space-2) var(--space-3) 0 0;
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
  }

  table.stack td.meta[data-label]::before {
    content: attr(data-label) " ";
    color: var(--color-text-tertiary);
  }

  table.stack td.actions {
    margin-top: var(--space-3);
  }

  table.stack td.meta:empty,
  table.stack td.actions:empty {
    display: none;
  }

  .invoice table.stack tr {
    padding-left: 0;
    padding-right: 0;
  }

  table.stack .row-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  .account-email {
    max-width: 160px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }

  .tile:hover {
    transform: none;
  }
}

/* ---- Billing (ADR-0040) ------------------------------------------------- */

.billing-banner {
  background: var(--color-warning-tint);
  color: var(--color-warning);
  border-bottom: 1px solid var(--color-separator);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.billing-banner.danger {
  background: var(--color-danger-tint);
  color: var(--color-danger);
}

.billing-banner-inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  max-width: var(--width-content);
  margin: 0 auto;
  padding: var(--space-3) var(--space-5);
}

.billing-banner a {
  color: inherit;
  text-decoration: underline;
}

.invoice .invoice-parties {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-5);
  margin: var(--space-5) 0;
}

.invoice .invoice-parties h3 {
  margin: 0 0 var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.invoice .invoice-parties p {
  margin: 0;
}

/* The invoice's card already insets its table. */
.invoice th:first-child,
.invoice td:first-child {
  padding-left: 0;
}

.invoice th:last-child,
.invoice td:last-child {
  padding-right: 0;
}

/* Totals read down one column: each name on the left, its figure on the
 * right, under the amounts above. */
.invoice .invoice-totals {
  flex-direction: column;
  gap: var(--space-2);
  max-width: 360px;
  margin-top: var(--space-5);
  margin-left: auto;
}

.invoice .invoice-totals > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
}

.invoice .invoice-totals dt {
  margin: 0;
  font-size: var(--text-sm);
}

.invoice .invoice-totals dd {
  font-variant-numeric: tabular-nums;
}

.invoice > .fineprint {
  margin-top: var(--space-5);
}

@media print {
  .site-header,
  .no-print,
  .billing-banner,
  a.back {
    display: none !important;
  }

  body {
    background: var(--color-surface);
  }

  .card.invoice {
    box-shadow: none;
    border: 0;
  }
}

/* ---- Folder grid, toolbar, drawers, tabs (ADR-0049, ADR-0050) ---------- */

/* Subfolders are cards in a grid, so a folder is never mistaken for a file. */
.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.folder-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  height: 100%;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  color: var(--color-text);
  transition: box-shadow var(--transition);
}

.folder-card:hover {
  box-shadow: var(--shadow-card-hover);
  text-decoration: none;
}

.folder-card .icon {
  width: 36px;
  height: 36px;
  color: var(--color-brand);
}

.folder-card .folder-name {
  font-weight: var(--weight-semibold);
  overflow-wrap: anywhere;
}

.folder-card .folder-meta {
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
}

.folder-grid .add-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 100px;
  height: 100%;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
}

.folder-grid .add-card:hover {
  border-color: var(--color-text-tertiary);
  text-decoration: none;
}

.folder-grid .add-card .icon {
  width: 18px;
  height: 18px;
}

/* The breadcrumb above a folder's title. */
.crumbs {
  margin: 0 0 var(--space-2);
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.crumbs li + li::before {
  content: "/";
  margin-right: var(--space-1);
  color: var(--color-text-tertiary);
}

/* The bar under a page's title: search on the left, filters on the right. */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

/* The search box, its scope, and its button stay on one line; when there is
 * not room for the filters beside them, the filters take the next line. */
.toolbar .search-bar {
  flex: 1 1 33rem;
  align-items: center;
}

.toolbar .search-bar input[type="search"] {
  flex: 1 1 0;
  min-width: 0;
}

/* On a phone, with a scope to choose as well, the box takes its own line. */
@media (max-width: 680px) {
  .toolbar .search-bar {
    flex-wrap: wrap;
  }

  .toolbar .search-bar:has(.scope) input[type="search"] {
    flex-basis: 100%;
  }
}

.toolbar .filter-bar {
  flex: 0 1 auto;
}

/* Where a search looks: two radio buttons drawn as one control, so the
   choice is posted with the plain GET form and needs no script. */
.scope {
  display: inline-flex;
  flex-shrink: 0;
  margin: 0;
  padding: 2px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-secondary-fill);
}

.scope label {
  position: relative;
  font-weight: var(--weight-regular);
}

.scope input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.scope span {
  display: inline-flex;
  align-items: center;
  min-height: var(--size-control-small);
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  white-space: nowrap;
  cursor: pointer;
}

.scope input:checked + span {
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  color: var(--color-text);
}

.scope input:focus-visible + span {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}

/* A drawer: a form beside the page rather than above it. It opens when its
   id is the URL's fragment (a link to "#id"), so it needs no script; a page
   re-shown with an error in the form opens it with "open". */
.drawer-wrap {
  display: none;
}

.drawer-wrap:target,
.drawer-wrap.open {
  display: block;
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--color-scrim);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  width: min(460px, 100%);
  padding: var(--space-5);
  overflow-y: auto;
  background: var(--color-surface);
  box-shadow: var(--shadow-card-hover);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.drawer-head h2 {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.drawer-head .button {
  flex-shrink: 0;
}

/* A button naming a person may need two lines on a narrow screen. */
.drawer button {
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
}

.drawer .field {
  margin-bottom: var(--space-4);
}

/* One group of related actions in a drawer. */
.drawer-part + .drawer-part {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-separator);
}

.drawer-part h3 {
  margin-bottom: var(--space-3);
  font-size: var(--text-base);
}

.drawer-part .row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.drawer-part form + .row-actions {
  margin-top: var(--space-3);
}

/* Files dragged over a folder page. */
body.dragging .content {
  outline: 2px dashed var(--color-primary);
  outline-offset: var(--space-2);
  border-radius: var(--radius-md);
}

/* Tabs: each is a link to its own URL, so a tab works without script. */
.tabs {
  display: flex;
  gap: var(--space-1);
  margin: 0 0 var(--space-5);
  padding: 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--color-separator);
  list-style: none;
}

.tabs a {
  display: block;
  padding: var(--space-2) var(--space-4);
  border-bottom: 2px solid transparent;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.tabs a:hover {
  color: var(--color-text);
  text-decoration: none;
}

.tabs a[aria-current="page"] {
  border-bottom-color: var(--color-primary);
  color: var(--color-text);
  font-weight: var(--weight-medium);
}

/* A row of figures at the top of a tab. */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin: 0 0 var(--space-5);
}

.stats > div {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.stats dt {
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
}

.stats dd {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
}

.stats dd .subtle {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
}

/* A list of what happened, newest first. */
.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline li {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
}

.timeline li + li {
  border-top: 1px solid var(--color-separator);
}

.timeline time {
  flex-shrink: 0;
  width: 150px;
  color: var(--color-text-tertiary);
}

/* One line of a bill being raised: what, the period, the amount. */
.bill-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-sm);
}

.bill-item-row {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: var(--space-3);
}

.bill-total {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-separator);
  font-size: var(--text-lg);
}
