/*
 * 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;
}

/* ---- Navigation (ADR-0059) ----------------------------------------------- */

/* A sidebar beside the page. On a narrow screen the same markup is a bar along
 * the top, with the main sections along the bottom (see Small screens). */
.shell {
  display: grid;
  grid-template-columns: var(--width-sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.shell.plain-shell {
  display: block;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  height: 100vh;
  box-sizing: border-box;
  padding: var(--space-4) var(--space-3);
  background: var(--color-header);
  border-right: 1px solid var(--color-separator);
  font-size: var(--text-sm);
}

/* The bar on a page with no navigation, such as an error. */
.site-header.bar {
  flex-direction: row;
  align-items: center;
  height: var(--height-header);
  border-right: 0;
  border-bottom: 1px solid var(--color-separator);
}

.site-header.bar .account {
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
}

.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: 28px;
  height: 28px;
  color: var(--color-brand);
}

.site-header .brand {
  min-width: 0;
  padding: var(--space-1) var(--space-2) var(--space-4);
}

.site-header.bar .brand {
  padding: 0 var(--space-2);
}

.brand-text {
  min-width: 0;
  line-height: 1.25;
}

.brand-name,
.brand-product {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-product {
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
}

.site-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.site-nav + .site-nav {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-separator);
}

.site-nav.last {
  margin-top: auto;
  border-top: 0;
}

.site-nav a,
.pop a,
.pop button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-3);
  box-sizing: border-box;
  width: 100%;
  min-height: 36px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  transition: background var(--transition), color var(--transition);
}

.site-nav a:hover,
.pop a:hover,
.pop button:hover {
  background: var(--color-primary-tint);
  color: var(--color-text);
  text-decoration: none;
}

.site-nav a[aria-current="page"],
.pop a[aria-current="page"] {
  background: var(--color-primary-tint-hover);
  color: var(--color-text);
  font-weight: var(--weight-semibold);
}

.site-nav .icon,
.account .icon {
  width: 18px;
  height: 18px;
}

.site-nav a[aria-current="page"] .icon {
  color: var(--color-brand);
}

/* A menu: a <details>, so it opens with no script. ui.js also closes it when
 * something else is clicked. */
.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
  cursor: pointer;
}

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

.pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  box-sizing: border-box;
  min-width: 180px;
  padding: 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-pop);
  font-size: var(--text-sm);
}

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

.pop form {
  margin: 0;
}

.pop-note {
  display: none;
  padding: var(--space-2);
  overflow-wrap: anywhere;
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
}

.account {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-separator);
}

.site-nav + .account:not(.site-nav.last + .account) {
  margin-top: auto;
}

.account > summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
}

.account > summary:hover {
  background: var(--color-primary-tint);
}

.account .pop {
  top: auto;
  right: 0;
  bottom: 100%;
  left: 0;
}

.site-header.bar .account .pop {
  top: 100%;
  bottom: auto;
  left: auto;
}

.account-who {
  min-width: 0;
  line-height: 1.3;
}

.account-email,
.account-role {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.account-link {
  white-space: nowrap;
}

.nav-more {
  display: none;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-5);
  box-sizing: border-box;
  width: 100%;
  max-width: var(--width-content);
  margin-top: auto;
  padding: 0 var(--space-7) var(--space-5);
  font-size: var(--text-xs);
}

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

.wide-only {
  display: flex;
}

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

.content {
  box-sizing: border-box;
  width: 100%;
  max-width: var(--width-content);
  padding: 28px var(--space-7) var(--space-8);
}

.plain-shell .content,
.plain-shell .site-footer {
  margin: 0 auto;
}

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

.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-1);
  color: var(--color-text-secondary);
  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: 30px;
}

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

.section > h2 {
  margin-bottom: 10px;
}

/* 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-2) var(--space-3);
  min-height: var(--size-control-small);
  margin-bottom: var(--space-2);
}

.section-head.start {
  justify-content: flex-start;
}

.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: 1px solid var(--color-separator);
  border-radius: var(--radius-lg);
  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);
  background: var(--color-surface-hover);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-align: left;
  white-space: nowrap;
}

td {
  padding: 10px 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;
}

/* A heading that sorts its column (ADR-0063): the heading's own colour
   until the list is sorted by it, with a faint mark that it can be. */
th a.sort {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: inherit;
  text-decoration: none;
}

th a.sort:hover,
th a.sort.on {
  color: var(--color-text);
}

th a.sort .sort-mark {
  width: 12px;
  height: 12px;
  flex: none;
  opacity: 0.45;
}

th a.sort.on .sort-mark {
  opacity: 1;
}

th.num .pick-head {
  justify-content: flex-end;
}

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 {
  max-width: 120px;
  line-height: 1.35;
  text-wrap: balance;
}

