/* Design tokens. Every color, size and font used below comes from here. Anthracite surfaces with a copper accent;
   text colors meet WCAG AA contrast on their backgrounds in both schemes. */
:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;

  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;

  --radius: 8px;
  --radius-lg: 12px;
  --content-width: 76rem;
  --transition: 120ms ease-out;

  --color-bg: #f2f1ee;
  --color-surface: #ffffff;
  --color-surface-2: #f6f5f2;
  --color-input: #ffffff;
  --color-text: #1f1e1c;
  --color-text-muted: #67635d;
  --color-border: #dedad3;
  --color-border-strong: #b5afa5;
  --color-accent: #c2531c;
  --color-accent-hover: #a8461a;
  /* The accent as text on light backgrounds, dark enough for small type. */
  --color-accent-strong: #a8461a;
  --color-accent-text: #ffffff;
  --color-accent-soft: #fbeadf;
  --color-danger: #b42318;
  --color-danger-soft: #fdecea;
  --color-success: #2e7d4f;
  --color-success-soft: #e6f4ec;
  --shadow-1: 0 1px 2px rgb(31 30 28 / 0.06), 0 2px 8px rgb(31 30 28 / 0.05);
  --shadow-2: 0 4px 12px rgb(31 30 28 / 0.12), 0 12px 32px rgb(31 30 28 / 0.1);
  --ring: 0 0 0 3px color-mix(in srgb, var(--color-accent) 28%, transparent);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%2367635d' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1c1c1c;
    --color-surface: #252525;
    --color-surface-2: #2e2e2e;
    --color-input: #1f1f1f;
    --color-text: #ecebe8;
    --color-text-muted: #a3a09a;
    --color-border: #383838;
    --color-border-strong: #5a5a5a;
    --color-accent: #f08c50;
    --color-accent-hover: #f4a273;
    --color-accent-strong: #f4a273;
    --color-accent-text: #1a1a1a;
    --color-accent-soft: #3b2b21;
    --color-danger: #f08a7e;
    --color-danger-soft: #3a2422;
    --color-success: #7fcf9c;
    --color-success-soft: #1f3327;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-2: 0 8px 24px rgb(0 0 0 / 0.5);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%23a3a09a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

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

html {
  font-family: var(--font-sans);
  font-size: 100%;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 var(--space-4);
}

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

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

a {
  color: var(--color-accent-strong);
  text-underline-offset: 0.15em;
  transition: color var(--transition);
}

a:hover {
  color: var(--color-accent);
}

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

::selection {
  background: var(--color-accent-soft);
}

/* Page frame */
.site-header,
.site-main,
.site-footer {
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding-inline: var(--space-4);
}

.site-header {
  padding-block: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  /* The header bar spans the whole window while its content keeps the page width. */
  background: var(--color-surface);
  box-shadow: 0 0 0 100vmax var(--color-surface);
  clip-path: inset(0 -100vmax);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
  color: var(--color-text);
  text-decoration: none;
}

.wordmark img {
  width: 2rem;
  height: 2rem;
  transition: transform var(--transition);
}

.wordmark:hover {
  color: var(--color-text);
}

.wordmark:hover img {
  transform: rotate(-6deg) scale(1.05);
}

.site-main {
  flex: 1;
  padding-block: var(--space-12);
}

.site-footer {
  padding-block: var(--space-6);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.site-nav form {
  margin: 0;
}

.nav-button {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  color: var(--color-text);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.nav-button:hover {
  color: var(--color-accent-strong);
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
}

/* Content */
.intro {
  max-width: 40rem;
}

.lead {
  font-size: var(--text-lg);
  color: var(--color-text-muted);
}

h2 {
  font-size: var(--text-lg);
  font-weight: 600;
}

.muted,
.hint {
  color: var(--color-text-muted);
}

.hint {
  font-size: var(--text-sm);
  margin: var(--space-1) 0 0;
}

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

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  max-width: 44rem;
}

.panel.narrow {
  max-width: 26rem;
  margin-inline: auto;
}

.panel > :last-child {
  margin-bottom: 0;
}

/* Elements with the hidden attribute stay hidden even when a class sets their display. */
[hidden] {
  display: none !important;
}

/* Forms */
.form {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  width: 100%;
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}

label,
.label {
  font-size: var(--text-sm);
  font-weight: 600;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  font: inherit;
  color: var(--color-text);
  background-color: var(--color-input);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  padding: 0.55rem var(--space-3);
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
}

input:not([type="checkbox"]):not([type="radio"]):hover,
select:hover,
textarea:hover {
  border-color: var(--color-text-muted);
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--ring);
}

:disabled:is(input, select, textarea),
fieldset:disabled :is(input, select, textarea) {
  color: var(--color-text-muted);
  background-color: var(--color-surface-2);
  border-color: var(--color-border);
  cursor: not-allowed;
}

