/*
  Caelion workspace · v5 · the parts every page is made of

  Headings, buttons, links, fields, filters, panels, tables, badges and messages, written once
  against the tokens over the names the pages already use (workspace.css). This is the Space
  Gold reading; systems.css gives Material 3, Fluent 2 and Liquid Glass their own.

  The rules of the house:
  - One typeface. Titles are modest and a little wide; figures are plain and tight.
  - Ink is the everyday button. Gold is kept for a person's decision (approve, run, send)
    and for where they are looking (focus). It is never a link colour.
  - Verdigris marks what an agent or the system finished. Amber asks for attention.
  - Navigation looks like navigation (tabs, links), never like a row of equal buttons.
  - A filter applies when you change it. Nothing asks you to press "Apply".
*/

:root[data-layout="v5"] {
  --fs-title: 1.42rem;
  --fs-section: 1rem;
  --fs-body: .92rem;
  --fs-small: .84rem;
  --fs-micro: .76rem;
  --r-field: min(var(--r-ctl), 9px);
  --h-field: max(var(--h-ctl), 36px);
  accent-color: var(--a-fill);

  /* ---------- Type ---------- */

  h1, h2, h3, b, strong {
    font-weight: 620;
  }

  .page-head {
    align-items: flex-start;
    gap: 12px 20px;
    margin: 0 0 18px;
  }

  .page-head h1,
  .auth-card h1 {
    font-size: var(--fs-title);
    font-weight: 640;
    font-stretch: 106%;
    line-height: 1.25;
    letter-spacing: -.02em;
    text-wrap: balance;
  }

  .page-head p {
    max-width: 68ch;
    margin-top: 3px;
    font-size: .9rem;
    line-height: 1.5;
    color: var(--t-3);
  }

  .page-head > .actions {
    gap: 8px;
  }

  .panel-head p,
  .muted {
    color: var(--t-3);
  }

  /* the small line over a title: what kind of record this is, and its state */
  .eyeline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
    font-size: .82rem;
    font-weight: 540;
    letter-spacing: 0;
    text-transform: none;
    color: var(--t-3);
  }

  .back {
    gap: 5px;
    margin: 0 0 10px;
    font-size: .82rem;
    font-weight: 540;
    color: var(--t-3);
    transition: color var(--d-1) ease;
  }

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

  /*
    Mona Sans draws a slashed zero in its tabular figures. Money reads better with the plain
    one, so figures are proportional everywhere in v5, charts and tables included.
  */
  *,
  *::before,
  *::after {
    font-variant-numeric: normal !important;
    font-feature-settings: "tnum" 0 !important;
  }

  kbd {
    border: 1px solid var(--b-1);
    border-radius: 5px;
    background: var(--s-2);
    color: var(--t-3);
    font-family: var(--font-ui);
  }

  /* ---------- Links ---------- */

  /* a link is ink; gold is a decision, and a link is not one */
  .text-link,
  .auth-link a {
    color: var(--t-2);
    font-size: .84rem;
    font-weight: 570;
    transition: color var(--d-1) ease;
  }

  .text-link .icon {
    width: 15px;
    height: 15px;
    color: var(--t-3);
  }

  .record-link {
    color: var(--t-1);
    font-weight: 590;
  }

  /* a link inside running text is underlined, so it reads as one without colour */
  .workspace-content :is(p, li, dd, .message, .muted) > .record-link,
  .workspace-content :is(p, dd, .message) > a:not([class]) {
    text-decoration: underline;
    text-decoration-color: var(--b-2);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
  }

  /* ---------- Sibling pages: a strip of tabs under the title ---------- */

  .w5-links {
    display: flex;
    gap: 2px;
    margin: -4px 0 18px;
    overflow-x: auto;
    border-bottom: 1px solid var(--b-0);
    scrollbar-width: none;
  }

  .w5-links::-webkit-scrollbar {
    display: none;
  }

  .w5-links > :is(a, span) {
    position: relative;
    flex: none;
    padding: 8px 10px 10px;
    font-size: .88rem;
    font-weight: 550;
    white-space: nowrap;
    color: var(--t-3);
    transition: color var(--d-1) ease;
  }

  .w5-links > :first-child {
    padding-left: 2px;
  }

  .w5-links > [aria-current] {
    color: var(--t-1);
  }

  .w5-links > [aria-current]::after {
    content: "";
    position: absolute;
    right: 10px;
    bottom: -1px;
    left: 10px;
    height: 2px;
    border-radius: 2px 2px 0 0;
    background: var(--t-1);
  }

  .w5-links > [aria-current]:first-child::after {
    left: 2px;
  }

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

  .btn,
  .small-btn {
    min-height: var(--h-ctl);
    padding: 0 13px;
    border-radius: var(--r-ctl);
    font-size: .87rem;
    font-weight: 590;
    letter-spacing: -.003em;
    transition:
      background-color var(--d-1) ease,
      border-color var(--d-1) ease,
      color var(--d-1) ease,
      box-shadow var(--d-2) ease,
      filter var(--d-1) ease,
      transform var(--d-1) var(--e-out);
  }

  .btn .icon,
  .small-btn .icon {
    width: 16px;
    height: 16px;
  }

  .btn.compact,
  .small-btn {
    min-height: var(--h-ctl-s);
    padding: 0 10px;
    border-radius: max(calc(var(--r-ctl) - 2px), 4px);
    font-size: .8rem;
    font-weight: 570;
  }

  /* everyday action: an ink key */
  .btn.primary {
    border-color: transparent;
    background: var(--t-1);
    color: var(--s-base);
    box-shadow: inset 0 1px 0 oklch(1 0 0 / .12), var(--sh-1);
  }

  /* a person's decision: gold, lit from above, sinks when pressed */
  .btn.gold {
    border-color: color-mix(in oklch, var(--a-fill-2) 70%, oklch(.3 .05 var(--acc-h)));
    background: linear-gradient(180deg, color-mix(in oklch, var(--a-fill) 92%, white), var(--a-fill) 45%, var(--a-fill-2));
    color: var(--a-on);
    box-shadow:
      inset 0 1px 0 oklch(1 0 0 / .45),
      inset 0 -1px 0 oklch(0 0 0 / .08),
      0 1px 2px color-mix(in oklch, var(--a-fill-2) 40%, transparent),
      0 6px 14px -7px var(--a-glow);
  }

  .btn.gold:active {
    box-shadow: inset 0 1px 2px oklch(0 0 0 / .16), 0 0 0 transparent;
    transform: translateY(.5px) scale(.985);
  }

  .btn.secondary,
  .small-btn {
    border: 1px solid var(--b-1);
    background: var(--s-1);
    color: var(--t-1);
    box-shadow: var(--sh-1);
  }

  .btn.secondary .icon,
  .small-btn .icon {
    color: var(--t-3);
  }

  /* the quietest button: for the third thing on a row */
  .btn.quiet {
    border-color: transparent;
    background: transparent;
    color: var(--t-2);
    box-shadow: none;
  }

  .icon-btn {
    display: inline-grid;
    place-items: center;
    width: calc(var(--h-ctl) - 2px);
    height: calc(var(--h-ctl) - 2px);
    padding: 0;
    border: 0;
    border-radius: var(--r-item);
    background: transparent;
    color: var(--t-3);
    box-shadow: none;
    transition: background-color var(--d-1) ease, color var(--d-1) ease;
  }

  .icon-btn .icon {
    width: 17px;
    height: 17px;
  }

  .small-btn.danger,
  .btn.danger {
    color: var(--bad);
  }

  .btn:disabled,
  .small-btn:disabled,
  .icon-btn:disabled {
    opacity: .45;
  }

  /* ---------- Fields ---------- */

  .field,
  .filterbar > label,
  .inline-form label {
    gap: 6px;
    font-size: .84rem;
    font-weight: 560;
    color: var(--t-2);
  }

  :is(.field, .inline-form, .filterbar, .auth-form) :is(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]), select, textarea) {
    min-height: var(--h-field);
    border: 1px solid var(--b-1);
    border-radius: var(--r-field);
    background-color: var(--s-well);
    color: var(--t-1);
    font-size: .92rem;
    font-weight: 450;
    box-shadow: none;
    transition: border-color var(--d-1) ease, box-shadow var(--d-1) ease, background-color var(--d-1) ease;
  }

  /* a hint in an empty field is still text to be read: the quiet ink at full strength, in every
     field of the suite (the older sheets drew it at 85% of an ink that only just passed) */
  ::placeholder {
    color: var(--t-3);
    opacity: 1;
  }

  :is(.field, .inline-form, .filterbar, .auth-form) :is(input:not([type="checkbox"], [type="radio"]), select, textarea):focus-visible {
    outline: 0;
    border-color: var(--a-ring);
    background-color: var(--s-1);
    box-shadow: 0 0 0 3px color-mix(in oklch, var(--a-ring) 22%, transparent);
  }

  .field small,
  .field .help {
    font-size: .8rem;
    font-weight: 430;
    line-height: 1.45;
    color: var(--t-3);
  }

  .field.invalid :is(input, select, textarea) {
    border-color: var(--bad);
  }

  .field :is(.errorlist, .form-error) {
    font-weight: 500;
    color: var(--bad);
  }

  .form-pane {
    padding: 22px 24px 24px;
  }

  .form-footer {
    gap: 8px;
  }

  /* ---------- Filters: one quiet row over a table ---------- */

  .filterbar {
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--b-0);
  }

  .filterbar .search-field {
    flex: 0 1 300px;
    gap: 6px;
    max-width: none;
    height: 32px;
    padding-left: 10px;
    border: 1px solid var(--b-1);
    border-radius: var(--r-field);
    background: var(--s-well);
    transition: border-color var(--d-1) ease, box-shadow var(--d-1) ease, background-color var(--d-1) ease;
  }

  .filterbar .search-field:focus-within {
    border-color: var(--a-ring);
    background: var(--s-1);
    box-shadow: 0 0 0 3px color-mix(in oklch, var(--a-ring) 22%, transparent);
  }

  .filterbar .search-field .icon {
    width: 15px;
    height: 15px;
    color: var(--t-4);
  }

  .filterbar .search-field input {
    min-height: 0;
    height: 30px;
    padding: 0 8px 0 0;
    font-size: .88rem;
  }

  /* the capsule is the field: the input inside has no box of its own. Each design system
     restyles every field with a rule that outweighs a plain reset, and Liquid Glass's
     translucent fill, laid over the capsule's, showed as a darker slab beside the icon. */
  .filterbar .search-field.search-field input:not([type="checkbox"], [type="radio"]),
  .filterbar .search-field.search-field input:not([type="checkbox"], [type="radio"]):focus-visible {
    border: 0;
    background-color: transparent;
    box-shadow: none;
  }

  /* a filter reads as a sentence: "Status  All", the name in grey and the choice in ink */
  .filterbar > .w5-filter {
    position: relative;
    flex-direction: row;
    align-items: center;
    gap: 0;
    height: 32px;
    padding-left: 10px;
    border: 1px solid var(--b-1);
    border-radius: var(--r-field);
    background: var(--s-1);
    font-size: .84rem;
    font-weight: 500;
    white-space: nowrap;
    color: var(--t-3);
    box-shadow: var(--sh-1);
    transition: border-color var(--d-1) ease, box-shadow var(--d-1) ease;
  }

  .filterbar > .w5-filter:focus-within {
    border-color: var(--a-ring);
    box-shadow: 0 0 0 3px color-mix(in oklch, var(--a-ring) 22%, transparent);
  }

  .filterbar > .w5-filter :is(select, input) {
    flex: none;
    width: auto;
    min-height: 0;
    height: 30px;
    padding-block: 0;
    padding-left: 6px;
    line-height: 30px;
    border: 0;
    border-radius: 0 var(--r-field) var(--r-field) 0;
    background-color: transparent;
    font-size: .84rem;
    font-weight: 570;
    box-shadow: none;
  }

  .filterbar > .w5-filter :is(select, input):focus-visible {
    background-color: transparent;
    box-shadow: none;
  }

  /* the choice inside a chip is never a field of its own: Material, Fluent and Liquid Glass each
     restyle every field, and their rule outweighs the reset above, which had put a second
     outline, a taller box or a fill inside the chip */
  .filterbar > .w5-filter.w5-filter :is(select, input):not([type="checkbox"], [type="radio"]) {
    min-height: 0;
    border: 0;
    background-color: transparent;
    box-shadow: none;
  }

  .filterbar > .w5-filter.w5-filter :is(select, input):not([type="checkbox"], [type="radio"]):focus-visible {
    border: 0;
    background-color: transparent;
    box-shadow: none;
  }

  /* a filter that is set stands out from the ones that are not */
  .filterbar > .w5-filter.is-set {
    border-color: var(--b-2);
    background: var(--s-2);
  }

  .filterbar .btn {
    min-height: 32px;
  }

  /* changes apply as they are made (v5.js); the button stays for when scripts are off */
  .filterbar[data-live] > :is(.btn, button[type="submit"]) {
    display: none;
  }

  .filterbar .w5-count {
    margin-left: auto;
    padding-right: 4px;
    font-size: .8rem;
    font-weight: 500;
    white-space: nowrap;
    color: var(--t-3);
  }

  .filterbar[aria-busy="true"] ~ :is(.table-scroll, .table-footer) {
    opacity: .55;
    transition: opacity var(--d-2) ease 120ms;
  }

  .column-picker summary {
    gap: 6px;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--b-1);
    border-radius: var(--r-field);
    background: var(--s-1);
    font-size: .84rem;
    font-weight: 570;
    box-shadow: var(--sh-1);
  }

  /* ---------- Plates ---------- */

  .panel {
    border: 1px solid var(--b-1);
    border-radius: var(--r-card);
    background: var(--s-1);
    box-shadow: var(--sh-1);
  }

  .panel h2 {
    font-size: var(--fs-section);
    font-weight: 640;
    font-stretch: 103%;
    letter-spacing: -.014em;
  }

  .panel h3 {
    font-size: .92rem;
    font-weight: 620;
  }

  .panel-head {
    padding: 14px 18px;
  }

  .panel-head p {
    margin-top: 2px;
    font-size: .84rem;
  }

  .panel-foot {
    border-top-color: var(--b-0);
    color: var(--t-3);
  }

  .tile-icon {
    border-radius: min(var(--r-ctl), 9px);
    background: var(--s-2);
    box-shadow: inset 0 0 0 1px var(--b-0);
    color: var(--t-2);
  }

  .count {
    background: var(--f-press);
    color: var(--t-2);
  }

  .attention-row {
    border-radius: min(var(--r-card), 10px);
  }

  /* the bank account being looked at is a choice, and what is chosen is ink: gold stays for what needs deciding */
  .account-card {
    border-color: var(--b-1);
    border-radius: var(--r-card);
    background: var(--s-1);
    box-shadow: var(--sh-1);
    transition:
      border-color var(--d-1) ease,
      box-shadow var(--d-1) ease;
  }

  .account-card:hover {
    border-color: var(--b-2);
  }

  .account-card.selected,
  .account-card.selected:hover {
    border-color: var(--t-2);
    box-shadow:
      0 0 0 1px var(--t-2),
      var(--sh-2);
  }

  .attention-row .count {
    background: var(--a-soft);
    color: var(--a-ink);
  }

  .empty {
    padding: 44px 24px;
    font-size: .9rem;
    color: var(--t-3);
  }

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

  .table-scroll table {
    font-size: .88rem;
  }

  th {
    padding-block: 9px;
    background: transparent;
    color: var(--t-3);
    font-size: .76rem;
    font-weight: 560;
  }

  td {
    padding-block: 10px;
  }

  td,
  th {
    padding-inline: 14px;
    border-bottom-color: var(--b-0);
  }

  th:first-child,
  td:first-child {
    padding-left: 18px;
  }

  th:last-child,
  td:last-child {
    padding-right: 18px;
  }

  thead th {
    border-top-color: transparent;
    border-bottom-color: var(--b-1);
  }

  /* A row's own heading belongs to its row: the row's ink at the row's size. The column heading's
     small grey, which every th took, made an account in a budget, a period in a table of figures
     and the label of a totals row read as captions. */
  :is(tbody, tfoot) th {
    color: var(--t-1);
    font-size: inherit;
    font-weight: 520;
  }

  /* the last row has no rule under it, and that goes for its heading cell too */
  tbody:last-of-type > tr:last-child > th {
    border-bottom: 0;
  }

  tbody tr:hover {
    background: var(--f-hover);
  }

  .sub {
    margin-top: 1px;
    font-size: .78rem;
    color: var(--t-3);
  }

  .row-actions {
    justify-content: flex-end;
    gap: 6px;
  }

  .table-footer {
    padding: 9px 18px;
    border-top-color: var(--b-0);
    font-size: .8rem;
    color: var(--t-3);
  }

  .table-footer nav a {
    height: 26px;
    border-color: var(--b-1);
    border-radius: max(calc(var(--r-ctl) - 2px), 4px);
    background: var(--s-1);
    font-weight: 560;
  }

  /* ---------- Badges and messages ---------- */

  .badge {
    height: 21px;
    padding: 0 8px 0 7px;
    background: var(--f-hover);
    color: var(--t-2);
    font-size: .75rem;
    font-weight: 550;
    box-shadow: inset 0 0 0 1px var(--b-0);
  }

  .badge.amber {
    background: var(--warn-soft);
    color: var(--warn);
    box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--warn) 22%, transparent);
  }

  .badge.amber::before {
    background: var(--warn);
  }

  .message {
    border-radius: min(var(--r-card), 10px);
    font-size: .88rem;
  }

  .message.warning {
    background: var(--warn-soft);
    color: var(--warn);
    box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--warn) 22%, transparent);
  }

  /* ---------- Metric strip: readings in a row, no boxes ---------- */

  .metric-strip {
    border-color: var(--b-1);
  }

  .metric-strip > div + div {
    border-left-color: var(--b-0);
  }

  .metric-strip strong {
    font-stretch: 104%;
    letter-spacing: -.025em;
  }

  /* ---------- Scrollbars ---------- */

  * {
    scrollbar-color: color-mix(in oklch, var(--t-3) 45%, transparent) transparent;
  }
}

