/* Layout and components.
 *
 * Implements design_handoff_invoicing_ui/ (hifi). Every value here comes from
 * that handoff via tokens.css — no template adds CSS or a style attribute
 * (the Content-Security-Policy in base.html forbids inline code on purpose).
 *
 * Two rules from the handoff that are easy to undo by accident:
 *   * Borders only. No shadows anywhere except the modal sheet.
 *   * No transitions or animations. The UI should feel instant.
 */

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

[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

input, button, select, textarea { font-family: inherit; }
::placeholder { color: var(--placeholder); }

/* Money and quantities always line up in columns. */
.num, input[inputmode="decimal"] { font-variant-numeric: tabular-nums; }

/* Numbers that are identifiers, not amounts: invoice/customer/article numbers,
 * IBAN, tax ids, dates in the dashboard header. */
.mono { font-family: var(--font-mono); }

/* Focus must always be visible — keyboard and screen-reader users depend on it.
 * Never remove this. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: -1px; }

/* The app never body-scrolls; each screen scrolls its own body region. */
.screen__body, .artikel-grid, .positions__list { scrollbar-width: thin; }
.screen__body::-webkit-scrollbar,
.artikel-grid::-webkit-scrollbar,
.positions__list::-webkit-scrollbar { width: 10px; }
.screen__body::-webkit-scrollbar-thumb,
.artikel-grid::-webkit-scrollbar-thumb,
.positions__list::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: content-box;
}

/* ---------------------------------------------------------------- app shell */

.app {
  display: flex;
  height: 100vh;
  min-height: 700px;
  overflow: hidden;
  background: var(--canvas);
}

.rail {
  flex: 0 0 var(--rail-w);
  width: var(--rail-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 14px 18px;
  display: flex;
  flex-direction: column;
}
.rail__brand { padding: 0 10px 22px; display: flex; flex-direction: column; gap: 3px; }
.rail__brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail__brand-sub { font-family: var(--font-mono); font-size: 12px; color: var(--ink-4); }

.rail__nav { display: flex; flex-direction: column; gap: 2px; }
.rail__item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--tap);
  padding: 0 12px;
  border-radius: var(--r-lg);
  color: var(--ink-2);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
}
.rail__item:hover { background: var(--surface-hover); text-decoration: none; }
.rail__item[aria-current="page"] { background: var(--accent-tint); color: var(--accent-dark); }
/* Inactive items render the same bar in transparent, so labels stay aligned. */
.rail__bar { flex: 0 0 3px; width: 3px; height: 20px; border-radius: 2px; background: transparent; }
.rail__item[aria-current="page"] .rail__bar { background: var(--accent); }

.rail__spacer { flex: 1; }
.rail__foot {
  padding: 14px 12px 0;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rail__foot-label { font-size: 12px; color: var(--ink-4); }
.rail__logout {
  font-size: 13px;
  font-weight: 500;
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
}

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

/* ------------------------------------------------------------------ screen */

.screen { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

.screen__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--gap);
  padding: 26px var(--page-pad) 20px;
  border-bottom: 1px solid var(--border);
}
/* The invoice wizard's header sits on white and centres its two halves. */
.screen__head--surface { background: var(--surface); align-items: center; padding: 20px 32px; }

.screen__body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 24px var(--page-pad) var(--page-pad);
}
/* Screens whose body is a split pane manage their own padding. */
.screen__body--flush { padding: 0; overflow: hidden; display: flex; }
/* Screens with a pinned action bar: the bar provides the bottom edge. */
.screen__body--bar { padding-bottom: 0; }

.head__titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.head__titles--inline { flex-direction: row; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-4);
}
.page-title { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.page-title--xl { font-size: 30px; }
.head__count { font-size: 14px; color: var(--ink-4); }
.head__sub { font-size: 13px; color: var(--ink-4); }
.head__date { font-family: var(--font-mono); font-size: 13px; color: var(--ink-3); }
.head__actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.head__actions .search { margin: 0; width: 340px; max-width: 100%; }
.head__actions form { display: contents; }

/* ---------------------------------------------------------------- buttons */

.btn {
  min-height: var(--tap);
  padding: 8px 26px;
  border: 1px solid transparent;
  border-radius: var(--r-lg);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { text-decoration: none; }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }

.btn--secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
  font-weight: 500;
}
.btn--secondary:hover { background: var(--surface-muted); }

