/*
 * HxCore hx blocks (M5 F4): the 48 Hx* components of the former admin
 * (../hxcore/admin/src/design/components) as plain CSS on the design tokens.
 * One BEM block per catalog block (`hx-<block>`), modifiers `--x`, parts `__y`.
 * Rules (PATTERNS.md): only tokens, no outer margins on blocks (the parent
 * stack's gap spaces them), every colour pair from tokens.css (AA, HxContrastIT).
 */
@layer components {
  /* ---------- Shared control look (controls.css) ---------- */

  .hx-control {
    width: 100%;
    min-height: var(--control-height);
    padding: var(--space-2) var(--space-3);
    font: inherit;
    font-size: var(--size-body);
    color: var(--text);
    background: var(--surface-sunken);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    transition:
      border-color var(--transition-fast),
      box-shadow var(--transition-fast);
  }

  .hx-control:hover:not(:disabled, :focus) {
    border-color: var(--border-stronger);
  }

  .hx-control:focus-visible {
    outline: none;
    border-color: var(--focus-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-color) 25%, transparent);
  }

  .hx-control[aria-invalid='true'] {
    border-color: var(--danger);
  }

  .hx-control--mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

  textarea.hx-control {
    min-height: 72px;
    resize: vertical;
  }

  select.hx-control {
    padding-right: var(--space-8);
    appearance: none;
    background-image:
      linear-gradient(45deg, transparent 50%, var(--text-subtle) 50%),
      linear-gradient(135deg, var(--text-subtle) 50%, transparent 50%);
    background-position:
      calc(100% - 17px) 55%,
      calc(100% - 12px) 55%;
    background-size:
      5px 5px,
      5px 5px;
    background-repeat: no-repeat;
  }

  /* ---------- Icon ---------- */

  .hx-icon {
    display: inline-block;
    flex-shrink: 0;
    width: var(--size-icon-md);
    height: var(--size-icon-md);
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .hx-icon--sm {
    width: var(--size-icon-sm);
    height: var(--size-icon-sm);
    stroke-width: 2;
  }

  .hx-icon--md {
    width: var(--size-icon);
    height: var(--size-icon);
    stroke-width: 2;
  }

  .hx-icon--lg {
    width: var(--size-icon-lg);
    height: var(--size-icon-lg);
  }

  /* ---------- Page header ---------- */

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

  .hx-page-header__eyebrow {
    margin: 0 0 var(--space-1);
    font-size: var(--size-label);
    font-weight: 500;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    font-weight: 600;
    color: var(--highlight-text); /* HexaMain: eyebrows are one of the few orange places */
  }

  .hx-page-header__title {
    margin: 0;
    font-family: var(--font-display);
    font-size: var(--size-h1);
    font-weight: 700;
    letter-spacing: var(--tracking-display);
    color: var(--text-strong);
  }

  .hx-page-header__title:focus {
    outline: none;
  }

  .hx-page-header--display .hx-page-header__title {
    font: var(--text-display);
    letter-spacing: var(--tracking-display);
  }

  .hx-page-header__meta {
    margin: var(--space-1) 0 0;
    font-family: var(--font-mono);
    font-size: var(--size-small);
    font-variant-numeric: tabular-nums;
    color: var(--text-subtle);
  }

  /* U1: term hint (plugin) under the page title (setting "Begriffe aus dem Altsystem anzeigen"). */
  .hx-page-header__legacy,
  .hx-legacy-term {
    font-family: var(--font-sans);
    font-size: var(--size-small);
    font-weight: 400;
    color: var(--text-subtle);
  }

  .hx-page-header__legacy {
    margin: var(--space-0-5) 0 0;
  }

  /* U1: Schnellauskunft (quickInfo block). */
  .hx-quick-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    font-size: var(--size-control);
  }

  .hx-quick-info__eyebrow,
  .hx-quick-info__label {
    margin: 0;
    font-size: var(--size-label);
    font-weight: 500;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--text-subtle);
  }

  .hx-quick-info__title {
    margin: var(--space-0-5) 0 0;
    font-family: var(--font-display);
    font-size: var(--size-h3, 18px);
    font-weight: 700;
    color: var(--text-strong);
  }

  .hx-quick-info__title a { color: inherit; text-decoration: none; }
  .hx-quick-info__title a:hover { text-decoration: underline; }

  .hx-quick-info__meta {
    margin: var(--space-0-5) 0 0;
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-quick-info__flags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: var(--space-2) 0 0;
  }

  .hx-quick-info__note,
  .hx-quick-info__empty {
    margin: var(--space-1) 0 0;
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-quick-info__figures {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: var(--space-2);
    margin: 0;
  }

  .hx-quick-info__figure {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
  }

  .hx-quick-info__figure dt {
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-quick-info__figure dd {
    margin: var(--space-0-5) 0 0;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text-strong);
  }

  .hx-quick-info__figure dd a { color: inherit; text-decoration: none; }
  .hx-quick-info__figure dd a:hover { text-decoration: underline; }
  .hx-quick-info__figure--danger { border-color: var(--danger); background: var(--danger-bg); }
  .hx-quick-info__figure--danger dd { color: var(--danger); }

  .hx-quick-info__docs,
  .hx-quick-info__contacts {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: var(--space-1-5) 0 0;
    padding: 0;
    list-style: none;
  }

  .hx-quick-info__docs li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: baseline;
    gap: var(--space-2);
  }

  .hx-quick-info__number,
  .hx-quick-info__date,
  .hx-quick-info__amount {
    font-family: var(--font-mono);
    font-size: var(--size-small);
    font-variant-numeric: tabular-nums;
  }

  .hx-quick-info__date { color: var(--text-subtle); }
  .hx-quick-info__amount { text-align: right; color: var(--text); }

  .hx-quick-info__contacts li {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
  }

  .hx-quick-info__contact { color: var(--text); }

  .hx-quick-info__activity {
    margin: 0;
    font-size: var(--size-small);
    color: var(--text-muted);
  }

  .hx-quick-info__docs .hx-code { margin-right: 0; }

  /* U1: document code plaque (AN/AB/LS/RG/GS/BE/WE/ER) in lists, page header and document chain. */
  .hx-code {
    display: inline-block;
    margin-right: var(--space-1-5);
    padding: 0 5px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-sunken);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    vertical-align: 0.1em;
    white-space: nowrap;
  }

  .hx-code--lg {
    margin-right: var(--space-2);
    padding: 1px 7px;
    font-size: 13px;
    vertical-align: 0.3em;
  }

  .hx-page-header__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  /* ---------- Stack ---------- */

  .hx-stack {
    display: grid;
    min-width: 0;
    align-content: start;
    gap: var(--space-5);
  }

  .hx-stack--tight {
    gap: var(--space-3);
  }

  .hx-stack--tight > .hx-btn {
    justify-self: start;
  }

  .hx-stack--compact {
    gap: var(--space-2);
  }

  .hx-stack--cell {
    gap: var(--space-2);
    justify-items: start;
  }

  ul.hx-stack,
  ol.hx-stack {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* ---------- Detail grid (main + side column) ---------- */

  .hx-detail-grid {
    display: grid;
    align-items: start;
    gap: var(--space-5);
    grid-template-columns: minmax(0, 2fr) minmax(var(--min-side), 1fr);
  }

  /* ---------- Pair ---------- */

  .hx-pair,
  .hx-meta-list--pair {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min-pair)), 1fr));
    align-items: start;
    gap: var(--space-4);
  }

  .hx-pair > fieldset {
    margin: 0;
  }

  /* Grid items may shrink below their content (wide tables scroll inside their card instead of widening the page). */
  .hx-pair > * {
    min-width: 0;
  }

  /* ---------- Panel ---------- */

  .hx-panel {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
  }

  .hx-panel__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-5) 0;
  }

  .hx-panel--flush > .hx-panel__header {
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
  }

  .hx-panel__title {
    margin: 0;
    font-family: var(--font-display);
    font-size: var(--size-h2);
    font-weight: 700;
    letter-spacing: var(--tracking-title);
  }

  .hx-panel__meta {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-panel__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
  }

  .hx-panel__meta + .hx-panel__actions {
    margin-left: 0;
  }

  .hx-panel__body {
    padding: var(--space-5);
  }

  .hx-panel--flush > .hx-panel__body {
    padding: 0;
  }

  .hx-panel--flush > .hx-panel__body > .hx-table {
    border: 0;
    border-radius: 0;
  }

  .hx-panel--flush > .hx-panel__body > .hx-alert,
  .hx-panel--flush > .hx-panel__body > .hx-empty {
    margin: var(--space-4);
  }

  /* ---------- Actions ---------- */

  .hx-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .hx-actions--end {
    justify-content: flex-end;
  }

  /* ---------- Button + link button ---------- */

  .hx-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: var(--control-height);
    min-height: 0;
    padding: 0 var(--space-3-5);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text);
    font-size: var(--size-control);
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition:
      background-color var(--transition-fast),
      border-color var(--transition-fast),
      color var(--transition-fast);
  }

  /* Links in the content area are underlined (base.css); a link button is not. */
  :is(.hx-content, .hx-auth__card, .hx-auth-split__panel) a.hx-btn {
    text-decoration: none;
  }

  .hx-btn:hover:not(:disabled) {
    border-color: var(--border-stronger);
    background: var(--surface-hover);
    color: var(--text);
  }

  .hx-btn--sm {
    height: var(--control-height-sm);
    padding: 0 var(--space-2-5);
    font-size: var(--size-small);
  }

  .hx-btn--lg {
    height: var(--control-height-lg);
    padding: 0 var(--space-4-5);
    font-size: var(--size-body);
  }

  .hx-btn--primary,
  button[type='submit'].hx-btn--primary {
    border-color: transparent;
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
  }

  .hx-btn--primary:hover:not(:disabled) {
    border-color: transparent;
    background: color-mix(in srgb, var(--accent) 86%, var(--text-strong));
    color: var(--on-accent);
  }

  /* A submit button that is not primary keeps its variant (base.css paints submit in the primary cyan). */
  button[type='submit'].hx-btn:not(.hx-btn--primary) {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text);
    font-weight: 500;
  }

  .hx-btn--ghost,
  button[type='submit'].hx-btn--ghost {
    border-color: transparent;
    color: var(--text-muted);
  }

  .hx-btn--ghost:hover:not(:disabled) {
    border-color: transparent;
    color: var(--text);
  }

  .hx-btn--danger,
  button[type='submit'].hx-btn--danger {
    border-color: color-mix(in srgb, var(--danger) 55%, transparent);
    color: var(--danger);
  }

  .hx-btn--danger:hover:not(:disabled) {
    border-color: var(--danger);
    background: var(--danger-bg);
    color: var(--danger);
  }

  .hx-btn--icon-only {
    width: var(--control-height);
    padding: 0;
  }

  .hx-btn--sm.hx-btn--icon-only {
    width: var(--control-height-sm);
  }

  .hx-btn:disabled,
  .hx-btn[aria-disabled='true'] {
    cursor: not-allowed;
    opacity: 1;
    border-style: dashed;
    border-color: var(--border-stronger);
    background: var(--surface-sunken);
    color: var(--text-faint);
  }

  /* ---------- Tabs (segment tabs) ---------- */

  .hx-tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: var(--space-0-5);
    padding: var(--size-bar);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
  }

  .hx-tabs__tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1-5);
    min-height: 0;
    padding: 5px var(--space-2-5);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-subtle);
    font-size: var(--size-small);
    font-weight: inherit;
    line-height: inherit;
    text-decoration: none;
    cursor: pointer;
  }

  :is(.hx-content) a.hx-tabs__tab {
    text-decoration: none;
  }

  .hx-tabs__tab:hover:not(:disabled) {
    background: transparent;
    color: var(--text);
  }

  .hx-tabs__tab[aria-selected='true'],
  .hx-tabs__tab[aria-current='page'] {
    background: var(--surface-active);
    color: var(--text);
    font-weight: 600;
  }

  .hx-tabs__tab:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 1px;
  }

  .hx-tabs__count {
    font-family: var(--font-mono);
    font-size: var(--size-label);
    color: var(--text-subtle);
  }

  /* ---------- Field + form grid ---------- */

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

  /* Labels wrap instead of being cut off (M5 Formulare): the whole text stays readable at every width. */
  .hx-field__label {
    display: block;
    padding-bottom: var(--space-1-5);
    font-size: var(--size-control);
    font-weight: 500;
    line-height: 1.35;
    overflow-wrap: anywhere;
    color: var(--text-muted);
  }

  .hx-field__head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-1-5);
  }

  .hx-field__head > .hx-field__label {
    min-width: 0;
  }

  .hx-field__required {
    color: var(--danger);
  }

  .hx-field__messages {
    display: flex;
    flex-direction: column;
    gap: var(--space-1-5);
    padding-top: var(--space-1-5);
  }

  .hx-field__help {
    margin: 0;
    font-size: var(--size-small);
    line-height: 1.4;
    color: var(--text-subtle);
  }

  p.hx-field__error,
  .hx-field__error {
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: var(--size-small);
    line-height: 1.4;
    color: var(--danger);
  }

  .hx-field__error:empty {
    display: none;
  }

  .hx-check {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text);
    font-size: var(--size-body);
  }

  .hx-form-grid {
    container-type: inline-size;
  }

  /*
   * Form grid (M5 Formulare): 6 tracks on narrow forms, 12 from 40rem form width. Field width via data-w
   * (HxFormFields): xs 2 · sm 3 · md 6 (default, two per row) · lg 8 · full 12; narrow: xs 2, sm 3, rest full.
   */
  .hx-form-grid__fields {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    align-items: start;
    gap: var(--space-4);
  }

  .hx-form-grid__fields > * {
    min-width: 0;
    grid-column: span 6;
  }

  .hx-form-grid__fields > [data-w='xs'] {
    grid-column: span 2;
  }

  .hx-form-grid__fields > [data-w='sm'] {
    grid-column: span 3;
  }

  .hx-form-grid__fields > [data-span='full'],
  .hx-form-grid__fields > [data-w='full'],
  /*
   * Text, tables and notes are not fields: they take the full row (e.g. long text inside a disclosure). The same holds
   * for whole blocks inside a disclosure (its body is a form grid too): a form („Positionen bearbeiten“), a stack, a
   * panel or tabs would otherwise get the half row of a field (span 6 of 12).
   */
  .hx-form-grid__fields > .hx-text,
  .hx-form-grid__fields > .hx-table,
  .hx-form-grid__fields > .hx-alert,
  .hx-form-grid__fields > .hx-actions,
  .hx-form-grid__fields > .hx-form-grid,
  .hx-form-grid__fields > .hx-stack,
  .hx-form-grid__fields > .hx-panel,
  .hx-form-grid__fields > .hx-tabs,
  .hx-form-grid__fields > .hx-markdown,
  .hx-form-grid__fields > .hx-lazy {
    grid-column: 1 / -1;
  }

  @container (min-width: 40rem) {
    .hx-form-grid__fields {
      grid-template-columns: repeat(12, minmax(0, 1fr));
      gap: var(--space-4) var(--space-5);
    }

    .hx-form-grid__fields > [data-w='lg'] {
      grid-column: span 8;
    }
  }

  /* A row of checkboxes (e.g. „Aktiv“, „Gesperrt“) sits on the baseline of the inputs beside it. */
  .hx-form-grid__fields > .hx-field:has(> .hx-check) {
    align-self: end;
    min-height: var(--control-height);
    justify-content: center;
  }

  .hx-disclosure {
    container-type: inline-size;
  }

  .hx-form-grid--row .hx-form-grid__fields {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 8rem), 1fr));
    align-items: end;
  }

  .hx-form-grid--row .hx-form-grid__fields > * {
    grid-column: auto;
  }

  .hx-form-grid--row .hx-form-grid__fields > :first-child {
    grid-column: span 2;
  }

  .hx-form-grid--row .hx-form-grid__fields > [data-span='full'] {
    grid-column: 1 / -1;
  }

  .hx-form-grid__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-4);
  }

  .hx-form-grid--row .hx-form-grid__actions {
    align-self: end;
    justify-content: flex-start;
    margin-top: 0;
  }

  /* ---------- Choice group, checkbox grid ---------- */

  .hx-choice-group {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
  }

  /* Chips (variant "chips"): Radio-Auswahl als Touch-Chips in einer Zeile; das gewählte Chip ist gefüllt. */
  .hx-choice-group--chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1-5);
  }

  .hx-choice-group--chips > legend {
    float: left;
    width: 100%;
    margin-bottom: var(--space-1);
    color: var(--text-muted);
    font-size: var(--size-small);
  }

  .hx-choice-group--chips .hx-check {
    position: relative;
    min-height: var(--control-height);
    padding: 0 var(--space-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-full);
    background: var(--surface);
    font-size: var(--size-small);
    cursor: pointer;
    user-select: none;
  }

  .hx-choice-group--chips .hx-check > input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
  }

  .hx-choice-group--chips .hx-check:has(> input:checked) {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
  }

  .hx-choice-group--chips .hx-check:has(> input:focus-visible) {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
  }

  .hx-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--min-check), 1fr));
    gap: var(--space-2) var(--space-4);
  }

  /* ---------- Progress steps (waiting screen) ---------- */

  .hx-progress {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    gap: var(--space-6, 1.5rem);
    align-items: start;
    padding: var(--space-5, 1.25rem);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
  }
  .hx-progress:not(:has(.hx-progress__preview)) { grid-template-columns: minmax(0, 1fr); }
  .hx-progress__preview .hx-file-preview__frame,
  .hx-progress__preview .hx-file-preview__image { max-height: 22rem; }
  .hx-progress__body { display: grid; gap: var(--space-4, 1rem); }
  .hx-progress__title { margin: 0; font: var(--text-h2); color: var(--text-strong); }
  .hx-progress__steps { display: grid; gap: var(--space-3); margin: 0; padding: 0; list-style: none; }
  .hx-progress__step {
    display: grid;
    grid-template-columns: 1.75rem minmax(0, 1fr);
    column-gap: var(--space-3);
    align-items: center;
    color: var(--text-subtle);
  }
  .hx-progress__mark {
    display: inline-grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid var(--border-strong);
    border-radius: 50%;
    font-weight: 700;
    line-height: 1;
  }
  .hx-progress__detail { grid-column: 2; font: var(--text-small); color: var(--text-subtle); }
  .hx-progress__step--done { color: var(--text-strong); }
  .hx-progress__step--done .hx-progress__mark { border-color: var(--success-fill); background: var(--success-fill); color: var(--on-tone); }
  .hx-progress__step--active { color: var(--text-strong); font-weight: 600; }
  .hx-progress__step--active .hx-progress__mark { border-color: var(--border); border-top-color: var(--accent, currentColor); }
  .hx-progress__step--failed { color: var(--danger); }
  .hx-progress__step--failed .hx-progress__mark { border-color: currentColor; }
  .hx-progress__step--skipped .hx-progress__label { text-decoration: line-through; }
  @media (prefers-reduced-motion: no-preference) {
    .hx-progress__step--active .hx-progress__mark { animation: hx-progress-spin 0.9s linear infinite; }
  }
  @keyframes hx-progress-spin { to { transform: rotate(360deg); } }
  @media (max-width: 720px) { .hx-progress { grid-template-columns: minmax(0, 1fr); } }

  .hx-drop__progress { display: flex; gap: var(--space-3); align-items: center; }
  .hx-drop__progress[hidden] { display: none; }
  .hx-drop__progress img { width: 3rem; height: 3rem; object-fit: cover; border-radius: var(--radius-sm); }
  .hx-drop__progress progress { flex: 1; accent-color: var(--accent, currentColor); }

  /* ---------- Photo capture (camera button + thumbnail grid) ---------- */
  .hx-photos { display: grid; gap: var(--space-2); min-width: 0; }
  .hx-photos__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr)); gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
  .hx-photos__item { position: relative; display: grid; gap: var(--space-1); min-width: 0; }
  .hx-photos__link { display: block; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); background: var(--surface-sunken); }
  .hx-photos__link:focus-visible { outline: 2px solid var(--focus-color); outline-offset: 2px; }
  .hx-photos__img { display: block; width: 100%; aspect-ratio: 1; height: auto; object-fit: cover; }
  .hx-photos__caption { font: var(--text-small); color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hx-photos__remove { position: absolute; top: var(--space-1); right: var(--space-1); margin: 0; }
  .hx-photos__remove-btn { background: var(--surface); border: 1px solid var(--border); min-width: 2rem; min-height: 2rem; }
  .hx-photos__empty { margin: 0; font: var(--text-small); color: var(--text-subtle); }
  .hx-photos__form { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: 0; }
  .hx-photos__take { position: relative; cursor: pointer; }
  .hx-photos__take:focus-within { outline: 2px solid var(--focus-color); outline-offset: 2px; }
  .hx-photos__input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
  .hx-photos__hint { font: var(--text-small); color: var(--text-subtle); }
  .hx-photos__status { margin: 0; font: var(--text-small); color: var(--text-subtle); min-height: 1em; }
  .hx-photos[aria-busy="true"] .hx-photos__take { opacity: 0.6; pointer-events: none; }

  /* ---------- Pick list (search + hits) ---------- */

  .hx-pick {
    position: relative;
    display: grid;
    gap: var(--space-2);
  }

  .hx-pick-list {
    display: grid;
    max-height: var(--height-pick);
    gap: var(--space-0-5);
    margin: 0;
    padding: var(--space-1);
    overflow-y: auto;
    list-style: none;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-md);
  }

  .hx-pick-list:empty {
    display: none;
  }

  .hx-pick-list > li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
  }

  .hx-pick-list > li:hover,
  .hx-pick-list > li[aria-selected='true'] {
    background: var(--surface-hover);
  }

  .hx-pick-list__group {
    padding: var(--space-1) var(--space-3) 0;
    font: var(--text-small);
    font-weight: 600;
    color: var(--text-subtle);
  }

  .hx-pick-list__empty {
    padding: var(--space-1) var(--space-3);
    color: var(--text-subtle);
  }

  .hx-pick-chosen {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1-5);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .hx-pick-chosen:empty {
    display: none;
  }

  .hx-pick-chosen__item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-0-5) var(--space-1) var(--space-0-5) var(--space-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-size: var(--size-small);
  }

  .hx-pick-chosen__remove {
    padding: 0 var(--space-1);
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
  }

  .hx-pick-chosen__remove:hover {
    background: var(--surface-hover);
    color: var(--text-strong);
  }

  .hx-picked-value {
    display: inline-flex;
    min-height: var(--control-height);
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    margin: 0;
  }

  /* ---------- Table (data table + hand-written table) ---------- */

  .hx-table {
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
  }

  .hx-table__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
  }

  .hx-table__caption-text {
    margin: 0 auto 0 0;
    font-family: var(--font-display);
    font-size: var(--size-h2);
    font-weight: 700;
  }

  .hx-table__filter {
    width: min(100%, 16rem);
    min-height: var(--control-height-sm);
    padding: var(--space-1) var(--space-2-5);
  }

  .hx-table__count {
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-table__columns {
    position: relative;
  }

  .hx-table__columns > summary {
    display: inline-flex;
    align-items: center;
    height: var(--control-height-sm);
    padding: 0 var(--space-2-5);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: var(--size-small);
    font-weight: 500;
    list-style: none;
    cursor: pointer;
  }

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

  .hx-table__columns-menu {
    position: absolute;
    right: 0;
    z-index: var(--z-menu);
    display: grid;
    min-width: var(--width-menu);
    gap: var(--space-1);
    margin-top: var(--space-1);
    padding: var(--space-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-md);
  }

  .hx-table__scroll {
    overflow-x: auto;
  }

  .hx-table table {
    width: 100%;
    margin: 0;
    border: 0;
    border-collapse: collapse;
    background: transparent;
    font-size: var(--size-body);
  }

  .hx-table th {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    background: transparent;
    font-size: var(--size-label);
    font-weight: 500;
    letter-spacing: var(--tracking-label);
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--text-subtle);
  }

  .hx-table td {
    padding: var(--space-3-5) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text);
  }

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

  .hx-table [data-cell='num'] {
    text-align: right;
  }

  .hx-table [data-cell='center'] {
    text-align: center;
  }

  .hx-table td:is([data-cell='num'], [data-cell='mono']) {
    font-family: var(--font-mono);
    font-size: var(--size-mono);
    font-variant-numeric: tabular-nums;
    white-space: nowrap; /* numbers, dates and document numbers never break (the table scrolls instead) */
  }

  .hx-table th[data-sort] {
    cursor: pointer;
  }

  .hx-table th[aria-sort='ascending']::after {
    content: ' \2191';
  }

  .hx-table th[aria-sort='descending']::after {
    content: ' \2193';
  }

  .hx-table__row--link {
    cursor: pointer;
  }

  .hx-content .hx-table__link,
  .hx-table__link {
    color: inherit;
    text-decoration: none;
  }

  .hx-table__link:hover {
    color: var(--text-strong);
  }

  .hx-table__link:focus-visible,
  .hx-table :is(a, button):focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: -2px;
  }

  .hx-table__row--selected > td {
    background: var(--surface-hover);
  }

  .hx-table__row--selected > td:first-child {
    box-shadow: inset var(--size-bar) 0 0 var(--accent-text);
  }

  .hx-table__state > td,
  .hx-table tbody > tr.hx-table__state:hover > td {
    background: transparent;
  }

  .hx-table tfoot :is(th, td) {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    background: transparent;
    font-weight: 600;
    color: var(--text-strong);
  }

  .hx-table__footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  /* No note and no pager (the pager nav stays in the markup, hidden until hx.js pages): no empty band under the rows. */
  .hx-table__footer:empty,
  .hx-table__footer:not(:has(> :not([hidden]))) {
    display: none;
  }

  /* ---------- Filter bar + chips ---------- */

  .hx-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3) var(--space-4);
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .hx-filter-bar--top {
    align-items: flex-start;
  }

  .hx-filter-bar > .hx-field {
    min-width: min(100%, 12rem);
  }

  .hx-filter-bar__search {
    flex: 1 1 18rem;
    max-width: 28rem;
  }

  .hx-filter-bar__chips {
    display: flex;
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .hx-filter-bar__chips:empty {
    display: none;
  }

  .hx-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    height: var(--control-height-sm);
    padding: 0 var(--space-2-5);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: var(--size-small);
    white-space: nowrap;
    color: var(--text-muted);
  }

  .hx-content a.hx-chip {
    text-decoration: none;
  }

  .hx-chip--add {
    border-style: dashed;
    border-color: var(--border-stronger);
    background: transparent;
    font-weight: inherit;
    cursor: pointer;
  }

  .hx-chip--add:hover:not(:disabled) {
    border-color: var(--text-subtle);
    background: transparent;
    color: var(--text);
  }

  .hx-chip__remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--space-4-5);
    height: var(--space-4-5);
    min-height: 0;
    margin-right: calc(var(--space-1) * -1);
    padding: 0;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-subtle);
    text-decoration: none;
  }

  .hx-chip__remove:hover:not(:disabled) {
    background: var(--surface-hover);
    color: var(--text);
  }

  /* ---------- Pager ---------- */

  .hx-pager {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  /* ---------- Empty state ---------- */

  .hx-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-12) var(--space-6);
    text-align: center;
    color: var(--text-muted);
  }

  .hx-empty--compact {
    padding: var(--space-6) var(--space-4);
  }

  .hx-empty__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--size-rail-item);
    height: var(--size-rail-item);
    margin-bottom: var(--space-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    color: var(--text-subtle);
  }

  .hx-empty__title {
    margin: 0;
    font-family: var(--font-display);
    font-size: var(--size-h3);
    font-weight: 700;
    color: var(--text);
  }

  .hx-empty__text {
    max-width: var(--max-prose);
    margin: 0;
    font-size: var(--size-control);
    color: var(--text-subtle);
  }

  .hx-empty__actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-3);
  }

  /* ---------- Badge + status ---------- */

  /* Status menu (statusMenu): current badge as toggle, other values as POST buttons. */
  .hx-status-menu {
    position: relative;
    display: inline-flex;
    align-items: center;
  }

  .hx-status-menu__toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1-5);
    min-height: var(--control-height-sm);
    padding: 0 var(--space-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: var(--size-small);
    color: var(--text-muted);
    list-style: none;
    cursor: pointer;
  }

  .hx-status-menu__toggle::-webkit-details-marker { display: none; }
  .hx-status-menu__toggle:focus-visible { outline: 2px solid var(--focus-color); outline-offset: 2px; }
  .hx-status-menu__empty { font-size: var(--size-small); color: var(--text-subtle); }

  .hx-status-menu__list {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: var(--z-menu);
    display: grid;
    min-width: var(--width-menu);
    gap: var(--space-1);
    margin: var(--space-1) 0 0;
    padding: var(--space-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-md);
  }

  .hx-status-menu__item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-height: var(--control-height-sm);
    padding: 0 var(--space-2);
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    font: inherit;
    font-size: var(--size-small);
    color: var(--text);
    text-align: left;
    cursor: pointer;
  }

  .hx-status-menu__item:hover,
  .hx-status-menu__item:focus-visible { background: var(--surface-sunken); }
  .hx-status-menu__item[aria-current="true"] { background: var(--surface-sunken); }
  .hx-status-menu__item--clear { color: var(--text-muted); border-top: 1px solid var(--border); border-radius: 0; }

  .hx-table [data-cell="select"] { width: 1%; text-align: center; }

  .hx-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1-5);
    padding: var(--space-0-5) 9px;
    border: 1px solid currentColor;
    border-radius: var(--radius-sm);
    font-size: var(--size-small);
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
  }

  .hx-badge__dot {
    width: var(--size-dot);
    height: var(--size-dot);
    border-radius: 50%;
    background: currentColor;
  }

  .hx-badge--neutral { color: var(--neutral); }
  .hx-badge--info { color: var(--info); }
  .hx-badge--success { color: var(--success); }
  .hx-badge--accent { color: var(--highlight-text); }
  .hx-badge--warning { color: var(--warning); }
  .hx-badge--danger { color: var(--danger); }
  .hx-badge--purple { color: var(--purple); }

  .hx-badge--solid {
    border-color: transparent;
    font-family: var(--font-mono);
    font-weight: 700;
  }

  /* Solid = filled with the tone, text always dark (--on-tone, HexaMain: never white on a status fill). */
  .hx-badge--solid.hx-badge--neutral { background: var(--neutral-fill); color: var(--on-tone); }
  .hx-badge--solid.hx-badge--info { background: var(--info-fill); color: var(--on-tone); }
  .hx-badge--solid.hx-badge--success { background: var(--success-fill); color: var(--on-tone); }
  .hx-badge--solid.hx-badge--warning { background: var(--warning-fill); color: var(--on-tone); }
  .hx-badge--solid.hx-badge--danger { background: var(--danger-fill); color: var(--on-tone); }
  .hx-badge--solid.hx-badge--purple { background: var(--info-fill); color: var(--on-tone); }
  .hx-badge--solid.hx-badge--accent { background: var(--highlight); color: var(--on-highlight); }

  /* ---------- KPI ---------- */

  .hx-kpi {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .hx-kpi__label {
    font-size: var(--size-small);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--text-subtle);
  }

  .hx-kpi__row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-3-5);
  }

  .hx-kpi__value {
    font-family: var(--font-display);
    font-size: var(--size-kpi-fluid);
    font-weight: 800;
    line-height: 1;
    letter-spacing: var(--tracking-kpi);
    font-variant-numeric: tabular-nums;
    color: var(--text);
  }

  .hx-kpi--md .hx-kpi__value {
    font-size: var(--size-kpi-md);
    letter-spacing: var(--tracking-kpi-md);
  }

  .hx-kpi__fraction {
    color: var(--text-subtle);
  }

  .hx-kpi__delta {
    padding: var(--size-bar) var(--space-2);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: var(--size-mono);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
  }

  .hx-kpi__delta--positive { background: var(--success-bg); color: var(--success); }
  .hx-kpi__delta--negative { background: var(--danger-bg); color: var(--danger); }
  .hx-kpi__delta--neutral { background: var(--neutral-bg); color: var(--text-muted); }

  .hx-kpi__note {
    margin: 0;
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-kpi__link {
    justify-self: start;
    font-size: var(--size-small);
  }

  .hx-kpi-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5) var(--space-10);
    margin: 0;
  }

  .hx-kpi-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(var(--min-kpi-tile), 100%), 1fr));
    gap: var(--space-5);
    margin: 0;
  }

  /* ---------- Num, totals, meta list ---------- */

  .hx-num--negative,
  .hx-num[data-negative] {
    color: var(--danger);
  }

  .hx-num--mono {
    font-family: var(--font-mono);
    font-size: var(--size-mono);
    font-variant-numeric: tabular-nums;
  }

  .hx-totals {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-2) var(--space-4);
    margin: 0;
  }

  .hx-totals dd {
    margin: 0;
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

  .hx-totals > :nth-last-child(-n + 2) {
    padding-top: var(--space-2);
    border-top: 1px solid var(--border);
    font-weight: 600;
    color: var(--text-strong);
  }

  .hx-totals > dd[data-negative] {
    color: var(--danger);
  }

  .hx-meta-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--min-meta), 1fr));
    gap: var(--space-4) var(--space-6);
    margin: 0;
  }

  .hx-meta-list dt {
    font-size: var(--size-label);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--text-subtle);
  }

  .hx-meta-list dd {
    margin: var(--space-1) 0 0;
    overflow-wrap: anywhere;
    color: var(--text-strong);
  }

  /* ---------- Task list ---------- */

  .hx-task-list {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .hx-task-list > li > * {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text);
  }

  .hx-content .hx-task-list > li > a {
    text-decoration: none;
  }

  .hx-task-list > li > a:hover {
    color: var(--text-strong);
  }

  .hx-task-list > li:last-child > * {
    border-bottom: 0;
  }

  .hx-task-list__text {
    min-width: 0;
    flex: 1;
  }

  .hx-task-list__meta {
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-task-mark {
    display: inline-grid;
    flex: none;
    width: var(--control-height);
    height: var(--control-height);
    place-items: center;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-task-mark--danger {
    border-color: var(--danger);
    background: var(--danger-bg);
    color: var(--danger);
  }

  .hx-mono {
    font-family: var(--font-mono);
    font-size: var(--size-mono);
    font-variant-numeric: tabular-nums;
  }

  /* ---------- Doc chain ---------- */

  .hx-chain {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--size-control);
  }

  .hx-chain__arrow {
    padding: var(--space-4-5) var(--space-4) 0 0;
    color: var(--border-stronger);
  }

  .hx-chain__step {
    display: flex;
    flex-direction: column;
    gap: var(--size-bar);
    padding: var(--space-2-5) var(--space-5-5) var(--space-3-5) 0;
    color: var(--text-subtle);
  }

  .hx-chain__step--current {
    padding-bottom: var(--space-3);
    border-bottom: 2px solid var(--accent);
  }

  .hx-chain__link {
    display: flex;
    flex-direction: column;
    gap: var(--size-bar);
    color: inherit;
  }

  .hx-content .hx-chain__link {
    text-decoration: none;
  }

  .hx-chain__label {
    font-size: var(--size-label);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
  }

  .hx-chain__step--current .hx-chain__label {
    color: var(--accent-text);
  }

  .hx-chain__number {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
  }

  .hx-chain__link:hover .hx-chain__number {
    color: var(--text);
  }

  .hx-chain__step--pending .hx-chain__number {
    color: var(--text-subtle);
  }

  .hx-chain__step--current .hx-chain__number {
    color: var(--text-strong);
  }

  /* ---------- T-account ---------- */

  .hx-taccount {
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface);
  }

  .hx-taccount__header {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2-5) var(--space-3-5);
    border-bottom: 1px solid var(--border-strong);
    font-size: var(--size-control);
  }

  .hx-taccount__number {
    font-family: var(--font-mono);
    font-weight: 600;
  }

  .hx-taccount__name {
    text-align: right;
    color: var(--text-subtle);
  }

  .hx-taccount__sides {
    display: grid;
    grid-template-columns: 1fr 1fr;
    font-family: var(--font-mono);
    font-size: var(--size-mono);
    font-variant-numeric: tabular-nums;
  }

  .hx-taccount__side {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-0-5) var(--space-1-5);
    padding: var(--space-3) var(--space-3-5);
    color: var(--border-stronger);
  }

  .hx-taccount__side--debit {
    border-right: 1px solid var(--border-strong);
  }

  .hx-taccount__side--debit.hx-taccount__side--filled { color: var(--info); }
  .hx-taccount__side--credit.hx-taccount__side--filled { color: var(--warning); }

  .hx-taccount__amount + .hx-taccount__amount {
    flex-basis: 100%;
    padding-left: 1.2ch;
  }

  /* ---------- Alert, confirm, live region ---------- */

  .hx-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin: 0;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text);
    font-size: var(--size-control);
    line-height: 1.45;
  }

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

  /* Status message (HexaMain): tinted ground + 1px border + icon in the status colour, text in --text. The icon is
     a CSS mask (no markup needed, so JS-built alerts get it too); --hx-alert-tone colours border, icon and links. */
  .hx-alert--info { --hx-alert-tone: var(--info); --hx-alert-icon: var(--icon-info); background: var(--info-bg); }
  .hx-alert--warning { --hx-alert-tone: var(--warning); --hx-alert-icon: var(--icon-warning); background: var(--warning-bg); }
  .hx-alert--danger { --hx-alert-tone: var(--danger); --hx-alert-icon: var(--icon-danger); background: var(--danger-bg); }
  .hx-alert--success { --hx-alert-tone: var(--success); --hx-alert-icon: var(--icon-success); background: var(--success-bg); }
  .hx-alert--neutral,
  .hx-alert--purple { --hx-alert-tone: var(--neutral); --hx-alert-icon: var(--icon-info); background: var(--neutral-bg); }
  .hx-alert--accent { --hx-alert-tone: var(--highlight); --hx-alert-icon: var(--icon-star); background: var(--highlight-bg); }
  :is(.hx-alert--info, .hx-alert--warning, .hx-alert--danger, .hx-alert--success, .hx-alert--neutral, .hx-alert--purple, .hx-alert--accent) {
    position: relative;
    padding-left: calc(var(--space-4) + var(--size-icon) + var(--space-2-5));
    border-color: var(--hx-alert-tone);
    color: var(--text);
  }
  :is(.hx-alert--info, .hx-alert--warning, .hx-alert--danger, .hx-alert--success, .hx-alert--neutral, .hx-alert--purple, .hx-alert--accent)::before {
    content: '';
    position: absolute;
    top: calc(var(--space-3) + var(--space-0-5));
    left: var(--space-4);
    width: var(--size-icon);
    height: var(--size-icon);
    background: var(--hx-alert-tone);
    -webkit-mask: var(--hx-alert-icon) center / contain no-repeat;
    mask: var(--hx-alert-icon) center / contain no-repeat;
  }
  ul:is(.hx-alert--info, .hx-alert--warning, .hx-alert--danger, .hx-alert--success) { list-style-position: inside; }

  .hx-alert--column {
    flex-direction: column;
    align-items: stretch;
  }

  .hx-alert a {
    color: inherit;
  }

  .hx-confirm p {
    margin: 0;
  }

  .hx-confirm__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .hx-live-region:empty {
    position: absolute;
  }

  /* ---------- Dialog ---------- */

  .hx-dialog {
    width: 100%;
    max-width: var(--width-dialog-md);
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
  }

  .hx-dialog--sm { max-width: var(--width-dialog-sm); }
  .hx-dialog--lg { max-width: var(--width-dialog-lg); }

  .hx-dialog::backdrop {
    background: var(--scrim);
  }

  .hx-dialog__header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
  }

  .hx-dialog__title {
    flex: 1;
    margin: 0;
    font-family: var(--font-display);
    font-size: var(--size-h2);
    font-weight: 700;
  }

  .hx-dialog__body {
    padding: var(--space-5);
  }

  .hx-dialog__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
  }

  /* ---------- Small text blocks ---------- */

  .hx-wordmark {
    margin: 0;
    font: var(--text-display);
    letter-spacing: var(--tracking-display);
    color: var(--text-strong);
  }

  .hx-wordmark__sub {
    display: block;
    margin-top: var(--space-1);
    font-family: var(--font-sans);
    font-size: var(--size-label);
    font-weight: 500;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--text-subtle);
  }

  .hx-cell-note {
    display: block;
    padding-top: var(--space-1);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-secret {
    font-family: var(--font-mono);
    font-size: var(--size-mono);
    overflow-wrap: anywhere;
    user-select: all;
  }

  .hx-text {
    margin: 0;
    max-width: 72ch;
    overflow-wrap: anywhere;
  }

  .hx-text--pre {
    white-space: pre-line;
  }

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

  .hx-muted {
    color: var(--text-subtle);
  }

  /* ---------- Chart (ECharts host) ---------- */

  .hx-chart__canvas {
    width: 100%;
    height: var(--height-chart);
  }

  /* ---------- Kanban ---------- */

  .hx-kanban {
    display: grid;
    grid-auto-columns: minmax(14rem, 1fr);
    grid-auto-flow: column;
    gap: var(--space-4);
    overflow-x: auto;
  }

  .hx-kanban__lane {
    display: grid;
    align-content: start;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
  }

  .hx-kanban__title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 var(--space-1);
    font-size: var(--size-label);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--text-subtle);
  }

  .hx-kanban__card {
    display: grid;
    gap: var(--space-1);
    padding: var(--space-2-5) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }

  .hx-kanban-board {
    display: grid;
    gap: var(--space-2);
    min-width: 0;
  }

  .hx-kanban-board > .hx-kanban {
    min-width: 0;
  }

  .hx-kanban__meta {
    margin: 0;
    font-family: var(--font-mono);
    font-size: var(--size-label);
    color: var(--text-subtle);
  }

  .hx-kanban--movable .hx-kanban__card[draggable="true"] {
    cursor: grab;
  }

  .hx-kanban--movable .hx-kanban__card:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
  }

  .hx-kanban__card.is-dragging {
    opacity: 0.5;
  }

  .hx-kanban__lane.is-drop-target {
    border-color: var(--focus-color);
    background: var(--surface);
  }

  .hx-kanban__hint {
    margin: 0;
    font-size: var(--size-label);
  }

  /* ---------- Timeline (CRM / mail history, calendar agenda) ---------- */

  .hx-timeline {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .hx-timeline__item {
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr);
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-subtle);
  }

  .hx-timeline__item:last-child {
    border-bottom: 0;
  }

  .hx-timeline__item--today .hx-timeline__when {
    color: var(--accent-text);
    font-weight: 600;
  }

  .hx-timeline__when {
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-timeline__body {
    display: grid;
    gap: var(--space-0-5);
  }

  .hx-timeline__meta {
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-timeline__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .hx-timeline__actions {
    gap: var(--space-1-5);
  }

  /* ---------- Grid (GridStack host of AI views) ---------- */

  .hx-grid {
    min-height: var(--space-8);
    margin: 0 calc(-1 * var(--space-1-5));
  }

  .hx-grid[data-static='true'] .hx-grid__head {
    cursor: default;
  }

  .hx-grid .grid-stack-placeholder > .placeholder-content {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-xl);
    background: var(--surface-hover);
  }

  .hx-grid .grid-stack-item-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
  }

  .hx-grid__head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    cursor: move;
  }

  .hx-grid__title {
    flex: 1;
    margin: 0;
    font-family: var(--font-display);
    font-size: var(--size-h3);
    font-weight: 700;
  }

  .hx-grid__body {
    flex: 1;
    overflow: auto;
    padding: var(--space-4);
  }

  .hx-grid__body > .hx-table {
    border: 0;
    border-radius: 0;
  }

  /* ---------- Lazy region (HTMX loaded section) ---------- */

  .hx-lazy[aria-busy='true'] {
    color: var(--text-subtle);
    font-size: var(--size-small);
  }

  /* ---------- Swatches (style guide) ---------- */

  .hx-swatches {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: var(--space-3);
  }

  .hx-swatch {
    display: grid;
    gap: var(--space-1);
    font-size: var(--size-small);
  }

  .hx-swatch__chip {
    height: var(--space-10);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
  }

  .hx-swatch__chip[data-token='--bg'] { background: var(--bg); }
  .hx-swatch__chip[data-token='--surface'] { background: var(--surface); }
  .hx-swatch__chip[data-token='--surface-2'] { background: var(--surface-2); }
  .hx-swatch__chip[data-token='--surface-hover'] { background: var(--surface-hover); }
  .hx-swatch__chip[data-token='--border'] { background: var(--border); }
  .hx-swatch__chip[data-token='--border-strong'] { background: var(--border-strong); }
  .hx-swatch__chip[data-token='--text'] { background: var(--text); }
  .hx-swatch__chip[data-token='--text-muted'] { background: var(--text-muted); }
  .hx-swatch__chip[data-token='--text-subtle'] { background: var(--text-subtle); }
  .hx-swatch__chip[data-token='--accent'] { background: var(--accent); }
  .hx-swatch__chip[data-token='--accent-text'] { background: var(--accent-text); }
  .hx-swatch__chip[data-token='--info'] { background: var(--info); }
  .hx-swatch__chip[data-token='--info-bg'] { background: var(--info-bg); }
  .hx-swatch__chip[data-token='--success'] { background: var(--success); }
  .hx-swatch__chip[data-token='--success-bg'] { background: var(--success-bg); }
  .hx-swatch__chip[data-token='--warning'] { background: var(--warning); }
  .hx-swatch__chip[data-token='--warning-bg'] { background: var(--warning-bg); }
  .hx-swatch__chip[data-token='--danger'] { background: var(--danger); }
  .hx-swatch__chip[data-token='--danger-bg'] { background: var(--danger-bg); }
  .hx-swatch__chip[data-token='--purple'] { background: var(--purple); }
  .hx-swatch__chip[data-token='--purple-bg'] { background: var(--purple-bg); }
  .hx-swatch__chip[data-token='--highlight'] { background: var(--highlight); }
  .hx-swatch__chip[data-token='--highlight-bg'] { background: var(--highlight-bg); }
  .hx-swatch__chip[data-token='--chart-1'] { background: var(--chart-1); }
  .hx-swatch__chip[data-token='--chart-2'] { background: var(--chart-2); }
  .hx-swatch__chip[data-token='--chart-3'] { background: var(--chart-3); }
  .hx-swatch__chip[data-token='--chart-4'] { background: var(--chart-4); }
  .hx-swatch__chip[data-token='--chart-5'] { background: var(--chart-5); }
  .hx-swatch__chip[data-token='--chart-6'] { background: var(--chart-6); }
  .hx-swatch__chip[data-token='--neutral'] { background: var(--neutral); }
  .hx-swatch__chip[data-token='--neutral-bg'] { background: var(--neutral-bg); }

  .hx-theme-pair {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 30rem), 1fr));
    gap: var(--space-5);
  }

  .hx-theme-pair > [data-theme] {
    padding: var(--space-5);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
  }

  /* ---------- Planning board (M5 A2) ---------- */

  .hx-board {
    display: grid;
    gap: var(--space-3);
    min-width: 0;
  }

  .hx-board__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
  }

  .hx-board__title {
    margin: 0 auto 0 0;
    font-family: var(--font-display);
    font-size: var(--size-h2);
    font-weight: 700;
  }

  .hx-board__nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .hx-board__scroll {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
  }

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

  .hx-board__table {
    width: 100%;
    min-width: 56rem;
    margin: 0;
    border: 0;
    border-collapse: collapse;
    table-layout: fixed;
    background: transparent;
  }

  .hx-board__table th,
  .hx-board__table td {
    padding: var(--space-2-5) var(--space-3);
    border-right: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: top;
    text-align: left;
  }

  .hx-board__table thead th {
    font-size: var(--size-label);
    font-weight: 500;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--text-subtle);
  }

  .hx-board__table tr > :last-child {
    border-right: 0;
  }

  .hx-board__table tbody > tr:last-child > * {
    border-bottom: 0;
  }

  .hx-board__resource {
    width: 10rem;
    font-weight: 600;
    color: var(--text-strong);
  }

  .hx-board__table tbody th.hx-board__resource {
    display: table-cell;
  }

  .hx-board__day--today {
    background: var(--surface-2);
  }

  .hx-board__table thead .hx-board__day--today {
    color: var(--accent-text);
  }

  .hx-board__entries {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .hx-board__entry {
    display: grid;
    gap: var(--space-0-5);
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }

  .hx-board__time {
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-board__link {
    font-weight: 600;
    overflow-wrap: anywhere;
  }

  .hx-board__meta {
    display: block;
    font-size: var(--size-small);
    font-weight: 400;
    color: var(--text-subtle);
    overflow-wrap: anywhere;
  }

  /* ---------- Resource timeline (Gantt, block resourceTimeline) ---------- */

  .hx-timeline__table td.hx-timeline__cell {
    padding: var(--space-1-5) var(--space-1);
    vertical-align: middle;
  }

  .hx-timeline__table tbody th.hx-board__resource {
    width: 12rem;
    text-transform: none;
    letter-spacing: normal;
    white-space: normal;
    font-size: var(--size-body);
  }

  .hx-timeline__table tbody th .hx-board__meta {
    overflow-wrap: anywhere;
  }

  .hx-timeline__table thead th.hx-timeline__day {
    padding-inline: var(--space-1);
    text-align: center;
  }

  .hx-timeline--dense .hx-timeline__table {
    min-width: 90rem;
  }

  .hx-timeline--dense .hx-timeline__table thead th.hx-timeline__day {
    font-size: var(--size-small);
    letter-spacing: 0;
  }

  .hx-timeline__bar {
    display: grid;
    gap: var(--space-0-5);
    min-width: 0;
    padding: var(--space-1) var(--space-2);
    border: 1px solid currentColor;
    border-radius: var(--radius-md);
    overflow: hidden;
  }

  .hx-timeline__label {
    font-weight: 600;
    font-size: var(--size-small);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
  }

  .hx-timeline__meta {
    font-size: var(--size-small);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-subtle);
  }

  .hx-timeline__bar--info { color: var(--info); background: var(--info-bg); }
  .hx-timeline__bar--success { color: var(--success); background: var(--success-bg); }
  .hx-timeline__bar--warning { color: var(--warning); background: var(--warning-bg); }
  .hx-timeline__bar--danger { color: var(--danger); background: var(--danger-bg); }
  .hx-timeline__bar--purple { color: var(--purple); background: var(--purple-bg); }
  .hx-timeline__bar--neutral { color: var(--neutral); background: var(--neutral-bg); }

  .hx-timeline__bar--buffer {
    border-style: dashed;
    background-image: repeating-linear-gradient(135deg, transparent 0 0.35rem, var(--border-subtle) 0.35rem 0.5rem);
  }

  .hx-timeline__legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-timeline__legend li {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1-5);
  }

  .hx-timeline__swatch {
    display: inline-block;
    width: 1.5rem;
    height: 0.85rem;
    border: 1px solid currentColor;
    border-radius: var(--radius-sm);
  }

  /* ---------- Line table + extra fields (M5 A2) ---------- */

  .hx-lines,
  .hx-extra {
    display: grid;
    gap: var(--space-2);
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .hx-lines__table td {
    padding: var(--space-1-5) var(--space-1);
    vertical-align: top;
  }

  /* Headers may wrap („Preis € je Periode“), so a label never widens a narrow number column; text starts where the
     text of the field below starts. */
  .hx-lines__table th {
    padding: var(--space-2-5) var(--space-1) var(--space-2-5) calc(var(--space-1) + var(--space-2) + 1px);
    vertical-align: bottom;
    white-space: normal;
  }

  .hx-lines__table th[data-cell='num'] {
    padding-inline: var(--space-1) calc(var(--space-1) + var(--space-2) + 1px);
  }

  .hx-lines__table th:is(.hx-lines__pos, .hx-lines__del, [data-col='checkbox']) {
    padding-inline: var(--space-2);
  }

  /* Dense fields: less inner padding than in a form, so eleven columns still fit a wide panel. */
  .hx-lines__table .hx-control {
    width: 100%;
    min-width: 6rem;
    padding-inline: var(--space-2);
  }

  .hx-lines__table select.hx-control { padding-right: var(--space-7); }

  /*
   * Column widths (data-col = type, data-w = HxLineColumn.width): numbers, dates, selections, checkboxes, computed values
   * and columns with a small width (xs 4rem · sm 6rem · md 9rem, e.g. an article number) take just what their field needs
   * (width 1% = shrink to the field); text, mono text, static and pick columns share the rest of the row, lg (12rem) and
   * xl (16rem) set their least width. A date or selection is as wide as its value or longest option, a number field 6rem.
   * The table scrolls sideways only when even the least widths do not fit.
   */
  .hx-lines__table :is(th, td):is([data-col='number'], [data-col='date'], [data-col='select'], [data-col='checkbox'], [data-col='computed'], [data-w='xs'], [data-w='sm'], [data-w='md']),
  .hx-lines__table .hx-lines__pos {
    width: 1%;
  }

  .hx-lines__table [data-col='number'] .hx-control { min-width: 6rem; text-align: right; }
  .hx-lines__table :is([data-col='date'], [data-col='select']) .hx-control { width: auto; min-width: 100%; }
  .hx-lines__table [data-w='xs'] .hx-control { min-width: 4rem; }
  .hx-lines__table [data-w='sm'] .hx-control { min-width: 6rem; }
  .hx-lines__table [data-w='md'] .hx-control { min-width: 9rem; }
  .hx-lines__table [data-w='lg'] .hx-control { min-width: 12rem; }
  .hx-lines__table [data-w='xl'] .hx-control { min-width: 16rem; }
  .hx-lines__table :is(th, td)[data-col='checkbox'] { text-align: center; }
  /* Position number and checkbox sit on the text line of the fields beside them. */
  .hx-lines__table td:is(.hx-lines__pos, [data-col='checkbox']) { padding-top: calc(var(--space-1-5) + 10px); }
  .hx-lines__table td[data-col='static'] { padding-top: calc(var(--space-1-5) + 10px); }

  /* A pick cell (lineTable type pick): search field, hits below in the flow, small source hint. */
  .hx-lines__table .hx-pick--cell { gap: var(--space-1); min-width: 16rem; }
  .hx-lines__hint { font: var(--text-small); color: var(--text-subtle); }
  .hx-lines__hint:empty { display: none; }

  .hx-lines__pos {
    width: 3rem;
    font-family: var(--font-mono);
    color: var(--text-subtle);
  }

  /*
   * The delete column, the line amount and the label of the total stay visible while a wide line table scrolls
   * sideways (otherwise the total row is an empty band under the rows).
   */
  .hx-lines__table .hx-lines__del { width: 2.5rem; min-width: 2.5rem; padding-inline: 0; text-align: center; position: sticky; right: 0; background: var(--surface); }
  .hx-lines__table td.hx-lines__del { padding-top: var(--space-2); }
  .hx-lines__table td.hx-lines__amount { padding-top: calc(var(--space-1-5) + 10px); }
  .hx-lines__table .hx-lines__amount { width: 7rem; min-width: 7rem; position: sticky; right: 0; background: var(--surface); text-align: right; white-space: nowrap; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
  .hx-lines__table:has(.hx-lines__del) .hx-lines__amount { right: 2.5rem; }
  .hx-lines__table th.hx-lines__amount { white-space: normal; font-family: inherit; padding-right: var(--space-1); }
  .hx-lines__total-text { display: inline-block; position: sticky; right: calc(7rem + var(--space-2)); }
  .hx-lines__table:has(.hx-lines__del) .hx-lines__total-text { right: calc(9.5rem + var(--space-2)); }
  .hx-lines__table td.hx-lines__pos { padding-inline: var(--space-2); }
  /* Computed cell (column type computed): plain text aligned with the inputs of the row. */
  .hx-lines__computed { display: inline-block; padding-top: 10px; white-space: nowrap; color: var(--text); }
  .hx-lines__computed--mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
  .hx-lines__table tfoot th,
  .hx-lines__table tfoot td { border-top: 1px solid var(--border); font-weight: 600; color: var(--text-strong); }
  .hx-lines__table tfoot td.hx-lines__amount { padding: var(--space-3) var(--space-1); }
  .hx-lines__table .hx-lines__total-label { text-align: right; }

  .hx-lines__del-btn {
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: var(--size-h3);
    line-height: 1;
    padding: var(--space-1) var(--space-1-5);
    cursor: pointer;
    border-radius: var(--radius-xs);
  }

  .hx-lines__del-btn:hover { color: var(--danger); background: var(--danger-bg); }
  .hx-lines__del-btn:focus-visible { outline: 2px solid var(--focus-color); outline-offset: 1px; }
  /* M5 S: Tabellen-Bearbeitung (sheet) – dichte Zellen, geänderte Zellen markiert. */
  .hx-lines--sheet .hx-lines__table td { padding: 2px var(--space-1); }
  .hx-lines--sheet .hx-lines__table .hx-control { min-width: 7rem; }
  .hx-lines--sheet .hx-lines__table td[data-changed] { background: var(--warning-bg); }
  .hx-lines--sheet .hx-lines__table td[data-changed] .hx-control { border-color: var(--warning); }

  .hx-extra__multi {
    gap: var(--space-1-5);
    margin: 0;
    padding: 0;
    border: 0;
  }

  /* ---------- Narrow screens ---------- */

  @media (max-width: 64rem) {
    .hx-detail-grid {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  @media (max-width: 45rem) {
    .hx-timeline__item {
      grid-template-columns: minmax(0, 1fr);
      gap: var(--space-1);
    }
  }

  /* fieldset (M5 A3): a titled section inside a form, spanning the whole form grid. */
  .hx-fieldset {
    display: grid;
    gap: var(--space-3);
    min-width: 0;
    margin: 0;
    padding: var(--space-4) 0 0;
    border: 0;
    border-top: 1px solid var(--border-subtle);
  }

  .hx-fieldset__legend {
    float: left;
    width: 100%;
    padding: 0 0 var(--space-1);
    font-family: var(--font-display);
    font-size: var(--size-h3);
    font-weight: 600;
    color: var(--text-strong);
  }

  .hx-fieldset__help {
    margin: 0;
    font-size: var(--size-body);
    color: var(--text-muted);
  }

  .hx-fieldset > .hx-form-grid__fields {
    clear: both;
  }

  /* fieldset.compact: sub-section without rule; showWhen hides it via [hidden]. */
  .hx-fieldset--compact {
    padding-top: 0;
    border-top: 0;
  }

  .hx-fieldset--compact > .hx-fieldset__legend {
    font-size: var(--size-body);
  }

  .hx-fieldset[hidden] {
    display: none;
  }

  /* image (M5 A3): article pictures and other images with caption. */
  .hx-image {
    display: grid;
    gap: var(--space-1-5);
    justify-items: start;
    margin: 0;
  }

  .hx-image img {
    display: block;
    max-width: 100%;
    height: auto;
    object-fit: contain;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-2);
  }

  .hx-image--sm img {
    max-width: calc(var(--space-12) * 2.5);
    max-height: calc(var(--space-12) * 2.5);
  }

  .hx-image--md img {
    max-width: calc(var(--space-12) * 6);
    max-height: calc(var(--space-12) * 6);
  }

  .hx-image__caption {
    font-size: var(--size-body);
    color: var(--text-muted);
  }

  /* textarea richText (M5 A3): the small HTML editor of html-editor.js in the hx look. */
  .hx-rich-text__toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    padding-bottom: var(--space-1-5);
  }

  .hx-rich-text__box {
    min-height: calc(var(--control-height) * 4);
    height: auto;
    padding: var(--space-2) var(--space-3);
    overflow-wrap: anywhere;
  }
}

/* ---------- M5 A1: disclosure, lineEntry (quick entry), variantMatrix ---------- */
@layer components {
  .hx-disclosure {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface);
  }

  .hx-disclosure__summary {
    cursor: pointer;
    padding: var(--space-2) var(--space-3);
    font-size: var(--size-control);
    color: var(--text-muted);
  }

  .hx-disclosure[open] > .hx-disclosure__summary {
    border-bottom: 1px solid var(--border-subtle);
  }

  .hx-disclosure__body {
    padding: var(--space-3);
  }

  /* Quick entry: dense, spreadsheet-like grid for keyboard entry (line-entry.js). */
  .hx-line-entry {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-width: 0;
  }

  .hx-line-entry kbd {
    font-family: var(--font-mono);
    font-size: var(--size-label);
    padding: 0 var(--space-1);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: var(--radius-xs);
    background: var(--surface-2);
    color: var(--text);
  }

  .hx-line-entry__keys {
    margin: 0;
    font-size: var(--size-small);
    color: var(--text-muted);
    line-height: 1.9;
  }

  .hx-line-entry__form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    min-width: 0;
  }

  /*
    Header: column count follows the header's own width (container query), so the party and its addresses get room
    for their values: 1 column (phone), 2, 4 (party + billing address in row 1), 6 (party, billing, shipping address
    in row 1, each two tracks wide). position/z-index: the container is a stacking context, the party hits must stay
    above the line grid that follows.
  */
  .hx-line-entry__wrap-header {
    container-type: inline-size;
    position: relative;
    z-index: 2;
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
  }

  .hx-line-entry__header {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3) var(--space-4);
    align-items: end;
  }

  @container (min-width: 34rem) {
    .hx-line-entry__header { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hx-line-entry__party { grid-column: span 2; }
  }

  @container (min-width: 52rem) {
    .hx-line-entry__header { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .hx-line-entry__party-fields > .hx-field:nth-child(-n + 3 of .hx-field),
    .hx-line-entry__header > .hx-field:has(> .hx-check) { grid-column: span 2; }
  }

  @container (min-width: 80rem) {
    .hx-line-entry__header { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .hx-line-entry__party-fields > .hx-field:nth-child(3 of .hx-field) { grid-column: span 1; }
  }

  .hx-line-entry__header > .hx-disclosure,
  .hx-line-entry__header > .hx-alert,
  .hx-line-entry__header > .hx-choice-group,
  .hx-line-entry__party-fields > .hx-alert {
    grid-column: 1 / -1;
  }

  .hx-line-entry__header .hx-control { text-overflow: ellipsis; }

  .hx-line-entry__party {
    position: relative;
  }

  .hx-line-entry__party-fields {
    display: contents;
  }

  .hx-line-entry__party-input {
    font-weight: 600;
  }

  .hx-line-entry__header .hx-field__messages:has(.hx-field__error:empty):not(:has(.hx-field__help)) {
    display: none;
  }

  .hx-line-entry__scroll {
    overflow-x: auto;
    min-width: 0;
  }

  /*
    Line grid: fixed column widths, only „Bezeichnung“ flexes. Wide screens use the full widths; below 1500px viewport a
    compact set keeps the grid scroll-free at 1280px; the table never gets narrower than its columns plus a usable
    description (then the wrapper scrolls horizontally). Header labels share the inset of the inputs below them.
  */
  .hx-line-entry__lines {
    --le-pos: 48px; --le-art: 220px; --le-qty: 110px; --le-price: 120px; --le-disc: 90px;
    --le-amount: 130px; --le-info: 140px; --le-del: 36px; --le-desc-min: 220px;
    --le-inset: calc(var(--space-1) + var(--space-2) + 1px);
    width: 100%;
    min-width: calc(var(--le-pos) + var(--le-art) + var(--le-qty) + var(--le-price) + var(--le-disc) + var(--le-amount) + var(--le-info) + var(--le-del) + var(--le-desc-min));
    border-collapse: collapse;
    table-layout: fixed;
  }

  @media (max-width: 1500px) {
    .hx-line-entry__lines {
      --le-pos: 44px; --le-art: 140px; --le-qty: 112px; --le-price: 100px; --le-disc: 86px;
      --le-amount: 104px; --le-info: 96px; --le-del: 32px; --le-desc-min: 136px;
    }
  }

  .hx-line-entry__lines th {
    text-align: left;
    font-size: var(--size-label);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: var(--space-2) var(--le-inset);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .hx-line-entry__lines th.c-pos,
  .hx-line-entry__lines th.c-info,
  .hx-line-entry__lines th.c-del {
    padding-inline: var(--space-1);
  }

  .hx-line-entry__lines td {
    padding: var(--space-0-5) var(--space-1);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: top;
  }

  .hx-line-entry__lines .c-pos { width: var(--le-pos); white-space: nowrap; }
  .hx-line-entry__lines .c-art { width: var(--le-art); position: relative; }
  .hx-line-entry__lines .c-qty { width: var(--le-qty); white-space: nowrap; }
  .hx-line-entry__lines .c-price { width: var(--le-price); }
  .hx-line-entry__lines .c-disc { width: var(--le-disc); }
  .hx-line-entry__lines .c-amount { width: var(--le-amount); text-align: right; }
  .hx-line-entry__lines .c-info { width: var(--le-info); font-size: var(--size-small); color: var(--text-muted); overflow-wrap: anywhere; }
  .hx-line-entry__lines td.c-info { padding-top: var(--space-2); }
  .hx-line-entry__lines .c-del { width: var(--le-del); text-align: center; padding-inline: 0; }
  .hx-line-entry__lines .c-type { width: 116px; }
  .hx-line-entry__lines .c-loc { width: 132px; }

  .hx-line-entry__lines .linetype,
  .hx-line-entry__lines .location {
    width: 100%;
    font: inherit;
    font-size: var(--size-small);
    color: var(--text);
    padding: var(--space-1-5) var(--space-1);
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xs);
  }

  .hx-line-entry__lines .location[hidden] { display: none; }

  .hx-line-entry__lines .linetype:focus,
  .hx-line-entry__lines .location:focus {
    border-color: var(--focus-color);
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-color) 25%, transparent);
  }

  .hx-line-entry__lines th.c-amount,
  .hx-line-entry__lines th.c-qty,
  .hx-line-entry__lines th.c-price,
  .hx-line-entry__lines th.c-disc {
    text-align: right;
  }

  /* Quantity: number right-aligned, unit in its own slot behind it (the header label sits above the number). */
  .hx-line-entry__lines th.c-qty { padding-right: calc(var(--le-inset) + 2rem); }

  .hx-line-entry__lines input.cell,
  .hx-line-entry__lines .lotinput {
    width: 100%;
    font: inherit;
    font-size: var(--size-body);
    color: var(--text);
    padding: var(--space-1-5) var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--radius-xs);
    background: transparent;
  }

  .hx-line-entry__lines .lotinput {
    border-color: var(--border-subtle);
    font-family: var(--font-mono);
    font-size: var(--size-small);
  }

  .hx-line-entry__lines input.cell:hover {
    border-color: var(--border);
  }

  .hx-line-entry__lines input.cell:focus,
  .hx-line-entry__lines .lotinput:focus {
    border-color: var(--focus-color);
    background: var(--surface);
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-color) 25%, transparent);
  }

  .hx-line-entry__lines input.num {
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

  .hx-line-entry__lines .c-art input.cell {
    font-family: var(--font-mono);
  }

  .hx-line-entry__lines .c-qty input { width: calc(100% - 2rem); vertical-align: middle; }
  .hx-line-entry__lines .unit {
    display: inline-block;
    width: 2rem;
    padding-left: var(--space-1);
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    font-size: var(--size-small);
    color: var(--text-muted);
  }

  .hx-line-entry__lines .amount {
    display: block;
    padding: var(--space-1-5) calc(var(--space-2) + 1px);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--text-strong);
  }

  .hx-line-entry__lines tr.line:focus-within > td {
    background: color-mix(in srgb, var(--accent) 7%, transparent);
  }

  /* Manually typed price/discount: marked so nobody mistakes it for the price determination. */
  .hx-line-entry__lines input.manual,
  .hx-line-entry__lines .origin.manual {
    color: var(--warning);
    font-weight: 600;
  }

  .hx-line-entry__lines .avail.short {
    color: var(--danger);
    font-weight: 600;
  }

  .hx-line-entry__lines .c-info span:empty { display: none; }
  .hx-line-entry__lines .c-info span:not(:empty) ~ span:not(:empty)::before { content: " · "; color: var(--text-subtle); }

  .hx-line-entry__lines .taxcat {
    display: none;
    width: 100%;
    margin-top: var(--space-1);
    font: inherit;
    font-size: var(--size-small);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
  }

  .hx-line-entry__lines tr.free-line .taxcat { display: block; }

  /* Text lines: only the description is used. */
  .hx-line-entry__lines tr.text-line .c-art input.cell,
  .hx-line-entry__lines tr.text-line .c-qty > *,
  .hx-line-entry__lines tr.text-line .c-price input,
  .hx-line-entry__lines tr.text-line .c-disc input {
    visibility: hidden;
  }

  .hx-line-entry__lines tr.text-line .c-desc input.cell { font-style: italic; }
  .hx-line-entry__lines tr.text-line .lotinput { visibility: hidden; }

  /* Line styles (Positionstypen): Zwischensumme, Gruppentitel, Seitenwechsel, Alternativposition. */
  .hx-line-entry__lines .style-badge:empty { display: none; }
  .hx-line-entry__lines .style-badge {
    display: inline-block;
    margin: 0 0 var(--space-1) var(--space-1);
    padding: 0 var(--space-1-5);
    font-size: var(--size-caption, 0.6875rem);
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--surface-sunken);
  }
  .hx-line-entry__lines tr.style-line .c-desc input.cell { font-style: normal; font-weight: 600; }
  .hx-line-entry__lines tr.style-group_title > td,
  .hx-line-entry__lines tr.style-group_title_subtotal > td { border-top: 2px solid var(--border-strong, var(--border)); }
  .hx-line-entry__lines tr.style-group_title .c-desc input.cell,
  .hx-line-entry__lines tr.style-group_title_subtotal .c-desc input.cell { color: var(--text-strong); }
  .hx-line-entry__lines tr.style-subtotal .amount,
  .hx-line-entry__lines tr.style-subtotal .c-desc input.cell { color: var(--text-strong); }
  .hx-line-entry__lines tr.style-page_break .c-desc input.cell { color: var(--text-muted); border-style: dashed; }
  .hx-line-entry__lines tr.alternative-line .style-badge { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 45%, var(--border)); }
  .hx-line-entry__lines tr.addon-line .style-badge { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
  .hx-line-entry__lines tr.addon-line .c-desc { padding-left: var(--space-2); }
  .hx-line-entry__lines .row-actions { margin-top: var(--space-1); }
  .hx-line-entry__lines tr.alternative-line .amount { color: var(--text-muted); font-style: italic; }
  .hx-line-entry__lines tr.alternative-line .amount:not(:empty)::before { content: "("; }
  .hx-line-entry__lines tr.alternative-line .amount:not(:empty)::after { content: ")"; }

  /* Set components (read-only) and line warnings under the description. */
  .hx-line-entry__lines ul.components,
  .hx-line-entry__lines ul.notes {
    list-style: none;
    margin: 0;
    padding: 0 0 0 var(--space-2);
    font-size: var(--size-small);
  }

  .hx-line-entry__lines ul.components li {
    color: var(--text-muted);
    padding-left: var(--space-3);
    border-left: 2px solid var(--border);
  }

  .hx-line-entry__lines ul.components .c-qty { float: right; }

  .hx-line-entry__lines .handle {
    cursor: grab;
    color: var(--text-subtle);
    padding: 0 var(--space-1);
    user-select: none;
  }

  .hx-line-entry__lines .no {
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-muted);
  }

  .hx-line-entry__lines tr.dragging { opacity: 0.4; }

  .hx-line-entry__lines .del {
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: var(--size-h3);
    line-height: 1;
    padding: var(--space-1);
    cursor: pointer;
    border-radius: var(--radius-xs);
  }

  .hx-line-entry__lines .del:hover { color: var(--danger); background: var(--danger-bg); }

  /* Warnings at line and header (levels info, warning, critical, error). */
  .hx-line-entry .note {
    padding: var(--space-0-5) var(--space-2);
    margin: var(--space-0-5) 0;
    border-left: 3px solid var(--border);
    font-size: var(--size-small);
    color: var(--text-muted);
  }

  .hx-line-entry .note.warning { border-color: var(--warning); background: var(--warning-bg); color: var(--warning); }

  .hx-line-entry .note.critical,
  .hx-line-entry .note.error { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }

  .hx-line-entry .calc-notes { list-style: none; padding: 0; margin: 0 0 var(--space-2); }

  /* Search hits (customer, supplier, article) under the input. */
  .hx-line-entry .results {
    position: absolute;
    z-index: 20;
    left: 0;
    top: 100%;
    min-width: min(34rem, 90vw);
    max-width: 90vw;
    margin-top: var(--space-1);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
  }

  /* Article hits in the grid: fixed to the viewport (placed by line-entry.js) so the scroll wrapper cannot clip them. */
  .hx-line-entry__lines .results {
    position: fixed;
    margin-top: 0;
    z-index: 40;
  }

  .hx-line-entry__hits {
    list-style: none;
    margin: 0;
    padding: var(--space-1) 0;
    max-height: 22rem;
    overflow-y: auto;
  }

  .hx-line-entry__hits li {
    display: flex;
    gap: var(--space-3);
    align-items: baseline;
    padding: var(--space-1-5) var(--space-3);
    font-size: var(--size-body);
    color: var(--text);
  }

  .hx-line-entry__hits li.option { cursor: pointer; }
  .hx-line-entry__hits li.option:hover { background: var(--surface-hover); }
  .hx-line-entry__hits li.active { background: var(--accent); color: var(--on-accent); }
  .hx-line-entry__hits li.active .o-meta { color: var(--on-accent); }
  .hx-line-entry__hits li.empty { color: var(--text-muted); }
  .hx-line-entry__hits li.new { border-top: 1px solid var(--border-subtle); font-weight: 600; }
  .hx-line-entry__hits li.blocked .o-name { text-decoration: line-through; }
  .hx-line-entry__hits .o-no { min-width: 6rem; font-family: var(--font-mono); font-size: var(--size-mono); }
  .hx-line-entry__hits .o-name { flex: 1; }
  .hx-line-entry__hits .o-price { min-width: 5rem; text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
  .hx-line-entry__hits .o-meta { color: var(--text-muted); font-size: var(--size-small); }

  /* Bottom: add buttons left, totals right; save row. */
  .hx-line-entry__bottom {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--space-4);
  }

  .hx-line-entry__add { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: flex-start; min-width: 0; }
  .hx-line-entry__calc { min-width: min(100%, 22rem); }

  .hx-line-entry__totals {
    border-collapse: collapse;
    margin-left: auto;
    font-variant-numeric: tabular-nums;
  }

  .hx-line-entry__totals th {
    text-align: left;
    font-weight: 500;
    color: var(--text-muted);
    padding: var(--space-1) var(--space-3) var(--space-1) 0;
  }

  .hx-line-entry__totals td { padding: var(--space-1) 0 var(--space-1) var(--space-4); font-family: var(--font-mono); }
  .hx-line-entry__totals .num { text-align: right; }
  .hx-line-entry__totals tr.total-net > * { border-top: 1px solid var(--border); }
  .hx-line-entry__totals tr.total-gross > * { font-weight: 700; color: var(--text-strong); font-size: var(--size-h3); border-top: 1px solid var(--border-strong); }

  .hx-line-entry__result .calc-hint { margin: 0; color: var(--text-muted); }

  .hx-line-entry__save {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-subtle);
  }

  .hx-line-entry__save kbd { margin-left: var(--space-1); background: transparent; border-color: currentColor; color: inherit; }

  .hx-line-entry__form.locked input.cell { color: var(--text); }

  /* Dialogs (Neuer Kunde, Mengenmatrix). */
  .hx-line-entry__dialog {
    width: min(40rem, 94vw);
    padding: var(--space-6);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
  }

  .hx-line-entry__dialog--wide { width: min(64rem, 96vw); }
  .hx-line-entry__dialog::backdrop { background: color-mix(in srgb, var(--text-strong) 35%, transparent); }
  .hx-line-entry__dialog--preview { width: min(44rem, 96vw); padding: var(--space-3); }

  /* Tools: preview toggle, „Preise aktualisieren“, signature. */
  .hx-line-entry__tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: calc(-1 * var(--space-2)); }
  .hx-line-entry__tools-end { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-left: auto; }
  .hx-line-entry__signed { font-size: var(--size-small); color: var(--text-muted); }
  #entry-preview-toggle[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

  /* Entry and live PDF preview side by side (wide screens); the preview sticks while the grid scrolls. */
  .hx-line-entry__main { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); align-items: start; }
  .hx-line-entry.preview-open .hx-line-entry__main { grid-template-columns: minmax(0, 1fr) minmax(20rem, 34%); }
  .hx-line-entry__preview {
    position: sticky;
    top: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    max-height: calc(100vh - 2 * var(--space-4));
    min-width: 0;
  }
  .hx-line-entry__preview-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
  .hx-line-entry__preview-nav { display: flex; align-items: center; gap: var(--space-1); }
  .hx-line-entry__preview-nav .preview-page-no { font-size: var(--size-small); color: var(--text-muted); min-width: 4.5rem; text-align: center; }
  .hx-line-entry__preview-body { overflow: auto; min-height: 12rem; }
  .hx-line-entry__preview-body.updating { opacity: 0.6; transition: opacity 120ms; }
  .hx-line-entry__preview-pages img.preview-page {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
  }
  .hx-line-entry__preview-pages img.preview-page[hidden] { display: none; }
  #preview-dialog .hx-line-entry__preview { position: static; border: 0; padding: 0; max-height: 86vh; }

  /* Reprice dialog: old → new per line. */
  .hx-line-entry__reprice { width: 100%; border-collapse: collapse; font-size: var(--size-small); }
  .hx-line-entry__reprice th, .hx-line-entry__reprice td { padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--border-subtle); text-align: left; }
  .hx-line-entry__reprice .num { text-align: right; font-family: var(--font-mono); white-space: nowrap; }
  .hx-line-entry__reprice .up { color: var(--danger); }
  .hx-line-entry__reprice .down { color: var(--success); }

  /* Signature pad (block signaturePad): wide drawing area, touch-action none so the finger draws instead of scrolling. */
  .hx-signature { display: flex; flex-direction: column; gap: var(--space-3); max-width: 40rem; }
  .hx-signature__pad {
    display: block;
    width: 100%;
    height: clamp(9rem, 32vh, 14rem);
    background: var(--surface-sunken);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    touch-action: none;
    cursor: crosshair;
  }
  .hx-signature__existing { margin: 0; display: flex; flex-direction: column; gap: var(--space-1); }
  .hx-signature__existing img { max-width: 18rem; max-height: 7rem; background: var(--surface-sunken); border-radius: var(--radius-md); }
  .hx-signature__caption { font-size: var(--size-small); color: var(--text-muted); }

  /* Tablet mode (user option): bigger touch targets. */
  .hx-line-entry--tablet { --control-height-sm: 2.75rem; }
  .hx-line-entry--tablet .hx-line-entry__lines input.cell,
  .hx-line-entry--tablet .hx-line-entry__lines .lotinput { min-height: 2.75rem; font-size: 1.05rem; }
  .hx-line-entry--tablet .hx-line-entry__lines .del { min-width: 2.75rem; min-height: 2.75rem; font-size: 1.3rem; }
  .hx-line-entry--tablet .hx-btn--sm { min-height: 2.75rem; padding-inline: var(--space-3); }
  .hx-line-entry--tablet .hx-line-entry__hits li { min-height: 2.75rem; align-items: center; }
  .hx-line-entry--tablet .hx-control { min-height: 2.75rem; font-size: 1.05rem; }

  /* Variant matrix. */
  .hx-variant-matrix__scroll { overflow-x: auto; }

  .hx-variant-matrix__table { border-collapse: collapse; }
  .hx-variant-matrix__table caption { text-align: left; font-weight: 600; padding: var(--space-1) 0; }

  .hx-variant-matrix__table th,
  .hx-variant-matrix__table td {
    border: 1px solid var(--border);
    padding: var(--space-1-5) var(--space-2);
    vertical-align: top;
    text-align: left;
  }

  .hx-variant-matrix__table th { font-size: var(--size-small); color: var(--text-muted); font-weight: 600; }
  .hx-variant-matrix__table td small { display: block; font-size: var(--size-small); color: var(--text-muted); }
  .hx-variant-matrix__table .hx-variant-matrix__no { font-family: var(--font-mono); }
  .hx-variant-matrix__table .matrix-qty { width: 5rem; min-height: var(--control-height-sm); }
  .hx-variant-matrix__cell--disabled { background: var(--surface-sunken); }
  .hx-variant-matrix__cell--warning .hx-variant-matrix__warn { color: var(--warning); }
  /* Große Matrizen: Suche filtert Zeilen/Zellen (ausgeblendet, Mengen bleiben), Nachladen hängt Tabellen an. */
  .hx-variant-matrix__search .matrix-search { width: 100%; max-width: 24rem; }
  .hx-variant-matrix [data-matrix-row][hidden] { display: none; }
  .hx-variant-matrix__table td.matrix-dim { opacity: 0.35; }
  .hx-variant-matrix .matrix-more-wrap { display: inline-flex; align-items: center; gap: var(--space-2); margin-right: auto; }

  @media (max-width: 45rem) {
    .hx-line-entry__party { grid-column: auto; }
    .hx-line-entry__form { padding: var(--space-3); }
  }
}

