/* ============================================================================
   FamilyHub Komponenten (aus BusinessHub übernommen)
   Alle Klassen nutzen ausschließlich semantische Tokens (tokens.css).
   Legacy-Namen (btn, card, badge, form-control, table-responsive, alert, tabs,
   stat-card, empty-state, kanban-modal-*) bleiben erhalten und werden hier neu
   gestylt, damit noch nicht migrierte Seiten weiter funktionieren.
   ============================================================================ */

/* ---------------------------------------------------------------- Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    min-height: 40px; padding: 0 var(--sp-4);
    border-radius: var(--r-sm); border: 1px solid transparent;
    font-size: var(--fs-base); font-weight: 500; line-height: 1.2; white-space: nowrap;
    background: var(--color-surface-2); color: var(--color-text);
    cursor: pointer; text-decoration: none; user-select: none;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; background: var(--color-surface-3); }
.btn:active { transform: translateY(1px); }
.btn .icon { width: 1.15em; height: 1.15em; }

.btn-primary { background: var(--color-primary); color: var(--color-primary-fg); }
.btn-primary:hover { background: var(--color-primary-hover); color: var(--color-primary-fg); }
.btn-accent { background: var(--color-accent); color: var(--color-accent-fg); }
.btn-accent:hover { background: var(--color-primary-hover); color: var(--color-accent-fg); }
.btn-secondary, .btn-light { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover, .btn-light:hover { background: var(--color-surface-2); }
.btn-outline { background: transparent; border-color: var(--color-border-strong); color: var(--color-text); }
.btn-outline:hover { background: var(--color-surface-2); }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }
.btn-danger { background: var(--color-danger-solid); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--color-danger); border-color: transparent; }
.btn-danger-ghost:hover { background: var(--color-danger-bg); color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger-solid-hover); color: #fff; }
.btn-success { background: var(--color-success-solid); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }
.btn-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: transparent; }
.btn-warning:hover { background: #fde68a; color: #854d0e; }
.btn-info { background: var(--color-info-bg); color: var(--color-info); }
.btn-info:hover { background: #bfdbfe; }
.btn-outline-danger { background: transparent; border-color: var(--color-danger); color: var(--color-danger); }
.btn-outline-danger:hover { background: var(--color-danger-bg); }
.btn-outline-success { background: transparent; border-color: var(--color-success); color: var(--color-success); }
.btn-outline-success:hover { background: var(--color-success-bg); }
.btn-outline-secondary { background: transparent; border-color: var(--color-border-strong); color: var(--color-text-muted); }
.btn-outline-secondary:hover { background: var(--color-surface-2); }
.btn-link { background: none; color: var(--color-link); padding: 0; min-height: 0; }
.btn-link:hover { text-decoration: underline; background: none; }

.btn-sm { min-height: 34px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn-lg { min-height: 48px; padding: 0 var(--sp-6); font-size: var(--fs-md); }
.btn-icon { padding: 0; width: 40px; min-width: 40px; }
.btn-icon.btn-sm { width: 34px; min-width: 34px; }
.btn-block { width: 100%; }
.btn-disabled { pointer-events: none; opacity: 0.55; }
.btn-remove { background: var(--color-surface-2); color: var(--color-danger); border: 0; border-radius: var(--r-sm); min-width: 36px; min-height: 36px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.btn-remove:hover { background: var(--color-danger-bg); }

.btn-group { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.btn-group form { display: contents; }
.btn-group form[style*="inline"] { display: contents !important; }

@media (max-width: 768px) {
    .btn { min-height: var(--touch); font-size: var(--fs-md); }
    .btn-sm { min-height: 40px; font-size: var(--fs-base); }
    .btn-icon { width: var(--touch); min-width: var(--touch); }
    .btn-icon.btn-sm { width: 40px; min-width: 40px; }
}

/* --------------------------------------------------------------- Badges */
.badge {
    display: inline-flex; align-items: center; gap: 0.35em;
    padding: 0.2em 0.65em; border-radius: var(--r-full);
    font-size: var(--fs-xs); font-weight: 600; line-height: 1.4; white-space: nowrap;
    background: var(--color-surface-2); color: var(--color-text-muted);
}
.badge .icon { width: 1em; height: 1em; }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-bg);  color: var(--color-danger); }
.badge-info    { background: var(--color-info-bg);    color: var(--color-info); }
.badge-primary { background: var(--color-primary-soft); color: var(--color-accent-text); }
.badge-accent  { background: var(--color-accent-soft); color: var(--color-accent-text); }
.badge-secondary, .badge-dark { background: var(--color-surface-2); color: var(--color-text-muted); }
.badge-solid   { background: var(--color-primary); color: var(--color-primary-fg); }
.badge-dot::before { content: ''; width: 0.5em; height: 0.5em; border-radius: 50%; background: currentColor; }
.badge-lg { font-size: var(--fs-sm); padding: 0.3em 0.8em; }

/* ---------------------------------------------------------------- Cards */
.card {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--r); box-shadow: var(--shadow-xs); overflow: hidden;
}
.card + .card, .card + .stats-grid, .stats-grid + .card { margin-top: var(--sp-4); }
.card-header {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
    padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--color-border);
}
.card-title { font-size: var(--fs-md); font-weight: 600; display: flex; align-items: center; gap: var(--sp-2); margin: 0; }
.card-title .icon { color: var(--color-accent-text); }
.card-body { padding: var(--sp-4); }
.card-footer { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--color-border); display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: flex-end; }
.card-body > .card-body { padding: 0; }
.card-subtitle { flex: 1 0 100%; margin: 0; font-size: var(--fs-sm); color: var(--color-text-muted); }
.card-header-inner { border-top: 1px solid var(--color-border); }
.card-footer.card-footer-start { justify-content: flex-start; }
.form-row-cards { align-items: start; }
.form-row-cards > .card { margin: 0; }
.inline-actions { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
/* Einzeilige Info + Aktionen (z.B. PDF-Zeile) */
.pdf-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.pdf-row-text { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.pdf-row-text > .icon { color: var(--color-accent-text); flex-shrink: 0; width: 1.25rem; height: 1.25rem; }
.pdf-row-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
@media (max-width: 600px) { .pdf-row-actions { width: 100%; } .pdf-row-actions .btn, .pdf-row-actions form { flex: 1; } .pdf-row-actions form .btn { width: 100%; } }
.card.is-flush .card-body { padding: 0; }
.card-accent { border-left: 4px solid var(--color-accent); }
.card-info    { border-left: 4px solid var(--color-info);    background: var(--color-surface); }
.card-warning { border-left: 4px solid var(--color-warning); }
.card-danger  { border-left: 4px solid var(--color-danger); }
.card-success { border-left: 4px solid var(--color-success); }
@media (min-width: 769px) { .card-body { padding: var(--sp-5); } .card-header { padding: var(--sp-4) var(--sp-5); } }

/* Aufklappbare Karten-Sektion (Details/Summary) */
.card details > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--sp-2); }
.card details > summary::-webkit-details-marker { display: none; }