@media (hover: hover) and (pointer: fine) {
  :root[data-layout="v5"] {
    .btn.primary:hover {
      background: color-mix(in oklch, var(--t-1) 86%, var(--s-1));
    }

    .btn.gold:hover {
      filter: brightness(1.04) saturate(1.04);
    }

    .btn.secondary:hover,
    .small-btn:hover,
    .column-picker summary:hover,
    .filterbar > .w5-filter:hover {
      border-color: var(--b-2);
      background: var(--s-1);
      color: var(--t-1);
    }

    .btn.quiet:hover,
    .icon-btn:hover {
      background: var(--f-hover);
      color: var(--t-1);
    }

    .text-link:hover,
    .back:hover,
    .w5-links > a:hover {
      color: var(--t-1);
    }

    .text-link:hover,
    .record-link:hover {
      text-decoration: underline;
      text-decoration-color: var(--b-2);
      text-decoration-thickness: 1px;
      text-underline-offset: 3px;
    }

    :is(.field, .inline-form, .filterbar, .auth-form) :is(input:not([type="checkbox"], [type="radio"]), select, textarea):hover:not(:focus-visible) {
      border-color: var(--b-2);
    }

    .filterbar > .w5-filter :is(select, input):hover:not(:focus-visible) {
      border-color: transparent;
    }
  }
}