/* ---------- M5 A5 Kommunikation + KI: chatThread, chatMessage, reasoningSteps, confirmCard, htmlFrame ---------- */
@layer components {
  /* Chat thread (sidebar and /ui/chat). */
  .hx-chat-thread {
    display: flex;
    flex-direction: column;
    gap: var(--space-2-5, var(--space-3));
  }

  .hx-chat-thread__empty {
    margin: 0;
    color: var(--text-muted);
    font-size: var(--size-small);
  }

  .hx-chat-msg {
    max-width: 92%;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-lg);
    overflow-wrap: anywhere;
    line-height: 1.5;
  }

  .hx-chat-msg--user {
    align-self: flex-end;
    background: color-mix(in srgb, var(--accent) 22%, var(--surface));
    color: var(--text-strong);
  }

  .hx-chat-msg--assistant {
    align-self: flex-start;
    border: 1px solid var(--border);
    background: var(--surface);
  }

  .hx-chat-msg--streaming {
    white-space: pre-wrap;
  }

  /* Markdown in assistant answers and the `markdown` block (rendered and sanitized server-side, ChatMarkdown). */
  :is(.hx-chat-msg--assistant, .hx-markdown) > :first-child { margin-top: 0; }
  :is(.hx-chat-msg--assistant, .hx-markdown) > :last-child { margin-bottom: 0; }

  :is(.hx-chat-msg--assistant, .hx-markdown) :is(p, ul, ol, pre, blockquote, table) {
    margin: var(--space-1-5, var(--space-2)) 0;
  }

  :is(.hx-chat-msg--assistant, .hx-markdown) :is(ul, ol) { padding-left: var(--space-5); }
  :is(.hx-chat-msg--assistant, .hx-markdown) li + li { margin-top: var(--space-0-5, var(--space-1)); }

  :is(.hx-chat-msg--assistant, .hx-markdown) :is(h1, h2, h3, h4) {
    margin: var(--space-2) 0 var(--space-1);
    font-size: var(--size-body);
  }

  :is(.hx-chat-msg--assistant, .hx-markdown) code {
    padding: 0 var(--space-1);
    border-radius: var(--radius-xs);
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: var(--size-mono);
  }

  :is(.hx-chat-msg--assistant, .hx-markdown) pre {
    overflow-x: auto;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    background: var(--surface-2);
  }

  :is(.hx-chat-msg--assistant, .hx-markdown) pre code { padding: 0; background: none; }

  :is(.hx-chat-msg--assistant, .hx-markdown) blockquote {
    padding-left: var(--space-2);
    border-left: 3px solid var(--border-strong);
    color: var(--text-muted);
  }

  :is(.hx-chat-msg--assistant, .hx-markdown) table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    font-size: var(--size-small);
    font-variant-numeric: tabular-nums;
  }

  :is(.hx-chat-msg--assistant, .hx-markdown) :is(th, td) {
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
  }

  :is(.hx-chat-msg--assistant, .hx-markdown) th { background: var(--surface-2); font-weight: 600; }
  :is(.hx-chat-msg--assistant, .hx-markdown) :is(th, td)[align='right'] { text-align: right; }
  :is(.hx-chat-msg--assistant, .hx-markdown) :is(th, td)[align='center'] { text-align: center; }
  :is(.hx-chat-msg--assistant, .hx-markdown) hr { border: 0; border-top: 1px solid var(--border); }

  /* `markdown` block: AI text over the full panel width, headings stepped, tables as wide as needed. */
  .hx-markdown {
    max-width: none;
    overflow-wrap: anywhere;
    line-height: 1.55;
  }

  .hx-markdown :is(h1, h2) { font-size: var(--size-h3, var(--size-body)); color: var(--text-strong); }
  .hx-markdown :is(h3, h4) { color: var(--text-strong); }
  .hx-markdown strong { color: var(--text-strong); }
  .hx-markdown hr { margin: var(--space-3) 0; }
  .hx-markdown li::marker { color: var(--text-subtle); }
  .hx-markdown.hx-muted :is(strong, h1, h2, h3, h4) { color: inherit; }

  /* Live state while a turn streams (chat.js). */
  .hx-chat-live {
    display: flex;
    flex-direction: column;
    gap: var(--space-1-5, var(--space-2));
    align-self: stretch;
  }

  .hx-chat-live__thinking {
    margin: 0;
    font-size: var(--size-small);
    font-style: italic;
    color: var(--text-muted);
  }

  .hx-chat-live__thinking::before {
    content: '';
    display: inline-block;
    width: var(--space-2);
    height: var(--space-2);
    margin-right: var(--space-1-5, var(--space-2));
    border-radius: var(--radius-full);
    background: var(--accent);
    animation: hx-chat-pulse 1s ease-in-out infinite alternate;
  }

  @keyframes hx-chat-pulse {
    from { opacity: 0.25; }
    to { opacity: 1; }
  }

  @media (prefers-reduced-motion: reduce) {
    .hx-chat-live__thinking::before { animation: none; }
  }

  .hx-chat-live__steps {
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--size-small);
    color: var(--text-muted);
  }

  .hx-chat-live__steps li::before { content: '✓ '; color: var(--accent-text); }
  .hx-chat-live__steps:empty { display: none; }

  /* Reasoning (one outer block per answer, one collapsible per model step). */
  .hx-reasoning {
    align-self: flex-start;
    max-width: 92%;
    font-size: var(--size-small);
    color: var(--text-muted);
  }

  .hx-reasoning summary { cursor: pointer; }
  .hx-reasoning__step { margin: var(--space-1) 0 0 var(--space-3); }

  .hx-reasoning__text {
    max-height: calc(var(--space-12) * 5);
    overflow-y: auto;
    margin-top: var(--space-1);
    padding: var(--space-1-5, var(--space-2)) var(--space-2);
    border-left: 2px solid var(--border-strong);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  /* Confirm card. */
  .hx-confirm-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-lg);
    background: var(--surface);
  }

  .hx-confirm-card--decided {
    border-left-color: var(--border-strong);
    background: var(--surface-2);
  }

  .hx-confirm-card__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2);
  }

  .hx-confirm-card__label {
    font-size: var(--size-label);
    font-weight: 600;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--text-muted);
  }

  .hx-confirm-card--open .hx-confirm-card__label { color: var(--accent-text); }

  .hx-confirm-card__tool,
  .hx-confirm-card__meta {
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-confirm-card__meta { margin-left: auto; }

  .hx-confirm-card__title { font-weight: 600; color: var(--text-strong); }
  .hx-confirm-card__text { margin: 0; white-space: pre-line; }
  .hx-confirm-card__text.hx-markdown { white-space: normal; }

  .hx-confirm-card__lines {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--space-1) var(--space-3);
    margin: 0;
    font-size: var(--size-control);
  }

  .hx-confirm-card__lines dt { color: var(--text-muted); }
  .hx-confirm-card__lines dd { margin: 0; overflow-wrap: anywhere; }

  .hx-confirm-card__details {
    font-size: var(--size-small);
    color: var(--text-muted);
  }

  .hx-confirm-card__details summary { cursor: pointer; }

  .hx-confirm-card__details ul {
    margin: var(--space-1) 0 0;
    padding-left: var(--space-5);
    font-family: var(--font-mono);
    overflow-wrap: anywhere;
  }

  .hx-confirm-card__warnings {
    margin: 0;
    padding-left: var(--space-5);
    font-size: var(--size-control);
    color: var(--warning);
  }

  .hx-confirm-card__slot:empty { display: none; }

  .hx-confirm-card__status {
    margin: 0;
    font-size: var(--size-control);
  }

  /* filePreview (M6 K): image or PDF of the document store; others show a download note. */
  .hx-file-preview {
    display: grid;
    gap: var(--space-2);
    margin: 0;
  }

  .hx-file-preview__frame {
    display: block;
    width: 100%;
    height: calc(var(--space-12) * 12);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
  }

  .hx-file-preview--sm .hx-file-preview__frame { height: calc(var(--space-12) * 6); }

  .hx-file-preview__image {
    display: block;
    max-width: 100%;
    max-height: calc(var(--space-12) * 12);
    object-fit: contain;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-2);
  }

  .hx-file-preview--sm .hx-file-preview__image { max-height: calc(var(--space-12) * 4); }

  .hx-file-preview__none {
    padding: var(--space-4);
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
  }

  /* Sandboxed HTML frame (mails, template previews). */
  .hx-html-frame {
    display: block;
    width: 100%;
    height: calc(var(--space-12) * 10);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }

  .hx-html-frame--sm { height: calc(var(--space-12) * 6); }
  .hx-html-frame--lg { height: calc(var(--space-12) * 14); }

  /* Character counter under a textarea (app.js toggles .over). */
  .hx-field__counter {
    margin: 0;
    font-family: var(--font-mono);
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-field__counter.over { color: var(--danger); }

  .hx-control--code {
    white-space: pre;
    overflow-x: auto;
    font-size: var(--size-mono);
  }

  /* Code-Editor (textarea code = "jinja"): Feld über die ganze Breite; Editorfarben in code-editor.css (ohne Layer). */
  .hx-field--code { grid-column: 1 / -1; }


  /* Scanner (M6 P): scan field for keyboard-wedge scanners + camera; frame colour = last scan result (scanner.js). */
  .hx-scanner {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-4);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    transition: border-color 120ms ease, background-color 120ms ease;
  }

  .hx-scanner__form { display: flex; flex-direction: column; gap: var(--space-2); }
  .hx-scanner__row { display: flex; gap: var(--space-2); align-items: stretch; }
  .hx-scanner__input { flex: 1 1 auto; min-width: 0; height: var(--control-height-lg); font-size: var(--size-h3); }
  .hx-scanner__qty { flex: 0 0 calc(var(--space-12) * 1.5); height: var(--control-height-lg); text-align: right; font-size: var(--size-h3); }
  .hx-scanner__row .hx-btn { height: var(--control-height-lg); }
  .hx-scanner__tools { display: flex; flex-wrap: wrap; gap: var(--space-1); }
  .hx-scanner__video { width: 100%; max-height: calc(var(--space-12) * 6); border-radius: var(--radius-md); background: var(--surface-sunken); object-fit: cover; }

  .hx-scanner__status {
    margin: 0;
    font-size: var(--size-h3);
    font-weight: 600;
    color: var(--text-muted);
    min-height: calc(var(--size-h3) * 1.5);
  }

  .hx-scanner--busy .hx-scanner__status { color: var(--text-subtle); }
  .hx-scanner--ok { border-color: var(--success); background: var(--success-bg); }
  .hx-scanner--ok .hx-scanner__status { color: var(--success); }
  .hx-scanner--warning { border-color: var(--warning); background: var(--warning-bg); }
  .hx-scanner--warning .hx-scanner__status { color: var(--warning); }
  .hx-scanner--error { border-color: var(--danger); background: var(--danger-bg); }
  .hx-scanner--error .hx-scanner__status { color: var(--danger); }

  @media (max-width: 720px) {
    .hx-scanner { padding: var(--space-3); }
    .hx-scanner__row { flex-wrap: wrap; }
    .hx-scanner__input { flex-basis: 100%; }
    .hx-scanner__row .hx-btn { flex: 1 1 auto; }
  }

  /* ---------- Rechnungseingang: split view, file drop, field attention ---------- */

  .hx-split {
    display: grid;
    align-items: start;
    gap: var(--space-5);
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .hx-split[data-ratio="3:2"] { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .hx-split[data-ratio="2:3"] { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }

  .hx-split--sticky > .hx-split__start {
    position: sticky;
    top: calc(var(--header-height) + var(--space-4));
  }

  .hx-split__start .hx-file-preview__frame {
    height: calc(100vh - var(--header-height) - var(--space-12) * 2);
    min-height: calc(var(--space-12) * 8);
  }

  .hx-split__start .hx-file-preview__image {
    max-height: calc(100vh - var(--header-height) - var(--space-12) * 2);
  }

  .hx-split__summary { display: none; }

  .hx-split__fold > .hx-stack { margin: 0; }

  @media (max-width: 1024px) {
    .hx-split,
    .hx-split[data-ratio] {
      grid-template-columns: minmax(0, 1fr);
    }

    .hx-split--sticky > .hx-split__start { position: static; }

    .hx-split__start .hx-file-preview__frame { height: calc(var(--space-12) * 7); min-height: 0; }

    .hx-split__summary {
      display: list-item;
      cursor: pointer;
      padding: var(--space-2) var(--space-3);
      border: 1px solid var(--border);
      border-radius: var(--radius-md);
      background: var(--surface);
      font-weight: 600;
    }

    .hx-split__fold[open] > .hx-split__summary { margin-bottom: var(--space-3); }
  }

  .hx-drop {
    display: grid;
    gap: var(--space-3);
  }

  .hx-drop__zone {
    position: relative;
    display: grid;
    justify-items: center;
    gap: var(--space-1-5);
    padding: var(--space-6) var(--space-4);
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    color: var(--text-muted);
    text-align: center;
    cursor: pointer;
    transition: border-color 120ms ease, background-color 120ms ease;
  }

  .hx-drop__zone:hover,
  .hx-drop--over .hx-drop__zone {
    border-color: var(--accent-text);
    background: var(--surface-hover);
  }

  .hx-drop__zone:focus-within {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
  }

  .hx-drop__label {
    font-weight: 600;
    color: var(--text-strong);
  }

  .hx-drop__hint {
    font-size: var(--size-small);
    color: var(--text-subtle);
  }

  .hx-drop__icon { color: var(--text-subtle); }

  .hx-drop__input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
  }

  .hx-drop__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: flex-end;
  }

  .hx-drop__photo {
    position: relative;
    cursor: pointer;
  }

  .hx-drop__photo:focus-within {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
  }

  .hx-drop__status {
    margin: 0;
    font-size: var(--size-small);
    color: var(--text-muted);
  }

  .hx-drop__status:empty { display: none; }

  /* Per-file upload rows (fileAction): name · bar · state; wraps under each other on narrow screens. */
  .hx-drop__files {
    display: grid;
    gap: var(--space-1-5);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .hx-drop__files[hidden] { display: none; }

  .hx-drop__file {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(6rem, 3fr) minmax(0, 2fr);
    gap: var(--space-2);
    align-items: center;
    font-size: var(--size-small);
  }

  .hx-drop__file-name {
    overflow: hidden;
    color: var(--text-strong);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .hx-drop__file progress {
    --bar: var(--accent-text);
    width: 100%;
    height: 0.375rem;
    border: 0;
    border-radius: var(--radius-full);
    background: var(--border-strong);
    color: var(--bar);
    appearance: none;
    overflow: hidden;
  }

  .hx-drop__file progress::-webkit-progress-bar { background: var(--border-strong); border-radius: var(--radius-full); }
  .hx-drop__file progress::-webkit-progress-value { background: var(--bar); border-radius: var(--radius-full); }
  .hx-drop__file progress::-moz-progress-bar { background: var(--bar); border-radius: var(--radius-full); }
  .hx-drop__file-state { color: var(--text-muted); }
  .hx-drop__file--done progress { --bar: var(--success); }
  .hx-drop__file--done .hx-drop__file-state { color: var(--success); }
  .hx-drop__file--failed progress { --bar: var(--danger); }
  .hx-drop__file--failed .hx-drop__file-state { color: var(--danger); }

  @media (max-width: 640px) {
    .hx-drop__file { grid-template-columns: minmax(0, 1fr) auto; }
    .hx-drop__file progress { grid-column: 1 / -1; grid-row: 2; }
  }

  /* Photo button only where a camera is likely (touch devices). */
  @media (hover: hover) and (pointer: fine) {
    .hx-drop__photo { display: none; }
  }

  .hx-field--attention .hx-control {
    border-color: var(--warning);
    background: var(--warning-bg);
  }

  .hx-field__attention {
    margin: 0;
    font-size: var(--size-small);
    line-height: 1.4;
    color: var(--warning);
  }

  /* Field reached by a jump link (#f:<name>, settings search): briefly outlined in the focus colour. */
  .hx-field--found {
    outline: 2px solid var(--focus-color);
    outline-offset: 6px;
    border-radius: var(--radius-control);
  }
  @media (prefers-reduced-motion: no-preference) {
    .hx-field--found { transition: outline-color 0.6s ease; }
  }

  /* Line tables in the narrower edit side of a split view: tighter cells. */
  .hx-split__end .hx-lines__table td { padding-inline: var(--space-1); }
  .hx-split__end .hx-lines__pos { width: 2rem; }
}

/* ---------- Month calendar + map (completion package D) ---------- */
@layer components {
  .hx-month { display: grid; gap: var(--space-3); min-width: 0; }
  .hx-month__scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); }
  .hx-month__table { width: 100%; min-width: 42rem; margin: 0; border: 0; border-collapse: collapse; table-layout: fixed; background: transparent; }
  .hx-month__table th {
    padding: var(--space-2) var(--space-2-5);
    border-bottom: 1px solid var(--border-subtle);
    font-size: var(--size-label); font-weight: 500; letter-spacing: var(--tracking-label); text-transform: uppercase;
    text-align: left; color: var(--text-subtle);
  }
  .hx-month__day {
    height: 6.5rem; padding: var(--space-1-5) var(--space-2);
    border-right: 1px solid var(--border-subtle); border-bottom: 1px solid var(--border-subtle);
    vertical-align: top;
  }
  .hx-month__table tr > :last-child { border-right: 0; }
  .hx-month__table tbody > tr:last-child > * { border-bottom: 0; }
  .hx-month__day.is-out { background: var(--surface-2); color: var(--text-subtle); }
  .hx-month__day.is-out .hx-month__entries { opacity: .7; }
  .hx-month__day.is-out .hx-month__num { font-weight: 400; color: var(--text-subtle); }
  .hx-month__num { display: inline-flex; align-items: center; justify-content: center; min-width: 1.6rem; height: 1.6rem; font-size: var(--size-small); font-weight: 600; font-variant-numeric: tabular-nums; }
  .hx-month__wd { display: none; }
  .hx-month__day.is-today .hx-month__num { border-radius: var(--radius-full); background: var(--accent); color: var(--on-accent); }
  .hx-month__entries { display: grid; gap: var(--space-1); margin: var(--space-1) 0 0; padding: 0; list-style: none; }
  .hx-month__entry {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-1-5);
    padding: var(--space-0-5) var(--space-1-5); border-left: 3px solid var(--accent-text); border-radius: var(--radius-sm);
    background: var(--surface-2); font-size: var(--size-small); min-width: 0;
  }
  .hx-month__link { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .hx-month__meta { display: none; }
  .hx-month__more { font-size: var(--size-small); color: var(--text-subtle); padding-left: var(--space-1-5); }

  /* Narrow: list of the days with entries (weekday + date, entries with their meta line). */
  @media (max-width: 45rem) {
    .hx-month__scroll { overflow: visible; }
    .hx-month__table, .hx-month__table tbody, .hx-month__table tr, .hx-month__table td { display: block; min-width: 0; width: auto; }
    .hx-month__table thead { display: none; }
    .hx-month__day { height: auto; border-right: 0; }
    .hx-month__day.is-empty, .hx-month__day.is-out { display: none !important; }
    .hx-month__wd { display: inline; margin-right: .25em; }
    .hx-month__meta { display: block; width: 100%; color: var(--text-subtle); }
    .hx-month__link { white-space: normal; }
  }

  .hx-map { display: grid; gap: var(--space-3); min-width: 0; }
  .hx-map__canvas { height: 22rem; min-height: 14rem; border: 1px solid var(--border); border-radius: var(--radius-xl); overflow: hidden; background: var(--surface-2); z-index: 0; }
  .hx-grid__body .hx-map__canvas { height: 18rem; }
  .hx-map__list { max-height: 14rem; overflow-y: auto; }
  .hx-map .leaflet-popup-content { font-family: var(--font-sans); font-size: var(--size-small); }
  .hx-map .leaflet-popup-content a { font-weight: 600; }
  [data-theme='dark'] .hx-map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme='light']) .hx-map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
  }

  /* View editor (own views editable by click): block cards in edit mode. */
  .hx-editor-block__meta { font-family: var(--font-mono); font-size: var(--size-small); color: var(--text-subtle); }

  /* Action pad (time clock and other terminal-like pages): state + big running time, large touch buttons. */
  .hx-pad {
    display: grid; gap: var(--space-4); padding: var(--space-5); min-width: 0;
    border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface);
  }
  .hx-pad__head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); }
  .hx-pad__state { display: grid; gap: var(--space-1-5); justify-items: start; min-width: 0; }
  .hx-pad__title { margin: 0; font-family: var(--font-display); font-size: var(--size-h2); font-weight: 700; color: var(--text-strong); }
  .hx-pad__meta { margin: 0; font-family: var(--font-mono); font-size: var(--size-mono); color: var(--text-muted); }
  .hx-pad__time { display: grid; justify-items: end; gap: var(--space-0-5); }
  .hx-pad__time-label { font-size: var(--size-label); text-transform: uppercase; letter-spacing: var(--tracking-label, .06em); color: var(--text-subtle); }
  .hx-pad__value {
    font-family: var(--font-display); font-size: var(--size-kpi-fluid); font-weight: 800; line-height: 1;
    letter-spacing: var(--tracking-kpi); font-variant-numeric: tabular-nums; color: var(--text);
  }
  .hx-pad__buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); gap: var(--space-3); }
  .hx-pad__form { display: contents; }
  .hx-pad__button {
    display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; align-items: center; column-gap: var(--space-3);
    min-height: 4.5rem; padding: var(--space-3) var(--space-4); text-align: left; cursor: pointer;
    border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-2); color: var(--text-strong);
    font-family: var(--font-sans); font-size: var(--size-h3); font-weight: 700;
    touch-action: manipulation;
  }
  .hx-pad__button > .hx-icon { grid-row: 1 / span 2; }
  .hx-pad__button:hover:not(:disabled) { background: var(--surface-hover); }
  .hx-pad__button:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
  .hx-pad__button:disabled { opacity: .5; cursor: not-allowed; }
  .hx-pad__button--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
  .hx-pad__button--primary:hover:not(:disabled) { background: var(--accent); filter: brightness(.96); }
  .hx-pad__button--danger { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }
  .hx-pad__label { grid-column: 2; }
  .hx-pad__hint { grid-column: 2; font-size: var(--size-small); font-weight: 400; color: inherit; opacity: .8; }
  .hx-pad__note { margin: 0; font-size: var(--size-small); color: var(--text-muted); }
  @media (max-width: 45rem) {
    .hx-pad { padding: var(--space-4); }
    .hx-pad__head { align-items: flex-start; }
    .hx-pad__time { justify-items: start; }
    .hx-pad__button { min-height: 4rem; }
  }

  /* ---------- Work queue (Arbeitsliste, Bankabgleich) ---------- */
  .hx-queue { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); min-width: 0; }
  .hx-queue__keys { margin: 0; font-size: var(--size-small); color: var(--text-subtle); }
  .hx-queue__list { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
  .hx-queue__item {
    display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); min-width: 0; padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); background: var(--surface);
  }
  .hx-queue__item.is-active { border-color: var(--border-stronger); background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
  .hx-queue__item:focus-visible { outline: 2px solid var(--focus-color); outline-offset: 2px; }
  .hx-queue__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); }
  .hx-queue__title { flex: 1 1 12rem; min-width: 0; font-weight: 600; color: var(--text-strong); overflow-wrap: anywhere; }
  .hx-queue__amount { margin-left: auto; font-weight: 600; }
  .hx-queue__meta { margin: 0; font-size: var(--size-small); color: var(--text-muted); overflow-wrap: anywhere; }
  .hx-queue__choices { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); }
  .hx-queue__choice {
    display: grid; gap: var(--space-1); padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: var(--bg);
  }
  .hx-queue__item:not(.is-active) .hx-queue__choice:not(:first-child) { display: none; }
  .hx-queue__item:not(.is-active) .hx-queue__reasons { display: none; }
  .hx-queue__choice.is-selected { border-color: var(--accent-text); }
  .hx-queue__choice-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
  .hx-queue__choice-label { flex: 1 1 10rem; min-width: 0; overflow-wrap: anywhere; }
  .hx-queue__score { flex: none; font-family: var(--font-mono); }
  .hx-queue__reasons { margin: 0; padding-left: var(--space-5); font-size: var(--size-small); color: var(--text-muted); }
  .hx-queue__none { margin: 0; font-size: var(--size-small); color: var(--text-subtle); }
  .hx-queue__manual { justify-self: start; }
  @media (max-width: 45rem) {
    .hx-queue__item { padding: var(--space-3); }
    .hx-queue__amount { margin-left: 0; }
  }
}