::placeholder {
  color: var(--color-text-muted);
  opacity: 0.75;
}

/* Dropdowns with the same frame as text fields and a chevron of their own instead of the browser's. */
select {
  appearance: none;
  padding-right: 2.25rem;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 1rem;
  cursor: pointer;
}

/* Text areas grow with their text; autosize.js does the same in browsers without field-sizing. */
textarea {
  field-sizing: content;
  min-height: 2.75rem;
  max-height: 28rem;
  resize: vertical;
  line-height: 1.45;
}

/* Checkboxes and radio buttons drawn in the same style as the fields, with a copper fill when chosen. */
input[type="checkbox"],
input[type="radio"] {
  appearance: none;
  display: inline-grid;
  place-content: center;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  flex: none;
  background: var(--color-input);
  border: 1.5px solid var(--color-border-strong);
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

input[type="radio"] {
  border-radius: 50%;
}

input[type="checkbox"]:hover,
input[type="radio"]:hover {
  border-color: var(--color-accent);
}

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

input[type="checkbox"]:checked::before {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  background: var(--color-accent-text);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

input[type="radio"]:checked::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--color-accent-text);
}

:is(input[type="checkbox"], input[type="radio"]):disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.field-check label {
  cursor: pointer;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font: inherit;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  color: var(--color-accent-text);
  background: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  padding: 0.55rem var(--space-4);
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background var(--transition), border-color var(--transition), color var(--transition),
    box-shadow var(--transition), transform var(--transition);
}

.button:hover {
  color: var(--color-accent-text);
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  box-shadow: var(--shadow-2);
  transform: translateY(-1px);
}

.button:active {
  box-shadow: none;
  transform: translateY(0);
}

.button:disabled,
.button.htmx-request {
  opacity: 0.6;
  cursor: progress;
  transform: none;
}

.button-secondary {
  color: var(--color-text);
  background: var(--color-surface);
  border-color: var(--color-border-strong);
}

.button-secondary:hover {
  color: var(--color-accent-strong);
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
}

.button-small {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
}

.button-danger {
  color: var(--color-danger);
  background: var(--color-surface);
  border-color: var(--color-danger);
}

.button-danger:hover {
  color: var(--color-danger);
  background: var(--color-danger-soft);
  border-color: var(--color-danger);
}

.link-button {
  font: inherit;
  color: var(--color-accent);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.actions form {
  margin: 0;
}

.divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--color-border);
}

.aside {
  font-size: var(--text-sm);
}

.disclosure {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
}

.disclosure summary {
  cursor: pointer;
  color: var(--color-accent);
  margin-bottom: var(--space-3);
}

/* Notices */
.notice {
  border-left: 4px solid;
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin: 0 0 var(--space-4);
  background: var(--color-surface);
  box-shadow: var(--shadow-1);
}

.notice ul,
.notice p {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.notice-success {
  border-color: var(--color-success);
  background: var(--color-success-soft);
}

.notice-error {
  border-color: var(--color-danger);
  background: var(--color-danger-soft);
  color: var(--color-text);
}

/* Lists */
.settings {
  margin: 0;
}

.settings > div {
  display: grid;
  grid-template-columns: 12rem 1fr;
  gap: var(--space-4);
  padding-block: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.settings dt {
  font-weight: 600;
}

.settings dd {
  margin: 0;
  display: flex;
  gap: var(--space-3);
}

.item-list {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
}

.item-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-3);
  padding-block: var(--space-2);
  border-top: 1px solid var(--color-border);
}

.item-list form {
  margin: 0 0 0 auto;
}

.code-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2) var(--space-6);
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-6);
}

.steps {
  padding-left: var(--space-6);
}

.qr-code svg {
  display: block;
  width: 12rem;
  height: auto;
  margin-bottom: var(--space-4);
  border-radius: var(--radius);
}

/* Application shell: sidebar with company and navigation next to the content */
.app-shell {
  flex: 1;
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
}

.sidebar {
  padding: var(--space-6) var(--space-4);
  border-right: 1px solid var(--color-border);
  font-size: var(--text-sm);
}

.app-main {
  padding: var(--space-8) var(--space-6);
  min-width: 0;
}

.company-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  margin: 0 0 var(--space-6);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  text-align: left;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

button.company-switcher {
  cursor: pointer;
}

button.company-switcher:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.company-switcher-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.company-switcher-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.company-switcher-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.chevron {
  flex: none;
  width: 1rem;
  height: 1rem;
  color: var(--color-text-muted);
}

.nav-list a {
  display: block;
  padding: 0.4rem var(--space-3);
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

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

/* Popovers: menus and info hints, positioned by popovers.js */
[popover][data-anchored] {
  position: fixed;
  inset: auto;
  margin: 0;
}

.menu {
  padding: var(--space-1);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
  font-size: var(--text-sm);
}

.menu a {
  display: block;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-6);
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
}