/* ------------------------------------------------------------- Seitenkopf */
.page-header {
    display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
    gap: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4);
}
.page-header > div:first-child, .page-header-main { flex: 1 1 260px; min-width: 0; }
.page-header-actions, .page-header > .btn-group, .page-header > div:not(:first-child) {
    display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; flex: 0 1 auto;
}
.page-title {
    font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.01em; color: var(--color-text);
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-1);
}
.page-title .badge { font-size: var(--fs-xs); }
.page-subtitle { color: var(--color-text-muted); font-size: var(--fs-sm); margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.35em var(--sp-2); }
.page-back { display: inline-flex; align-items: center; gap: var(--sp-1); color: var(--color-text-muted); font-size: var(--fs-sm); margin-bottom: var(--sp-2); }
.page-back:hover { color: var(--color-text); text-decoration: none; }
@media (min-width: 769px) { .page-title { font-size: var(--fs-2xl); } .page-header { margin-bottom: var(--sp-6); } }
@media (max-width: 768px) {
    /* Aktionen unter dem Titel, volle Breite, nie neben dem Titel */
    .page-header-actions, .page-header > .btn-group, .page-header > div:not(:first-child) { flex: 1 0 100%; }
    .page-header-actions > .btn, .page-header > div:not(:first-child) > .btn,
    .page-header-actions form, .page-header > div:not(:first-child) form { flex: 1 1 auto; }
    .page-header-actions > .btn-primary, .page-header > div:not(:first-child) > .btn-primary { flex-basis: 100%; }
    .page-header-actions > .menu, .page-header > div:not(:first-child) > .menu { flex: 0 0 auto; }
    /* Nur Hauptknopf und ⋯-Menü: beide in eine Zeile. Die Regel darüber gibt
       dem Hauptknopf sonst eine ganze Zeile, und das Menü hing verloren
       darunter (Buchhaltung, Ausgaben). Mit weiteren Knöpfen bleibt der
       Hauptknopf oben allein. Prüfen: node tools/ui-audit/header-check.js */
    .page-header-actions > .btn-primary:first-child:nth-last-child(2):has(+ .menu),
    .page-header > div:not(:first-child) > .btn-primary:first-child:nth-last-child(2):has(+ .menu) { flex: 1 1 0; }
    /* Speichern + Versenden (Angebot bearbeiten) teilen sich die erste Zeile;
       dahinter passen Kundenansicht und ⋯ in die zweite. Mit dem Hauptknopf
       allein oben rutschte das Menü in eine dritte Zeile. */
    .page-header-actions > .btn-primary:first-child:has(+ .btn-success) { flex: 1 1 0; }
    .page-header-actions form .btn, .page-header > div:not(:first-child) form .btn { width: 100%; }
}

/* ------------------------------------------------------------ Filterleiste */
.toolbar {
    display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); align-items: flex-end;
    padding: var(--sp-3) var(--sp-4); background: var(--color-surface);
    border: 1px solid var(--color-border); border-radius: var(--r); margin-bottom: var(--sp-4);
}
.toolbar .form-group { margin: 0; flex: 1 1 160px; min-width: 0; }
.toolbar .form-group.is-search { flex: 2 1 220px; }
.toolbar .form-label { font-size: var(--fs-xs); margin-bottom: 4px; }
.toolbar .toolbar-actions { display: flex; gap: var(--sp-2); flex: 0 0 auto; }
.toolbar .form-check { min-height: 40px; }
@media (max-width: 768px) {
    .toolbar { padding: var(--sp-3); }
    .toolbar .form-group { flex: 1 1 calc(50% - var(--sp-2)); }
    .toolbar .form-group.is-search, .toolbar .toolbar-actions { flex: 1 1 100%; }
    .toolbar .toolbar-actions .btn { flex: 1; }
    /* Zusammenklappbar auf Mobile */
    .toolbar[data-collapsible] > :not(.toolbar-toggle):not(.is-search):not(.toolbar-actions) { display: none; }
    .toolbar[data-collapsible].is-open > * { display: flex; }
}
.toolbar-toggle { display: none; }
@media (max-width: 768px) { .toolbar-toggle { display: inline-flex; flex: 0 0 auto; } }

/* --------------------------------------------------------------- Formulare */
.form-group { margin-bottom: var(--sp-4); }
.form-label { display: block; margin-bottom: var(--sp-1); font-weight: 500; font-size: var(--fs-sm); color: var(--color-text); }
.form-label .req, .form-label abbr { color: var(--color-danger); text-decoration: none; }
.form-hint, .form-text, .form-group small, .form-group .text-muted:not(.badge) { display: block; margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--color-text-muted); line-height: 1.45; }
.form-error { color: var(--color-danger); font-size: var(--fs-xs); margin-top: var(--sp-1); }

.form-control, .form-select, .q-input, .q-textarea {
    display: block; width: 100%; min-height: 40px; padding: 0.5rem 0.75rem;
    background: var(--color-input-bg); color: var(--color-text);
    border: 1px solid var(--color-input-border); border-radius: var(--r-sm);
    font-size: var(--fs-base); line-height: 1.4;
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.form-control:focus, .form-select:focus, .q-input:focus, .q-textarea:focus {
    outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px var(--color-ring-glow);
}
.form-control::placeholder { color: var(--color-text-faint); }
.form-control[readonly], .form-control:disabled { background: var(--color-surface-2); color: var(--color-text-muted); }
.form-control.is-invalid { border-color: var(--color-danger); }
.form-control-sm { min-height: 34px; padding: 0.3rem 0.6rem; font-size: var(--fs-sm); }
textarea.form-control { min-height: 96px; resize: vertical; line-height: 1.5; }
select.form-control, .form-select {
    appearance: none; padding-right: 2.25rem; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%234a5a6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.7rem center;
}
html[data-theme="dark"] select.form-control, html[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a7b6c5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
select.form-control[multiple] { background-image: none; padding-right: 0.75rem; }
input[type="date"].form-control, input[type="datetime-local"].form-control { min-width: 0; }
input[type="file"].form-control { padding: 0.35rem 0.5rem; cursor: pointer; }
input[type="file"].form-control::file-selector-button {
    border: 1px solid var(--color-border-strong); background: var(--color-surface-2); color: var(--color-text);
    border-radius: var(--r-sm); padding: 0.3rem 0.75rem; margin-right: 0.75rem; font: inherit; font-size: var(--fs-sm); cursor: pointer;
}
input[type="color"].form-control { padding: 2px; width: 48px; }
@media (max-width: 768px) {
    .form-control, .form-select, .q-input, .q-textarea { min-height: var(--touch); font-size: 16px; } /* verhindert Zoom auf iOS */
    .form-control-sm { min-height: 40px; font-size: 15px; }
}

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--sp-3) var(--sp-4); }
.form-row .form-group { margin-bottom: 0; }
.form-row + .form-row, .form-row + .form-group, .form-group + .form-row { margin-top: var(--sp-4); }
.form-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: var(--sp-4) var(--sp-5); }