/*
 * Narrow screens (phones from 360 px): nothing may widen the page – NarrowScreenIT checks every page at 390 px.
 * Scroll containers contain their positioned descendants: an absolutely positioned child (e.g. the visually hidden
 * label of a checkbox in a table row) would otherwise be laid out against the page and stretch it sideways.
 * Form controls and media never exceed their column; long values (numbers, e-mail addresses, file names) wrap.
 */
@layer components {
  :is(.hx-table__scroll, .hx-kanban, .hx-grid__body, .hx-board__scroll, .hx-line-entry__scroll, .hx-line-entry__preview-body,
    .hx-variant-matrix__scroll, .hx-month__scroll, .hx-check) {
    position: relative;
  }

  .hx-content :is(input, select, textarea, img, video, canvas, iframe, pre, .hx-control) {
    max-width: 100%;
  }

  .hx-content,
  .hx-dialog {
    overflow-wrap: break-word;
  }

  .hx-dialog {
    max-width: min(var(--width-dialog-md), calc(100vw - 2 * var(--space-4)));
  }

  .hx-dialog--sm { max-width: min(var(--width-dialog-sm), calc(100vw - 2 * var(--space-4))); }
  .hx-dialog--lg { max-width: min(var(--width-dialog-lg), calc(100vw - 2 * var(--space-4))); }
}