@media (max-width: 640px) {
  :root[data-layout="v5"] {
    /* a page's actions wrap onto a second line instead of running off the side; the main one leads */
    .page-head > .actions {
      flex-wrap: wrap;
      overflow: visible;
      width: 100%;
      margin: 0;
      padding: 0;
    }

    .page-head > .actions > .btn.primary,
    .page-head > .actions > .new-menu {
      order: -1;
    }

    /*
      The chart of accounts: four columns do not fit a phone. A row becomes the account and its
      balance, with what the account is for and its doors underneath.
    */
    .coa-group table,
    .coa-group tbody {
      display: block;
    }

    .coa-group tr {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      align-items: baseline;
      gap: 3px 12px;
      padding: 12px 16px;
      border-top: 1px solid var(--b-0);
    }

    .coa-group td,
    .coa-group td:first-child,
    .coa-group td:last-child {
      width: auto;
      padding: 0;
      border: 0;
    }

    .coa-name {
      grid-area: 1 / 1;
    }

    .coa-group tr.sub .coa-name {
      padding-left: 14px;
    }

    .coa-balance {
      grid-area: 1 / 2;
      text-align: right;
    }

    .coa-desc {
      grid-area: 2 / 1 / auto / -1;
    }

    .coa-desc:empty {
      display: none;
    }

    .coa-actions {
      grid-area: 3 / 1 / auto / -1;
      margin-top: 6px;
      text-align: left;
    }

    /* a list as stacked rows: the cells give their padding back to the row */
    .stack-table td,
    .stack-table td:first-child,
    .stack-table td:last-child {
      padding: 0;
    }

    .stack-table tr {
      gap: 5px 14px;
      padding: 12px 16px;
    }

    .stack-table td[data-label]:not(:first-child)::before {
      color: var(--t-3);
    }

    .filterbar > .w5-filter {
      flex: 1 1 auto;
    }

    .filterbar > .w5-filter :is(select, input) {
      flex: 1 1 auto;
    }
  }
}