/* Row action: Öffnen, Bearbeiten, Bezahlt. 44px — the tablet minimum. */
.btn--sm {
  min-height: var(--tap-min);
  padding: 0 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--r-md);
}
.btn--sm.btn--secondary:hover { background: var(--surface); border-color: var(--ink); }

/* Smallest secondary, only inside a panel header. */
.btn--xs {
  min-height: var(--tap-xs);
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--r-md);
  color: var(--accent);
}
.btn--xs.btn--secondary:hover { background: var(--surface); border-color: var(--accent); }

/* Abbrechen in the wizard header: quiet until you aim at it. */
.btn--cancel { color: var(--ink-3); font-size: 14px; }
.btn--cancel.btn--secondary:hover {
  background: var(--surface);
  border-color: var(--danger);
  color: var(--danger);
}

.btn--xl { min-height: var(--tap-lg); font-size: 16px; }
.btn--block { width: 100%; }

.btn--danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn--danger:hover { filter: brightness(.94); }

/* Destructive-but-quiet: Storno, Teilzahlung. Deliberately not a button. */
.btn--danger-link {
  background: none;
  border: 0;
  padding: 0 4px;
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }

/* A disabled control always states why, right next to it. */
.btn-reason { font-size: 12px; color: var(--ink-4); margin: 6px 0 0; }

/* Bottom action bar of the invoice wizard — same pixels on every step. */
.actionbar {
  position: sticky;
  bottom: 0;
  margin: var(--gap-lg) calc(var(--page-pad) * -1) 0;
  padding: 14px var(--page-pad) 18px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ---------------------------------------------------------------- surfaces */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 22px 24px 24px;
}
.card__title { font-size: 16px; font-weight: 600; margin: 0 0 18px; }
.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 18px;
}
.card__head .card__title { margin: 0; }
.card__note { font-size: 12px; color: var(--ink-4); }

.grid { display: grid; gap: 12px; }
.grid--tiles { grid-template-columns: repeat(auto-fill, minmax(186px, 1fr)); }
.grid--cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid--split { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }

/* A tile that has to sit in a <form> (because tapping it posts something):
 * the form itself must not become the grid cell, or the tiles come out ragged. */
.grid > form { display: contents; }
.grid > form > .tile { width: 100%; }

.tile {
  min-height: 88px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font-size: 15px;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile--add {
  align-items: center;
  justify-content: center;
  border-style: dashed;
  color: var(--accent);
  font-weight: 600;
}
.tile__name { font-weight: 600; }
.tile__meta { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tile__tag { margin-top: auto; font-size: 12px; color: var(--ink-4); }
.tile--customer.is-chosen { border-color: var(--accent); background: var(--accent-tint); }

/* ------------------------------------------------------------------ tables
 * One table component; each screen only sets its own column template.
 * Header and rows share that template, so the columns cannot drift apart.
 */

.table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow: hidden;
}
.table__caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.table__caption h2 { margin: 0; font-size: 16px; font-weight: 600; }
.table__caption a { font-size: 13px; font-weight: 500; }

.table__head, .table__row { display: grid; align-items: center; }
.table__head {
  padding: 9px 20px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border-soft);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-4);
}
.table__row {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-row);
  font-size: 14px;
}
.table__row:last-child { border-bottom: 0; }
.table__row:hover { background: var(--surface-sunken); }

/* Column templates, one per screen (handoff § per screen). */
/* Start keeps a sixth column for the one-tap "Bezahlt" — the 90 % action of
 * this screen. Its 44px button sets the row height, so the vertical padding
 * comes down to hold the handoff's row rhythm. */