/*
 * Page dialog (#hx-page-dialog, Plugin-API 2.9): a whole page's content (e.g. a plugin form) over the current page –
 * header fixed, body scrolls; on phones (≤ 45rem) full screen without rounded frame.
 */
@layer components {
  .hx-dialog--page[open] {
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 2 * var(--space-6));
  }

  .hx-dialog--page .hx-dialog__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
  }

  .hx-dialog--page .hx-dialog__body[aria-busy="true"] {
    opacity: 0.6;
  }

  @media (max-width: 45rem) {
    .hx-dialog--page[open] {
      width: 100vw;
      max-width: 100vw;
      height: 100dvh;
      max-height: 100dvh;
      margin: 0;
      border: 0;
      border-radius: 0;
    }

    .hx-dialog--page .hx-dialog__body { padding: var(--space-4); }
  }
}

/* ---------- Kommissionierung v2: scan task, hold button, flash, traffic light marks ---------- */
@layer components {
  /* Ampel-Töne der Listenmarkierung (taskList, HxTaskItem.tone). */
  .hx-task-mark--success { border-color: var(--success); background: var(--success-bg); color: var(--success); }
  .hx-task-mark--warning { border-color: var(--warning); background: var(--warning-bg); color: var(--warning); }
  .hx-task-mark--info { border-color: var(--info); background: var(--info-bg); color: var(--info); }

  /* Gedrückt halten (HxButton.hold): Fortschritt füllt den Knopf von links (hx.js setzt --hx-hold 0..1). */
  .hx-btn--hold { position: relative; overflow: hidden; isolation: isolate; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
  .hx-btn--hold::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--text-strong);
    opacity: 0.18;
    transform-origin: left center;
    transform: scaleX(var(--hx-hold, 0));
  }

  /* Vollbild-Blitz nach einem Scan (scanner.js, HxScanner.flash). */
  .hx-flash {
    position: fixed;
    inset: 0;
    z-index: var(--z-skip);
    pointer-events: none;
    opacity: 0;
    background: var(--success-fill); /* scan flash: status colours only (never cyan/orange) */
    transition: opacity 280ms ease-out;
  }
  .hx-flash--warning { background: var(--warning-fill); }
  .hx-flash--error { background: var(--danger-fill); }
  .hx-flash--on { opacity: 0.55; transition: none; }
  @media (prefers-reduced-motion: reduce) {
    .hx-flash--on { opacity: 0.35; }
  }

  .hx-scanner__queue { margin: 0; font-size: var(--size-small); font-weight: 600; color: var(--warning); }

  /* Scan-Aufgabe: eine Aufgabe groß auf dem Handy. */
  .hx-scan-task { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }

  .hx-scan-task__notes {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px solid var(--warning);
    background: var(--warning-bg);
    color: var(--text-strong);
  }
  .hx-scan-task__notes-label { display: block; font-size: var(--size-small); font-weight: 600; color: var(--warning); }
  .hx-scan-task__note { margin: var(--space-1) 0 0; font-size: var(--size-h3); font-weight: 600; overflow-wrap: anywhere; }

  .hx-scan-task__card {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-4);
    border: 2px solid var(--accent);
    border-radius: var(--radius-xl);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }
  .hx-scan-task__card--done { border-color: var(--success); }

  .hx-scan-task__row { display: flex; align-items: center; gap: var(--space-2); min-height: var(--control-height-lg); }
  .hx-scan-task__label { flex: 1 1 auto; font-size: var(--size-body); color: var(--text-muted); }
  .hx-scan-task__location {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md);
    background: var(--accent);
    color: var(--on-accent);
    font-size: var(--size-h2);
    font-weight: 700;
    overflow-wrap: anywhere;
  }
  .hx-scan-task__title { margin: var(--space-1) 0 0; font-size: var(--size-h2); line-height: 1.2; color: var(--text-strong); overflow-wrap: anywhere; }
  .hx-scan-task__code { margin: 0; color: var(--text-muted); overflow-wrap: anywhere; }
  .hx-scan-task__counter { min-width: 0; font-size: var(--size-kpi-md); font-weight: 700; color: var(--text-strong); text-align: right; overflow-wrap: anywhere; }
  .hx-scan-task__hint { margin: 0; font-weight: 600; color: var(--info); }

  .hx-scan-task__check {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: var(--control-height);
    height: var(--control-height);
    border-radius: var(--radius-full);
    border: 2px solid var(--border-strong);
    color: transparent;
  }
  .hx-scan-task__check--on { border-color: var(--success-fill); background: var(--success-fill); color: var(--on-tone); }

  .hx-scan-task__empty { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4); border-radius: var(--radius-xl); background: var(--success-bg); font-size: var(--size-h3); font-weight: 600; color: var(--text-strong); }
  .hx-scan-task__empty p { margin: 0; }

  .hx-scan-task__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
  .hx-scan-task__actions > * { flex: 1 1 calc(var(--space-12) * 3); }
  .hx-scan-task__actions .hx-btn-form { display: flex; }
  .hx-scan-task__actions .hx-btn { width: 100%; min-height: var(--control-height-lg); justify-content: center; font-size: var(--size-body); }
  .hx-scan-task__actions .hx-btn--primary { min-height: calc(var(--control-height-lg) * 1.25); font-size: var(--size-h3); }
  .hx-scan-task__actions > .hx-btn--primary,
  .hx-scan-task__actions > :has(.hx-btn--primary) { flex-basis: 100%; }

  .hx-scan-task__list-label { margin: var(--space-2) 0 0; font-size: var(--size-small); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: var(--tracking-label); }
  .hx-scan-task__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
  .hx-scan-task__item-body {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: inherit;
    text-decoration: none;
    min-height: var(--control-height-lg);
  }
  .hx-scan-task__item--current .hx-scan-task__item-body { border-color: var(--accent-text); box-shadow: 0 0 0 1px var(--accent-text); }
  .hx-scan-task__item--done .hx-scan-task__item-body { opacity: 0.7; }
  .hx-scan-task__item--short .hx-scan-task__item-body { border-color: var(--danger); }
  .hx-scan-task__item-main { display: flex; flex-direction: column; gap: var(--space-0-5); min-width: 0; flex: 1 1 auto; }
  .hx-scan-task__chip { align-self: flex-start; padding: 0 var(--space-2); border-radius: var(--radius-sm); background: var(--accent); color: var(--on-accent); font-weight: 700; }
  .hx-scan-task__item--done .hx-scan-task__chip { background: var(--surface-sunken); color: var(--text-muted); }
  .hx-scan-task__item--short .hx-scan-task__chip { background: var(--danger-bg); color: var(--danger); }
  .hx-scan-task__item-title { font-weight: 600; overflow-wrap: anywhere; }
  .hx-scan-task__item-meta { font-size: var(--size-small); color: var(--text-muted); overflow-wrap: anywhere; }
  .hx-scan-task__badge {
    flex: none;
    min-width: var(--control-height);
    padding: var(--space-0-5) var(--space-2);
    border-radius: var(--radius-full);
    background: var(--surface-sunken);
    text-align: center;
    font-weight: 700;
  }
}