@media (max-width: 620px) {
  :root[data-layout="v5"] {
    .filterbar .search-field {
      flex: 1 1 100%;
    }

    .filterbar .w5-count {
      display: none;
    }
  }
}

/* ---------- The sweep: the same rules for the pages that were built by hand ---------- */

:root[data-layout="v5"] {
  /* a panel that pads itself: its head must not pad again */
  .panel-head.bare {
    padding: 0;
  }

  .detail-panel,
  .statement,
  .issues {
    padding: 18px 20px;
  }

  .detail-panel > .panel-head.bare {
    margin-bottom: 4px;
  }

  /* any filter row, not only a list's: the name in grey, the choice in ink, no "Apply" */
  .filterbar > label:not(.search-field, .w5-filter) {
    position: relative;
    flex-direction: row;
    align-items: center;
    gap: 0;
    height: 32px;
    padding-left: 10px;
    border: 1px solid var(--b-1);
    border-radius: var(--r-field);
    background: var(--s-1);
    font-size: .84rem;
    font-weight: 500;
    white-space: nowrap;
    color: var(--t-3);
    box-shadow: var(--sh-1);
  }

  .filterbar > label:not(.search-field, .w5-filter) :is(select, input) {
    flex: none;
    width: auto;
    min-height: 0;
    height: 30px;
    padding-block: 0;
    padding-left: 6px;
    border: 0;
    border-radius: 0 var(--r-field) var(--r-field) 0;
    background-color: transparent;
    font-size: .84rem;
    font-weight: 570;
    line-height: 30px;
    box-shadow: none;
  }

  .filterbar > label:not(.search-field, .w5-filter):focus-within {
    border-color: var(--a-ring);
    box-shadow: 0 0 0 3px color-mix(in oklch, var(--a-ring) 22%, transparent);
  }

  .filterbar > label:not(.search-field, .w5-filter) :is(select, input):focus-visible {
    background-color: transparent;
    box-shadow: none;
  }

  /* a report's or a register's chip holds a choice, not a field of its own, in every system (as
     the list's chips above): each system restyles every field with a rule that outweighs the
     reset, which had drawn a second outline, or a fill, inside the chip */
  .filterbar.filterbar > label:not(.search-field, .w5-filter) :is(select, input):not([type="checkbox"], [type="radio"]) {
    min-height: 0;
    border: 0;
    border-radius: 0 var(--r-field) var(--r-field) 0;
    background-color: transparent;
    box-shadow: none;
  }

  .filterbar.filterbar > label:not(.search-field, .w5-filter) :is(select, input):not([type="checkbox"], [type="radio"]):focus-visible {
    border: 0;
    background-color: transparent;
    box-shadow: none;
  }

  /* a yes-or-no chip: the box at its own size, the words in the middle, room at both ends. The
     base sheet lifts this label by its bottom padding to meet fields that a chip row has not, and
     the chip's field rule had stretched the box to the chip's height */
  .filterbar > label.check:not(.search-field, .w5-filter) {
    gap: 7px;
    padding: 0 12px 0 10px;
    color: var(--t-2);
    cursor: pointer;
  }

  .filterbar > label.check:not(.search-field, .w5-filter):has(input:checked) {
    color: var(--t-1);
  }

  .filterbar.filterbar > label.check:not(.search-field, .w5-filter) input:is([type="checkbox"], [type="radio"]) {
    flex: none;
    width: 14px;
    height: 14px;
    margin: 0;
    padding: 0;
    line-height: normal;
  }

  /* The list of columns is often taller than a short report, and the panel that holds a report cuts
     whatever leaves it. While the list is open the panel lets it out (its first and last parts keep
     the corners), and a long list scrolls in itself. */
  .data-panel:has(.column-picker[open]) {
    overflow: visible;
  }

  .data-panel:has(.column-picker[open]) > :first-child {
    border-top-left-radius: inherit;
    border-top-right-radius: inherit;
  }

  .data-panel:has(.column-picker[open]) > :last-child {
    border-bottom-right-radius: inherit;
    border-bottom-left-radius: inherit;
  }

  .column-picker > div {
    max-height: min(26rem, 60vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--b-2) transparent;
  }

  /* The figures behind a chart scroll inside their card. The part that holds them is a flex or grid
     item, and it had been as wide as its table: on a phone the table ran off the left of the screen,
     or widened the whole page. */
  :is(.chart-table, .viz-figures) {
    min-width: 0;
    max-width: 100%;
  }

  /* a filter row that stands on the page rather than in a panel */
  .workspace-content > .filterbar,
  .workspace-content > form.filterbar {
    padding: 0 0 12px;
    border-bottom: 0;
  }

  /* people are drawn as people: a round mark of their initials */
  .portrait {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--t-1);
    color: var(--s-1);
    font-size: 1.05rem;
    font-weight: 640;
    font-stretch: 100%;
    box-shadow: none;
  }

  .w5-person {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
  }

  .w5-avatar {
    display: grid;
    flex: none;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--s-2);
    color: var(--t-2);
    font-size: .72rem;
    font-weight: 640;
    letter-spacing: .01em;
    box-shadow: inset 0 0 0 1px var(--b-1);
  }

  .w5-person > span:last-child {
    display: grid;
    min-width: 0;
  }

  /* reports: a list to choose from, not a wall of cards */
  .report-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
    gap: 10px;
  }

  .report-card {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 16px;
    grid-template-areas: "icon title arrow" "icon text arrow";
    align-items: center;
    gap: 1px 12px;
    padding: 12px 14px;
    transition: border-color var(--d-1) ease, box-shadow var(--d-2) ease;
  }

  .report-card > div {
    display: contents;
  }

  .report-card .tile-icon {
    grid-area: icon;
    width: 34px;
    height: 34px;
  }

  .report-card .tile-icon .icon {
    width: 17px;
    height: 17px;
  }

  .report-card > div > .icon {
    grid-area: arrow;
    width: 15px;
    height: 15px;
    color: var(--t-4);
    transition: transform var(--d-2) var(--e-out), color var(--d-1) ease;
  }

  .report-card h2 {
    grid-area: title;
    margin: 0;
    font-size: .92rem;
    font-weight: 600;
    font-stretch: 100%;
    letter-spacing: -.004em;
  }

  .report-card p {
    grid-area: text;
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    font-size: .82rem;
    line-height: 1.4;
    color: var(--t-3);
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  /* a tab strip that runs past the edge says so (v5.js marks it) */
  .w5-links[data-more] {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent);
  }

  /* the agent's settings page: what is chosen is marked in ink, as everywhere else */
  .mode-option[aria-pressed="true"] {
    border-color: var(--t-1);
    background: var(--f-selected);
    box-shadow: none;
  }

  .mode-option[aria-pressed="true"] .icon {
    color: var(--t-1);
  }
}