.table--offen .table__head, .table--offen .table__row {
  grid-template-columns: 108px minmax(0, 1fr) 96px 116px 108px 104px;
}
.table--offen .table__row { padding-top: 8px; padding-bottom: 8px; }
.table--kunden .table__head, .table--kunden .table__row {
  grid-template-columns: minmax(0, 1.4fr) 96px minmax(0, 1fr) 130px 130px 108px;
  padding-left: 22px;
  padding-right: 22px;
}
.table--kunden .table__head { padding-top: 10px; padding-bottom: 10px; }
.table--kunden .table__row { padding-top: 16px; padding-bottom: 16px; }
.table--artikel .table__head, .table--artikel .table__row {
  grid-template-columns: 56px minmax(0, 1.4fr) 96px 140px 96px 140px 108px;
  gap: 0 14px;
  padding-left: 22px;
  padding-right: 22px;
}
.table--artikel .table__head { padding-top: 10px; padding-bottom: 10px; }
.table--artikel .table__row { padding-top: 12px; padding-bottom: 12px; }

/* Cell helpers. */
.r { text-align: right; }
.clip { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cell-no { font-family: var(--font-mono); font-size: 13px; color: var(--ink-3); }
.cell-name { font-size: 16px; font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--ink-4); }
.cell-date { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.cell-amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.cell-amount--lg { font-size: 15px; }
.cell-actions { display: flex; justify-content: flex-end; }
/* A cell whose text is the link into the record: reads as text, not as a link. */
.cell-link { color: var(--ink); font-weight: 500; text-decoration: none; }
.cell-link:hover { text-decoration: underline; }
.cell-chip {
  font-size: 12px;
  color: var(--ink-2);
  padding: 4px 10px;
  background: var(--surface-muted);
  border-radius: var(--r-chip);
}
.thumb {
  width: 56px;
  height: 48px;
  background: var(--surface-muted);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-thumb);
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ------------------------------------------------------------------ status
 * Never colour alone: mark + colour + German word, so the status is readable
 * in greyscale and by a colour-blind user.
 */
.status, .pill, .pill--neutral {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-muted);
  color: var(--ink-2);
}
.status__mark { font-size: 11px; }
.status--draft     { color: var(--ink-4); }
.status--paid,     .pill--due  { background: var(--accent-tint); color: var(--accent-dark); }
.status--overdue,  .pill--over { background: var(--warn-bg); color: var(--warn); }
.status--partial   { background: var(--warn-bg); color: var(--warn); }
.status--cancelled { background: var(--danger-bg); color: var(--danger); }

/* ------------------------------------------------------------------ chips
 * Segmented control: category filter on the invoice screen, status filter on
 * the invoice list. One control, both uses.
 */
.chips {
  display: inline-flex;
  gap: 6px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--r-lg);
  margin-bottom: var(--gap);
  flex-wrap: wrap;
}
.chip {
  height: var(--tap-seg);
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  cursor: pointer;
}
.chip:hover { background: var(--surface-muted); text-decoration: none; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; }
.chip__count { opacity: .6; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- forms */

.field { margin-bottom: 16px; max-width: 520px; }
.field__label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  height: var(--tap-in);
  padding: 0 14px;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--r-md);
}
.field select { padding: 0 10px; }
.field textarea { height: auto; min-height: 96px; padding: 12px 14px; resize: vertical; }
.field input[type="file"] { height: auto; padding: 12px 14px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.field__hint { font-size: 12px; color: var(--ink-4); margin: 6px 0 0; }
.field__error { font-size: 12px; font-weight: 600; color: var(--danger); margin: 6px 0 0; }
.field--invalid input, .field--invalid select { border-color: var(--danger); }

/* Two fields side by side (PLZ + Ort, Menge + Einheit). */
.row-fields { display: flex; gap: 16px; flex-wrap: wrap; }
.row-fields .field { flex: 1; min-width: 150px; }

/* The settings-card field grid: full-width fields span both columns. */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.fields .field, .fields .row-fields { margin-bottom: 0; max-width: none; }
.field--wide { grid-column: 1 / -1; }

/* Optional fields hide behind this, so a new customer is 5 fields, not 14. */
.disclosure { margin-bottom: var(--gap); }
.disclosure > summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
}

.search { display: flex; align-items: center; gap: 12px; margin-bottom: var(--gap); }
.search input {
  flex: 1;
  min-width: 0;
  height: var(--tap);
  padding: 0 18px;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--r-lg);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* A checkbox big enough for a thumb, with its explanation beside it. */
