/* ==========================================================================
   TESM Design-System -- Teil 2: Komponenten
   ========================================================================== */

@layer components {
  /* -- Karten ------------------------------------------------------------- */
  .card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-xs);
  }
  .card__header {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border-subtle);
  }
  .card__header > .row { flex: 1; min-width: 0; }
  .card__title {
    font-size: var(--fs-md);
    font-weight: 640;
    letter-spacing: -0.008em;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
  }
  .card__sub {
    font-size: var(--fs-xs);
    color: var(--text-faint);
    margin-top: 2px;
  }
  .card__body { padding: var(--sp-5); }
  .card__body--flush { padding: 0; }
  .card__footer {
    display: flex;
    gap: var(--sp-2);
    justify-content: flex-end;
    padding: var(--sp-3) var(--sp-5);
    border-top: 1px solid var(--border-subtle);
    background: var(--surface-2);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
  }
  .card--accent { border-color: color-mix(in srgb, var(--accent) 42%, var(--border)); }
  .card--danger { border-color: color-mix(in srgb, var(--danger) 42%, var(--border)); }

  /* -- Schaltflaechen ----------------------------------------------------- */
  .btn {
    --btn-bg: var(--surface-1);
    --btn-fg: var(--text);
    --btn-border: var(--border-strong);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 7px 14px;
    min-height: 34px;
    border: 1px solid var(--btn-border);
    border-radius: var(--r-sm);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font-size: var(--fs-base);
    font-weight: 570;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--dur-fast), border-color var(--dur-fast),
      color var(--dur-fast), box-shadow var(--dur-fast), transform var(--dur-fast);
  }
  .btn:hover { background: var(--surface-3); text-decoration: none; }
  .btn:active { transform: translateY(1px); }
  .btn[disabled], .btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
  }
  .btn svg { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 1.9; }

  .btn--primary {
    --btn-bg: var(--accent);
    --btn-fg: var(--accent-text);
    --btn-border: transparent;
    box-shadow: var(--shadow-accent);
  }
  .btn--primary:hover { --btn-bg: var(--accent-hover); }

  .btn--danger {
    --btn-bg: var(--danger);
    --btn-fg: #fff;
    --btn-border: transparent;
  }
  .btn--danger:hover { filter: brightness(1.08); background: var(--danger); }

  .btn--ghost {
    --btn-bg: transparent;
    --btn-border: transparent;
    --btn-fg: var(--text-muted);
  }
  .btn--ghost:hover { --btn-fg: var(--text); background: var(--surface-3); }

  .btn--subtle {
    --btn-bg: var(--surface-3);
    --btn-border: transparent;
  }

  .btn--sm { padding: 4px 10px; min-height: 28px; font-size: var(--fs-sm); }
  .btn--sm svg { width: 14px; height: 14px; }
  .btn--lg { padding: 10px 20px; min-height: 42px; font-size: var(--fs-md); }
  .btn--icon { padding: 7px; min-width: 34px; }
  .btn--icon.btn--sm { padding: 5px; min-width: 28px; }
  .btn--block { width: 100%; }

  .btn-group {
    display: inline-flex;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    overflow: hidden;
  }
  .btn-group .btn {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .btn-group .btn + .btn { border-left: 1px solid var(--border); }
  .btn-group .btn[aria-pressed="true"] {
    background: var(--accent-soft);
    color: var(--accent-soft-text);
  }

  /* -- Formulare ---------------------------------------------------------- */
  .field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
  .field__label {
    font-size: var(--fs-sm);
    font-weight: 570;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--sp-2);
  }
  .field__label .req { color: var(--danger); }
  .field__hint { font-size: var(--fs-xs); color: var(--text-faint); }
  .field__error { font-size: var(--fs-xs); color: var(--danger); font-weight: 550; }
  .field--inline { flex-direction: row; align-items: center; gap: var(--sp-3); }

  .input, .select, .textarea {
    width: 100%;
    padding: 8px 11px;
    min-height: 36px;
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    color: var(--text);
    font-size: var(--fs-base);
    transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  }
  .input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
  .input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
  }
  .input[readonly], .input[disabled], .select[disabled], .textarea[disabled] {
    background: var(--surface-inset);
    color: var(--text-muted);
    cursor: not-allowed;
  }
  .input[aria-invalid="true"] { border-color: var(--danger); }
  .textarea { min-height: 96px; resize: vertical; line-height: var(--lh-normal); }
  .input--mono { font-family: var(--font-mono); font-size: var(--fs-sm); }
  .select {
    appearance: none;
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238f96a6' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 15px;
  }

  .input-group { display: flex; align-items: stretch; }
  .input-group .input { border-radius: var(--r-sm) 0 0 var(--r-sm); }
  .input-group .btn { border-radius: 0 var(--r-sm) var(--r-sm) 0; border-left: 0; }

  .search-input {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 180px;
  }
  .search-input svg {
    position: absolute;
    left: 10px;
    width: 15px;
    height: 15px;
    color: var(--text-faint);
    pointer-events: none;
  }
  .search-input .input { padding-left: 32px; }

  .check {
    display: inline-flex;
    align-items: flex-start;
    gap: var(--sp-2);
    cursor: pointer;
    font-size: var(--fs-base);
    line-height: 1.35;
  }
  .check input[type="checkbox"], .check input[type="radio"] {
    appearance: none;
    flex-shrink: 0;
    width: 17px;
    height: 17px;
    margin: 1px 0 0;
    border: 1.5px solid var(--border-strong);
    border-radius: 5px;
    background: var(--surface-1);
    cursor: pointer;
    transition: background var(--dur-fast), border-color var(--dur-fast);
  }
  .check input[type="radio"] { border-radius: 50%; }
  .check input:checked {
    background: var(--accent);
    border-color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
    background-size: 13px;
    background-position: center;
    background-repeat: no-repeat;
  }
  .check input[type="radio"]:checked {
    background-image: none;
    box-shadow: inset 0 0 0 4px var(--surface-1);
  }
  .check input:disabled { opacity: 0.42; cursor: not-allowed; }
  .check input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .check--disabled { color: var(--text-faint); cursor: not-allowed; }

  .switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
  .switch input {
    appearance: none;
    width: 38px;
    height: 22px;
    border-radius: var(--r-full);
    background: var(--border-strong);
    position: relative;
    cursor: pointer;
    transition: background var(--dur) var(--ease);
    flex-shrink: 0;
  }
  .switch input::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-xs);
    transition: transform var(--dur) var(--ease);
  }
  .switch input:checked { background: var(--accent); }
  .switch input:checked::after { transform: translateX(16px); }
  .switch input:disabled { opacity: 0.45; cursor: not-allowed; }

  fieldset.fieldset {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--sp-4);
    margin: 0;
  }
  fieldset.fieldset > legend {
    padding: 0 var(--sp-2);
    font-size: var(--fs-sm);
    font-weight: 620;
    color: var(--text-muted);
  }

  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: var(--sp-4);
  }
  .form-grid--wide { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
  .form-grid > .field--full { grid-column: 1 / -1; }

  /* -- Tabellen ----------------------------------------------------------- */
  .table-wrap {
    overflow-x: auto;
    border-radius: var(--r-lg);
  }
  .table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fs-base);
  }
  .table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 9px var(--sp-4);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    color: var(--text-faint);
    font-size: var(--fs-xs);
    font-weight: 650;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
  }
  .table tbody td {
    padding: 10px var(--sp-4);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
  }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover { background: var(--surface-2); }
  .table th.sortable { cursor: pointer; user-select: none; }
  .table th.sortable:hover { color: var(--text); }
  .table th.sortable::after {
    content: "\2195";
    margin-left: 5px;
    opacity: 0.4;
    font-size: 1.05em;
  }
  .table th[aria-sort="ascending"]::after { content: "\2191"; opacity: 1; color: var(--accent); }
  .table th[aria-sort="descending"]::after { content: "\2193"; opacity: 1; color: var(--accent); }
  .table td.numeric, .table th.numeric { text-align: right; font-variant-numeric: tabular-nums; }
  .table td.actions { text-align: right; white-space: nowrap; }
  .table td.mono { font-family: var(--font-mono); font-size: var(--fs-sm); }
  .table--compact tbody td { padding: 6px var(--sp-3); }
  .table--fixed { table-layout: fixed; }

  .table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-subtle);
  }
  .table-toolbar__spacer { flex: 1; }

  /* -- Statusanzeigen ----------------------------------------------------- */
  .pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: var(--r-full);
    background: var(--neutral-pill);
    color: var(--neutral-pill-text);
    font-size: var(--fs-xs);
    font-weight: 650;
    white-space: nowrap;
    line-height: 1.5;
  }
  .pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
  }
  .pill--plain::before { display: none; }
  .pill--online, .pill--ok, .pill--success, .pill--green {
    background: var(--success-soft);
    color: var(--success);
  }
  .pill--offline, .pill--error, .pill--danger, .pill--red {
    background: var(--danger-soft);
    color: var(--danger);
  }
  .pill--warning, .pill--unknown, .pill--orange {
    background: var(--warning-soft);
    color: var(--warning);
  }
  .pill--info, .pill--blue { background: var(--info-soft); color: var(--info); }
  .pill--accent, .pill--admin { background: var(--accent-soft); color: var(--accent-soft-text); }
  .pill--lg { padding: 5px 12px; font-size: var(--fs-sm); }

  .status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 12px;
    border-radius: var(--r-full);
    background: var(--surface-1);
    border: 1px solid var(--border);
    font-size: var(--fs-sm);
    font-weight: 570;
    color: var(--text-muted);
    white-space: nowrap;
  }
  .status-pill__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
  }
  .status-pill__dot--pulse { animation: pulse-ring 2.4s var(--ease) infinite; }
  .status-pill--danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); color: var(--danger); }
  .status-pill--danger .status-pill__dot { background: var(--danger); }
  .status-pill--warning { border-color: color-mix(in srgb, var(--warning) 45%, var(--border)); color: var(--warning); }
  .status-pill--warning .status-pill__dot { background: var(--warning); }

  @keyframes pulse-ring {
    0%   { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
    70%  { box-shadow: 0 0 0 6px transparent; opacity: 0.85; }
    100% { box-shadow: 0 0 0 0 transparent; opacity: 1; }
  }

  .badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    border-radius: var(--r-xs);
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-weight: 620;
    font-family: var(--font-mono);
  }

  .avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent-soft-text);
    font-size: var(--fs-sm);
    font-weight: 700;
    object-fit: cover;
    overflow: hidden;
  }
  .avatar--lg { width: 56px; height: 56px; font-size: var(--fs-lg); }
  .avatar--sm { width: 24px; height: 24px; font-size: var(--fs-xs); }

  /* -- Kennzahlen --------------------------------------------------------- */
  .stat {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: var(--sp-4);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    transition: border-color var(--dur-fast), transform var(--dur-fast);
  }
  a.stat:hover, button.stat:hover {
    border-color: var(--accent);
    text-decoration: none;
    transform: translateY(-1px);
  }
  .stat[aria-pressed="true"] {
    border-color: var(--accent);
    background: var(--accent-soft);
  }
  .stat__label {
    font-size: var(--fs-xs);
    font-weight: 620;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-faint);
  }
  .stat__value {
    font-size: var(--fs-2xl);
    font-weight: 680;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
  }
  .stat__hint { font-size: var(--fs-xs); color: var(--text-faint); }
  .stat--ok .stat__value { color: var(--success); }
  .stat--danger .stat__value { color: var(--danger); }
  .stat--warning .stat__value { color: var(--warning); }
  .stat--muted .stat__value { color: var(--text-faint); }
  button.stat { cursor: pointer; text-align: left; font: inherit; }

  .progress {
    height: 6px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    overflow: hidden;
  }
  .progress__bar {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width var(--dur-slow) var(--ease);
  }
  .progress--success .progress__bar { background: var(--success); }
  .progress--danger .progress__bar { background: var(--danger); }

  /* -- Hinweise ----------------------------------------------------------- */
  .alert {
    display: flex;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
  }
  .alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
  .alert__body { min-width: 0; flex: 1; }
  .alert__title { font-weight: 640; margin-bottom: 2px; }
  .alert--info { background: var(--info-soft); border-color: transparent; color: var(--text); }
  .alert--info svg { color: var(--info); }
  .alert--success { background: var(--success-soft); border-color: transparent; }
  .alert--success svg { color: var(--success); }
  .alert--warning { background: var(--warning-soft); border-color: transparent; }
  .alert--warning svg { color: var(--warning); }
  .alert--danger { background: var(--danger-soft); border-color: transparent; }
  .alert--danger svg { color: var(--danger); }

  .empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-12) var(--sp-5);
    text-align: center;
    color: var(--text-muted);
  }
  .empty svg { width: 34px; height: 34px; color: var(--text-faint); stroke-width: 1.4; }
  .empty__title { font-size: var(--fs-md); font-weight: 620; color: var(--text); }
  .empty p { max-width: 46ch; font-size: var(--fs-base); }

  /* -- Toasts ------------------------------------------------------------- */
  .toast-stack {
    position: fixed;
    top: var(--sp-4);
    right: var(--sp-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    width: min(380px, calc(100vw - var(--sp-8)));
    pointer-events: none;
  }
  .toast {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    font-size: var(--fs-base);
    pointer-events: auto;
    animation: toast-in var(--dur) var(--ease);
  }
  .toast--success { border-left-color: var(--success); }
  .toast--danger { border-left-color: var(--danger); }
  .toast--warning { border-left-color: var(--warning); }
  .toast--info { border-left-color: var(--info); }
  .toast__body { flex: 1; min-width: 0; line-height: var(--lh-normal); }
  .toast__close {
    flex-shrink: 0;
    padding: 0;
    width: 20px;
    height: 20px;
    border: 0;
    background: none;
    color: var(--text-faint);
    cursor: pointer;
    line-height: 1;
    font-size: 17px;
  }
  .toast__close:hover { color: var(--text); }
  .toast.is-leaving { animation: toast-out 160ms var(--ease) forwards; }

  @keyframes toast-in {
    from { opacity: 0; transform: translateX(14px) scale(0.98); }
    to { opacity: 1; transform: none; }
  }
  @keyframes toast-out {
    to { opacity: 0; transform: translateX(14px) scale(0.98); }
  }

  /* -- Dialoge ------------------------------------------------------------ */
  dialog.modal {
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface-1);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    width: min(560px, calc(100vw - var(--sp-8)));
    max-height: calc(100dvh - var(--sp-12));
    overflow: visible;
  }
  dialog.modal--wide { width: min(880px, calc(100vw - var(--sp-8))); }
  dialog.modal--narrow { width: min(420px, calc(100vw - var(--sp-8))); }
  dialog.modal::backdrop {
    background: var(--surface-overlay);
    backdrop-filter: blur(3px);
  }
  dialog.modal[open] { animation: modal-in var(--dur) var(--ease); }
  @keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(0.985); }
    to { opacity: 1; transform: none; }
  }
  .modal__header {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border-subtle);
  }
  .modal__title { font-size: var(--fs-md); font-weight: 640; flex: 1; }
  .modal__sub { font-size: var(--fs-xs); color: var(--text-faint); margin-top: 2px; }
  .modal__body {
    padding: var(--sp-5);
    overflow-y: auto;
    max-height: min(64dvh, 640px);
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
  }
  .modal__footer {
    display: flex;
    gap: var(--sp-2);
    justify-content: flex-end;
    padding: var(--sp-3) var(--sp-5);
    border-top: 1px solid var(--border-subtle);
    background: var(--surface-2);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
  }
  .modal__footer--split { justify-content: space-between; }

  /* -- Tabs --------------------------------------------------------------- */
  .tabs {
    display: flex;
    gap: var(--sp-1);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .tab {
    padding: 9px var(--sp-3);
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-muted);
    font-size: var(--fs-base);
    font-weight: 570;
    white-space: nowrap;
    cursor: pointer;
  }
  .tab:hover { color: var(--text); text-decoration: none; }
  .tab[aria-selected="true"], .tab.is-active {
    color: var(--accent);
    border-bottom-color: var(--accent);
  }

  /* -- Befehlspalette ----------------------------------------------------- */
  dialog.palette {
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface-1);
    box-shadow: var(--shadow-lg);
    width: min(560px, calc(100vw - var(--sp-6)));
    margin-top: 10vh;
    overflow: hidden;
  }
  dialog.palette::backdrop { background: var(--surface-overlay); backdrop-filter: blur(3px); }
  .palette__input {
    width: 100%;
    padding: var(--sp-4) var(--sp-5);
    border: 0;
    border-bottom: 1px solid var(--border-subtle);
    background: none;
    color: var(--text);
    font-size: var(--fs-md);
  }
  .palette__input:focus { outline: none; }
  .palette__list { max-height: 46dvh; overflow-y: auto; padding: var(--sp-2); }
  .palette__item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    padding: 9px var(--sp-3);
    border: 0;
    border-radius: var(--r-sm);
    background: none;
    color: var(--text);
    font-size: var(--fs-base);
    text-align: left;
    cursor: pointer;
  }
  .palette__item svg { width: 16px; height: 16px; color: var(--text-faint); flex-shrink: 0; }
  .palette__item:hover, .palette__item.is-active { background: var(--accent-soft); color: var(--accent-soft-text); }
  .palette__item.is-active svg { color: currentColor; }
  .palette__group { margin-left: auto; font-size: var(--fs-xs); color: var(--text-faint); }
  .palette__hint {
    padding: var(--sp-2) var(--sp-5);
    border-top: 1px solid var(--border-subtle);
    background: var(--surface-2);
    font-size: var(--fs-xs);
    color: var(--text-faint);
    display: flex;
    gap: var(--sp-4);
  }

  kbd {
    display: inline-block;
    padding: 1px 5px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-xs);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-family: var(--font-mono);
    line-height: 1.5;
  }

  /* -- Rechtematrix ------------------------------------------------------- */
  .matrix { width: 100%; border-collapse: separate; border-spacing: 0; }
  .matrix th, .matrix td { padding: 7px var(--sp-3); border-bottom: 1px solid var(--border-subtle); }
  .matrix thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-2);
    font-size: var(--fs-xs);
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    text-align: center;
  }
  .matrix thead th:first-child { text-align: left; }
  .matrix td:not(:first-child), .matrix th:not(:first-child) { width: 62px; text-align: center; }
  .matrix tr.matrix__area > td {
    background: var(--surface-2);
    font-weight: 640;
  }
  .matrix tr.matrix__area > td:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); }
  .matrix tr.is-locked td:not(.matrix__killswitch) { opacity: 0.42; }
  /* Was es fuer eine Zeile nicht gibt: dunkler und eingesenkt statt heller.
     Vorher war es ein natives Kaestchen -- im dunklen Thema ein helles Quadrat,
     das kraeftiger wirkte als ein echtes, nicht gesetztes Recht. */
  .matrix__na {
    display: inline-block;
    width: 17px;
    height: 17px;
    border-radius: 5px;
    background: var(--surface-0);
    border: 1px solid var(--border-subtle);
    box-shadow: inset 0 1px 2px rgb(0 0 0 / 28%);
    vertical-align: -3px;
    opacity: 0.55;
  }
  .matrix__resource-label { display: flex; flex-direction: column; gap: 1px; }
  .matrix__resource-label small { color: var(--text-faint); font-size: var(--fs-xs); }
  .matrix__legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-4);
    font-size: var(--fs-xs);
    color: var(--text-muted);
  }
  .matrix__legend b { color: var(--text); font-family: var(--font-mono); }

  /* -- Sonstiges ---------------------------------------------------------- */
  .code-block {
    margin: 0;
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface-inset);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
    line-height: 1.55;
    overflow-x: auto;
    white-space: pre;
    tab-size: 2;
  }
  .code-block--wrap { white-space: pre-wrap; word-break: break-all; }

  .log-view {
    margin: 0;
    padding: var(--sp-3) var(--sp-4);
    max-height: 62dvh;
    overflow: auto;
    background: var(--surface-inset);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
  }
  .log-view mark { background: var(--warning-soft); color: var(--warning); border-radius: 3px; }

  .kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-base); }
  .kv dt { color: var(--text-faint); white-space: nowrap; }
  .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

  .breadcrumb { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-faint); }
  .breadcrumb a { color: var(--text-muted); }
  .breadcrumb span::after { content: "/"; margin-left: 6px; opacity: 0.5; }
  .breadcrumb > :last-child::after { content: none; }

  .divider { height: 1px; background: var(--border-subtle); margin: var(--sp-2) 0; }

  .hint-icon {
    display: inline-grid;
    place-items: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--text-faint);
    font-size: 10px;
    font-weight: 700;
    cursor: help;
    flex-shrink: 0;
  }
  .hint-icon:hover { background: var(--accent-soft); color: var(--accent-soft-text); }

  .skeleton {
    border-radius: var(--r-sm);
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
    min-height: 1em;
  }
  @keyframes shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
  }

  .spin { animation: spin 900ms linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* -- Anmeldeseite ------------------------------------------------------- */
  .auth-page {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: var(--sp-6);
    background:
      radial-gradient(1100px 520px at 12% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%),
      radial-gradient(900px 480px at 100% 110%, color-mix(in srgb, var(--info) 10%, transparent), transparent 70%),
      var(--canvas);
  }
  .auth-card {
    width: min(410px, 100%);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-8) var(--sp-6);
    display: flex;
    flex-direction: column;
    gap: var(--sp-5);
  }
  .auth-card--wide { width: min(520px, 100%); }
  .auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-3);
    text-align: center;
  }
  .auth-brand__mark {
    width: 46px;
    height: 46px;
    border-radius: var(--r-md);
    display: grid;
    place-items: center;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 800;
    font-size: var(--fs-lg);
  }
  .auth-brand h1 { font-size: var(--fs-xl); }
  .auth-brand p { color: var(--text-muted); font-size: var(--fs-sm); }
  .auth-footnote { text-align: center; font-size: var(--fs-xs); color: var(--text-faint); }
}