@media (hover: hover) and (pointer: fine) {
  :root[data-layout="v5"] {
    a.report-card:hover {
      border-color: var(--b-2);
      box-shadow: var(--sh-2);
    }

    a.report-card:hover h2 {
      color: var(--t-1);
    }

    a.report-card:hover > div > .icon {
      color: var(--t-2);
      transform: translateX(2px);
    }
  }
}

/* ---------- A person's page ---------- */

:root[data-layout="v5"] {
  .person-title {
    gap: 14px;
  }

  .profile-grid {
    gap: 16px;
  }

  .profile-grid > .detail-panel {
    margin-bottom: 0;
  }

  .profile-grid + * {
    margin-top: 16px;
  }

  .facts dt {
    font-size: .8rem;
    color: var(--t-3);
  }

  .facts dd {
    margin-top: 2px;
    font-weight: 560;
  }

  .facts dd .text-link {
    margin-left: 8px;
    font-size: .8rem;
  }

  .large-number {
    font-size: 2rem;
    font-weight: 640;
    font-stretch: 104%;
    letter-spacing: -.03em;
  }

  .large-number small {
    font-size: .86rem;
    font-weight: 450;
    letter-spacing: 0;
    color: var(--t-3);
  }

  /* panels that only lead somewhere (benefits, contact details, withholding, I-9) are one list */
  .link-panel {
    margin-bottom: 0;
    padding: 13px 18px;
    border-radius: 0;
    box-shadow: none;
  }

  .link-panel + .link-panel {
    border-top: 0;
  }

  :not(.link-panel) + .link-panel,
  .link-panel:first-child {
    border-top-left-radius: var(--r-card);
    border-top-right-radius: var(--r-card);
  }

  .link-panel:not(:has(+ .link-panel)) {
    margin-bottom: 16px;
    border-bottom-right-radius: var(--r-card);
    border-bottom-left-radius: var(--r-card);
  }

  .link-panel .panel-head h2 {
    font-size: .93rem;
    font-weight: 600;
    font-stretch: 100%;
  }

  .link-panel .panel-head p {
    margin-top: 1px;
    font-size: .84rem;
  }
}

