/*
 * Učto: "Priepisový blok" (a carbon-copy receipt pad).
 *
 * The app is a pad of documents. The stub carries the navigation, a perforation separates it
 * from the white original that carries the data. Everything is written in carbon ink, record
 * numbers are in numbering-machine red, forms are pre-printed ruled cells, and the tint of the
 * copy tells which interface you are in (blue for everyone, pink for superadmin).
 */

/* Tokens ------------------------------------------------------------------------------- */

:root {
    --ink: #22307e;
    --ink-deep: #18235f;
    --ink-text: #1b2563;
    --ink-soft: #545f8e;

    --paper: #fff;
    --copy: #eef1f9;
    --copy-deep: #dde2f1;
    --rule: #dfe3f0;
    --rule-strong: #bcc4dc;

    --serial: #c5203a;
    --serial-tint: #fdeff1;

    --font: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'Red Hat Mono', ui-monospace, Consolas, monospace;

    --control: 30px;
    --gutter: 20px;
    --radius: 3px;
    --hole: 3px;
    --hole-pitch: 14px;
    --ease: cubic-bezier(.16, 1, .3, 1);

    --caret: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='m1 1 4 4 4-4' fill='none' stroke='%23545f8e' stroke-width='1.5'/%3E%3C/svg%3E");
}

.copy-pink {
    --copy: #fbe9ec;
    --copy-deep: #f4d6dc;
    --rule: #f0dfe3;
    --rule-strong: #dcbfc8;
}

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

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

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

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink-text);
    font: 400 14px/1.45 var(--font);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}

h1, h2, p, dl, dd {
    margin: 0;
}

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

button, input, select, textarea {
    color: inherit;
    font: inherit;
}

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