.switch { display: flex; align-items: center; gap: 12px; margin: var(--gap) 0; }
.switch input { width: 28px; height: 28px; flex: 0 0 28px; accent-color: var(--accent); }
/* The label is the second tap target, and it is the big one. */
.switch label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  justify-content: center;
  min-height: var(--tap-min);
  font-size: 14px;
  cursor: pointer;
}

/* Shows the user the consequence of a setting, in their own invoice's words. */
.note-preview {
  background: var(--accent-tint);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin-bottom: var(--gap);
  font-size: 13px;
}
.note-preview p { margin: 4px 0; }

/* ---------------------------------------------------------------- stepper
 * The quantity control from the positions panel (handoff §Screen 2). 112px
 * wide, 44px tall: do not widen it or the meta line beside it starts clipping.
 */
.qty {
  display: flex;
  align-items: center;
  height: var(--tap-min);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}
.qty button {
  flex: 0 0 34px;
  width: 34px;
  height: var(--tap-seg);
  border: 0;
  background: var(--surface);
  font-size: 19px;
  color: var(--ink);
  cursor: pointer;
}
.qty button:hover { background: var(--surface-muted); }
.qty__cell {
  flex: 1;
  min-width: 0;
  height: var(--tap-seg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0 4px;
  border-left: 1px solid var(--border-soft);
  border-right: 1px solid var(--border-soft);
}
.qty__input {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.qty__unit { font-size: 12px; color: var(--ink-4); }
/* Standalone (styleguide, free-line form): give it room to breathe. */
.qty--wide { width: 160px; }

/* ------------------------------------------------------------------ rows
 * The list row: invoice list, drafts, payments. Same hairlines and hover as
 * the tables, so a list and a table read as one system.
 */
.rows {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow: hidden;
  margin-bottom: var(--gap);
}
.row {
  display: flex;
  align-items: center;
  gap: var(--gap);
  min-height: 64px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-row);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  text-decoration: none;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-sunken); }
/* The row's text area is the link; buttons sit beside it. A button nested
 * inside a link is invalid HTML and unusable with a keyboard. */
.row__link { flex: 1; min-width: 0; text-decoration: none; color: inherit; }
.row__link:hover { text-decoration: none; }
.row__grow { flex: 1; min-width: 0; }
.row__strong { font-weight: 600; }
.row__meta { color: var(--ink-4); font-size: 12px; }
.row__amount { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

.month-head {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding: var(--gap-lg) 0 8px;
}

/* ---------------------------------------------------------------- totals */

.totals { display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: var(--ink-3); }
.totals__line { display: flex; justify-content: space-between; gap: var(--gap); }
.totals__label { color: var(--ink-3); }
.totals__value { color: var(--ink); font-variant-numeric: tabular-nums; }
.totals__grand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap);
  border-top: 1px solid var(--border);
  margin-top: 5px;
  padding-top: 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.totals__grand .totals__value {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-transform: none;
}

/* ------------------------------------------------------------------ sheet */

/* Native <dialog> — the browser gives us the backdrop, Esc to close and focus
 * handling for free. */
dialog.sheet {
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 22px 24px 24px;
  max-width: 520px;
  width: calc(100% - 32px);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sheet);
  font-size: 14px;
}
dialog.sheet::backdrop { background: rgba(22, 33, 28, .45); }
.sheet__title { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 12px; }
.sheet__body { margin: 0 0 20px; }
.sheet__consequence { color: var(--ink-3); }
.sheet__actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }
.sheet--danger .sheet__title { color: var(--danger); }

/* ------------------------------------------------------------------ toast */

/* The alternative to asking. Something reversible happened; here is the way
 * back, for 8 seconds. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sheet);
  display: flex;
  align-items: center;
  gap: var(--gap);
  font-size: 14px;
  z-index: 50;
}
.toast__btn {
  min-height: var(--tap-min);
  padding: 0 16px;
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* ------------------------------------------------------------------ empty */

/* No empty state without a button that fills it. */
.empty { text-align: center; padding: 44px 24px; color: var(--ink-4); font-size: 14px; }
.empty__title { font-size: 16px; font-weight: 600; color: var(--ink); margin: 0 0 6px; }
.empty__body { margin: 0 0 20px; }

/* ---------------------------------------------------------------- banners */