/* ---------- The agent's settings page (it shares its markup with the earlier designs) ---------- */

:root[data-layout="v5"] {
  /* a switch that can be seen: its word, then the switch, at the row's right edge */
  .switch-btn {
    gap: 9px;
    padding: 2px;
    color: var(--t-3);
    font-size: .78rem;
  }

  .switch-btn > .switch {
    position: relative;
    flex: none;
    order: 2;
    width: 32px;
    height: 19px;
    border-radius: 999px;
    background: var(--b-2);
    transition: background-color var(--d-2) ease;
  }

  .switch-btn > .switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px oklch(0 0 0 / .25);
    transition: transform var(--d-2) var(--e-out);
  }

  .switch-btn[aria-pressed="true"] > .switch {
    background: var(--t-1);
  }

  .switch-btn[aria-pressed="true"] > .switch::after {
    transform: translateX(13px);
  }

  &[data-theme="dark"] .switch-btn[aria-pressed="true"] > .switch::after {
    background: var(--s-base);
  }

  /* a section's icon names it; it is not a decision, so it is not gold */
  .settings-block > header > .icon {
    color: var(--t-3);
  }
}

/*
  Pages with a column beside them (a document and its actions, the cash card and what waits on
  you, a contact and its card, a form and its notes). The older rule turned them into one column
  by the window's width, which knows nothing of the app rail, the sidebar or a docked agent: at
  1024 the paper was left 295px. Here the two stand side by side while both have room and the
  side column moves under the main one when they do not, whatever took the room.
*/
@media screen {
  :root[data-layout="v5"] {
    :is(.doc-layout, .books-top, .party-layout, .settings-layout) {
      display: flex;
      flex-wrap: wrap;
      align-items: flex-start;
    }

    :is(.doc-layout, .books-top, .party-layout, .settings-layout) > * {
      flex: 999 1 520px;
      min-width: 0;
    }

    :is(.party-layout, .settings-layout) > aside {
      flex: 1 1 320px;
    }

    .doc-layout > .doc-side,
    .books-top > .attention {
      flex: 1 1 340px;
    }
  }
}