.form-check, .custom-control { display: flex; align-items: flex-start; gap: var(--sp-2); cursor: pointer; font-size: var(--fs-base); }
.form-check input, .custom-control-input { width: 18px; height: 18px; margin-top: 0.15em; accent-color: var(--color-accent); flex-shrink: 0; cursor: pointer; }
.form-check-inline { display: inline-flex; margin-right: var(--sp-4); }
.form-check-group { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); }
/* Erklärung unter der Beschriftung. Stand bisher nur in settings.css und
   griff deshalb nur in den Einstellungen; im Ausgaben-Formular lief der
   Hinweis in derselben Zeile weiter. */
.form-check span > small { display: block; font-weight: 400; color: var(--color-text-muted); font-size: var(--fs-xs); margin-top: 2px; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; padding-top: var(--sp-4); margin-top: var(--sp-4); border-top: 1px solid var(--color-border); }
.form-actions .spacer { flex: 1; }
/* Aktionen direkt unter ihrem Block, ohne trennende Linie darueber —
   fuer eingebettete Formulare wie den Upload in der Dokumentenkarte. */
.form-actions-flush { padding-top: var(--sp-3); margin-top: 0; border-top: 0; }
@media (max-width: 768px) { .form-actions .btn { flex: 1 1 calc(50% - var(--sp-2)); } .form-actions .btn-primary { flex-basis: 100%; order: -1; } }

/* Umschalter (Netto/Brutto etc.) */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-slider { position: absolute; inset: 0; background: var(--color-border-strong); border-radius: var(--r-full); transition: background var(--dur) var(--ease); }
.switch-slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; box-shadow: var(--shadow-xs); transition: transform var(--dur) var(--ease); }
.switch input:checked + .switch-slider { background: var(--color-accent); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:focus-visible + .switch-slider { outline: 2px solid var(--color-ring); outline-offset: 2px; }
.switch-group { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); font-weight: 500; background: var(--color-surface); border: 1px solid var(--color-border); padding: 4px 10px; border-radius: var(--r-full); }
.switch-group .switch-label { color: var(--color-text-faint); }
.switch-group .switch-label.active { color: var(--color-text); }

/* Segment-Auswahl (Radio als Buttons) */
.segmented { display: inline-flex; background: var(--color-surface-2); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.segmented label { position: relative; padding: 0.35rem 0.8rem; border-radius: 4px; font-size: var(--fs-sm); font-weight: 500; color: var(--color-text-muted); cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.segmented label:has(input:checked) { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-xs); }
/* Umschalter als Links (Finanzen, Aufgaben) */
.segmented a { display: inline-flex; align-items: center; min-height: 32px; padding: 0.3rem 0.8rem; border-radius: 4px; font-size: var(--fs-sm); font-weight: 500; color: var(--color-text-muted); text-decoration: none; white-space: nowrap; }
.segmented a:hover { color: var(--color-text); text-decoration: none; }
.segmented a.active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-xs); }


/* ------------------------------------------------------------- Tabellen */
.table-wrap, .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table.table, .table-responsive table, .table-wrap table, .table-scroll table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
th, td { padding: 0.65rem 0.85rem; text-align: left; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
thead th {
    background: var(--color-surface-2); color: var(--color-text-muted);
    font-size: var(--fs-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--color-surface-2); }
tr.is-muted td { color: var(--color-text-muted); }
td.actions, th.actions { text-align: right; white-space: nowrap; }
td.actions .btn-group { justify-content: flex-end; flex-wrap: nowrap; }
td .badge { vertical-align: middle; }
.table-sm th, .table-sm td { padding: 0.4rem 0.6rem; font-size: var(--fs-sm); }
.detail-table th { background: transparent; text-transform: none; letter-spacing: 0; font-size: var(--fs-sm); font-weight: 500; color: var(--color-text-muted); width: 34%; }

/* Karten-Modus auf Mobile (Legacy-Klasse .table-responsive + neue .table-cards) */
@media (max-width: 768px) {
    .table-responsive, .table-cards { overflow: visible; }
    .table-responsive table, .table-responsive thead, .table-responsive tbody, .table-responsive tr, .table-responsive td, .table-responsive th,
    .table-cards table, .table-cards thead, .table-cards tbody, .table-cards tr, .table-cards td, .table-cards th { display: block; }
    .table-responsive thead, .table-cards thead { display: none; }
    .table-responsive tr, .table-cards tr {
        background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r);
        padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-3); box-shadow: var(--shadow-xs);
        position: relative;
    }
    .table-responsive tr:hover td, .table-cards tr:hover td { background: transparent; }
    .table-responsive td, .table-cards td {
        display: grid; grid-template-columns: minmax(84px, 38%) 1fr; gap: var(--sp-3); align-items: start;
        padding: 0.45rem 0; border-bottom: 1px solid var(--color-border); text-align: left;
    }
    .table-responsive td:last-child, .table-cards td:last-child { border-bottom: 0; }
    .table-responsive td::before, .table-cards td::before {
        content: attr(data-label); font-size: var(--fs-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
        color: var(--color-text-muted); padding-top: 0.2em; overflow-wrap: normal; word-break: normal; hyphens: manual;
    }
    .table-responsive td:not([data-label])::before, .table-responsive td[data-label=""]::before,
    .table-cards td:not([data-label])::before, .table-cards td[data-label=""]::before { display: none; }
    .table-responsive td:not([data-label]), .table-responsive td[data-label=""],
    .table-cards td:not([data-label]), .table-cards td[data-label=""] { grid-template-columns: 1fr; }
    .table-responsive td.text-right, .table-cards td.text-right { text-align: left; }
    /* Erste Zelle = Titel der Karte */
    .table-responsive td:first-child, .table-cards td:first-child { grid-template-columns: 1fr; font-size: var(--fs-md); font-weight: 600; padding-top: 0; padding-right: 44px; }
    .table-responsive td:first-child::before, .table-cards td:first-child::before { display: none; }
    /* Aktionen: als Reihe unten (Legacy) bzw. „⋯"-Menü oben rechts (neu, .row-menu) */
    .table-responsive td.actions, .table-cards td.actions { grid-template-columns: 1fr; padding-top: var(--sp-3); padding-bottom: 0; }
    .table-responsive td.actions::before, .table-cards td.actions::before { display: none; }
    .table-responsive td.actions .btn-group, .table-cards td.actions .btn-group { justify-content: stretch; flex-wrap: wrap; }
    .table-responsive td.actions .btn, .table-cards td.actions .btn { flex: 1 1 calc(50% - var(--sp-2)); }
    td.actions.has-menu { position: absolute; top: var(--sp-2); right: var(--sp-2); padding: 0; border: 0; width: auto; }
    td.actions.has-menu .btn-group { display: none; }
}
@media (min-width: 769px) { .row-menu-only-mobile { display: none !important; } }