/* The tile beside a document's name: what kind of file it is. */
.file-kind {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  box-sizing: border-box;
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: 0.625rem;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.02em;
}

.file-name {
  color: var(--color-text);
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

/* A document's state in a list: quiet, unless it is bad news. */
.state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.state::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.state.ok::before {
  background: var(--color-success);
}

.state.wait::before {
  background: var(--color-warning);
}

.state.bad {
  color: var(--color-danger);
  font-weight: var(--weight-medium);
}

.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: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-secondary-fill);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  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,
.tinted,
.plain {
  border-color: transparent;
}

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

/* A button that is only an icon, named for a screen reader in its markup. */
.icon-button {
  display: inline-grid;
  place-items: center;
  box-sizing: border-box;
  width: var(--size-control-small);
  height: var(--size-control-small);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
}

.icon-button:hover {
  background: var(--color-primary-tint);
  color: var(--color-text);
}

.icon-button .icon {
  width: 18px;
  height: 18px;
}

summary.icon-button {
  border: 1px solid var(--color-border);
}

/* A "?" beside something that needs explaining. */
.tip > summary {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  box-sizing: border-box;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  color: var(--color-text-secondary);
  font-size: 0.6875rem;
  font-weight: var(--weight-semibold);
  line-height: 1;
}

.tip .pop {
  right: -90px;
  width: 260px;
  padding: var(--space-3) var(--space-4);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  line-height: 1.45;
}

.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"],
textarea,
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);
}

textarea {
  box-sizing: border-box;
  padding: var(--space-3) var(--space-4);
  line-height: var(--leading-body);
  resize: vertical;
}

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

input:focus,
textarea: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: 0 6px;
  border: 1px solid var(--color-separator);
  border-radius: 4px;
  background: var(--color-surface-hover);
  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;
}

/* ---- Many documents at once (ADR-0062) ---------------------------------- */

/* A tick box before each document's name, and Select all before the
 * column's heading. */
.pick-row,
.pick-head {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

input.pick {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--color-primary);
}

/* The bar under the list. Without script it is always shown, in place;
 * with it, only while something is ticked, and it stays in view at the
 * bottom of the window as the list scrolls. */
.bulk-bar {
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.bulk.scripted .bulk-bar {
  position: sticky;
  bottom: var(--space-3);
  z-index: 5;
  max-height: 50vh;
  overflow-y: auto;
  box-shadow: var(--shadow-pop);
}

.bulk.scripted:not(.has-selection) .bulk-bar {
  display: none;
}

.bulk-count {
  margin: 0 0 var(--space-3);
  font-weight: var(--weight-medium);
}

.bulk-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-4);
}

.bulk-fields > .field {
  margin: 0;
}

.bulk-plain,
.bulk-labels {
  flex: 1 1 22rem;
}

/* One label in the bar: whether all, some, or none of the selection carry
 * it, and what Apply will do with it. */
.chip-tri {
  min-height: 0;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  line-height: var(--leading-body);
}

.chip-tri:hover {
  background: var(--color-surface);
  border-color: var(--color-text-tertiary);
}

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

.chip-tri.has-all {
  border-color: var(--color-primary);
  background: var(--color-primary-tint);
  color: var(--color-link);
}

.chip-tri.has-some {
  border-style: dashed;
  border-color: var(--color-primary);
}

.chip-tri.will-add {
  border-style: solid;
  border-color: var(--color-success);
  background: var(--color-success-tint);
  color: var(--color-success);
}

.chip-tri.will-remove {
  border-style: solid;
  border-color: var(--color-danger);
  background: var(--color-danger-tint);
  color: var(--color-danger);
  text-decoration: line-through;
}

.chip-note {
  display: inline-block;
  margin-left: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-decoration: none;
}

.bulk-names {
  margin: 0;
  padding-left: var(--space-5);
  list-style: disc;
}

/* The label and year to narrow to, inside the toolbar's form. */
.filter-bar {
  display: flex;
  gap: var(--space-2);
  min-width: 0;
}

.filter-bar select {
  width: auto;
  max-width: 150px;
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

/* 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);
}

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

.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 9px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-hover);
  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 (ADR-0059) ------------------------------------------------------ */

/* Two columns: the wider one first. One, where there is nothing beside it. */
.columns {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}

.columns.single {
  grid-template-columns: minmax(0, 1fr);
}

.columns > .section {
  margin-top: 0;
}

.section-head h2 {
  margin: 0;
}

/* What needs a person: what it is, and a link to where it is done. */
.todo {
  margin: 0;
  padding: 0;
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-lg);
  list-style: none;
}

.todo li {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) var(--space-4);
}

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

.todo .icon {
  width: 20px;
  height: 20px;
  color: var(--color-text-tertiary);
}

.todo .warn .icon {
  color: var(--color-warning);
}

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