/* Lager-App, weitere Abläufe: Startkacheln (tileMenu) und Zifferntasten (numPad) – große Touch-Flächen, eine Hand. */
@layer components {
  .hx-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9.5rem), 1fr)); gap: var(--space-3); }
  .hx-tiles__tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-height: calc(var(--control-height-lg) * 2.75);
    padding: var(--space-3) var(--space-4) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
    color: inherit;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
  }
  .hx-tiles__tile:hover { border-color: var(--border-strong); }
  .hx-tiles__tile:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
  .hx-tiles__tile:active { background: var(--surface-sunken); }
  .hx-tiles__tile--disabled { opacity: 0.5; box-shadow: none; cursor: not-allowed; }
  .hx-tiles__tile--disabled:hover { border-color: var(--border); }
  .hx-tiles__tile--disabled:active { background: var(--surface); }
  .hx-tiles__tile--disabled .hx-tiles__icon { background: var(--surface-sunken); color: var(--text-muted); }
  .hx-tiles__icon {
    display: inline-grid;
    place-items: center;
    width: var(--control-height-lg);
    height: var(--control-height-lg);
    margin-bottom: var(--space-2);
    border-radius: var(--radius-lg);
    background: var(--accent);
    color: var(--on-accent);
  }
  .hx-tiles__count { position: absolute; top: var(--space-3); right: var(--space-3); font-size: var(--size-h2); font-weight: 700; color: var(--text-strong); }
  .hx-tiles__count--success { color: var(--success); }
  .hx-tiles__count--warning { color: var(--warning); }
  .hx-tiles__count--danger { color: var(--danger); }
  .hx-tiles__count--info { color: var(--info); }
  .hx-tiles__label { font-size: var(--size-h3); font-weight: 700; line-height: 1.2; color: var(--text-strong); overflow-wrap: anywhere; }
  .hx-tiles__meta { font-size: var(--size-small); color: var(--text-muted); overflow-wrap: anywhere; }

  .hx-numpad { display: flex; flex-direction: column; gap: var(--space-2); }
  .hx-numpad__display { min-height: var(--control-height-lg); font-size: var(--size-h2); font-weight: 700; text-align: right; }
  .hx-numpad__keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
  .hx-numpad__key {
    min-height: var(--control-height-lg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text-strong);
    font-size: var(--size-h3);
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
  }
  .hx-numpad__key:active { background: var(--surface-sunken); }
  .hx-numpad__key:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
  .hx-numpad__submit { width: 100%; justify-content: center; min-height: var(--control-height-lg); }

  /* ---------- Kachelraster und Bestellblock (Kasse/POS, Theke, Kiosk) ---------- */
  .hx-tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr)); gap: var(--space-2); min-width: 0; }
  .hx-tgrid__empty { grid-column: 1 / -1; margin: 0; color: var(--text-muted); }
  .hx-tgrid__form { display: contents; }
  .hx-tgrid__tile {
    display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: var(--space-1);
    min-height: 5.5rem; padding: var(--space-3); text-align: left; cursor: pointer; text-decoration: none;
    border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text-strong);
    font-family: var(--font-sans); touch-action: manipulation; -webkit-user-select: none; user-select: none;
  }
  .hx-tgrid__tile:hover:not(:disabled) { border-color: var(--border-strong); }
  .hx-tgrid__tile:active:not(:disabled) { background: var(--surface-sunken); }
  .hx-tgrid__tile:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
  .hx-tgrid__tile:disabled { opacity: .5; cursor: not-allowed; }
  .hx-tgrid__tile--accent { box-shadow: inset 3px 0 0 var(--highlight); }
  .hx-tgrid__tile--info { box-shadow: inset 3px 0 0 var(--info); }
  .hx-tgrid__tile--warning { box-shadow: inset 3px 0 0 var(--warning); }
  .hx-tgrid__label { font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .hx-tgrid__sub { font-size: var(--size-small); color: var(--text-muted); font-family: var(--font-mono); }
  .hx-tgrid__value { font-size: var(--size-h3); font-weight: 700; font-variant-numeric: tabular-nums; }
  .hx-tgrid__tile { position: relative; }
  .hx-tgrid__badge {
    position: absolute; top: var(--space-2); right: var(--space-2); min-width: 1.5rem; padding: 0 var(--space-1); text-align: center;
    border-radius: var(--radius-lg); font-size: var(--size-small); font-weight: 600; font-variant-numeric: tabular-nums;
    background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
  }
  .hx-tgrid__badge--danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
  .hx-tgrid__badge--success { color: var(--success); }
  .hx-tgrid__badge + .hx-tgrid__label { padding-right: var(--space-8); }

  .hx-order {
    display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); min-width: 0; padding: var(--space-4);
    border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface);
  }
  .hx-order__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
  .hx-order__title { margin: 0; font-size: var(--size-h2); color: var(--text-strong); }
  .hx-order__empty { margin: 0; padding: var(--space-6) 0; text-align: center; color: var(--text-muted); }
  .hx-order__lines { display: grid; gap: var(--space-1); margin: 0; padding: 0; list-style: none; max-height: 52vh; overflow-y: auto; overscroll-behavior: contain; }
  .hx-order__line {
    display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "main qty amount" "tools tools tools";
    align-items: center; column-gap: var(--space-3); row-gap: var(--space-1); padding: var(--space-2) 0; border-bottom: 1px solid var(--border-subtle);
  }
  .hx-order__main { grid-area: main; display: flex; flex-direction: column; min-width: 0; }
  .hx-order__label { font-weight: 600; color: var(--text-strong); overflow-wrap: anywhere; }
  .hx-order__meta { font-size: var(--size-small); color: var(--text-muted); }
  .hx-order__warn { font-size: var(--size-small); color: var(--warning); font-weight: 600; }
  .hx-order__qty { grid-area: qty; font-size: var(--size-h3); font-weight: 700; font-variant-numeric: tabular-nums; }
  .hx-order__amount { grid-area: amount; font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; min-width: 5rem; }
  .hx-order__tools { grid-area: tools; display: flex; flex-wrap: wrap; gap: var(--space-1); }
  .hx-order__tools .hx-btn { min-width: var(--control-height-lg); min-height: 2.75rem; justify-content: center; touch-action: manipulation; }
  .hx-order__totals { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-1); margin: 0; padding-top: var(--space-2); border-top: 1px solid var(--border); }
  .hx-order__total { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); color: var(--text-muted); }
  .hx-order__total dt, .hx-order__total dd { margin: 0; }
  .hx-order__total dd { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .hx-order__total--strong { color: var(--text-strong); font-size: var(--size-h1); font-weight: 700; line-height: 1.1; }
  .hx-order__total--strong dd { font-size: var(--size-display); }
  .hx-order__primary .hx-btn-form, .hx-order__primary .hx-btn { width: 100%; }
  .hx-order__primary .hx-btn { justify-content: center; min-height: 4rem; font-size: var(--size-h3); touch-action: manipulation; }
  .hx-order__actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr)); gap: var(--space-2); }
  .hx-order__actions .hx-btn-form, .hx-order__actions .hx-btn { width: 100%; }
  .hx-order__actions .hx-btn { justify-content: center; min-height: 2.75rem; touch-action: manipulation; }

  /* orderPad.selectable (Kasse): kompakte Zeilen – Menge als Plakette, Name und Einzelpreis einzeilig, Summe; die Knöpfe
     erscheinen nur an der angetippten Zeile (hx.js, aria-expanded). */
  .hx-order--select .hx-order__lines { gap: 0; }
  /* Zeilen oben anfangen, auch wenn die Liste die Spalte füllt (Kasse: eine Zeile nicht mitten im Warenkorb). */
  .hx-order__lines { align-content: start; }
  .hx-order--select .hx-order__line {
    grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "qty main amount" "tools tools tools";
    column-gap: var(--space-2); padding: var(--space-1) var(--space-2); border-radius: var(--radius-md); cursor: pointer;
  }
  .hx-order--select .hx-order__line[aria-expanded="false"] .hx-order__tools { display: none; }
  .hx-order--select .hx-order__line[aria-expanded="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); padding-bottom: var(--space-2); }
  .hx-order--select .hx-order__line:focus-visible { outline: 2px solid var(--accent-text); outline-offset: -2px; }
  .hx-order--select .hx-order__qty {
    min-width: 2.25rem; padding: 0 var(--space-1); border-radius: var(--radius-md); background: var(--surface-sunken);
    text-align: center; font-size: var(--size-body); line-height: 1.75rem;
  }
  .hx-order--select .hx-order__label, .hx-order--select .hx-order__meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hx-order--select .hx-order__line[aria-expanded="true"] .hx-order__label { white-space: normal; }

  @media (max-width: 600px) {
    .hx-tgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hx-order { padding: var(--space-3); }
    .hx-order__total--strong dd { font-size: var(--size-h1); }
  }
}