.icon {
    flex: none;
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

.serial {
    color: var(--serial);
    font: 500 12.5px/1 var(--mono);
    letter-spacing: .04em;
    white-space: nowrap;
}

/* Pad: stub + sheet -------------------------------------------------------------------- */

.pad {
    display: grid;
    grid-template-columns: 212px minmax(0, 1fr);
    min-height: 100dvh;
}

.stub {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100dvh;
    padding: 14px 20px 14px 14px;
    overflow-y: auto;
    background:
        radial-gradient(circle, var(--paper) var(--hole), transparent calc(var(--hole) + .5px))
        right calc(var(--hole-pitch) / -2) top 0 / var(--hole-pitch) var(--hole-pitch) repeat-y
        var(--copy);
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 6px;
    color: var(--ink);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -.01em;
    text-decoration: none;
}

.brand img {
    width: 20px;
    height: 24px;
}

.stub-company {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
    padding: 0 6px;
}

.stub-company-name {
    color: var(--ink);
    font-weight: 600;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.stub-nav {
    display: grid;
    flex: 1;
    align-content: start;
    gap: 1px;
    min-height: 0;
    /* The bar runs along the punched edge, clear of the holes, and keeps its place when it hides. */
    margin-right: -14px;
    padding-right: 6px;
    overflow-y: auto;
    scrollbar-color: var(--rule-strong) transparent;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
}

.stub-link {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--control);
    padding: 4px 6px;
    border-radius: var(--radius);
    color: var(--ink-soft);
    font-weight: 500;
    text-decoration: none;
}

.stub-link:hover {
    background: var(--copy-deep);
    color: var(--ink);
}

.stub-link[aria-current="page"] {
    background: var(--ink);
    color: #fff;
}

.stub-group {
    display: grid;
    gap: 1px;
}

.stub-group-title {
    padding: 8px 6px 2px;
    color: var(--ink-soft);
    font-size: 11.5px;
    font-weight: 600;
}

.stub-user {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 2px 8px;
    margin-top: auto;
    padding: 10px 6px 0;
    border-top: 1px solid var(--rule-strong);
}

.stub-user-name {
    overflow: hidden;
    color: var(--ink);
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stub-user-role {
    grid-row: 2;
    color: var(--ink-soft);
    font-size: 12px;
}

.stub-user form {
    grid-area: 1 / 2 / 3;
}

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

.sheet-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 12px;
    padding: 14px var(--gutter) 10px;
}

.sheet-head h1 {
    color: var(--ink);
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.sheet-back {
    align-self: center;
    margin-right: -6px;
}

.sheet-actions {
    display: flex;
    align-self: center;
    gap: 6px;
    margin-left: auto;
}

.sheet-actions > form {
    display: contents;
}

.sheet-body {
    display: grid;
    gap: 16px;
    max-width: 860px;
    padding: 4px var(--gutter) 24px;
}

/* A page with a table of rows takes the width there is, so the table does not scroll aside. */
.sheet-body:has(.listing) {
    max-width: none;
}

.section {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.section-title {
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.3;
}

.section .listing {
    --gutter: 10px;
}

.section .listing-tools {
    padding-inline: 0;
}

.empty-note {
    max-width: 60ch;
    padding: 4px var(--gutter);
    color: var(--ink-soft);
}

/* Controls ----------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: var(--control);
    padding: 0 10px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--paper);
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}

.btn:hover {
    border-color: var(--ink);
    background: var(--copy);
}

.btn:active {
    background: var(--copy-deep);
}

.btn:disabled {
    opacity: .55;
    cursor: progress;
}

.btn-primary {
    border-color: var(--ink);
    background: var(--ink);
    color: #fff;
}

.btn-primary:hover {
    border-color: var(--ink-deep);
    background: var(--ink-deep);
}

.btn-primary:active {
    background: var(--ink-deep);
}

.btn-danger {
    border-color: var(--serial);
    background: var(--serial);
    color: #fff;
}

.btn-danger:hover {
    border-color: #a31a30;
    background: #a31a30;
}

.btn-small {
    height: 24px;
    padding: 0 8px;
    font-size: 12.5px;
}

.btn-icon {
    width: 24px;
    height: 24px;
    padding: 0;
    border-color: transparent;
    background: none;
}

.btn-icon-danger:hover {
    border-color: var(--serial);
    background: var(--serial-tint);
    color: var(--serial);
}

.input {
    width: 100%;
    height: var(--control);
    padding: 0 8px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--paper);
    font-size: 13px;
}

.input:hover {
    border-color: var(--ink-soft);
}

.input::placeholder {
    color: var(--ink-soft);
}

select.input {
    width: auto;
    max-width: 100%;
    padding-right: 22px;
    background: var(--paper) var(--caret) no-repeat right 7px center / 9px;
    appearance: none;
    cursor: pointer;
}

.badge {
    display: inline-block;
    padding: 0 6px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--copy);
    color: var(--ink-soft);
    font-size: 11.5px;
    font-weight: 600;
    line-height: 18px;
    white-space: nowrap;
}

.badge-info {
    border-color: var(--ink);
    color: var(--ink);
}

.badge-success {
    border-color: var(--ink);
    background: var(--ink);
    color: #fff;
}

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

.badge-danger {
    border-color: var(--serial);
    background: var(--serial);
    color: #fff;
}

.dropzone {
    display: grid;
    place-items: center;
    gap: 4px;
    padding: 16px;
    border: 1px dashed var(--rule-strong);
    border-radius: var(--radius);
    color: var(--ink-soft);
    font-size: 13px;
    text-align: center;
    cursor: pointer;
}

.dropzone:hover,
.dropzone.is-over {
    border-color: var(--ink);
    background: var(--copy);
    color: var(--ink);
}

.field .dropzone input {
    width: auto;
    height: auto;
    max-width: 100%;
    color: var(--ink-soft);
    font-size: 12.5px;
}

.dropzone small {
    font-size: 11.5px;
}

/* Pre-printed form: ruled cells with a small label in the corner ------------------------ */

.form-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    border-top: 1px solid var(--rule-strong);
    border-left: 1px solid var(--rule-strong);
}

.field {
    position: relative;
    display: flex;
    flex-direction: column;
    grid-column: span var(--span, 12);
    min-width: 0;
    padding: 4px 8px 3px;
    border-right: 1px solid var(--rule-strong);
    border-bottom: 1px solid var(--rule-strong);
    background: var(--paper);
}

.field:focus-within {
    z-index: 1;
    outline: 2px solid var(--ink);
    outline-offset: -1px;
}

.field-label {
    color: var(--ink-soft);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.3;
}

.field-required {
    margin-left: 2px;
    color: var(--serial);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    height: 24px;
    padding: 0;
    border: 0;
    outline: 0;
    background: none;
    color: var(--ink-text);
    font-weight: 500;
}

.field select {
    padding-right: 14px;
    background: var(--caret) no-repeat right center / 9px;
    appearance: none;
    cursor: pointer;
}

.field textarea {
    display: block;
    height: auto;
    padding-top: 3px;
    resize: vertical;
}

.field-check {
    flex-flow: row wrap;
    align-items: center;
    gap: 0 8px;
    padding-block: 8px;
    cursor: pointer;
}

.field-check input {
    width: auto;
    height: auto;
    margin: 0;
    accent-color: var(--ink);
}

.field-check .field-label {
    color: var(--ink-text);
    font-size: 13px;
}

.field-check .field-error {
    flex-basis: 100%;
}

.field-value {
    min-height: 24px;
    color: var(--ink-text);
    font-weight: 500;
    line-height: 24px;
    overflow-wrap: anywhere;
}

.field-error:empty {
    display: none;
}

.field-error {
    color: var(--serial);
    font-size: 11.5px;
    line-height: 1.3;
    white-space: pre-line;
}

.field.has-error {
    background: var(--serial-tint);
}

.choice-group {
    display: grid;
    grid-column: span 12;
    grid-template-columns: 1fr 1fr;
    margin: 0;
    padding: 0;
    border: 0;
}

.choice {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 2px 8px;
    padding: 8px;
    border-right: 1px solid var(--rule-strong);
    border-bottom: 1px solid var(--rule-strong);
    cursor: pointer;
}

.choice:hover {
    background: var(--copy);
}

.choice:has(:checked) {
    outline: 2px solid var(--ink);
    outline-offset: -1px;
    background: var(--copy);
}

.choice input {
    margin: 2px 0 0;
    accent-color: var(--ink);
}

.choice-title {
    color: var(--ink);
    font-weight: 600;
}

.choice-text {
    grid-column: 2;
    color: var(--ink-soft);
    font-size: 12.5px;
    line-height: 1.35;
}

.edit-form {
    display: grid;
    gap: 16px;
}

.save-bar {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding: 10px 0;
    background: var(--paper);
}

.form-grid > .section {
    grid-column: 1 / -1;
    padding-block: 10px 0;
    border-right: 1px solid var(--rule-strong);
    border-bottom: 1px solid var(--rule-strong);
    background: var(--paper);
}

.form-grid > .section > .section-title {
    padding-inline: 8px;
}

.form-grid > .section > .form-grid {
    border-left: 0;
}

.repeater {
    display: grid;
    grid-column: 1 / -1;
    gap: 6px;
    min-width: 0;
    padding-block: 6px;
    border-right: 1px solid var(--rule-strong);
    border-bottom: 1px solid var(--rule-strong);
    background: var(--paper);
}

.repeater-rows {
    display: grid;
    gap: 4px;
}

.repeater-row {
    position: relative;
    margin-inline: 6px;
    padding-right: 34px;
    border-top-color: var(--rule);
}

.repeater-remove {
    position: absolute;
    top: 4px;
    right: 0;
}

.repeater-add {
    justify-self: start;
    margin-inline: 6px;
}

.repeater > .field-error {
    padding-inline: 6px;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    gap: 16px;
    align-items: start;
    padding: 4px var(--gutter) 24px;
}

.split-side {
    position: sticky;
    top: 8px;
    min-width: 0;
}

.split-side iframe {
    display: block;
    width: 100%;
    height: calc(100vh - 120px);
    border: 1px solid var(--rule-strong);
    background: var(--paper);
}

.split-side pre {
    max-height: calc(100vh - 120px);
    margin: 0;
    padding: 8px;
    overflow: auto;
    border: 1px solid var(--rule-strong);
    background: var(--paper);
    font: 12px/1.45 var(--mono);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.split-main {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.split .sheet-body {
    padding: 0;
}

.page-form {
    position: relative;
}

.page-form > summary {
    list-style: none;
}

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

.page-form[open] > .form-grid {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 3;
    width: 320px;
    background: var(--paper);
    box-shadow: 0 6px 18px rgb(24 35 95 / .18);
}

.page-form .form-grid > .btn {
    grid-column: 1 / -1;
    border-radius: 0;
}

/* Listing: toolbar + DataTable ---------------------------------------------------------- */

.listing {
    position: relative;
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.listing-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 0 var(--gutter) 10px;
}

.listing-search {
    position: relative;
    flex: 0 1 240px;
}

.listing-search .icon {
    position: absolute;
    top: 8px;
    left: 8px;
    color: var(--ink-soft);
    pointer-events: none;
}

.listing-search .input {
    padding-left: 28px;
}

.listing-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.listing .dt-container {
    display: flex;
    flex: 1;
    flex-direction: column;
}

.listing .dt-layout-table {
    overflow-x: auto;
    border-top: 1px solid var(--rule-strong);
}

.listing table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.listing th {
    position: relative;
    padding: 6px 10px;
    border-right: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule-strong);
    background: var(--copy);
    color: var(--ink-soft);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

.listing th.dt-orderable-asc,
.listing th.dt-orderable-desc {
    cursor: pointer;
}

.listing th.dt-orderable-asc:hover,
.listing th.dt-orderable-desc:hover,
.listing th.dt-ordering-asc,
.listing th.dt-ordering-desc {
    color: var(--ink);
}

.listing .dt-column-header {
    display: flex;
    align-items: center;
    gap: 5px;
}

.listing .dt-column-order:empty {
    display: none;
}

.listing th.dt-ordering-asc .dt-column-order,
.listing th.dt-ordering-desc .dt-column-order {
    display: block;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
}

.listing th.dt-ordering-asc .dt-column-order {
    border-bottom: 5px solid currentColor;
}

.listing th.dt-ordering-desc .dt-column-order {
    border-top: 5px solid currentColor;
}

.listing td {
    height: 34px;
    padding: 4px 10px;
    border-right: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
    vertical-align: middle;
}

.listing th:first-child,
.listing td:first-child {
    padding-left: var(--gutter);
}

.listing th:last-child,
.listing td:last-child {
    padding-right: var(--gutter);
    border-right: 0;
}

.listing tbody tr:hover td {
    background: var(--copy);
}

.listing td a {
    color: var(--ink);
    font-weight: 600;
    text-decoration: none;
}

.listing td a:hover {
    text-decoration: underline;
}

.listing td.dt-empty {
    height: 96px;
    color: var(--ink-soft);
    text-align: center;
}

.listing .col-serial {
    width: 1%;
    color: var(--serial);
    font: 500 12px var(--mono);
    letter-spacing: .04em;
}

.listing th.col-serial {
    color: var(--ink-soft);
    font-family: var(--font);
    letter-spacing: 0;
}

.listing .col-code {
    font-family: var(--mono);
    font-size: 12.5px;
    white-space: nowrap;
}

.listing th.col-code {
    font-family: var(--font);
    font-size: 12px;
}

.listing .col-number,
.listing .col-money,
.listing .col-date {
    width: 1%;
    white-space: nowrap;
}

.listing td.col-number,
.listing td.col-money {
    text-align: right;
}

.listing td.col-money .input {
    min-width: 120px;
    text-align: right;
}

.listing .col-actions {
    width: 1%;
    white-space: nowrap;
}

/* It is the first column, so it takes the gutter on both sides and its box stands in the middle. */
.listing .col-select {
    width: 1%;
    padding-inline: var(--gutter);
    text-align: center;
}

.listing .col-select input {
    display: block;
    margin: 0 auto;
    accent-color: var(--ink);
}

.changes {
    display: flex;
    flex-wrap: wrap;
    gap: 0 14px;
    font-size: 12.5px;
    overflow-wrap: anywhere;
}

.changes dt,
.changes dd {
    display: inline;
}

.changes dt {
    color: var(--ink-soft);
}

.changes dt::after {
    content: ':';
}

.changes del {
    color: var(--ink-soft);
}

.changes del:empty::before {
    content: '—';
    display: inline-block;
}

.changes ins {
    text-decoration: none;
}

.changes del + ins::before {
    content: '→ ';
    color: var(--ink-soft);
}

.row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
}

.row-actions .btn-small {
    margin-right: 4px;
}

.listing .dt-layout-row:last-child {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 8px var(--gutter);
    color: var(--ink-soft);
    font-size: 12.5px;
}

.listing .dt-layout-cell {
    display: flex;
    align-items: center;
    gap: 16px;
}

.listing .dt-length label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.listing .dt-length select {
    height: 24px;
    padding: 0 4px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--paper);
    font-size: 12.5px;
}

.listing .dt-paging nav {
    display: flex;
    gap: 2px;
}

.listing .dt-paging-button {
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: none;
    color: var(--ink);
    font-size: 12.5px;
    cursor: pointer;
}

.listing .dt-paging-button:hover:not(.disabled, .current) {
    border-color: var(--rule-strong);
    background: var(--copy);
}

.listing .dt-paging-button.current {
    background: var(--ink);
    color: #fff;
    cursor: default;
}

.listing .dt-paging-button.disabled {
    color: var(--rule-strong);
    cursor: default;
}

.listing .dt-paging .ellipsis {
    padding: 0 4px;
}

.listing .dt-processing {
    position: absolute;
    z-index: 2;
    inset: 0 0 auto;
    height: 2px;
    overflow: hidden;
    background: var(--copy-deep);
}

.listing .dt-processing::after {
    content: '';
    display: block;
    width: 30%;
    height: 100%;
    background: var(--ink);
    animation: progress 1s var(--ease) infinite;
}

.listing .dt-processing > div {
    display: none;
}

@keyframes progress {
    from { transform: translateX(-100%); }
    to { transform: translateX(340%); }
}

/* Modal: a sheet torn off the pad ------------------------------------------------------- */

.modal {
    width: min(620px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    filter: drop-shadow(0 14px 28px rgb(24 35 95 / .3));
}

.modal-narrow {
    width: min(400px, calc(100vw - 32px));
}

.modal-preview {
    width: min(1000px, calc(100vw - 32px));
    height: calc(100dvh - 32px);
}

.modal-preview .modal-sheet {
    height: 100%;
}

.modal-preview iframe {
    flex: 1;
    width: 100%;
    border: 1px solid var(--rule-strong);
}

.modal::backdrop {
    background: rgb(24 35 95 / .4);
}

.modal[open] {
    animation: sheet-in .22s var(--ease);
}

@keyframes sheet-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
}

.modal-sheet {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: inherit;
    padding: 16px;
    overflow-y: auto;
    background: var(--paper);
    -webkit-mask: radial-gradient(circle var(--hole) at calc(var(--hole-pitch) / 2) 0, transparent 98%, #000) 0 0 / var(--hole-pitch) 100% repeat-x;
    mask: radial-gradient(circle var(--hole) at calc(var(--hole-pitch) / 2) 0, transparent 98%, #000) 0 0 / var(--hole-pitch) 100% repeat-x;
}

.modal-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-head h2 {
    flex: 1;
    color: var(--ink);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.3;
}

.modal-text {
    color: var(--ink-text);
    overflow-wrap: anywhere;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.listing [popover] {
    text-align: left;
    white-space: normal;
}

.version-list {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.version-list li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--rule);
    color: var(--ink-soft);
    font-size: 12.5px;
    overflow-wrap: anywhere;
}

.version-list li:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.version-list li > :nth-child(n + 3) {
    grid-column: 1 / -1;
}

/* Toast --------------------------------------------------------------------------------- */

.toast {
    position: fixed;
    inset: auto 16px 16px auto;
    max-width: min(360px, calc(100vw - 32px));
    margin: 0;
    padding: 8px 12px;
    border: 0;
    border-radius: var(--radius);
    background: var(--ink);
    box-shadow: 0 6px 16px rgb(24 35 95 / .28);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    animation: sheet-in .22s var(--ease);
}

.toast-error {
    background: var(--serial);
}

/* Guest pages --------------------------------------------------------------------------- */

.guest {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: 24px 16px;
    background: var(--copy);
}

.guest-pad {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    width: min(620px, 100%);
    background: var(--paper);
    box-shadow: 0 10px 28px rgb(24 35 95 / .14);
}

.guest-pad-wide {
    width: min(820px, 100%);
}

.guest-stub {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 24px;
    padding: 18px 22px 18px 14px;
    background:
        radial-gradient(circle, var(--paper) var(--hole), transparent calc(var(--hole) + .5px))
        right calc(var(--hole-pitch) / -2) top 0 / var(--hole-pitch) var(--hole-pitch) repeat-y
        var(--copy-deep);
}

.guest-stub p {
    padding: 0 6px;
    color: var(--ink-soft);
    font-size: 12.5px;
    line-height: 1.4;
}

.guest-sheet {
    display: grid;
    align-content: start;
    gap: 12px;
    min-width: 0;
    padding: 18px 20px 20px;
}

.guest-sheet h1 {
    color: var(--ink);
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
}

.guest-sheet form {
    display: grid;
    gap: 12px;
}

.guest-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    font-size: 13px;
}

.guest-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.guest-check input {
    margin: 0;
    accent-color: var(--ink);
}

.notice {
    padding: 10px 14px;
    border: 1px solid var(--rule-strong);
    background: var(--copy);
    font-size: 13px;
    line-height: 1.45;
}

.sheet > .notice {
    margin: 0 var(--gutter) 10px;
}

/* Small screens: the stub becomes a strip, rows become small documents ------------------- */

@media (max-width: 760px) {
    :root {
        --control: 36px;
        --gutter: 14px;
    }

    .pad {
        display: block;
    }

    .stub {
        position: static;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px 10px;
        height: auto;
        padding: 10px var(--gutter) 16px;
        background:
            radial-gradient(circle, var(--paper) var(--hole), transparent calc(var(--hole) + .5px))
            left 0 bottom calc(var(--hole-pitch) / -2) / var(--hole-pitch) var(--hole-pitch) repeat-x
            var(--copy);
    }

    .brand {
        padding: 0;
    }

    .stub-company,
    .stub-nav {
        grid-column: 1 / -1;
        padding: 0;
    }

    .stub-nav {
        display: flex;
        gap: 4px;
        margin-right: 0;
        overflow-x: auto;
        scrollbar-gutter: auto;
        scrollbar-width: none;
    }

    .stub-link {
        flex: none;
        padding: 4px 8px;
    }

    .stub-group {
        display: contents;
    }

    .stub-group-title {
        display: none;
    }

    .stub-user {
        grid-area: 1 / 2;
        margin: 0;
        padding: 0;
        border: 0;
    }

    .stub-user-name,
    .stub-user-role {
        display: none;
    }

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

    .btn-small {
        height: 32px;
        padding: 0 10px;
    }

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

    .split-side {
        position: static;
    }

    .sheet-actions {
        flex-wrap: wrap;
    }

    .page-form[open] {
        flex-basis: 100%;
    }

    .page-form[open] > .form-grid {
        position: static;
        width: 100%;
        margin-top: 4px;
        box-shadow: none;
    }

    .listing-search {
        flex: 1 1 100%;
    }

    .listing-tools select.input {
        flex: 1 1 140px;
        min-width: 0;
    }

    .listing-actions {
        flex: 1 1 100%;
        flex-wrap: wrap;
        margin: 0;
    }

    .listing-actions .btn {
        flex: 1 1 auto;
    }

    .badge {
        max-width: 100%;
        overflow-wrap: anywhere;
        white-space: normal;
    }

    .listing thead {
        display: none;
    }

    .listing table,
    .listing tbody {
        display: block;
    }

    .listing tbody tr {
        display: grid;
        gap: 2px;
        padding: 10px var(--gutter);
        border-bottom: 1px solid var(--rule-strong);
    }

    .listing tbody tr:hover td {
        background: none;
    }

    .listing td,
    .listing td:first-child,
    .listing td:last-child {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 16px;
        width: auto;
        height: auto;
        padding: 0;
        border: 0;
        text-align: right;
        overflow-wrap: anywhere;
    }

    .listing td.col-serial,
    .listing td.col-number,
    .listing td.col-money,
    .listing td.col-date,
    .listing td.col-actions {
        width: auto;
    }

    .listing td.col-code {
        white-space: normal;
    }

    .listing td::before {
        content: attr(data-label);
        flex: none;
        color: var(--ink-soft);
        font: 400 12.5px var(--font);
        letter-spacing: 0;
    }

    .listing td:empty {
        display: none;
    }

    .listing td.dt-empty {
        display: block;
        height: auto;
        padding: 24px 0;
        text-align: center;
    }

    .listing td.dt-empty::before {
        content: none;
    }

    .listing td.col-serial {
        justify-content: flex-start;
    }

    .listing td.col-serial::before {
        content: none;
    }

    .listing td.col-actions {
        margin-top: 6px;
    }

    .listing td.col-actions::before {
        content: none;
    }

    .row-actions {
        flex: 1;
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 6px;
    }

    .row-actions .btn-small {
        flex: 1;
        margin: 0;
    }

    .listing .dt-layout-row:last-child,
    .listing .dt-layout-cell {
        justify-content: center;
    }

    .listing .dt-layout-cell {
        flex-wrap: wrap;
        max-width: 100%;
    }

    .listing .dt-paging {
        max-width: 100%;
    }

    .listing .dt-paging nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    .listing .dt-paging-button {
        min-width: 32px;
        height: 32px;
    }

    .field {
        grid-column: span 12;
    }

    .field input,
    .field select {
        height: 28px;
        font-size: 16px;
    }

    .field textarea {
        font-size: 16px;
    }

    .field-check input {
        height: auto;
    }

    .choice-group {
        grid-template-columns: 1fr;
    }

    .modal {
        width: 100vw;
        max-width: 100vw;
        max-height: 92dvh;
        margin: auto 0 0;
    }

    .modal-narrow {
        width: 100vw;
    }

    .modal-foot .btn,
    .save-bar .btn {
        flex: 1;
    }

    .guest {
        padding: 0;
        place-items: stretch;
    }

    .guest-pad {
        grid-template-columns: 1fr;
        width: 100%;
        box-shadow: none;
    }

    .guest-stub {
        flex-direction: row;
        align-items: center;
        padding: 12px var(--gutter) 18px;
        background:
            radial-gradient(circle, var(--paper) var(--hole), transparent calc(var(--hole) + .5px))
            left 0 bottom calc(var(--hole-pitch) / -2) / var(--hole-pitch) var(--hole-pitch) repeat-x
            var(--copy-deep);
    }

    .guest-stub p {
        display: none;
    }

    .guest-sheet {
        padding: 14px var(--gutter) 24px;
    }
}

/* Overview and statistics -------------------------------------------------------------- */

:root {
    --chart-revenue: #2a78d6;
    --chart-costs: #eb6834;
    --chart-result: #1baf7a;
    --chart-money: #6250d6;
    --chart-height: 220px;
}

.sheet-body-wide {
    max-width: none;
}

.overview-half,
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px var(--gutter);
    align-items: start;
}

.overview-half {
    padding: 4px var(--gutter) 16px;
}

.overview-data,
.overview-alerts {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.stats-wide {
    grid-column: 1 / -1;
    min-width: 0;
}

/* Each part of the statistics stands apart under a rule of its own. */
.stats-page,
.stats-page .stats-grid {
    row-gap: 32px;
}

.stats-page .section {
    gap: 10px;
    padding-top: 14px;
    border-top: 1px solid var(--rule-strong);
}

.stats-filter {
    display: flex;
    gap: 8px;
    align-items: center;
}

.stats-filter .input {
    width: auto;
}

.stats-note {
    color: var(--ink-soft);
    font-size: 12px;
}

.chart {
    display: grid;
    gap: 8px;
    min-width: 0;
    margin: 0;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    color: var(--ink-soft);
    font-size: 12px;
}

.chart-legend-item {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.chart-key {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.chart-key-line {
    width: 14px;
    height: 2px;
    border-radius: 1px;
}

.chart .is-revenue,
.chart-tip .is-revenue {
    background: var(--chart-revenue);
}

.chart .is-costs,
.chart-tip .is-costs {
    background: var(--chart-costs);
}

.chart .is-result,
.chart-tip .is-result {
    background: var(--chart-result);
}

.chart .is-money,
.chart-tip .is-money {
    background: var(--chart-money);
}

.chart .is-previous,
.chart-tip .is-previous {
    background: var(--rule-strong);
}

.chart-frame {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    column-gap: 8px;
}

.chart-ticks {
    position: relative;
    height: var(--chart-height);
}

.chart-tick {
    position: absolute;
    right: 0;
    color: var(--ink-soft);
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
    transform: translateY(50%);
}

.chart-plot {
    position: relative;
    height: var(--chart-height);
}

.chart-grid {
    position: absolute;
    right: 0;
    left: 0;
    height: 1px;
    background: var(--rule);
}

.chart-grid.is-zero {
    background: var(--rule-strong);
}

.chart-slots,
.chart-labels {
    display: grid;
    grid-template-columns: repeat(var(--slots), minmax(0, 1fr));
}

.chart-slots {
    position: absolute;
    inset: 0;
}

.chart-labels {
    grid-column: 2;
    padding-top: 4px;
    color: var(--ink-soft);
    font-size: 11px;
    text-align: center;
}

.chart-slot {
    position: relative;
    outline: 0;
}

.chart-slot:hover,
.chart-slot:focus-visible {
    background: color-mix(in srgb, var(--copy) 60%, transparent);
}

.chart-col {
    position: absolute;
    width: min(14px, 34%);
    border-radius: 4px 4px 0 0;
}

.chart-col.is-revenue {
    right: calc(50% + 1px);
}

.chart-col.is-costs {
    left: calc(50% + 1px);
}

.chart-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.chart .chart-lines .chart-area,
.chart .chart-lines .chart-line {
    background: none;
}

.chart-area {
    opacity: .1;
}

.chart-area.is-result {
    fill: var(--chart-result);
}

.chart-area.is-money {
    fill: var(--chart-money);
}

.chart-line {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-line.is-result {
    stroke: var(--chart-result);
}

.chart-line.is-money {
    stroke: var(--chart-money);
}

.chart-line.is-previous {
    stroke: var(--rule-strong);
}

.chart-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    border: 2px solid var(--paper);
    border-radius: 50%;
    pointer-events: none;
    transform: translate(-50%, 50%);
}

.chart-end {
    position: absolute;
    padding-bottom: 8px;
    color: var(--ink-text);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    transform: translateX(-100%);
}

.chart-end.is-start {
    transform: none;
}

.chart-slot-line:hover::after,
.chart-slot-line:focus-visible::after {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    background: var(--rule-strong);
    content: '';
}

.chart-bars {
    display: grid;
    gap: 2px;
}

.chart-row {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.4fr) 84px;
    gap: 8px;
    align-items: center;
    padding: 3px 4px;
    outline: 0;
}

.chart-row:hover,
.chart-row:focus-visible {
    background: var(--copy);
}

.chart-row-name {
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-row-track {
    display: block;
}

.chart-bar {
    display: block;
    min-width: 2px;
    height: 14px;
    border-radius: 0 4px 4px 0;
}

.chart-row-value {
    font-size: 13px;
    font-weight: 600;
    text-align: right;
}

.chart-tip {
    position: fixed;
    z-index: 50;
    display: grid;
    gap: 3px;
    max-width: 280px;
    padding: 8px 10px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: 0 4px 14px rgb(24 35 95 / 14%);
    font-size: 12px;
    pointer-events: none;
}

.chart-tip[hidden] {
    display: none;
}

.chart-tip strong {
    color: var(--ink);
}

.chart-tip-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.chart-tip-row span {
    color: var(--ink-soft);
}

.chart-tip-key {
    width: 12px;
    height: 2px;
    border-radius: 1px;
}

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

@media (prefers-reduced-motion: reduce) {
    .modal[open],
    .toast {
        animation: none;
    }
}