.todo strong {
  display: block;
  font-weight: var(--weight-semibold);
  overflow-wrap: anywhere;
}

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

.todo a {
  font-size: var(--text-sm);
  white-space: nowrap;
}

/* What happened, newest first, under a heading for each day. */
.feed {
  margin: 0;
  padding: 0;
  font-size: var(--text-sm);
  list-style: none;
}

.feed li {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--color-separator);
}

.feed li.day {
  display: block;
  padding: var(--space-3) 0 var(--space-1);
  border-top: 0;
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

.feed li.day:first-child {
  padding-top: 0;
}

.feed time {
  color: var(--color-text-tertiary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.feed strong {
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

/* ---- 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-name {
  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 {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-1) var(--space-5);
  margin-top: var(--space-5);
  font-size: var(--text-sm);
}

/* Running text on a public page (About): headings and lists spaced for
   reading rather than for a form. */
.prose h2 {
  margin: var(--space-6) 0 var(--space-2);
  font-size: var(--text-lg);
}

.prose ul {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-5);
}

.prose li {
  margin-bottom: var(--space-1);
}

.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: 760px) {
  .shell {
    display: block;
    padding-bottom: var(--height-tabbar);
  }

  .shell.plain-shell {
    padding-bottom: 0;
  }

  .wide-only {
    display: none;
  }

  .site-header {
    flex-direction: row;
    align-items: center;
    height: var(--height-header);
    padding: 0 var(--space-4);
    border-right: 0;
    border-bottom: 1px solid var(--color-separator);
  }

  .site-header .brand {
    padding: 0;
  }

  .site-header .brand-name {
    white-space: nowrap;
  }

  /* The main sections, along the bottom where a thumb reaches. */
  .site-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 15;
    flex-direction: row;
    gap: 0;
    background: var(--color-header);
    border-top: 1px solid var(--color-separator);
  }

  .site-nav.wide-only {
    display: none;
  }

  .site-nav > a,
  .nav-more > summary {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    width: auto;
    height: var(--height-tabbar);
    padding: 0;
    border-radius: 0;
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
  }

  .site-nav > a[aria-current="page"] {
    background: transparent;
    color: var(--color-brand);
  }

  .nav-more {
    display: block;
    flex: 1 1 0;
  }

  .nav-more .pop {
    top: auto;
    right: var(--space-2);
    bottom: calc(var(--height-tabbar) + 6px);
    width: 210px;
  }

  .pop a,
  .pop button {
    min-height: 44px;
  }

  .account {
    flex: none;
    margin: 0 0 0 auto !important;
    padding: 0;
    border: 0;
  }

  .account > summary {
    justify-content: center;
    width: 44px;
    padding: 0;
  }

  .account-who {
    display: none;
  }

  .account .pop {
    top: 100%;
    bottom: auto;
    left: auto;
    min-width: 210px;
  }

  .pop-note {
    display: block;
  }

  .site-footer {
    padding: 0 var(--space-4) var(--space-5);
  }

  .tip .pop {
    right: -60px;
    width: 240px;
  }

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

  .todo li {
    grid-template-columns: 20px minmax(0, 1fr);
  }

  .todo li > a {
    grid-column: 2;
  }

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

  .filter-bar select {
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
    min-height: 44px;
  }

  .page-head .button,
  .page-head button,
  .row-actions .button,
  .icon-button {
    min-height: 44px;
  }

  .icon-button {
    width: 44px;
  }

  .page-head .actions {
    flex-wrap: wrap;
    flex-shrink: 1;
  }

  .page-head .button,
  .page-head button {
    padding: 0 var(--space-3);
  }

  td.year {
    max-width: none;
  }
}

@media (max-width: 1080px) {
  .columns {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 680px) {
  .label-actions {
    margin-left: 0;
  }

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

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

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

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

  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 (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---- 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);
  padding: var(--space-3) var(--space-7);
}

.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,
  .site-footer,
  .no-print,
  .billing-banner,
  a.back {
    display: none !important;
  }

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

  .shell {
    display: block;
  }

  .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: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.folder-card,
.folder-grid .add-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 10px;
  box-sizing: border-box;
  height: 100%;
  min-height: 50px;
  padding: var(--space-2) 14px;
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition: background var(--transition), border-color var(--transition);
}

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

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

.folder-card .folder-name {
  flex: 1;
  min-width: 0;
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

.folder-card .folder-meta {
  flex-basis: 100%;
  padding-left: 32px;
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
}

.folder-grid .add-card {
  border-style: dashed;
  border-color: var(--color-border);
  color: var(--color-text-secondary);
}

.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 folder's title: search, where it looks, and what to narrow
 * to, in one form. */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-5);
}