/* Sortierbare Spaltenköpfe: Link füllt die Zelle, aktive Spalte hervorgehoben (aria-sort) */
th.th-sortable { padding: 0; }
th.th-sortable a { display: flex; align-items: center; gap: 0.3em; padding: 0.65rem 0.85rem; color: inherit; text-decoration: none; white-space: nowrap; }
th.th-sortable a:hover { color: var(--color-text); }
th.th-sortable .icon { width: 14px; height: 14px; opacity: 0.55; flex-shrink: 0; }
th.th-sortable[aria-sort] a { color: var(--color-text); }
th.th-sortable[aria-sort] .icon { opacity: 1; color: var(--color-accent-text); }
th.th-sortable.text-right a { justify-content: flex-end; }

/* Seitennavigation unter Listen */
.pagination { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--color-border); background: var(--color-surface-2); }
.pagination-info { color: var(--color-text-muted); font-size: var(--fs-sm); margin-right: auto; font-variant-numeric: tabular-nums; }
.pagination-page { color: var(--color-text-muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.pagination .btn.is-disabled { opacity: 0.5; pointer-events: none; }
@media (max-width: 768px) {
    .pagination { padding: var(--sp-2) 0 0; border-top: 0; background: transparent; }
    .pagination-info { flex: 1 1 100%; }
    .pagination .btn { flex: 1; }
}

/* ------------------------------------------------------------- Dropdown-Menü („⋯") */
.menu { position: relative; display: inline-block; }
.menu-panel {
    position: absolute; right: 0; top: calc(100% + 4px); min-width: 200px; z-index: var(--z-menu);
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r);
    box-shadow: var(--shadow-md); padding: var(--sp-1); display: none;
}
.menu.is-open .menu-panel, .menu-panel.open { display: block; }
.menu-panel.align-left { right: auto; left: 0; }
@media (min-width: 769px) { .menu-panel.drop-up { top: auto; bottom: calc(100% + 4px); } }
/* Das Panel hängt absolut im Fluss — ein Vorfahr mit overflow: hidden
   schneidet es ab. Typischer Fall: eine Tabelle in einer .card, deren
   letzte Zeile das Menü nach unten aufklappt (die Karte kappt bei ihrem
   Rand). Solange ein Menü offen ist, darf der Vorfahr überlaufen; die
   abgerundeten Ecken sind nur in diesem Moment nicht mehr beschnitten. */
.card:has(.menu.is-open), .card-body:has(.menu.is-open),
.table-wrap:has(.menu.is-open), .table-scroll:has(.menu.is-open) { overflow: visible; }
.menu-panel a, .menu-panel button, .menu-item {
    display: flex; align-items: center; gap: var(--sp-2); width: 100%; text-align: left;
    padding: 0.55rem 0.75rem; border-radius: var(--r-sm); color: var(--color-text); font-size: var(--fs-base);
    background: transparent; border: 0; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.menu-panel a:hover, .menu-panel button:hover, .menu-item:hover { background: var(--color-surface-2); text-decoration: none; }
.menu-panel .is-danger, .menu-panel .text-danger { color: var(--color-danger); }
.menu-panel .is-danger:hover { background: var(--color-danger-bg); }
.menu-panel hr, .menu-sep { margin: var(--sp-1) 0; border-top: 1px solid var(--color-border); }
.menu-panel .menu-section { padding: 0.5rem 0.75rem 0.2rem; font-size: var(--fs-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-faint); }
.menu-panel form { display: contents; }
.menu-panel .icon { color: var(--color-text-muted); }
@media (max-width: 768px) {
    /* Am Handy als Bottom-Sheet */
    .menu-panel { position: fixed; left: var(--sp-2); right: var(--sp-2); top: auto; bottom: calc(var(--sp-2) + env(safe-area-inset-bottom)); min-width: 0; padding: var(--sp-2); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); }
    .menu-panel a, .menu-panel button, .menu-item { min-height: var(--touch); font-size: var(--fs-md); }
    .menu-backdrop { position: fixed; inset: 0; background: var(--color-backdrop); z-index: calc(var(--z-menu) - 1); }
    /* Ein Vorfahre mit eigenem Stapel-Kontext sperrt das Menü ein: Seine
       z-index 300 gilt dann nur innerhalb, und der Schleier (299) legt sich
       darüber — der Bildschirm dunkelt ab und nichts ist mehr anklickbar.
       ui.js sucht diesen Vorfahren beim Öffnen und setzt die Klasse. Die
       drei Namen darunter bleiben als Sicherheitsnetz, falls JavaScript
       ausfällt; sie waren vorher die einzige Absicherung und deckten nur
       die damals bekannten Fälle ab.
       Der Klassenname steht doppelt, damit die Regel gewinnt: Die
       angehobenen Elemente tragen ihren z-index oft aus einer später
       geladenen Datei (`.sticky-actions` mit z-index 20 aus layout.css).
       Bei gleicher Spezifität entscheidet die Reihenfolge, und die ist hier
       ungünstig. `.has-open-menu.has-open-menu` schlägt jede
       Einzelklassen-Regel, unabhängig davon, wo sie steht. */
    .has-open-menu.has-open-menu { z-index: var(--z-menu); }
    .topbar:has(.menu.is-open), .bottom-nav:has(.menu.is-open), .page-header:has(.menu.is-open) { z-index: var(--z-menu); }
}

/* ------------------------------------------------------------------ Tabs */
.tabs, .user-tabs, .dashboard-tabs {
    display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--color-border); margin-bottom: var(--sp-4);
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; flex-wrap: nowrap;
}
.tabs::-webkit-scrollbar, .user-tabs::-webkit-scrollbar, .dashboard-tabs::-webkit-scrollbar { display: none; }
.tab, .user-tab, .dashboard-tab {
    display: inline-flex; align-items: center; gap: var(--sp-2); flex-shrink: 0;
    padding: 0.7rem 0.9rem; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
    background: transparent; color: var(--color-text-muted); font-weight: 500; font-size: var(--fs-base);
    cursor: pointer; text-decoration: none; white-space: nowrap; transition: color var(--dur-fast), border-color var(--dur-fast);
}
.tab:hover, .user-tab:hover, .dashboard-tab:hover { color: var(--color-text); text-decoration: none; background: transparent; }
.tab.active, .user-tab.active, .dashboard-tab.active { color: var(--color-accent-text); border-bottom-color: var(--color-accent); background: transparent; }
.dashboard-tab.active::after { display: none; }
.tab-count, .user-tab-count { background: var(--color-surface-2); color: var(--color-text-muted); border-radius: var(--r-full); padding: 0 0.5em; font-size: var(--fs-2xs); font-weight: 600; }
.tab.active .tab-count, .user-tab.active .user-tab-count { background: var(--color-accent-soft); color: var(--color-accent-text); }
html[data-theme="dark"] .tab.active, html[data-theme="dark"] .user-tab.active, html[data-theme="dark"] .dashboard-tab.active { color: var(--color-accent-text); }