/* ---------- Slot picker (Terminauswahl: Tag, dann Uhrzeit) ---------- */
@layer components {
  .hx-slots {
    display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: var(--space-4);
    padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); min-width: 0;
  }
  .hx-slots__month { min-width: 0; }
  .hx-slots__header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
  .hx-slots__title { margin: 0; font-size: var(--size-body); font-weight: 600; }
  .hx-slots__nav-placeholder { display: inline-block; width: 2rem; }
  .hx-slots__grid { width: 100%; margin: 0; border: 0; border-collapse: separate; border-spacing: var(--space-1); table-layout: fixed; background: transparent; }
  .hx-slots__grid th { padding: 0 0 var(--space-2); border: 0; font-size: var(--size-label); font-weight: 500; letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-subtle); text-align: center; background: transparent; }
  .hx-slots__cell { padding: 0; border: 0; text-align: center; background: transparent; }
  /* Every day cell has the same square box (available, unavailable, outside the month) – the grid never jumps. */
  .hx-slots__day {
    position: relative; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center;
    width: 100%; max-width: 3rem; aspect-ratio: 1; border: 1px solid transparent; border-radius: var(--radius-md);
    font-size: var(--size-small); font-variant-numeric: tabular-nums; color: var(--text-faint, var(--text-subtle));
  }
  /* Available: cyan outline and a light cyan fill (HexaMain: cyan = interactive), bold – clearly a link. */
  a.hx-slots__day.is-available {
    background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
    color: var(--text); font-weight: 700; text-decoration: none;
  }
  a.hx-slots__day.is-available:hover { background: color-mix(in srgb, var(--accent) 24%, var(--surface)); border-color: var(--accent); }
  a.hx-slots__day.is-available:focus-visible { outline: 2px solid var(--focus-color, var(--accent-text)); outline-offset: 2px; }
  a.hx-slots__day.is-selected, a.hx-slots__day.is-selected:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
  /* Today: dot under the number (also on unavailable days). */
  .hx-slots__day.is-today { color: var(--text); }
  .hx-slots__day.is-today::after {
    content: ""; position: absolute; bottom: 14%; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: var(--radius-full); background: var(--accent-text);
  }
  a.hx-slots__day.is-selected.is-today::after { background: var(--on-accent); }
  .hx-slots__times { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-2); min-width: 0; }
  .hx-slots__day-title { margin: 0; font-size: var(--size-body); font-weight: 600; }
  .hx-slots__zone { margin: 0; font-size: var(--size-small); color: var(--text-subtle); }
  /* Times scroll inside their column (the page keeps its height), with room for the focus ring. */
  .hx-slots__list {
    display: grid; gap: var(--space-2); margin: 0; padding: 2px; list-style: none; max-height: 24rem; overflow-y: auto; overscroll-behavior: contain;
  }
  .hx-slots__time {
    display: flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 2.75rem;
    padding: var(--space-2) var(--space-3); border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border)); border-radius: var(--radius-md);
    color: var(--text); font-weight: 600; text-decoration: none; background: var(--surface);
  }
  .hx-slots__time:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
  .hx-slots__time.is-selected { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
  .hx-slots__meta { font-size: var(--size-small); font-weight: 400; color: var(--text-subtle); }
  .hx-slots__time.is-selected .hx-slots__meta { color: inherit; }
  .hx-slots__hint { margin: 0; font-size: var(--size-small); color: var(--text-subtle); }
  /* Flat: inside a booking panel – no own frame; calendar | times are columns 2 and 3 of the booking card. */
  .hx-slots--flat { padding: 0; border: 0; border-radius: 0; background: transparent; gap: 0; grid-template-columns: minmax(0, 1fr) minmax(10rem, 13rem); }
  .hx-slots--flat .hx-slots__month { padding: var(--space-5); }
  .hx-slots--flat .hx-slots__times { padding: var(--space-5) var(--space-4); border-left: 1px solid var(--border); }
  @media (max-width: 45rem) {
    .hx-slots { grid-template-columns: minmax(0, 1fr); padding: var(--space-3); }
    .hx-slots__list { grid-template-columns: repeat(auto-fill, minmax(min(100%, 6.5rem), 1fr)); max-height: none; }
    .hx-slots--flat { grid-template-columns: minmax(0, 1fr); }
    .hx-slots--flat .hx-slots__month { padding: var(--space-4) 0; }
    .hx-slots--flat .hx-slots__times { padding: var(--space-4) 0 0; border-left: 0; border-top: 1px solid var(--border); }
  }
}