.menu a:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.menu a[aria-current="true"] {
  font-weight: 600;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='%23888' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: var(--space-2) center;
  background-size: 0.85rem;
}

.label-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.info-hint {
  display: inline-grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  font: italic 600 0.75rem/1 Georgia, "Times New Roman", serif;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-text-muted);
  border-radius: 50%;
  cursor: help;
}

.info-hint:hover,
.info-hint:focus-visible {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.info-popover {
  max-width: min(22rem, calc(100vw - 2rem));
  padding: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: 1.45;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
}

.nav-list {
  list-style: none;
  margin: 0 0 var(--space-6);
  padding: 0;
}

.nav-list a[aria-current="page"] {
  color: var(--color-accent-strong);
  background: var(--color-accent-soft);
  box-shadow: inset 3px 0 0 var(--color-accent);
  font-weight: 600;
  transition: background var(--transition), box-shadow var(--transition), padding var(--transition);
}

/* The current page answers the pointer too: its accent bar widens and the label moves along a little. */
.nav-list a[aria-current="page"]:hover {
  color: var(--color-accent-strong);
  background: var(--color-accent-soft);
  box-shadow: inset 5px 0 0 var(--color-accent);
  padding-left: calc(var(--space-3) + 3px);
}

@media (prefers-reduced-motion: reduce) {
  .nav-list a[aria-current="page"] {
    transition: none;
  }
}

.nav-heading {
  margin: 0 0 var(--space-2);
  padding-inline: var(--space-2);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

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

.page-header h1 {
  margin: 0;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  font-size: var(--text-sm);
}

.table th,
.table td {
  text-align: left;
  padding: 0.65rem var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table th {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
}

.table tbody tr {
  transition: background var(--transition);
}

.table tbody tr:hover {
  background: var(--color-surface-2);
}

/* Form layout */
.fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 var(--space-2);
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.fieldset legend {
  font-weight: 600;
  margin-bottom: var(--space-3);
}

.subheading {
  margin: var(--space-3) 0 0;
  padding-bottom: var(--space-1);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}

.field input.input-color {
  width: 4.5rem;
  height: 2.75rem;
  padding: 0.25rem;
  cursor: pointer;
}

.field-row {
  display: flex;
  gap: var(--space-4);
  width: 100%;
}

/* Groups fields without a frame, for example to disable them together or show them only for some choices. */
.form-fields {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
}

/* A checkbox in a field row, aligned with the inputs next to it. */
.field-check-cell {
  flex: 0 0 9rem;
  justify-content: flex-end;
  min-height: 2.6rem;
}

.badge-danger {
  color: var(--color-danger);
  background: var(--color-danger-soft);
  border-color: transparent;
}

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

.payment-form .field {
  flex: 0 1 12rem;
}

.summary-heading {
  display: inline;
  margin: 0;
}

details > summary {
  cursor: pointer;
}

/* Modal dialogs, opened by dialogs.js */
.dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: var(--space-6);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
  backdrop-filter: blur(2px);
}

.dialog .form {
  margin: 0;
}

/* A field with a button next to it, such as the customer choice with "Neuer Kunde". */
.input-with-action {
  display: flex;
  gap: var(--space-2);
}

.input-with-action .button {
  flex: none;
}

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

/* Document editor */
.document-form .panel {
  max-width: 52rem;
}

.line-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4) 0;
  border-top: 1px solid var(--color-border);
}

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

.line-head .field {
  flex: 1;
}

.line-position {
  min-width: 1.5rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.line-total {
  align-items: flex-end;
  justify-content: flex-end;
}

.line-total .amount {
  padding: var(--space-2) 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.line-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) 0;
  border-top: 1px solid var(--color-border);
}

.line-actions .field {
  flex: 1 1 18rem;
}

.totals {
  margin: 0 0 0 auto;
  max-width: 26rem;
  font-variant-numeric: tabular-nums;
}

.totals > div {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-1) 0;
}

.totals dd {
  margin: 0;
  white-space: nowrap;
}

.totals-grand {
  border-top: 1px solid var(--color-border);
  font-weight: 700;
}