/* ---------------------------------------------------------------- Alerts */
.alert {
    display: flex; align-items: flex-start; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4); border-radius: var(--r); margin-bottom: var(--sp-4);
    border: 1px solid transparent; font-size: var(--fs-sm); line-height: 1.5;
    background: var(--color-surface-2); color: var(--color-text);
}
.alert > .icon { flex-shrink: 0; margin-top: 0.1em; width: 1.25rem; height: 1.25rem; }
.alert > div, .alert-body { flex: 1 1 auto; min-width: 0; }
.alert strong { font-weight: 600; }
.alert .alert-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-left: auto; align-self: center; }
.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: color-mix(in srgb, var(--color-success) 25%, transparent); }
.alert-error, .alert-danger { background: var(--color-danger-bg); color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 25%, transparent); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: color-mix(in srgb, var(--color-warning) 30%, transparent); }
.alert-info { background: var(--color-info-bg); color: var(--color-info); border-color: color-mix(in srgb, var(--color-info) 25%, transparent); }
.alert-success strong, .alert-error strong, .alert-warning strong, .alert-info strong { color: inherit; }
@media (max-width: 768px) { .alert { flex-wrap: wrap; } .alert .alert-actions { flex: 1 0 100%; margin-left: 0; } .alert .alert-actions .btn { flex: 1; } }

/* Flash-Toast (Layout-Meldung) */
.toast-stack { position: fixed; z-index: var(--z-toast); left: var(--sp-3); right: var(--sp-3); bottom: calc(var(--bottomnav-h, 0px) + var(--sp-3) + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none; }
@media (min-width: 769px) { .toast-stack { left: auto; right: var(--sp-6); bottom: var(--sp-6); width: 380px; } }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r); background: var(--color-toast-bg); color: var(--color-toast-fg); box-shadow: var(--shadow-lg); font-size: var(--fs-sm); transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease); }
.toast.is-hiding { opacity: 0; transform: translateY(8px); }
.toast-success { border-left: 4px solid #4ade80; }
.toast-error, .toast-danger { border-left: 4px solid #f87171; }
.toast-warning { border-left: 4px solid #fbbf24; }
.toast .icon { flex-shrink: 0; margin-top: 0.1em; }
.toast-close { margin-left: auto; color: inherit; padding: 0 4px; }
.toast-close:hover { color: inherit; }

/* -------------------------------------------------------------- Stat-Karten */
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-4); }
@media (min-width: 640px) { .stats-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--sp-4); } }
.stat-card {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r);
    padding: var(--sp-3) var(--sp-4); display: flex; align-items: center; gap: var(--sp-3); min-width: 0; box-shadow: var(--shadow-xs);
}
.stat-card > a { display: contents; color: inherit; }
.stat-icon { width: 40px; height: 40px; border-radius: var(--r-sm); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--color-accent-soft); color: var(--color-accent-text); font-size: 1.1rem; }
.stat-icon .icon { width: 20px; height: 20px; }
.stat-icon.primary { background: var(--color-primary-soft); color: var(--color-accent-text); }
.stat-icon.success { background: var(--color-success-bg); color: var(--color-success); }
.stat-icon.warning { background: var(--color-warning-bg); color: var(--color-warning); }
.stat-icon.danger  { background: var(--color-danger-bg);  color: var(--color-danger); }
.stat-icon.info    { background: var(--color-info-bg);    color: var(--color-info); }
.stat-content { min-width: 0; }
.stat-content h3, .stat-value { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin: 0 0 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-content p, .stat-label { color: var(--color-text-muted); font-size: var(--fs-xs); margin: 0; line-height: 1.3; }
.stat-subtitle { font-size: var(--fs-2xs); color: var(--color-text-faint); margin-top: 2px; }
@media (max-width: 480px) { .stat-card { padding: var(--sp-3); gap: var(--sp-2); flex-direction: column; align-items: flex-start; } .stat-icon { width: 34px; height: 34px; } }
@media (min-width: 769px) { .stat-content h3, .stat-value { font-size: var(--fs-2xl); } .stat-icon { width: 46px; height: 46px; } }

/* ------------------------------------------------------------- Leerzustand */
.empty-state { text-align: center; padding: var(--sp-10) var(--sp-4); color: var(--color-text-muted); }
.empty-state .icon, .empty-state svg { width: 44px; height: 44px; margin: 0 auto var(--sp-3); color: var(--color-text-faint); opacity: 1; }
/* ------------------------------------------------------------- Erklärungsdialog (help('key')) */
.help-btn { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin: -4px 0 -4px 2px; padding: 0; border: 0; border-radius: var(--r-full); background: transparent; color: var(--color-text-muted); cursor: pointer; vertical-align: middle; flex-shrink: 0; }
.help-btn:hover { background: var(--color-surface-2); color: var(--color-accent-text); }
.help-btn:focus-visible { outline: 2px solid var(--color-ring); outline-offset: 1px; }
.help-btn .icon { width: 16px; height: 16px; }
.form-check .help-btn { align-self: center; }
.card-title .help-btn { margin-left: 0; }
.help-body { font-size: var(--fs-base); line-height: 1.55; color: var(--color-text); }
.help-body ul { margin: var(--sp-2) 0; padding-left: 1.2em; }
.help-body li { margin-bottom: var(--sp-1); }
.help-body code { font-family: var(--font-mono); font-size: 0.9em; background: var(--color-surface-2); padding: 1px 5px; border-radius: var(--r-sm); }

/* ------------------------------------------------------------- Platzhalter-Panel (partials/placeholder_panel.php) */
.code-inline { font-family: var(--font-mono); font-size: var(--fs-xs); background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--r-sm); padding: 1px 6px; white-space: nowrap; }
.ph-panel { border: 1px solid var(--color-border); border-radius: var(--r-sm); background: var(--color-surface); margin: 0 0 var(--sp-4); }
.ph-panel > summary { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); cursor: pointer; font-weight: 600; font-size: var(--fs-sm); list-style: none; user-select: none; }
.ph-panel > summary::-webkit-details-marker { display: none; }
.ph-panel > summary > .icon:first-child { transition: transform var(--dur) var(--ease); color: var(--color-text-muted); }
.ph-panel[open] > summary > .icon:first-child { transform: rotate(90deg); }
.ph-panel-hint { margin-left: auto; display: inline-flex; align-items: center; gap: var(--sp-1); font-weight: 400; font-size: var(--fs-xs); color: var(--color-text-muted); }
.ph-panel-body { padding: 0 var(--sp-4) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); }
.ph-panel-body .mail-info { margin-bottom: 0; }
.ph-example-code { margin: var(--sp-2) 0 0; white-space: pre; overflow-x: auto; color: var(--color-text); }
.ph-group-title { display: flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); margin: 0 0 var(--sp-2); }
.ph-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ph-row { display: grid; grid-template-columns: minmax(180px, max-content) 1fr minmax(0, 32%); gap: var(--sp-2) var(--sp-3); align-items: center; padding: var(--sp-1) 0; border-bottom: 1px solid var(--color-border); font-size: var(--fs-sm); }
.ph-row:last-child { border-bottom: 0; }
.ph-panel-compact .ph-row { grid-template-columns: minmax(160px, max-content) 1fr; }
.ph-desc { color: var(--color-text); line-height: 1.4; }
.ph-example { color: var(--color-text-muted); font-style: italic; overflow-wrap: anywhere; font-size: var(--fs-xs); }
.ph-chip { font-family: var(--font-mono); font-size: var(--fs-xs); padding: 4px 10px; border: 1px solid var(--color-border-strong); border-radius: var(--r-full); background: var(--color-surface-2); color: var(--color-text); cursor: pointer; white-space: nowrap; transition: background var(--dur-fast), border-color var(--dur-fast); justify-self: start; }
.ph-chip:hover { background: var(--color-accent-soft); border-color: var(--color-accent); }
.ph-chip:focus-visible { outline: 2px solid var(--color-ring); outline-offset: 2px; }
.ph-chip.is-copied { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success); }
.ph-panel-foot { margin: 0; font-size: var(--fs-xs); color: var(--color-text-muted); }
@media (max-width: 768px) {
    .ph-panel > summary { padding: var(--sp-3); }
    .ph-panel-hint { display: none; }
    .ph-panel-body { padding: 0 var(--sp-3) var(--sp-3); }
    .ph-row, .ph-panel-compact .ph-row { grid-template-columns: 1fr; gap: 2px; padding: var(--sp-2) 0; }
}