:root[data-layout="v5"] {
  /* a document on its paper keeps the paper's own ink, rules and margins in every theme: the
     workspace's table rules had inset its lines 18px and, in the dark, lit its headings */
  .paper-lines :is(th, td) {
    border-bottom-color: var(--paper-line);
  }

  /* (table.: Material and Fluent restyle every th, and theirs is the later sheet) */
  table.paper-lines th {
    padding: 10px 0;
    color: var(--paper-sub);
  }

  .paper-lines td {
    padding: 13px 0;
  }

  .paper-lines :is(td, th):first-child,
  .ledger-mini :is(td, th):first-child {
    padding-left: 0;
  }

  .paper-lines :is(td, th):last-child,
  .ledger-mini :is(td, th):last-child {
    padding-right: 0;
  }

  .paper-lines :is(td, th) + :is(td, th) {
    padding-left: 18px;
  }

  .paper-lines tbody tr:hover {
    background: none;
  }

  /* the small ledger in a side panel has no room for a table's margins */
  .ledger-mini :is(td, th) {
    padding: 7px 0;
  }

  .ledger-mini :is(td, th) + :is(td, th) {
    padding-left: 12px;
  }
}

/* Spanish names are longer: the app rail sets them a little narrower so "Contabilidad" stays inside it */
:root[data-layout="v5"]:lang(es) .w5-app-name {
  font-stretch: 88%;
}

:root[data-layout="v5"] {
  /* The Books overview's tiles stand three, two or one to a row by the width their grid really
     has, not the window's: three tiles in 890px left "Profit this month" no room for its head */
  .books-grid {
    container-type: inline-size;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .books-tile {
    grid-column: span 2;
  }

  .books-tile:is(.accounts-tile, .spend-tile) {
    grid-column: span 3;
  }

  @container (max-width: 1040px) {
    .books-tile {
      grid-column: span 3;
    }

    .books-tile.spend-tile {
      grid-column: 1 / -1;
    }
  }

  @container (max-width: 620px) {
    .books-tile,
    .books-tile:is(.accounts-tile, .spend-tile) {
      grid-column: 1 / -1;
    }
  }

  /* a document's title is sized by its paper, not by the window the paper stands in */
  .doc-paper {
    container-type: inline-size;
  }

  .paper-title h2 {
    font-size: clamp(1.6rem, 6.1cqi, 2.2rem);
  }
}

:root[data-layout="v5"] {
  /* A financial statement keeps its own hierarchy. The suite's table dress had made every account's
     name a small grey column heading, flush with its section's title, and a total's label lighter
     than its figure: the statement's own rules stand above that dress here. */
  .statement:not(.list, .ledger) :is(th, td) {
    padding-block: 8px;
  }

  .statement tbody th {
    color: var(--t-1);
    font-size: inherit;
    font-weight: 450;
  }

  .statement .st-section th {
    padding-top: 20px;
    font-weight: 640;
  }

  .statement .st-major th {
    padding-top: 24px;
    font-size: .96rem;
  }

  .statement .st-row.depth-0 th,
  .statement .st-subtotal th {
    padding-left: 32px;
  }

  .statement .st-row.depth-1 th {
    padding-left: 48px;
  }

  /* a subtotal that opens its own group (gross profit, the net change in cash) sums the whole
     statement so far, not a block of it: it stands flush, with the lines around it */
  .statement tbody > .st-subtotal:first-child th {
    padding-left: 18px;
  }

  .statement .st-row.st-hint th {
    color: var(--t-3);
    font-size: .8rem;
  }

  .statement .st-subtotal :is(th, td) {
    font-weight: 600;
  }

  .statement .st-total :is(th, td) {
    font-weight: 640;
  }

  .statement .st-net :is(th, td) {
    padding-top: 12px;
    font-size: .96rem;
    font-weight: 700;
  }

  /* an account's name is a way in to its ledger, at the weight of the line it stands on */
  .statement :is(.st-row, .st-section) .record-link {
    font-weight: inherit;
  }

  /* a document's title keeps its line: the sender's address gives way first */
  .paper-from {
    flex: 1 1 0%;
  }
}

@media (max-width: 640px) {
  :root[data-layout="v5"] {
    /* A first column held in place carries its own rules. With collapsed borders the rules belong
       to the table, and the held cell hid some of them: the head's, and a row's here and there.
       (A table's own padding, ignored until now, would start to count: it is set to nothing.) */
    .table-scroll:not(.stack-table) table {
      border-collapse: separate;
      border-spacing: 0;
      padding: 0;
    }

    /* on a phone the sheet's own margin is enough: the cells give theirs back to the names */
    .statement :is(th, td) {
      padding-inline: 8px;
    }

    .statement :is(th, td):first-child {
      padding-left: 2px;
    }

    .statement th[colspan] > :is(.st-stay, .record-link) {
      left: 2px;
    }

    .statement :is(th, td):last-child {
      padding-right: 2px;
    }

    .statement .st-row.depth-0 th,
    .statement .st-subtotal th {
      padding-left: 14px;
    }

    .statement .st-row.depth-1 th {
      padding-left: 26px;
    }

    .statement tbody > .st-subtotal:first-child th {
      padding-left: 2px;
    }
  }
}

:root[data-layout="v5"] {
  /* A button alone on its line is never wider than the card it stands in: its words take a second
     line (Spanish: "Configuración del agente del espacio de trabajo", on a phone) */
  .panel-head > .btn,
  .panel-head > .actions > .btn {
    max-width: 100%;
    padding-block: 5px;
    white-space: normal;
  }
}

/* ---------- On paper ---------- */

@media print {
  :root[data-layout="v5"] {
    /* A printed report or document is its sheet: no card drawn round it (the card's padding is
       already given back, so its border hugged the figures), and none of the page's own controls */
    .statement-sheet,
    .doc-paper {
      border: 0;
      border-radius: 0;
      background: none;
      box-shadow: none;
    }

    .recon-edit,
    .viz-figures:not([open]),
    .viz-figures > summary {
      display: none !important;
    }

    /* the sheet of paper is narrower than the window the table was laid out for */
    .table-scroll table {
      font-size: 9pt;
    }

    .table-scroll :is(td, th) {
      padding: 5px 8px;
    }

    table.statement {
      white-space: normal;
    }

    .statement :is(th, td) {
      padding: 4px 8px;
    }

    .statement .num {
      min-width: 0;
      white-space: nowrap;
    }

    .statement .st-row.depth-0 th,
    .statement .st-subtotal th {
      padding-left: 22px;
    }

    .statement .st-row.depth-1 th {
      padding-left: 36px;
    }

    .statement tbody > .st-subtotal:first-child th {
      padding-left: 8px;
    }

    .statement .st-section th {
      padding-top: 14px;
    }
  }
}

:root[data-layout="v5"] {
  /* The budget is a grid to type in: its cells sit close, its rows are named by their accounts,
     and each group of accounts stands under a quiet band. */
  .budget-table td {
    padding: 6px 4px;
  }

  .budget-table td:last-child {
    padding-right: 18px;
  }

  .budget-table tbody th[scope="row"] {
    font-size: .84rem;
    font-weight: 560;
  }

  .budget-table .budget-section th {
    padding-block: 7px;
    background: var(--s-2);
    color: var(--t-2);
    font-size: .78rem;
    font-weight: 600;
  }

  /* the rule between one group and the next (a group's last row had lost it under its figures
     and kept it under its name) */
  .budget-table tbody > tr:last-child > :is(td, th) {
    border-bottom: 1px solid var(--b-0);
  }

  .budget-table tbody:last-of-type > tr:last-child > :is(td, th) {
    border-bottom: 0;
  }

  /* twelve months do not fit beside the accounts on most screens: the names stay while the
     months pass under them */
  .budget-table {
    border-collapse: separate;
    border-spacing: 0;
  }

  .budget-table :is(thead th:first-child, tbody th[scope="row"]) {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--s-1);
  }

  .budget-table tbody tr:hover > th[scope="row"] {
    background: color-mix(in oklch, var(--s-1), var(--t-1) 5%);
  }

  .budget-table :is(thead th:first-child, tbody th[scope="row"])::after {
    content: "";
    position: absolute;
    top: 0;
    right: -8px;
    bottom: 0;
    width: 8px;
    background: linear-gradient(to right, oklch(.3 .02 70 / .07), transparent);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
  }

  .table-scroll.scrolled-x .budget-table :is(thead th:first-child, tbody th[scope="row"])::after {
    opacity: 1;
  }

  /* the worksheet's totals stand on one band from edge to edge (its label had lost the fill) */
  .gn-sheet tfoot :is(th, td) {
    background: var(--s-2);
    font-size: .84rem;
  }
}