/* ---------- Buchungskarte (Infospalte + Schritt, wie ein Buchungskalender) ----------
   With the flat slot picker three columns: info | calendar | times. Every track is minmax(0, …) and every column a
   one-track grid of minmax(0, 1fr), so long words, chips or the time-zone select never push into the next column.
   ≤ 68rem: info on top (text | facts), calendar + times side by side below. ≤ 45rem: everything stacked. */
@layer components {
  .hx-booking {
    display: grid; grid-template-columns: minmax(16rem, 20rem) minmax(0, 1fr); min-width: 0;
    border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); overflow: hidden;
  }
  .hx-booking--wide { grid-template-columns: minmax(16rem, 20rem) minmax(0, 1fr); }
  .hx-booking__info {
    display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-3);
    padding: var(--space-5); border-right: 1px solid var(--border); min-width: 0; overflow-wrap: anywhere;
  }
  .hx-booking__info > * { min-width: 0; }
  .hx-booking__head, .hx-booking__aside { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-3); min-width: 0; }
  .hx-booking__person { display: flex; align-items: center; gap: var(--space-2); }
  .hx-booking__avatar {
    display: inline-flex; flex: none; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; border-radius: var(--radius-full);
    background: var(--accent); color: var(--on-accent); font-size: var(--size-small); font-weight: 700;
  }
  .hx-booking__name { min-width: 0; font-size: var(--size-small); font-weight: 600; color: var(--text-subtle); }
  .hx-booking__eyebrow { margin: 0; font-size: var(--size-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--highlight-text); }
  .hx-booking__title { margin: 0; font-size: 1.375rem; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; overflow-wrap: anywhere; }
  .hx-booking__desc { margin: 0; color: var(--text-subtle); white-space: pre-line; overflow-wrap: anywhere; }
  .hx-booking__facts { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); margin: var(--space-1) 0 0; padding: 0; list-style: none; }
  .hx-booking__fact { display: flex; align-items: flex-start; gap: var(--space-2); font-weight: 500; min-width: 0; }
  .hx-booking__fact > .hx-icon { flex: none; margin-top: .2rem; color: var(--text-subtle); }
  .hx-booking__fact > span { min-width: 0; }
  /* Durations: chips that wrap inside the column; the chosen one cyan with dark text. */
  .hx-booking__chips { display: flex; flex: 1 1 0; flex-wrap: wrap; gap: var(--space-1-5, .375rem); min-width: 0; margin-top: -.25rem; }
  .hx-booking__chip {
    display: inline-flex; align-items: center; min-height: 2rem; padding: 0 var(--space-3); border: 1px solid var(--border-strong, var(--border));
    border-radius: var(--radius-full); font-size: var(--size-small); font-weight: 600; color: var(--text); text-decoration: none; white-space: nowrap;
  }
  .hx-booking__chip:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
  .hx-booking__chip:focus-visible { outline: 2px solid var(--focus-color, var(--accent-text)); outline-offset: 2px; }
  .hx-booking__chip.is-current, .hx-booking__chip.is-current:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
  .hx-booking__side { display: grid; grid-template-columns: minmax(0, 1fr); margin-top: var(--space-2); min-width: 0; }
  /* Side forms (time zone): field over the full column; with JavaScript the change submits itself (hx.js hides the button). */
  .hx-booking__side .hx-form-grid__fields > * { grid-column: 1 / -1; }
  .hx-booking__side .hx-form-grid__actions { justify-content: flex-start; margin-top: var(--space-2); }
  form[data-hx-autosubmit] .hx-form-grid__actions[hidden] { display: none; }
  .hx-booking__main { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-3); min-width: 0; }
  .hx-booking:not(.hx-booking--wide) .hx-booking__main { padding: var(--space-5); }
  .hx-booking--wide .hx-booking__back { margin: var(--space-4) var(--space-5) 0; }
  .hx-booking__back { justify-self: start; }
  .hx-booking--compact .hx-booking__info, .hx-booking--compact:not(.hx-booking--wide) .hx-booking__main { padding: var(--space-4); }
  /* Medium (tablet, narrow iframe): info on top (head | aside), calendar + times side by side below. */
  @media (max-width: 68rem) {
    .hx-booking:has(.hx-slots--flat) { grid-template-columns: minmax(0, 1fr); }
    .hx-booking:has(.hx-slots--flat) .hx-booking__info {
      grid-template-columns: minmax(0, 3fr) minmax(14rem, 2fr); column-gap: var(--space-6, 2rem); border-right: 0; border-bottom: 1px solid var(--border);
    }
  }
  @media (max-width: 45rem) {
    .hx-booking, .hx-booking--wide, .hx-booking:has(.hx-slots--flat) { grid-template-columns: minmax(0, 1fr); }
    .hx-booking__info, .hx-booking:has(.hx-slots--flat) .hx-booking__info {
      grid-template-columns: minmax(0, 1fr); padding: var(--space-4); border-right: 0; border-bottom: 1px solid var(--border);
    }
    .hx-booking--wide .hx-booking__main { padding: 0 var(--space-4) var(--space-4); }
    .hx-booking:not(.hx-booking--wide) .hx-booking__main { padding: var(--space-4); }
    .hx-booking--wide .hx-booking__back { margin: var(--space-3) 0 0; }
  }
}