.empty-state h3, .empty-state .empty-state-title { font-size: var(--fs-md); font-weight: 600; color: var(--color-text); margin: 0 0 var(--sp-1); max-width: none; }
.empty-state p { font-size: var(--fs-sm); max-width: 38ch; margin: 0 auto; }
.empty-state .btn { margin-top: var(--sp-4); }
.empty-state .btn .icon, .empty-state .btn svg { width: 1.15em; height: 1.15em; margin: 0; color: inherit; }
.empty-state-sm { padding: var(--sp-4); } .empty-state-sm .icon { width: 28px; height: 28px; margin-bottom: var(--sp-2); }

/* -------------------------------------------------------------- Modale */
.modal, .kanban-modal, .ot-modal {
    position: fixed; inset: 0; z-index: var(--z-modal); display: flex; align-items: center; justify-content: center; padding: var(--sp-4);
}
.modal[hidden], .kanban-modal[hidden], .ot-modal[hidden] { display: none !important; }
.modal-backdrop, .kanban-modal-backdrop, .ot-modal-backdrop { position: absolute; inset: 0; background: var(--color-backdrop); }
.modal-dialog, .kanban-modal-dialog, .ot-modal-card {
    position: relative; width: 100%; max-width: 560px; max-height: min(90vh, 90dvh);
    background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border);
    border-radius: var(--r-lg); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
}
.modal-sm, .kanban-modal-sm { max-width: 420px; }
.modal-lg, .kanban-modal-lg { max-width: 760px; }
.modal-md, .kanban-modal-md { max-width: 600px; }
.modal-header, .kanban-modal-header, .ot-modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--color-border); }
.modal-title, .kanban-modal-title, .ot-modal-head h3 { margin: 0; font-size: var(--fs-lg); font-weight: 600; }
.modal-close, .kanban-modal-close, .ot-modal-close { width: 36px; height: 36px; border-radius: var(--r-sm); display: inline-flex; align-items: center; justify-content: center; color: var(--color-text-muted); font-size: 1.4rem; line-height: 1; background: transparent; border: 0; cursor: pointer; }
.modal-close:hover, .kanban-modal-close:hover, .ot-modal-close:hover { background: var(--color-surface-2); color: var(--color-text); }
/* Das Formular zwischen Dialog und Inhalt muss mitschrumpfen.
   Fast jedes Popup ist so gebaut: Kopf, dann ein <form>, das Inhalt und
   Fußbereich umschließt. Damit ist NICHT der Inhalt das Flex-Element des
   Dialogs, sondern das Formular — und ohne diese Regel wächst es auf
   Inhaltshöhe, schiebt den Fußbereich aus dem Bild und der Inhalt bekommt
   nie einen Scrollbereich. */
.modal-dialog > form,
.kanban-modal-dialog > form,
.ot-modal-card > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

/* min-height: 0 ist hier NICHT optional.
   Ein Flex-Element schrumpft von sich aus nicht unter seine Inhaltsgröße
   (min-height: auto). Ohne diese Zeile wächst der Inhaltsbereich über den
   Dialog hinaus, der Dialog schneidet ihn per overflow ab — und der
   Fußbereich mit den Knöpfen landet außerhalb des Bildschirms. Gemessen im
   Aufgaben-Popup bei 360 px: Dialog 681 px hoch, Inhalt 1179 px, „Speichern"
   bei 1308 px. Es sah aus, als ließe sich das Popup nicht scrollen; in
   Wahrheit gab es gar keinen Scrollbereich.
   overscroll-behavior verhindert, dass die Geste am Ende auf die Seite
   dahinter überspringt — der zweite Teil desselben Fehlerbilds. */
.modal-body, .kanban-modal-body, .ot-modal-body {
    padding: var(--sp-4) var(--sp-5);
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.modal-footer, .kanban-modal-footer { display: flex; justify-content: flex-end; gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--color-border); background: var(--color-surface); }
.modal-footer form, .kanban-modal-footer form { display: contents; }
@media (max-width: 768px) {
    /* Bottom-Sheet am Handy */
    .modal, .kanban-modal, .ot-modal { align-items: flex-end; padding: 0; }
    .modal-dialog, .kanban-modal-dialog, .ot-modal-card { max-width: none; border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92dvh; border-bottom: 0; }
    .modal-header, .kanban-modal-header, .ot-modal-head, .modal-body, .kanban-modal-body, .ot-modal-body { padding-left: var(--sp-4); padding-right: var(--sp-4); }
    .modal-footer, .kanban-modal-footer { padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom)); }
    .modal-footer .btn, .kanban-modal-footer .btn { flex: 1 1 calc(50% - var(--sp-2)); }
}
.modal-dialog.is-danger .modal-title .icon, .kanban-modal-dialog.is-danger .kanban-modal-title .icon { color: var(--color-danger); }
.kanban-modal-title { display: flex; align-items: center; gap: var(--sp-2); }
.kanban-modal-title .icon { flex-shrink: 0; }