.toolbar input[type="search"] {
  flex: 1 1 200px;
  width: auto;
  min-width: 0;
  min-height: 36px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

.toolbar button {
  min-height: 36px;
}

/* 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: 1px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-hover);
}

.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: 5px;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  white-space: nowrap;
  cursor: pointer;
}

.scope input:checked + span {
  background: var(--color-primary-tint-hover);
  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);
  border-left: 1px solid var(--color-separator);
}

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

/* ---- The upload drawer (ADR-0061) ---------------------------------------- */

/* Wide enough for the review table: a name, its size, labels, year, and
 * status on one line. */
#upload-drawer .drawer {
  width: min(980px, 100%);
}

/* While files are being sent the drawer cannot be closed: its Close and
 * the dimmed page behind it do nothing (uploads.js also keeps the address
 * on the drawer). */
.drawer-wrap.locked .drawer-scrim {
  pointer-events: none;
}

.drawer-wrap.locked .drawer-head .button {
  visibility: hidden;
}

.uploads {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.uploads .notice {
  margin: 0;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-6) var(--space-4);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  text-align: center;
  cursor: pointer;
}

.drop-zone:hover,
.drop-zone:focus-within {
  border-color: var(--color-primary);
  background: var(--color-primary-tint);
}

.drop-title {
  color: var(--color-link);
  font-weight: var(--weight-medium);
}

.uploads-pick[hidden],
.uploads-progress[hidden],
.uploads-done[hidden] {
  display: none;
}

.uploads-progress progress {
  width: 100%;
  height: 10px;
  accent-color: var(--color-primary);
}

.uploads-counts {
  margin: var(--space-2) 0 0;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.uploads-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-lg);
}

.uploads-bar .hint,
.uploads-bar .field {
  margin: 0;
}

.uploads table {
  width: 100%;
}

.uploads table td {
  vertical-align: middle;
}

.uploads td.actions button {
  white-space: nowrap;
}

.uploads-bar[hidden] {
  display: none;
}

.uploads table .pick-cell {
  width: 1%;
}

.upload-name {
  width: 100%;
  min-width: 10rem;
}

.upload-labels .menu > summary {
  max-width: 14rem;
  overflow: hidden;
  color: var(--color-link);
  font-size: var(--text-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-labels .menu.disabled > summary {
  color: var(--color-text-secondary);
  pointer-events: none;
}

.label-pop {
  left: 0;
  right: auto;
  max-height: 50vh;
  overflow-y: auto;
}

.label-choice {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-weight: var(--weight-regular);
  white-space: nowrap;
}

.upload-year select {
  min-width: 9rem;
}

.upload-status {
  min-width: 8rem;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.upload-status.ok {
  color: var(--color-success);
}

.upload-status.bad {
  color: var(--color-danger);
  font-weight: var(--weight-medium);
}

.uploads table tr.has-problem td {
  background: var(--color-danger-tint);
}

/* 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);
  font-size: var(--text-sm);
  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-3);
  margin: 0 0 var(--space-5);
}

.stats > div {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-md);
}

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

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

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

/* Where a customer stands, under its name. */
.standing {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
}

/* Why, and what to do about it. */
.callout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1) var(--space-4);
  padding: 11px var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-danger-tint);
  color: var(--color-text);
  font-size: var(--text-sm);
}

/* The figures beside a customer's activity. */
.glance {
  margin: 0;
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-lg);
}

.glance > div {
  padding: var(--space-3) var(--space-4);
}

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

.glance dt {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.glance dd {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 2px 0 0;
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.glance small {
  display: block;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
}

.glance dd a {
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  white-space: nowrap;
}

/* Text someone typed, with the lines they typed it on. */
.prewrap {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* A section kept folded until it is wanted. */
.fold > summary {
  margin-bottom: var(--space-3);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
}

/* One question and its answer, or one topic, on the Help page. */
.help-topic {
  border-top: 1px solid var(--color-separator);
}

.help-topic > summary {
  padding: var(--space-3) 0;
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.help-topic > :not(summary) {
  max-width: 68ch;
  color: var(--color-text-secondary);
}

.help-topic > :last-child {
  padding-bottom: var(--space-4);
}

/* 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);
}

/* ---- Small screens, for the sections above ------------------------------- */

@media (max-width: 760px) {
  .folder-grid {
    grid-template-columns: 1fr 1fr;
  }

  .folder-card,
  .folder-grid .add-card {
    gap: 0 var(--space-2);
    padding: var(--space-2) 10px;
  }

  .toolbar input[type="search"] {
    flex-basis: 100%;
    min-height: 44px;
  }

  .toolbar .scope {
    display: flex;
    flex: 1 0 100%;
  }

  .scope label {
    flex: 1;
  }

  .scope span {
    display: flex;
    justify-content: center;
    min-height: 40px;
  }

  .toolbar button {
    min-height: 44px;
  }
}

/* Previous and Next under a folder's documents (ADR-0066). */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}