.totals-note {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.search-form {
  margin-bottom: var(--space-4);
}

.table-scroll {
  overflow-x: auto;
  margin-bottom: var(--space-4);
}

.table .number {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table a {
  font-weight: 600;
}

.field-short {
  flex: 0 0 9rem;
}

.field-medium {
  flex: 0 0 14rem;
}

/* In vertical containers the flex basis would set the height, so the sizes become widths there. */
:is(.form, .fieldset, .form-fields) > .field-short {
  flex: none;
  width: 9rem;
}

:is(.form, .fieldset, .form-fields) > .field-medium {
  flex: none;
  width: min(14rem, 100%);
}

.input-group {
  display: flex;
}

.input-prefix {
  display: grid;
  place-items: center;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-right: 0;
  border-radius: var(--radius) 0 0 var(--radius);
}

.input-prefix:not([hidden]) + input {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

[hidden] {
  display: none !important;
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
}

.form-inline .field {
  flex: 1 1 14rem;
  width: auto;
}

/* File choosers look like the other fields, with the choose button drawn like a secondary button. */
input[type="file"] {
  padding: 0.3rem;
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  margin-right: var(--space-3);
  padding: 0.35rem var(--space-3);
  font: inherit;
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-strong);
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

input[type="file"]:hover::file-selector-button {
  color: var(--color-accent-strong);
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
}

.form-inline .button {
  min-height: 2.75rem;
}

.checklist {
  margin: 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.logo-panel {
  margin-top: var(--space-6);
}

.logo-preview {
  display: block;
  max-width: 14rem;
  max-height: 6rem;
  padding: var(--space-3);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.form-inline .field-short {
  flex: 0 0 11rem;
}

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

.choice-list a {
  display: block;
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
  font-weight: 600;
}

/* Members */
.member-list {
  list-style: none;
  margin: 0 0 var(--space-6);
  padding: 0;
}

.member-list > li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-6);
  padding-block: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.member-name {
  display: flex;
  flex-direction: column;
  min-width: 14rem;
}

.role-checks {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  flex: 1;
  font-size: var(--text-sm);
}

.role-checks label {
  font-weight: 400;
}

.member-list form {
  margin: 0;
}

.danger-zone {
  max-width: 44rem;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.sidebar-toggle {
  display: none;
}

@media (max-width: 48rem) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
    padding-block: var(--space-3);
  }

  /* Folded navigation: a bar with company and current page; only with JavaScript, so it can always be opened. */
  .js .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font: inherit;
    text-align: left;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
  }

  .js .sidebar-toggle:hover {
    border-color: var(--color-accent);
    background: var(--color-accent-soft);
  }

  .sidebar-toggle-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .sidebar-toggle-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
  }

  .sidebar-toggle-page {
    font-weight: 700;
    color: var(--color-accent-strong);
  }

  .sidebar-toggle .chevron {
    transition: transform var(--transition);
  }

  .sidebar.is-open .sidebar-toggle .chevron {
    transform: rotate(180deg);
  }

  .js .sidebar:not(.is-open) .sidebar-content {
    display: none;
  }

  .js .sidebar.is-open .sidebar-content {
    margin-top: var(--space-4);
  }

  .app-main {
    padding: var(--space-6) var(--space-4);
  }

  .field-row {
    flex-direction: column;
  }

  .field-short,
  .field-medium,
  .field-check-cell {
    flex-basis: auto;
  }

  .field-check-cell {
    min-height: 0;
  }
}

@media (max-width: 40rem) {
  .settings > div {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }
}

/* Modules */
.module-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.module-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.module-head h2 {
  margin: 0;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 999px;
}

.badge-success {
  color: var(--color-success);
  background: var(--color-success-soft);
  border-color: transparent;
}

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

.inline-form label {
  font-weight: 400;
}

input.input-small {
  width: auto;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
}

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

/* Audit log */
.audit-table td {
  vertical-align: top;
}

.nowrap {
  white-space: nowrap;
}

.audit-details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0 var(--space-3);
  margin: 0;
}

.audit-details dt {
  color: var(--color-text-muted);
}

.audit-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.title-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.title-row h1 {
  margin: 0;
}

/* Notifications */
.count {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  margin-left: var(--space-1);
  padding: 0 var(--space-1);
  font-size: 0.75rem;
  color: var(--color-accent-text);
  background: var(--color-accent);
  border-radius: 999px;
}

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

.notification-list li {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--color-border);
}

.notification-list li.is-unread {
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--color-accent);
}

/* Compact header on narrow screens */
.menu-toggle {
  display: none;
}

.site-menu {
  min-width: 14rem;
}

.site-menu .nav-button {
  display: block;
  width: 100%;
  margin-bottom: var(--space-1);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-color: transparent;
}

.site-menu form {
  margin: 0;
}

@media (max-width: 40rem) {
  .site-nav {
    display: none;
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
  }
}

/* Footer and legal pages */
.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-6);
}

.footer-nav {
  display: flex;
  gap: var(--space-4);
}

.footer-nav a {
  color: var(--color-text-muted);
}

.legal {
  max-width: 44rem;
}

.legal h2 {
  margin-top: var(--space-8);
}

.placeholder {
  padding: 0 var(--space-1);
  color: var(--color-danger);
  background: transparent;
  border: 1px dashed var(--color-danger);
  border-radius: var(--radius);
}