/* -------------------------------------------------------- Portal-Aufrufe */
/* Zähler neben einem Dokument; Klick öffnet #portal-views-modal. */
.portal-views-btn { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 0; background: none; border: 0; cursor: pointer; color: var(--color-text-muted); font: inherit; font-size: var(--fs-xs); text-align: left; }
.portal-views-btn:hover { color: var(--color-link); text-decoration: underline; }
.portal-views-btn .icon { flex-shrink: 0; }
.portal-views-list { list-style: none; margin: var(--sp-3) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-1); }
.portal-views-item { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1) var(--sp-2); padding: var(--sp-2) 0; border-top: 1px solid var(--color-border); font-size: var(--fs-sm); }
.portal-views-item:first-child { border-top: 0; }
.portal-views-when { font-variant-numeric: tabular-nums; }
.portal-views-meta { color: var(--color-text-muted); font-size: var(--fs-xs); overflow-wrap: anywhere; }

/* -------------------------------------------------------------- Stepper */
.stage-stepper { display: flex; align-items: flex-start; gap: 0; margin: var(--sp-2) 0 var(--sp-4); overflow-x: auto; padding: var(--sp-2) 0 var(--sp-3); scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.stage-step { flex: 1 0 96px; min-width: 96px; text-align: center; position: relative; padding: 0 var(--sp-1); scroll-snap-align: center; }
.stage-step-circle { width: 32px; height: 32px; border-radius: 50%; background: var(--color-surface-2); color: var(--color-text-muted); border: 2px solid var(--color-border-strong); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: var(--fs-sm); margin-bottom: var(--sp-2); position: relative; z-index: 1; }
.stage-step.done .stage-step-circle { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success); }
.stage-step.active .stage-step-circle { background: var(--color-primary); color: var(--color-primary-fg); border-color: var(--color-primary); box-shadow: 0 0 0 4px var(--color-ring-glow); }
.stage-step-label { font-size: var(--fs-xs); color: var(--color-text-muted); line-height: 1.3; overflow-wrap: anywhere; }
.stage-step.active .stage-step-label { color: var(--color-text); font-weight: 600; }
.stage-step::after { content: ''; position: absolute; top: 16px; left: calc(50% + 16px); right: calc(-50% + 16px); height: 2px; background: var(--color-border-strong); }
.stage-step.done::after, .stage-step.done-line::after { background: var(--color-success); }
.stage-step:last-child::after { display: none; }
.stage-info-box { background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--r-sm); padding: var(--sp-3) var(--sp-4); font-size: var(--fs-sm); color: var(--color-text-muted); line-height: 1.5; }
.stage-info-box strong { color: var(--color-text); }

/* ------------------------------------------------------------- Avatar / Chips */
.user-avatar, .avatar { width: 32px; height: 32px; border-radius: 50%; color: #fff; font-weight: 600; font-size: var(--fs-xs); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; text-transform: uppercase; }
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.user-row { display: flex; align-items: center; gap: var(--sp-3); }
.chip { display: inline-flex; align-items: center; gap: 0.35em; padding: 0.25em 0.7em; border-radius: var(--r-full); background: var(--color-surface-2); color: var(--color-text-muted); font-size: var(--fs-xs); font-weight: 500; }
.chip.is-active { background: var(--color-accent-soft); color: var(--color-accent-text); }
.placeholder-chip { display: inline-block; font-family: var(--font-mono); font-size: var(--fs-xs); background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: 4px; padding: 0.1em 0.45em; cursor: pointer; margin: 2px; }
.placeholder-chip:hover { background: var(--color-accent-soft); border-color: var(--color-accent); }

/* ------------------------------------------------------------- Definitionslisten (Detail-Ansichten) */
.dl { display: grid; grid-template-columns: minmax(110px, 32%) 1fr; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-base); }
.dl dt { color: var(--color-text-muted); font-size: var(--fs-sm); padding-top: 0.1em; }
.dl dd { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .dl { grid-template-columns: 1fr; gap: 0; } .dl dt { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.04em; margin-top: var(--sp-3); } .dl dt:first-child { margin-top: 0; } }

/* ------------------------------------------------------------- Listen-Karten (mobile Standardliste) */
.list { display: flex; flex-direction: column; gap: var(--sp-2); }
.list-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r); min-width: 0; }
.list-item-main { flex: 1 1 auto; min-width: 0; }
.list-item-title { font-weight: 600; overflow-wrap: anywhere; }
.list-item-meta { font-size: var(--fs-xs); color: var(--color-text-muted); display: flex; flex-wrap: wrap; gap: 0.25em var(--sp-2); margin-top: 2px; }
.list-item-end { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }

/* ------------------------------------------------------------- Code-Ansicht */
.code-editor, textarea.code-editor { font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.6; border: 1px solid var(--color-input-border); border-radius: var(--r-sm); min-height: 300px; background: var(--color-input-bg); color: var(--color-text); padding: var(--sp-3); tab-size: 2; white-space: pre; overflow: auto; }
.code-block { font-family: var(--font-mono); font-size: var(--fs-xs); background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--r-sm); padding: var(--sp-2) var(--sp-3); overflow-wrap: anywhere; word-break: break-all; }

/* ------------------------------------------------------------- Fortschritt */
.progress { height: 8px; background: var(--color-surface-3); border-radius: var(--r-full); overflow: hidden; }
.progress-bar { height: 100%; background: var(--color-accent); border-radius: var(--r-full); transition: width var(--dur-slow) var(--ease); }
.progress-bar.success { background: var(--color-success); }
.progress-bar.warning { background: var(--color-warning); }
.progress-bar.danger { background: var(--color-danger); }