:root[data-layout="v5"] {
  /* The figures behind a chart, and the list under the cash chart, are set to their card's own
     margins: the first and last columns stand flush with the chart and the heading above. */
  :is(.viz-figures, .cash-items) :is(th, td):first-child {
    padding-left: 0;
  }

  :is(.viz-figures, .cash-items) :is(th, td):last-child {
    padding-right: 0;
  }

  .viz-figures tfoot :is(th, td) {
    border-top: 1px solid var(--b-1);
    border-bottom: 0;
    font-weight: 620;
  }

  /* the group's name stays in view while the months pass (as a statement's section titles do) */
  .budget-section .st-stay {
    position: sticky;
    left: 18px;
    display: inline-block;
  }

  /* Anything that opens says so. The older sheets hide the browser's marker on every summary and
     draw a chevron only on a panel that opens, so a part of a worksheet, a lookup or a plain
     details read as a heading with nothing under it. */
  :is(details.worksheet-section, details.notice-lookup, details:not([class])) > summary {
    display: flex;
    align-items: center;
    gap: 6px;
    width: fit-content;
    max-width: 100%;
  }

  :is(details.worksheet-section, details.notice-lookup, details:not([class])) > summary::after {
    content: "";
    flex: none;
    width: 16px;
    height: 16px;
    background: var(--t-3);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
    transition: transform var(--d-2) var(--e-out);
  }

  :is(details.worksheet-section, details.notice-lookup, details:not([class]))[open] > summary::after {
    transform: rotate(180deg);
  }

  :is(details.worksheet-section, details.notice-lookup, details:not([class])) > summary:hover::after {
    background: var(--t-1);
  }

  details:not([class]) > summary {
    font-weight: 600;
  }

  details:not([class])[open] > summary {
    margin-bottom: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root[data-layout="v5"] :is(details.worksheet-section, details.notice-lookup, details:not([class])) > summary::after {
    transition: none;
  }
}

/* ---------- What opens, on a phone ---------- */

@media (max-width: 640px) {
  :root[data-layout="v5"] {
    /* a page's first action leads at the left on a phone, so its list opens from that edge: hung
       from the button's right edge, as on a desk, it ran off the left of the screen */
    .page-head > .actions > .new-menu > .new-menu-list {
      right: auto;
      left: 0;
      max-width: calc(100vw - 36px);
      transform-origin: top left;
    }

    /* the list of columns opens in the row, under its button, and the table makes room: hung over
       the table it ended behind the bar at the foot of the screen */
    .filterbar > .column-picker[open] {
      flex: 1 1 100%;
    }

    .filterbar > .column-picker > summary {
      width: fit-content;
    }

    .filterbar > .column-picker > div {
      position: static;
      min-width: 0;
      max-height: none;
      overflow: visible;
      box-shadow: none;
      animation: none;
    }

    .filterbar > .column-picker label {
      min-height: 40px;
      padding: 6px 8px;
    }
  }
}