@layer utilities {
  .muted { color: var(--text-muted); }
  .faint { color: var(--text-faint); }
  .danger-text { color: var(--danger); }
  .success-text { color: var(--success); }
  .warning-text { color: var(--warning); }
  .accent-text { color: var(--accent); }
  .mono { font-family: var(--font-mono); font-size: 0.94em; }
  .nowrap { white-space: nowrap; }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .break-all { overflow-wrap: anywhere; }
  .tabular { font-variant-numeric: tabular-nums; }
  .fs-xs { font-size: var(--fs-xs); }
  .fs-sm { font-size: var(--fs-sm); }
  .fs-lg { font-size: var(--fs-lg); }
  .fw-600 { font-weight: 620; }
  .center { text-align: center; }
  .right { text-align: right; }
  .flex-1 { flex: 1; min-width: 0; }
  .mt-0 { margin-top: 0; }
  .mt-2 { margin-top: var(--sp-2); }
  .mt-3 { margin-top: var(--sp-3); }
  .mt-4 { margin-top: var(--sp-4); }
  .mb-2 { margin-bottom: var(--sp-2); }
  .mb-3 { margin-bottom: var(--sp-3); }
  .mb-4 { margin-bottom: var(--sp-4); }
  .gap-2 { gap: var(--sp-2); }
  .gap-4 { gap: var(--sp-4); }
  .w-full { width: 100%; }
  .hide-sm { }
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
  @media (max-width: 760px) {
    .hide-sm { display: none !important; }
  }
}