/* ------------------------------------------------------------- Skeleton / Lade-Indikator */
.spinner { width: 1.1em; height: 1.1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- Einstellungs-Übersicht */
.settings-group-title { font-size: var(--fs-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-faint); margin: var(--sp-6) 0 var(--sp-2); }
.settings-group-title:first-of-type { margin-top: 0; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: var(--sp-3); }
.settings-tile {
    display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); min-height: 72px;
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r); color: var(--color-text);
    transition: border-color var(--dur-fast), box-shadow var(--dur-fast), transform var(--dur-fast);
}
.settings-tile:hover { text-decoration: none; border-color: var(--color-accent); box-shadow: var(--shadow-sm); }
.settings-tile-icon { width: 40px; height: 40px; border-radius: var(--r-sm); background: var(--color-accent-soft); color: var(--color-accent-text); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.settings-tile-icon .icon { width: 20px; height: 20px; }
.settings-tile-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.settings-tile-title { font-weight: 600; }
.settings-tile-desc { font-size: var(--fs-xs); color: var(--color-text-muted); }

/* Trefferliste der Einstellungs-Suche (partials/settings_hits.php) */
.hit-list { list-style: none; margin: 0; padding: 0; }
.hit-list li + li { border-top: 1px solid var(--color-border); }
.hit { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); min-height: var(--touch); color: var(--color-text); }
.hit:hover, .hit:focus-visible { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.hit-icon { display: inline-flex; flex-shrink: 0; color: var(--color-text-faint); }
.hit-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hit-label { font-weight: 600; overflow-wrap: anywhere; }
.hit-context, .hit-value { font-size: var(--fs-xs); color: var(--color-text-muted); overflow-wrap: anywhere; }
.hit-value { font-family: var(--font-mono); }
.hit-chevron { flex-shrink: 0; color: var(--color-text-faint); }
.toolbar .toolbar-status { flex: 0 0 auto; align-self: center; margin: 0; font-size: var(--fs-xs); color: var(--color-text-muted); min-height: 1.2em; }

/* Sprungziel eines Treffers: kurz umrandet, dann ausgeblendet (ui.js setzt is-found/is-fading) */
.is-found { outline: 2px solid var(--color-accent); outline-offset: 3px; border-radius: var(--r-sm); scroll-margin-top: calc(var(--topbar-h) + var(--sp-8)); transition: outline-color var(--dur-slow) var(--ease); }
.is-found.is-fading { outline-color: transparent; }
tr.is-found { outline-offset: -2px; }
tr.is-found > td { background: var(--color-accent-soft); }
@media (prefers-reduced-motion: reduce) { .is-found { transition: none; } }
.settings-tile-chevron { color: var(--color-text-faint); }

/* Utility-Ergänzungen (UI-Refresh, Ersatz für letzte statische Inline-Styles) */
.eyebrow { text-transform: uppercase; letter-spacing: 0.04em; }
.form-actions-plain { border: 0; padding-top: var(--sp-3); margin-top: 0; }
.empty-state-md { padding: var(--sp-6); }
.code-editor-sm, textarea.code-editor-sm { min-height: 140px; }
.code-editor-xs, textarea.code-editor-xs { min-height: 90px; }
/* Abschnitts-Titel, Trennlinie, schmale Eingabe (Editoren, Portal) */
.mail-section-title { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); font-weight: 600; margin: 0 0 var(--sp-3); }
.mail-divider { border: 0; border-top: 1px solid var(--color-border); margin: var(--sp-5) 0; }
.form-control-narrow { max-width: 320px; }
.modal-dialog > form.modal-form { display: contents; }

/* ---------------------------------------------------------------- Unterschriftenfeld
   Abnahme- und Vertrags-Portal sowie Einstellungen. Kunden zeichnen fast
   immer am Handy, deshalb die Mindesthoehe und die Vollbild-Variante. */
.signature-field { border: 1px solid var(--color-border); border-radius: var(--r-md); background: var(--color-surface); padding: var(--sp-3); }
.signature-field.is-missing { border-color: var(--color-danger); box-shadow: 0 0 0 3px var(--color-ring); }

.signature-canvas-wrap { position: relative; background: #fff; border: 1px dashed var(--color-border-strong); border-radius: var(--r-sm); overflow: hidden; overscroll-behavior: contain; }
.signature-canvas-wrap canvas {
    display: block; width: 100%; height: 180px;
    /* Ohne das scrollt die Seite mit, waehrend gezeichnet wird, und der
       Strich bricht ab. Der wichtigste Wert in diesem Block. */
    touch-action: none;
    cursor: crosshair;
}

/* Grundlinie und Platzhalter verschwinden, sobald Tinte da ist. */
.signature-baseline { position: absolute; left: var(--sp-4); right: var(--sp-4); bottom: 34%; border-bottom: 1px solid var(--color-border); pointer-events: none; }
.signature-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--color-text-faint); font-size: var(--fs-sm); pointer-events: none; }
.signature-field:not(.is-empty) .signature-hint,
.signature-field:not(.is-empty) .signature-baseline { opacity: 0; }

.signature-tools { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; margin-top: var(--sp-3); }
.signature-tools .signature-spacer { flex: 1 1 auto; }
.signature-typed-row { margin-top: var(--sp-3); }

/* Vollbild: statt einer erzwungenen Drehung ins Querformat. */
.signature-field.is-expanded {
    position: fixed; inset: 0; z-index: var(--z-drawer);
    margin: 0; border-radius: 0; border: 0;
    display: flex; flex-direction: column; padding: var(--sp-4);
    padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
    background: var(--color-surface);
}
.signature-field.is-expanded .signature-canvas-wrap { flex: 1 1 auto; }
.signature-field.is-expanded .signature-canvas-wrap canvas { height: 100%; }
body.has-signature-overlay { overflow: hidden; }

@media (max-width: 480px) {
    .signature-canvas-wrap canvas { height: 200px; }
    .signature-tools .btn { flex: 1 1 auto; }
}

/* Vorschau der hinterlegten Unterschrift (Einstellungen). Schachbrett, damit
   man sieht, ob der Grund wirklich durchsichtig ist. */
.signature-preview {
    display: inline-block; padding: var(--sp-3); border: 1px solid var(--color-border); border-radius: var(--r-sm);
    background-color: #fff;
    background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%),
                      linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}
.signature-preview img { display: block; max-height: 90px; width: auto; }

/* Formular-Fieldset ohne eigenen Rahmen: Es dient nur dazu, alle Felder auf
   einmal zu sperren (Abnahme, Vertrag), nicht als sichtbare Gruppe. */
.fieldset-plain { border: 0; margin: 0; padding: 0; min-width: 0; }
/* Feld, das in einer .form-row die ganze Breite einnimmt (langer Text). */
.form-group-full { grid-column: 1 / -1; }
/* Gespeichertes HTML aus dem Editor, nur gelesen statt bearbeitet. */
.rich-text { line-height: 1.7; overflow-wrap: anywhere; }
.rich-text > :first-child { margin-top: 0; }
.rich-text > :last-child { margin-bottom: 0; }
.rich-text ul, .rich-text ol { padding-left: 1.4em; }
/* Knopf, der gerade nicht gemeint ist (Vertrags-Portal: wer Anmerkungen tippt,
   will nicht unterschreiben). Nicht gesperrt, nur zurückgenommen. */
.btn.is-muted { opacity: 0.55; }
/* Quelltext-Feld: Vertragsklauseln werden als HTML bearbeitet, weil die
   Bedingungen als Kommentar darin stehen (siehe contract-templates/edit.php). */
.source-area { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: var(--fs-xs); line-height: 1.6; white-space: pre-wrap; tab-size: 2; }

/* Erklaerung der Leistungs-Bedingungen an der Angebots-Bibliothek. */
.op-tag-effects { margin: var(--sp-2) 0 0; }
.op-tag-effects dt { margin-top: var(--sp-2); font-weight: 500; }
.op-tag-effects dd { margin: 0 0 0 var(--sp-3); color: var(--color-text-muted); }