.saved-banner, .warn-banner {
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin: 0 0 var(--gap);
  font-size: 14px;
  font-weight: 500;
}
.saved-banner { background: var(--accent-tint); color: var(--accent-dark); }
.warn-banner { background: var(--warn-bg); color: var(--warn); }
.warn-banner a { color: inherit; text-decoration: underline; }
.saved-mark { font-size: 12px; font-weight: 600; color: var(--accent); }

/* ------------------------------------------------------- start (dashboard) */

/* KPI strip: the 1px gap on a border-coloured background draws the hairlines. */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow: hidden;
  margin-bottom: var(--gap-lg);
}
.kpi { background: var(--surface); padding: 18px 20px; display: flex; flex-direction: column; gap: 7px; }
.kpi__label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-4);
}
.kpi__value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi__caption { font-size: 12px; color: var(--ink-3); }
.kpi--warn .kpi__value, .kpi--warn .kpi__caption { color: var(--warn); }
@media (max-width: 1180px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

.board { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--gap-lg); align-items: start; }
@media (max-width: 1000px) { .board { grid-template-columns: 1fr; } }

.quick { display: flex; flex-direction: column; gap: 10px; }
.quick__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding-left: 2px;
}
.quick__item {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 78px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  text-align: left;
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
}
.quick__item:hover { border-color: var(--accent); text-decoration: none; }
.quick__icon {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: var(--r-lg);
  background: var(--accent-tint);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.quick__icon svg { width: 22px; height: 22px; }
.quick__text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.quick__title { font-size: 15px; font-weight: 600; }
.quick__sub { font-size: 13px; color: var(--ink-3); }

/* --------------------------------------------------- invoice wizard header */

.wizard-steps { display: flex; align-items: center; gap: 10px; list-style: none; margin: 0; padding: 0; }
.wizard-steps li { display: flex; align-items: center; gap: 10px; }
/* The 22px separator between two steps, drawn instead of marked up. */
.wizard-steps li + li::before {
  content: "";
  width: 22px;
  height: 1px;
  background: var(--border-hairline);
}
.step {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 14px 6px 10px;
  border-radius: var(--r-pill);
}
.step__badge {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}
.step__label { font-size: 14px; }
.step--done { background: var(--accent-tint); }
.step--done .step__badge { background: var(--accent); color: #fff; }
.step--done .step__label { color: var(--accent); font-weight: 500; }
.step--current { background: var(--ink); }
.step--current .step__badge { background: #fff; color: var(--ink); }
.step--current .step__label { color: #fff; font-weight: 600; }
.step--next .step__badge { border: 1px solid var(--border-hairline); color: var(--ink-4); font-weight: 600; }
.step--next .step__label { color: var(--ink-4); }

.wizard-head__right { display: flex; align-items: center; gap: 20px; }
.wizard-who { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 0; }
.wizard-who__name { font-size: 15px; font-weight: 600; }
.wizard-who__meta { font-family: var(--font-mono); font-size: 12px; color: var(--ink-4); }

/* ------------------------------------------------- invoice screen 2: split
 * Articles left, positions right. Only the article grid and the position list
 * scroll — the totals and the primary action are always on screen. That is the
 * whole point of this screen (handoff §Screen 2).
 */

.kasse { display: flex; flex: 1; min-height: 0; width: 100%; overflow: hidden; }

.picker {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 22px 26px 22px 32px;
}
.picker__toolbar { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
/* Wrapping is required: the chips drop to their own line before the input goes
 * below 240px. */
.picker__toolbar .search { flex: 1 1 240px; min-width: 240px; margin: 0; }
.picker__toolbar .chips { margin-bottom: 0; }
.picker__toolbar form { display: contents; }

.artikel-grid {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(186px, 1fr));
  grid-auto-rows: min-content;
  align-content: start;
  gap: 12px;
  padding-right: 4px;
}
.artikel-grid > form { display: contents; }
.artikel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow: hidden;
}
/* The photo is not a tap target — only the button adds to the invoice. */
.artikel__photo {
  position: relative;
  height: 104px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border-soft);
}
.artikel__photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.artikel__no {
  position: absolute;
  top: 8px;
  right: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-2);
  background: rgba(255, 255, 255, .9);
  padding: 3px 6px;
  border-radius: var(--r-badge);
  pointer-events: none;
}
.artikel__body { padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.artikel__name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.artikel__row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.artikel__price { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.artikel__vat {
  font-size: 11px;
  color: var(--ink-3);
  padding: 3px 7px;
  background: var(--surface-muted);
  border-radius: var(--r-chip);
  white-space: nowrap;
}
.artikel__add {
  margin: 0 10px 10px;
  height: var(--tap-add);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-md);
  background: var(--accent-wash);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.artikel__add:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.picker__empty { padding-top: 12px; }

/* ------------------------------------------------- invoice screen 2: panel */

.positions {
  width: var(--panel-w);
  flex: 0 0 var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.positions__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.positions__title { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.positions__title h2 { margin: 0; font-size: 17px; font-weight: 600; }
.positions__count { font-size: 13px; color: var(--ink-4); font-variant-numeric: tabular-nums; }
.positions__list { flex: 1; min-height: 0; overflow: auto; }
.positions__empty { padding: 44px 24px; text-align: center; font-size: 14px; color: var(--ink-4); }

.pos {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px 78px 26px;
  gap: 8px;
  align-items: center;
  padding: 11px 14px 11px 16px;
  border-bottom: 1px solid var(--border-row);
}
.pos__text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pos__name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pos__meta {
  font-size: 12px;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pos__total { text-align: right; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
/* Small on purpose: removing a line should be findable but never the thing
 * your thumb hits by accident (handoff §Screen 2). */
.pos__remove {
  width: 26px;
  height: 30px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-5);
  font-size: 15px;
  cursor: pointer;
}
.pos__remove:hover { background: var(--danger-bg); color: var(--danger); }

.totals-block {
  border-top: 1px solid var(--border);
  padding: 16px 22px 18px;
  background: var(--surface-sunken);
}
.vat-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  column-gap: 14px;
  row-gap: 7px;
  font-size: 13px;
  color: var(--ink-3);
  margin-bottom: 12px;
}
.vat-grid__value { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.grand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.grand__label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.grand__value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.panel-actions {
  display: flex;
  gap: 12px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border-soft);
}
.panel-actions .btn--xl { flex: 1; }

/* Freie Position: a native <details> that opens as a small panel under its
 * button. No JavaScript, and it cannot get out of sync with anything. */
.free-line { position: relative; }
.free-line > summary {
  list-style: none;
  min-height: var(--tap-xs);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.free-line > summary::-webkit-details-marker { display: none; }
.free-line > summary::marker { content: ""; }
.free-line > summary:hover { border-color: var(--accent); }
/* 320px is narrow: let Menge/Einheit and Preis/USt. stay in pairs. */
.free-line__form .row-fields .field { min-width: 110px; }
.free-line__form {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 5;
  width: 320px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-sheet);
}

/* Below the designed range the split does not fit: stack it, panel last.
 * Flagged as an open item in the handoff — tablet portrait needs a real
 * design decision, this only keeps it usable. */
@media (max-width: 900px) {
  .kasse { flex-direction: column; overflow: auto; }
  .picker { overflow: visible; padding: 20px; }
  .artikel-grid { overflow: visible; }
  .positions { width: 100%; flex: 0 0 auto; border-left: 0; border-top: 1px solid var(--border); }
  .positions__list { overflow: visible; }
}

/* ------------------------------------------------- invoice screen 3, detail */

.review { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 20px; align-items: start; }
.review__form, .review__preview { min-width: 0; }
.preview-paper {
  width: 100%;
  height: 780px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: #fff;
}
@media (max-width: 1100px) {
  .review { grid-template-columns: 1fr; }
  .preview-paper { height: 600px; }
}

/* A single centred card: confirm, success, failure, payment form. */
.confirm-page { max-width: 680px; margin: 0 auto; }
.confirm-facts { font-size: 16px; margin: 0 0 var(--gap); }
.issued-mark { font-size: 44px; line-height: 1; color: var(--accent); margin: 0 0 12px; }
.issued-actions { justify-content: center; }
.problems { margin: var(--gap) 0; padding-left: 20px; }
.problems li { margin-bottom: 6px; }
.failure-reason {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow: auto;
}

/* Invoice detail: one primary, one secondary, quiet links below. */
.detail-actions {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
  margin-bottom: var(--gap);
  align-items: stretch;
}
.detail-actions .btn { width: 100%; }
.detail-actions__sub { font-weight: 400; font-size: 13px; opacity: .85; }
.detail-paid {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent-tint);
  border-radius: var(--r-card);
  padding: var(--gap);
  font-size: 14px;
}
.quiet-actions { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: var(--gap-lg); }
@media (max-width: 700px) { .detail-actions { grid-template-columns: 1fr; } }

/* Line table on the detail and report pages. */
table.lines { width: 100%; border-collapse: collapse; font-size: 14px; }
table.lines th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding: 0 8px 9px 0;
  border-bottom: 1px solid var(--border-soft);
}
table.lines td { padding: 12px 8px 12px 0; border-bottom: 1px solid var(--border-row); }
table.lines tr:last-child td { border-bottom: 0; }
table.lines .r { text-align: right; }

/* The audit trail, as plain sentences. */
.history { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.history li { display: flex; gap: var(--gap); padding: 9px 0; border-bottom: 1px solid var(--border-row); }
.history li:last-child { border-bottom: 0; }
.history__when { color: var(--ink-4); flex: 0 0 150px; font-family: var(--font-mono); font-size: 12px; }

/* ------------------------------------------------------------- settings */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 20px;
  align-items: start;
  max-width: 1180px;
}
.settings-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ------------------------------------------------------------- reports */
.period-form .row-fields { align-items: flex-end; margin-bottom: var(--gap); }

/* ------------------------------------------------------------- login */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap-lg);
  background: var(--canvas);
}
.login__card { width: 100%; max-width: 400px; }
.login__card .page-title { margin-bottom: 4px; }
.login__card form { margin-top: 20px; }

/* ------------------------------------------------------- product photos */

.photo-thumb {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: var(--r-thumb);
  object-fit: cover;
  background: var(--surface-muted);
}
.photo-thumb--lg { width: 120px; height: 120px; flex: 0 0 120px; border-radius: var(--r-card); }
.photo-current { display: flex; align-items: center; gap: var(--gap); margin-bottom: 12px; }

/* The camera field. The real <input type=file> is hidden and this label is the
 * control — accept + capture make the tablet open its camera directly. */
.photo-pick {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 14px 16px;
  border: 1px dashed var(--border-input);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 14px;
  cursor: pointer;
}
.photo-pick:hover { border-color: var(--accent); }
.photo-pick__icon { font-size: 24px; }
.photo-pick__input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.photo-pick__input:focus-visible + .photo-pick { outline: 2px solid var(--accent); }

/* ------------------------------------------------------------------ misc */

.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.inline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-title { font-size: 17px; font-weight: 600; margin: var(--gap-lg) 0 12px; }

/* The few spacing utilities that exist. Use these instead of a style
 * attribute — the Content-Security-Policy in base.html blocks inline styles. */
.mt-0 { margin-top: 0; }
.mb-lg { margin-bottom: var(--gap-lg); }
.mt-lg { margin-top: var(--gap-lg); }
.w-narrow { max-width: 320px; }

/* Available to screen readers, invisible on screen. */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Phone width: the rail becomes a bottom bar. Below 768px the handoff is
 * explicitly out of scope — this keeps the app navigable, nothing more. */
@media (max-width: 700px) {
  .app { flex-direction: column; height: auto; min-height: 100vh; overflow: visible; }
  .rail {
    order: 2;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    padding: 6px;
    border-right: 0;
    border-top: 1px solid var(--border);
    z-index: 10;
  }
  .rail__brand, .rail__spacer, .rail__foot { display: none; }
  .rail__nav { flex-direction: row; flex: 1; }
  .rail__item { flex: 1; justify-content: center; padding: 0 6px; font-size: 13px; }
  .rail__bar { display: none; }
  .main { overflow: visible; }
  .screen { height: auto; overflow: visible; }
  .screen__head { flex-direction: column; align-items: flex-start; padding: 20px; }
  .screen__body { overflow: visible; padding: 20px 20px 96px; }
  .head__actions .search { width: 100%; }
}

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