/* ---------- Öffentliche Seiten ohne Anmeldung (Buchungsseite, auch eingebettet) ---------- */
@layer components {
  .hx-public { min-height: 100vh; background: var(--bg); color: var(--text); }
  .hx-public__bar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); background: var(--surface); }
  .hx-public__brand { font-weight: 700; letter-spacing: -.01em; }
  .hx-public__main { max-width: 68rem; margin: 0 auto; padding: var(--space-6) var(--space-4); }
  .hx-public--embed { min-height: 0; background: transparent; }
  .hx-public--embed .hx-public__main { padding: var(--space-2); }
  @media (max-width: 45rem) { .hx-public__main { padding: var(--space-3) var(--space-3) var(--space-5); } }
  /* Kundenportal (/portal): Logo, Navigation der Bereiche, Benutzer, Fußzeile mit Rechtslinks, Hinweis „Büro-Ansicht“. */
  .hx-public__bar { flex-wrap: wrap; }
  .hx-public__logo { display: block; max-height: 2.25rem; max-width: 10rem; object-fit: contain; }
  .hx-public__spacer { flex: 1 1 auto; }
  .hx-public__user { display: flex; align-items: center; gap: var(--space-2); font: var(--text-small); color: var(--text-muted); min-width: 0; }
  .hx-public__user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 12rem; }
  .hx-public__nav { display: flex; gap: var(--space-1); overflow-x: auto; padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--border); background: var(--surface); scrollbar-width: none; }
  .hx-public__nav::-webkit-scrollbar { display: none; }
  .hx-public__nav a { display: inline-flex; align-items: center; gap: var(--space-1); padding: var(--space-1) var(--space-3); border-radius: var(--radius-pill, 999px); color: var(--text); text-decoration: none; white-space: nowrap; font: var(--text-small); }
  .hx-public__nav a:hover { background: var(--surface-2, var(--bg)); }
  .hx-public__nav a[aria-current="page"] { background: var(--portal-accent, var(--accent)); color: var(--portal-on-accent, var(--on-accent)); font-weight: 600; }
  .hx-public__banner { padding: var(--space-2) var(--space-4); background: var(--warning-bg); color: var(--warning); font: var(--text-small); text-align: center; }
  .hx-public__footer { max-width: 68rem; margin: 0 auto; padding: var(--space-4); display: flex; flex-wrap: wrap; gap: var(--space-3); font: var(--text-small); color: var(--text-muted); }
  .hx-public__footer a { color: inherit; }
  .hx-public__theme { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm, 6px); color: var(--text); padding: var(--space-1); display: inline-flex; cursor: pointer; }
  .hx-public--portal .hx-btn--primary { background: var(--portal-accent, var(--accent)); color: var(--portal-on-accent, var(--on-accent)); border-color: var(--portal-accent, var(--accent)); }
}

/* ---------- M5 Formulare: Formular-Seite (Abschnitte als Karten, stehende Aktionsleiste, Sprungliste, Zusammenfassung) ---------- */
@layer components {
  /* Form page: top-level sections are cards stacked one below the other (heading, description, fields). */
  .hx-form-grid--page > .hx-form-grid__fields {
    gap: var(--space-5);
  }

  .hx-form-grid--page > .hx-form-grid__fields > .hx-fieldset:not(.hx-fieldset--compact) {
    padding: var(--space-5);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
    scroll-margin-top: calc(var(--header-height) + var(--space-12));
  }

  .hx-form-grid--page > .hx-form-grid__fields > .hx-fieldset:not(.hx-fieldset--compact) > .hx-fieldset__legend {
    padding-bottom: 0;
  }

  /* A form page needs no card around it: the panel steps back, its sections are the cards. */
  .hx-panel:has(> .hx-panel__body > .hx-form-grid--page) {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .hx-panel:has(> .hx-panel__body > .hx-form-grid--page) > .hx-panel__body,
  .hx-panel:has(> .hx-panel__body > .hx-form-grid--page) > .hx-panel__header {
    padding-inline: 0;
  }

  .hx-panel:has(> .hx-panel__body > .hx-form-grid--page) > .hx-panel__body {
    padding-block: 0;
  }

  /* Sticky only works without a clipping ancestor. */
  .hx-panel:has(.hx-form-grid--sticky) {
    overflow: visible;
  }

  /* Collapsible section („Weitere Angaben“): the legend is the toggle. */
  .hx-fieldset--collapsible > .hx-fieldset__toggle {
    float: none;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    list-style: none;
  }

  .hx-fieldset--collapsible > .hx-fieldset__toggle::-webkit-details-marker {
    display: none;
  }

  .hx-fieldset--collapsible > .hx-fieldset__toggle::before {
    content: '';
    width: var(--space-2);
    height: var(--space-2);
    border-right: 2px solid var(--text-subtle);
    border-bottom: 2px solid var(--text-subtle);
    transform: rotate(-45deg);
    transition: transform var(--transition-fast);
  }

  .hx-fieldset--collapsible[open] > .hx-fieldset__toggle::before {
    transform: rotate(45deg);
  }

  .hx-fieldset--collapsible[open] > .hx-fieldset__toggle {
    padding-bottom: var(--space-3);
  }

  .hx-fieldset__inner {
    display: grid;
    gap: var(--space-3);
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .hx-fieldset--collapsible[hidden] {
    display: none;
  }

  /* Section nav: anchor chips of the sections, standing below the top bar. */
  .hx-form-nav {
    position: sticky;
    top: var(--header-height);
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1-5);
    margin-bottom: var(--space-5);
    padding: var(--space-2) 0;
    background: var(--bg);
  }

  .hx-form-nav__link {
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface);
    font-size: var(--size-control);
    color: var(--text-muted);
    text-decoration: none;
  }

  .hx-form-nav__link:hover {
    background: var(--surface-hover);
    color: var(--text);
  }

  /* Error summary on top of the form; hx.js turns the labels into links to the fields. */
  .hx-form-summary {
    margin-bottom: var(--space-5);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--danger);
    border-radius: var(--radius-lg);
    background: var(--danger-bg);
    color: var(--text);
  }

  .hx-form-summary:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
  }

  .hx-form-summary__title {
    margin: 0 0 var(--space-1);
    font-weight: 600;
  }

  .hx-form-summary__list {
    margin: 0;
    padding-left: var(--space-5);
  }

  .hx-form-summary__list a {
    color: var(--text);
  }

  /* Sticky action bar: stays at the bottom of the screen while the form is in view. */
  .hx-form-bar {
    position: sticky;
    bottom: 0;
    z-index: 3;
    align-items: center;
    margin-top: var(--space-5);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(4px);
    box-shadow: var(--shadow-md);
  }

  .hx-form-bar__status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-4);
    margin: 0 auto 0 0;
    font-size: var(--size-control);
    color: var(--text-subtle);
  }

  .hx-form-bar__dirty {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1-5);
    font-weight: 600;
    color: var(--text-strong);
  }

  .hx-form-bar__dirty[hidden] {
    display: none;
  }

  .hx-form-bar__dirty::before {
    content: '';
    width: var(--space-2);
    height: var(--space-2);
    border-radius: var(--radius-full);
    background: var(--warning);
  }

  /* The floating chat button sits bottom right: the bar keeps that corner free, so it never covers „Speichern“. */
  body:has(.hx-chat__toggle) .hx-form-bar {
    padding-right: calc(var(--space-4) + 8rem);
  }

  /* Info sign next to a label: tooltip on hover and keyboard focus. */
  .hx-field__info {
    position: relative;
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: var(--space-4);
    height: var(--space-4);
    margin-top: var(--space-0-5);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-full);
    font-size: var(--size-label);
    font-weight: 600;
    font-style: italic;
    color: var(--text-muted);
    cursor: help;
  }

  .hx-field__info:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 1px;
  }

  .hx-field__info:hover::after,
  .hx-field__info:focus-visible::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + var(--space-1-5));
    right: calc(var(--space-4) * -1);
    z-index: var(--z-menu);
    width: max-content;
    max-width: min(18rem, 70vw);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    background: var(--text-strong);
    box-shadow: var(--shadow-md);
    font-size: var(--size-small);
    font-style: normal;
    font-weight: 400;
    line-height: 1.4;
    color: var(--bg);
    white-space: normal;
  }

  /* Prefix/suffix addons (units, currency) inside the field. */
  .hx-control-group {
    display: flex;
    align-items: stretch;
    min-width: 0;
  }

  .hx-control-group > .hx-control {
    min-width: 0;
    flex: 1;
  }

  .hx-control-group__addon {
    display: inline-flex;
    flex: none;
    align-items: center;
    padding: 0 var(--space-3);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    font-size: var(--size-control);
    color: var(--text-muted);
    white-space: nowrap;
  }

  .hx-control-group > .hx-control:not(:first-child) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  .hx-control-group > .hx-control:not(:last-child) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  .hx-control-group__addon:first-child {
    border-right: 0;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  }

  .hx-control-group__addon:last-child {
    border-left: 0;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  }

  .hx-control--num {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  /* Display mode (form without write permission): values read like text, no actions. */
  .hx-form-grid--display .hx-control {
    border-color: transparent;
    background: transparent;
    padding-inline: 0;
    color: var(--text);
  }

  .hx-form-grid--display select.hx-control {
    background-image: none;
  }

  .hx-form-grid--display .hx-form-grid__actions {
    display: none;
  }

  /* A line table that is the only content of a section card: the card heading names it, its own legend is for screen readers only. */
  .hx-form-grid--page .hx-fieldset > .hx-form-grid__fields > .hx-lines:only-child > legend {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* The dense header of the quick entry keeps one-line labels. */
  .hx-line-entry__header .hx-field__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  @media (max-width: 45rem) {
    .hx-form-grid--page > .hx-form-grid__fields > .hx-fieldset:not(.hx-fieldset--compact) {
      padding: var(--space-4);
    }

    .hx-form-bar {
      padding: var(--space-2) var(--space-3);
    }

    .hx-form-bar__status {
      flex-basis: 100%;
    }
  }
}

/*
 * ---------- Anmelderahmen (hx/authSplit, HxAuthSplit; PATTERNS.md "Anmeldeseiten") ----------
 * Two cards on the page ground: left the sheet in the current theme (logo, theme toggle, content, footer), right the
 * brand cover, always dark (data-theme="dark" on the element, so its tokens are the dark ones): navy gradient lit by
 * the cyan from the top right, honeycomb pattern, the generic hexagon mark bleeding off the corner, eyebrow, headline,
 * chips at the bottom left. Narrow: the cover becomes a slim band above the sheet (mark only).
 */
@layer components {
  .hx-auth-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: var(--space-2-5);
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--space-2-5);
    background: var(--bg);
    color: var(--text);
  }

  .hx-auth-split__sheet {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: var(--space-10) clamp(var(--space-6), 4vw, 3.5rem);
    border: var(--size-hairline) solid var(--border-subtle);
    border-radius: var(--radius-xl);
    background: var(--surface);
    box-shadow: var(--shadow-md);
  }

  .hx-auth-split__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: var(--space-10);
  }

  .hx-auth-split__brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2-5);
    min-width: 0;
  }

  .hx-auth-split__logo {
    display: block;
    max-height: var(--space-10);
    max-width: min(14rem, 60vw);
    object-fit: contain;
  }

  /* A letterhead logo is made for white paper: in the dark theme it sits on a light plate so dark lettering stays legible. */
  :root:not([data-theme='light']) .hx-auth-split__logo--plate {
    padding: var(--space-1-5) var(--space-2-5);
    border-radius: var(--radius-md);
    background: var(--text-strong);
  }

  .hx-auth-split__mark {
    width: var(--size-brand-box);
    height: var(--size-brand-box);
    flex: none;
  }

  .hx-auth-split__name {
    overflow: hidden;
    font-family: var(--font-display);
    font-size: var(--size-brand);
    font-weight: 700;
    letter-spacing: var(--tracking-heading);
    color: var(--text-strong);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .hx-auth-split__theme-light { display: none; }
  .hx-auth-split__theme-dark { display: inline-flex; }
  [data-theme='light'] .hx-auth-split__theme-light { display: inline-flex; }
  [data-theme='light'] .hx-auth-split__theme-dark { display: none; }

  .hx-auth-split__body {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    padding-block: var(--space-12);
  }

  .hx-auth-split__panel {
    width: 100%;
    max-width: 24rem;
  }

  /* Content: big welcome title, intro close below it, fields stacked, full-width buttons. */
  .hx-auth-split__panel .hx-page-header__title {
    font-size: 1.75rem;
    line-height: 1.15;
    letter-spacing: var(--tracking-heading);
  }

  .hx-auth-split__panel .hx-page-header + .hx-text {
    margin-top: calc(var(--space-3) * -1);
    font-size: 0.9375rem;
    line-height: 1.6;
  }

  .hx-auth-split__panel .hx-form-grid__fields > * {
    grid-column: 1 / -1;
  }

  .hx-auth-split__panel .hx-form-grid__actions {
    flex-direction: column;
    align-items: stretch;
    margin-top: var(--space-6);
  }

  .hx-auth-split__panel .hx-btn--primary,
  .hx-auth-split__panel .hx-btn--secondary {
    width: 100%;
    height: var(--control-height-lg);
    font-size: var(--size-body);
  }

  .hx-auth-split__panel .hx-btn--ghost.hx-btn--sm {
    justify-self: start;
    margin-top: calc(var(--space-2) * -1);
    margin-left: calc(var(--space-2) * -1);
    padding-inline: var(--space-2);
    color: var(--text-muted);
  }

  .hx-auth-split__panel .hx-btn--ghost.hx-btn--sm:hover:not(:disabled) {
    color: var(--text);
  }

  .hx-auth-split--portal .hx-btn--primary {
    border-color: var(--portal-accent, var(--accent));
    background: var(--portal-accent, var(--accent));
    color: var(--portal-on-accent, var(--on-accent));
  }

  .hx-auth-split__foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-6);
    font: var(--text-small);
    color: var(--text-muted);
  }

  .hx-auth-split__legal {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5);
  }

  .hx-auth-split__legal a {
    color: inherit;
    text-decoration: none;
    text-underline-offset: 3px;
  }

  .hx-auth-split__legal a:hover {
    color: var(--text);
    text-decoration: underline;
  }

  /* Brand cover (dark tokens via data-theme="dark"; text sits bottom left on the darkest part). */
  .hx-auth-split__cover {
    position: relative;
    min-width: 0;
    overflow: hidden;
    isolation: isolate;
    border: var(--size-hairline) solid var(--border-subtle);
    border-radius: var(--radius-xl);
    background:
      radial-gradient(85% 65% at 100% 0%, color-mix(in srgb, var(--accent) 42%, transparent) 0%, transparent 62%),
      radial-gradient(55% 45% at 0% 100%, color-mix(in srgb, var(--accent) 13%, transparent) 0%, transparent 70%),
      linear-gradient(155deg, var(--surface-active) 0%, var(--surface-2) 48%, var(--surface-sunken) 100%);
    box-shadow: var(--shadow-md);
    color: var(--text);
  }

  .hx-auth-split__pattern {
    position: absolute;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    color: color-mix(in srgb, var(--text) 8%, transparent);
    mask-image: linear-gradient(200deg, black 15%, transparent 78%);
  }

  .hx-auth-split__cover-mark {
    position: absolute;
    top: -9%;
    right: -11%;
    z-index: -1;
    width: 54%;
    max-width: 31rem;
    opacity: 0.94;
    filter: drop-shadow(0 var(--space-5) 3.75rem color-mix(in srgb, var(--accent) 32%, transparent));
  }

  /* Uploaded company mark (img, never inline): same place, size and glow as the hexagon; keeps its aspect ratio. */
  .hx-auth-split__cover-img {
    height: auto;
    aspect-ratio: auto;
    object-fit: contain;
    object-position: top right;
    pointer-events: none;
    user-select: none;
  }

  .hx-auth-split__claim {
    position: absolute;
    right: var(--space-12);
    bottom: var(--space-12);
    left: var(--space-12);
    max-width: 30rem;
  }

  .hx-auth-split__eyebrow {
    margin: 0;
    font-size: var(--size-small);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  .hx-auth-split__headline {
    margin: var(--space-3) 0 0;
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 2.3vw, 1.875rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.025em;
    color: var(--text-strong);
    text-wrap: balance;
  }

  .hx-auth-split__chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: var(--space-6) 0 0;
    padding: 0;
    list-style: none;
  }

  .hx-auth-split__chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1-5);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    background: color-mix(in srgb, var(--text) 10%, transparent);
    box-shadow: inset 0 0 0 var(--size-hairline) color-mix(in srgb, var(--text) 14%, transparent);
    backdrop-filter: blur(6px);
    font-size: var(--size-control);
    font-weight: 600;
    color: var(--text-strong);
  }

  .hx-auth-split__chip .hx-icon {
    color: var(--accent);
  }

  /* Generic HxCore hexagon (hx/authSplit :: hexMark): ring and three facets in the accent colour. */
  /* HxCore wordmark: bar cyan, x orange, text follows the theme. */
  .hx-wordmark {
    display: block;
    height: var(--space-7);
    width: auto;
    flex: none;
  }

  .hx-wordmark__bar { fill: var(--primary); }
  .hx-wordmark__text { fill: currentColor; }
  .hx-wordmark__x { fill: var(--highlight); }

  /* Product label after the wordmark (e.g. „Kundenportal“): divider, muted. */
  .hx-auth-split__wordmark + .hx-auth-split__name {
    padding-left: var(--space-2-5);
    border-left: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 500;
  }

  .hx-hexmark {
    display: block;
    color: var(--accent);
  }

  .hx-hexmark__ring {
    fill: none;
    stroke: currentColor;
    stroke-width: 12;
    stroke-linejoin: round;
  }

  .hx-hexmark__top { fill: currentColor; }
  .hx-hexmark__right { fill: currentColor; opacity: 0.62; }
  .hx-hexmark__left { fill: currentColor; opacity: 0.34; }

  @media (max-width: 64rem) {
    .hx-auth-split {
      display: flex;
      flex-direction: column;
      gap: var(--space-2);
      padding: var(--space-2);
    }

    .hx-auth-split__cover {
      order: -1;
      flex: none;
      height: 6.5rem;
      box-shadow: none;
    }

    .hx-auth-split__cover-mark {
      top: 50%;
      right: -1.5rem;
      width: 10rem;
      transform: translateY(-50%);
    }

    .hx-auth-split__claim {
      display: none;
    }

    .hx-auth-split__sheet {
      flex: 1 1 auto;
      padding: var(--space-6);
    }

    .hx-auth-split__body {
      justify-content: center;
      padding-block: var(--space-8);
    }

/* ---------- Input and info panels (Robin 23.11.2026, PATTERNS.md "Eingabe- und Info-Karten") ----------
   Info panels (key/value, tables, text) stay flat and neutral. Input panels (HxPanelKind: operable form, line table,
   upload … inside, server-side class hx-panel--input) get a cyan edge on top, a faintly cyan surface and line, and a
   pencil before the title. Disclosures with a form get the pencil and cyan summary text (the summary is a control). */
@layer components {
  .hx-panel--input {
    border-color: var(--border-input);
    background: var(--surface-input);
    box-shadow: inset 0 var(--size-bar) 0 var(--input-edge);
  }

  .hx-panel__kind {
    width: var(--size-icon);
    height: var(--size-icon);
    margin-inline-end: var(--space-2);
    vertical-align: -0.1em;
    color: var(--accent-text);
  }

  /* A form page keeps its layout (the panel steps back, its sections are the cards): the section cards carry the
     input surface and line, the pencil stays on the title, no edge on every section. */
  .hx-panel--input:has(> .hx-panel__body > .hx-form-grid--page) {
    background: transparent;
    box-shadow: none;
  }

  .hx-form-grid--page > .hx-form-grid__fields > .hx-fieldset:not(.hx-fieldset--compact) {
    border-color: var(--border-input);
    background: var(--surface-input);
  }

  .hx-disclosure--input {
    border-color: var(--border-input);
  }

  .hx-disclosure--input > .hx-disclosure__summary,
  .hx-disclosure--input > .hx-disclosure__summary::marker {
    color: var(--accent-text);
    font-weight: 600;
  }

  .hx-disclosure__kind {
    width: var(--size-icon-sm);
    height: var(--size-icon-sm);
    margin-inline-end: var(--space-1-5);
    vertical-align: -0.15em;
  }
}
