/* =========================================================================
   FLT Telefon-KI – Komponenten
   Buttons · Formulare · Karten · Kennzahlen · Tabellen (+ mobile Karten) ·
   Badges · Alerts · Segmented Control · Filterleiste · Toolbar ·
   Pagination · Leerzustand · Beschreibungslisten · Tabs · Timeline ·
   Diff · Transkript · Audio · Code · Avatar · Fortschritt · Aufklappen
   Beispiele zu jeder Klasse: DESIGN.md und /styleguide (nur lokal).
   ========================================================================= */

/* ======================================================================
   Icons (partials/icon.ejs)
   ====================================================================== */
.icon {
    display: inline-block;
    flex-shrink: 0;
    vertical-align: -0.2em;
}

/* ======================================================================
   Buttons
   .btn (= sekundär) · .btn-primary · .btn-secondary · .btn-ghost ·
   .btn-danger (dezent) · .btn-destructive (vollflächig) · .btn-link
   Größen: .btn-sm · .btn-lg · .btn-icon (nur Icon, aria-label Pflicht) · .btn-block
   ====================================================================== */
.btn {
    --btn-h: var(--control-h);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: var(--btn-h);
    padding: 0 14px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
    color: var(--gray-800);
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    line-height: 1;
    letter-spacing: -0.003em;
    white-space: nowrap;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--duration-fast) var(--ease-standard),
        border-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard),
        box-shadow var(--duration-fast) var(--ease-standard);
}

.btn .icon {
    width: 16px;
    height: 16px;
    margin-inline: -2px;
    color: var(--gray-500);
}

.btn:hover {
    border-color: var(--gray-350);
    background: var(--gray-50);
    color: var(--gray-900);
}

.btn:active {
    background: var(--gray-100);
}

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

.btn-primary {
    border-color: var(--color-primary);
    background: var(--color-primary);
    box-shadow: var(--shadow-xs), var(--shadow-highlight);
    color: #fff;
}

.btn-primary .icon {
    color: rgb(255 255 255 / 0.82);
}

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

.btn-primary:active {
    background: var(--color-primary-active);
}

.btn-ghost {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    color: var(--gray-700);
}

.btn-ghost:hover {
    border-color: transparent;
    background: var(--gray-75);
}

.btn-ghost:active {
    background: var(--gray-100);
}

.btn-danger {
    border-color: var(--red-200);
    color: var(--red-700);
}

.btn-danger .icon {
    color: var(--red-600);
}

.btn-danger:hover {
    border-color: var(--red-300);
    background: var(--red-50);
    color: var(--red-800);
}

.btn-destructive {
    border-color: var(--red-600);
    background: var(--red-600);
    box-shadow: var(--shadow-xs), var(--shadow-highlight);
    color: #fff;
}

.btn-destructive .icon {
    color: rgb(255 255 255 / 0.85);
}

.btn-destructive:hover {
    border-color: var(--red-700);
    background: var(--red-700);
    color: #fff;
}

.btn-link {
    height: auto;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
    color: var(--color-link);
}

.btn-link:hover {
    background: none;
    color: var(--color-accent-hover);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.btn-sm {
    --btn-h: var(--control-h-sm);
    gap: 6px;
    padding: 0 10px;
    border-radius: 7px;
    font-size: var(--text-sm);
}

.btn-sm .icon {
    width: 15px;
    height: 15px;
}

.btn-lg {
    --btn-h: var(--control-h-lg);
    padding: 0 18px;
    border-radius: var(--radius-lg);
    font-size: var(--text-md);
}

.btn-icon {
    width: var(--btn-h);
    padding: 0;
}

.btn-icon .icon {
    margin: 0;
}

.btn-block {
    width: 100%;
}

/* Unter 640 px nur Icon (Text mit .visually-hidden-sm umschließen) */
@media (max-width: 639.98px) {
    .btn-icon-mobile {
        width: var(--btn-h);
        padding: 0;
    }

    .btn-icon-mobile .icon {
        margin: 0;
    }
}

.btn[disabled],
.btn.is-disabled,
.btn[aria-disabled='true'] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none;
}

/* Formular in einer Zeile (z. B. POST-Button in Tabellen) */
.inline-form {
    display: inline-flex;
    margin: 0;
    vertical-align: middle;
}

/* Gruppe von Zeilenaktionen */
.row-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
}

/* ======================================================================
   Formulare
   Eingabefelder sind global gestylt (keine Klasse nötig); .input für
   Sonderfälle. Aufbau: .field > label.field-label + Control + .field-help
   + .field-error. Fehler: .is-invalid oder aria-invalid="true".
   ====================================================================== */
:where(input:not([type='checkbox'], [type='radio'], [type='hidden'], [type='range'], [type='file'], [type='submit'], [type='button'], [type='reset'], [type='color'], [type='image']), select, textarea),
.input {
    display: block;
    width: 100%;
    height: var(--control-h);
    padding: 0 12px;
    border: 1px solid var(--color-control-border);
    border-radius: var(--radius-md);
    background-color: var(--color-surface);
    box-shadow: var(--shadow-xs);
    color: var(--color-text);
    font-size: var(--text-base);
    line-height: 1.4;
    transition: border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
    -webkit-appearance: none;
    appearance: none;
}

:where(input, select, textarea)::placeholder {
    color: var(--color-placeholder);
    opacity: 1;
}

:where(input:not([type='checkbox'], [type='radio']), select, textarea):hover {
    border-color: var(--color-control-border-hover);
}

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

:where(input, select, textarea):disabled {
    border-color: var(--color-border);
    background-color: var(--gray-50);
    box-shadow: none;
    color: var(--color-text-tertiary);
    cursor: not-allowed;
}

:where(input, textarea)[readonly] {
    background-color: var(--gray-50);
}

:where(input, select, textarea).is-invalid,
:where(input, select, textarea)[aria-invalid='true'] {
    border-color: var(--red-500);
}

:where(input, select, textarea).is-invalid:focus,
:where(input, select, textarea)[aria-invalid='true']:focus {
    border-color: var(--red-500);
    box-shadow: var(--shadow-xs), var(--focus-ring-danger);
}

:where(select) {
    padding-right: 34px;
    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='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 15 5 5 5-5'/%3E%3Cpath d='m7 9 5-5 5 5'/%3E%3C/svg%3E");
    background-position: right 10px center;
    background-repeat: no-repeat;
    background-size: 15px;
    text-overflow: ellipsis;
    cursor: pointer;
}

:where(textarea) {
    height: auto;
    min-height: 88px;
    padding: 8px 12px;
    line-height: var(--leading-normal);
    resize: vertical;
}

:where(input[type='date'], input[type='time'], input[type='number']) {
    font-variant-numeric: tabular-nums;
}

input[type='date']::-webkit-calendar-picker-indicator {
    opacity: 0.55;
    cursor: pointer;
}

input[type='date']::-webkit-datetime-edit {
    padding: 0;
}

input[type='search']::-webkit-search-decoration {
    -webkit-appearance: none;
}

.input-sm,
:where(input, select).input-sm {
    height: var(--control-h-sm);
    padding-inline: 10px;
    font-size: var(--text-sm);
}

select.input-sm {
    padding-right: 30px;
}

.input-lg {
    height: var(--control-h-lg);
    font-size: var(--text-md);
}

.input-mono,
textarea.input-mono {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

/* Feld mit vorangestelltem Icon */
.input-icon {
    position: relative;
    display: block;
    min-width: 0;
}

.input-icon > .icon {
    position: absolute;
    top: 50%;
    left: 11px;
    color: var(--gray-400);
    transform: translateY(-50%);
    pointer-events: none;
}

.input-icon > input,
.input-icon > select {
    padding-left: 34px;
}

/* Feldaufbau */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.field-label,
.field > label {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--gray-800);
}

.field-required {
    color: var(--red-600);
}

.field-optional {
    font-weight: var(--weight-regular);
    color: var(--color-text-tertiary);
}

.field-help {
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--color-text-tertiary);
}

.field-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 12.5px;
    font-weight: var(--weight-medium);
    line-height: 1.45;
    color: var(--red-700);
}

.field-error .icon {
    margin-top: 1px;
}

.field-inline {
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

.field-inline > label {
    flex-shrink: 0;
}

.field-w-auto :where(input, select) {
    width: auto;
}

/* Feldraster: .field-grid + .cols-2 | .cols-3 | .cols-4 */
.field-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 18px 20px;
}

@container (min-width: 480px) {
    .field-grid.cols-2,
    .field-grid.cols-3,
    .field-grid.cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@container (min-width: 720px) {
    .field-grid.cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .field-grid.cols-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.field-grid > .col-full {
    grid-column: 1 / -1;
}

/* Formular-Layout */
.form-stack {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-section {
    display: grid;
    gap: 16px;
    padding: 20px 0;
    border-top: 1px solid var(--color-border-subtle);
}

.form-section:first-child {
    padding-top: 0;
    border-top: 0;
}

.form-section:last-child {
    padding-bottom: 0;
}

.form-section > * {
    min-width: 0;
}

.form-section-aside > :last-child {
    container-type: inline-size;
}

.form-section-title {
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
}

.form-section-desc {
    margin-top: 2px;
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
}

@container (min-width: 820px) {
    .form-section-aside {
        grid-template-columns: minmax(200px, 280px) minmax(0, 1fr);
        gap: 32px;
    }
}

.fieldset {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface-subtle);
}

.fieldset > legend,
.fieldset-legend {
    float: left;
    width: 100%;
    margin-bottom: 2px;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--gray-800);
}

.fieldset > legend + * {
    clear: both;
}

.form-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

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

.form-actions-split {
    justify-content: space-between;
}

/* Checkbox & Radio */
input[type='checkbox'],
input[type='radio'] {
    display: inline-grid;
    place-content: center;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin: 0;
    border: 1px solid var(--color-control-border);
    border-radius: var(--radius-xs);
    background-color: var(--color-surface);
    background-position: center;
    background-repeat: no-repeat;
    box-shadow: var(--shadow-xs);
    vertical-align: middle;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard),
        background-position var(--duration) var(--ease-out);
    -webkit-appearance: none;
    appearance: none;
}

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

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

input[type='checkbox']:checked {
    border-color: var(--color-primary);
    background-color: var(--color-primary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
    background-size: 11px;
}

input[type='radio']:checked {
    border-color: var(--color-primary);
    background-color: var(--color-primary);
    background-image: radial-gradient(circle, #fff 0 3px, transparent 3.5px);
}

input[type='checkbox']:focus-visible,
input[type='radio']:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

input[type='checkbox']:disabled,
input[type='radio']:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

input[type='checkbox'].is-invalid,
input[type='checkbox'][aria-invalid='true'] {
    border-color: var(--red-500);
}

/* Schalter: <input type="checkbox" class="switch" role="switch"> */
input[type='checkbox'].switch {
    width: 36px;
    height: 20px;
    border: 0;
    border-radius: var(--radius-full);
    background-color: var(--color-control-border);
    background-image: radial-gradient(circle, #fff 0 7px, rgb(16 24 40 / 0.1) 7.5px 8px, transparent 8.5px);
    background-position: 0 0;
    background-size: 20px 20px;
    box-shadow: inset 0 1px 2px rgb(16 24 40 / 0.08);
}

input[type='checkbox'].switch:hover {
    background-color: var(--color-control-border-hover);
}

input[type='checkbox'].switch:checked:hover {
    background-color: var(--color-primary-hover);
}

input[type='checkbox'].switch:checked {
    background-color: var(--color-primary);
    background-image: radial-gradient(circle, #fff 0 7px, rgb(16 24 40 / 0.1) 7.5px 8px, transparent 8.5px);
    background-position: 16px 0;
    background-size: 20px 20px;
}

/* Zeile mit Checkbox/Radio/Schalter + Beschriftung */
.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: var(--text-base);
    line-height: 1.45;
    color: var(--color-text);
}

.check > input {
    margin-top: 2px;
}

.check > input.switch {
    margin-top: 0;
}

.check > label,
.check-text {
    cursor: pointer;
}

.check-desc {
    display: block;
    margin-top: 2px;
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
}

.check-card {
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    transition: border-color var(--duration-fast) var(--ease-standard), background-color var(--duration-fast) var(--ease-standard);
}

.check-card:has(input:checked) {
    border-color: var(--navy-200);
    background: var(--navy-50);
}

.check-card.is-invalid,
.check-card.is-invalid:has(input:checked) {
    border-color: var(--red-300);
    background: var(--red-50);
}

/* ======================================================================
   Karten
   .card > .card-header (.card-title, .card-subtitle, .card-actions)
         > .card-body | .card-flush (Tabelle direkt in der Karte)
         > .card-footer
   ====================================================================== */
.card {
    min-width: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px 16px;
    flex-wrap: wrap;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border-subtle);
}

.card-header-plain {
    padding-bottom: 0;
    border-bottom: 0;
}

.card-heading {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

.card-icon {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--gray-75);
    box-shadow: inset 0 0 0 1px var(--color-border);
    color: var(--gray-600);
}

/* Ton der Icon-Kachel: .card-icon.tone-brand | -success | -warning | -danger | -info */
.card-icon.tone-brand { background: var(--brand-bg); box-shadow: inset 0 0 0 1px var(--brand-border); color: var(--brand-fg); }
.card-icon.tone-success { background: var(--success-bg); box-shadow: inset 0 0 0 1px var(--success-border); color: var(--success-fg); }
.card-icon.tone-warning { background: var(--warning-bg); box-shadow: inset 0 0 0 1px var(--warning-border); color: var(--warning-fg); }
.card-icon.tone-danger { background: var(--danger-bg); box-shadow: inset 0 0 0 1px var(--danger-border); color: var(--danger-fg); }
.card-icon.tone-info { background: var(--info-bg); box-shadow: inset 0 0 0 1px var(--info-border); color: var(--info-fg); }

.card-title {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    line-height: 1.4;
    letter-spacing: var(--tracking-tight);
    color: var(--color-text);
}

.card-subtitle {
    margin-top: 2px;
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
}

.card-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.card-body {
    container-type: inline-size;
    padding: 20px;
}

.card-body > * + * {
    margin-top: 16px;
}

.card-flush {
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.card-body + .card-flush,
.card-header-plain + .card-flush {
    border-top: 1px solid var(--color-border-subtle);
}

.card-flush .table thead th {
    border-radius: 0;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 16px;
    padding: 12px 20px;
    border-top: 1px solid var(--color-border-subtle);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    background: var(--color-surface-subtle);
}

.card-footer-meta {
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
}

/* Telefon: Aktionen im Kartenfuß über die volle Breite (gleich breite Buttons) */
@media (max-width: 639.98px) {
    .card-footer > .form-actions {
        flex: 1 1 100%;
        margin-left: 0;
    }

    .card-footer > .form-actions > .btn,
    .card-footer > .form-actions > form {
        flex: 1 1 0;
    }

    .card-footer > .form-actions > form .btn {
        width: 100%;
    }
}

.card.is-error {
    border-color: var(--red-300);
    box-shadow: var(--shadow-xs), 0 0 0 3px rgb(240 68 56 / 0.08);
}

.card.is-highlight {
    border-color: var(--navy-200);
    box-shadow: var(--shadow-xs), 0 0 0 3px rgb(31 76 153 / 0.06);
}

a.card {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
}

a.card:hover {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-sm);
}

/* Dezente Hinweisfläche innerhalb von Karten */
.note {
    padding: 10px 12px;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: var(--gray-50);
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    overflow-wrap: anywhere;
}

/* Gegliederte Liste (z. B. Problemfälle, Jobs) */
.list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.list > li {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--color-border-subtle);
}

.list > li:first-child {
    padding-top: 0;
}

.list > li:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

/* Kleine Zwischenüberschrift in Versalien (z. B. „Worker-Jobs“, „Fehler 404“) */
.eyebrow {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    line-height: 1.4;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    color: var(--color-text-tertiary);
}

/* Icon vor (mehrzeiligem) Text, Icon auf die erste Zeile ausgerichtet:
   <p class="icon-text">{icon}<span>Text …</span></p> */
.icon-text {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    min-width: 0;
}

.icon-text > .icon {
    flex-shrink: 0;
    margin-top: 0.2em;
    color: var(--color-text-tertiary);
}

.icon-text.is-error,
.icon-text.is-error > .icon {
    color: var(--danger-fg);
}

/* Erläuterung unter Listen/Kennzahlen: Info-Icon + kleiner Text */
.footnote {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 110ch;
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    color: var(--color-text-tertiary);
}

.footnote > .icon {
    flex-shrink: 0;
    margin-top: 0.2em;
}

.footnote strong {
    color: var(--color-text-secondary);
}

/* ======================================================================
   Kennzahlen (partials/stat.ejs)
   .stats (Raster) > .stat[.stat-success|warning|danger|info|neutral|brand]
   ====================================================================== */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    gap: 16px;
}

.stat {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        'label icon'
        'value value'
        'hint hint';
    align-content: start;
    align-items: center;
    column-gap: 12px;
    min-width: 0;
    padding: 16px 18px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
    color: var(--color-text);
    text-decoration: none;
}

.stat-label {
    grid-area: label;
    overflow: hidden;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
    white-space: nowrap;
    text-overflow: ellipsis;
}

.stat-icon {
    grid-area: icon;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-md);
    background: var(--neutral-bg);
    color: var(--neutral-fg);
}

.stat-number {
    grid-area: value;
    margin-top: 6px;
    font-size: 28px;
    font-weight: var(--weight-semibold);
    line-height: 1.15;
    letter-spacing: -0.024em;
    font-variant-numeric: tabular-nums;
    color: var(--color-text);
}

.stat-unit {
    margin-left: 2px;
    font-size: var(--text-lg);
    font-weight: var(--weight-medium);
    letter-spacing: 0;
    color: var(--color-text-tertiary);
}

.stat-hint {
    grid-area: hint;
    margin-top: 4px;
    font-size: 12.5px;
    color: var(--color-text-tertiary);
}

.stat-success .stat-icon { background: var(--success-bg); color: var(--success-fg); }
.stat-warning .stat-icon { background: var(--warning-bg); color: var(--warning-fg); }
.stat-danger .stat-icon { background: var(--danger-bg); color: var(--danger-fg); }
.stat-info .stat-icon { background: var(--info-bg); color: var(--info-fg); }
.stat-brand .stat-icon { background: var(--brand-bg); color: var(--brand-fg); }

a.stat {
    transition: border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
}

a.stat:hover {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-sm);
    color: var(--color-text);
}

.stat.is-active {
    border-color: var(--navy-300);
    box-shadow: var(--shadow-xs), 0 0 0 3px rgb(31 76 153 / 0.08);
}

/* Telefon: zwei Kacheln je Zeile, kompakt, ohne Icon; Beschriftung bricht um
   (steht nach den Basisregeln, damit sie gewinnt) */
@media (max-width: 639.98px) {
    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .stat {
        padding: 14px;
    }

    .stat-icon {
        display: none;
    }

    .stat-number {
        font-size: var(--text-3xl);
    }

    .stat-label {
        white-space: normal;
        line-height: 1.35;
    }
}

/* ======================================================================
   Tabellen
   .table-wrap (Rahmen) > table.table[.table-stack] – Kopf haftet unter
   der Kopfleiste. Zellen: .num (rechtsbündig, tabellarische Ziffern),
   .col-actions, .cell-title, .cell-sub, .cell-full, .nowrap.
   Mobil (< 768 px) wird .table-stack zu gestapelten Karten; jede td
   bekommt data-label="Spaltenname" (leer = ohne Beschriftung).
   ====================================================================== */
.table-wrap {
    position: relative;
    min-width: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.card-flush > .table-wrap {
    border: 0;
    /* untere Ecken der Karte nicht mit der weißen Rahmenfläche überdecken */
    border-radius: 0 0 calc(var(--radius-xl) - 1px) calc(var(--radius-xl) - 1px);
    box-shadow: none;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--text-base);
    font-variant-numeric: tabular-nums;
}

.table th {
    position: sticky;
    top: var(--sticky-top);
    z-index: var(--z-sticky);
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-subtle);
    font-size: 12.5px;
    font-weight: var(--weight-medium);
    line-height: 1.3;
    color: var(--color-text-tertiary);
    text-align: left;
    white-space: nowrap;
}

.table-scroll .table th {
    position: static;
}

.table thead th:first-child {
    border-top-left-radius: calc(var(--radius-xl) - 1px);
}

.table thead th:last-child {
    border-top-right-radius: calc(var(--radius-xl) - 1px);
}

.table td {
    padding: 12px;
    border-bottom: 1px solid var(--color-border-subtle);
    color: var(--color-text);
    vertical-align: middle;
    transition: background-color var(--duration-fast) var(--ease-standard);
}

.table th:first-child,
.table td:first-child {
    padding-left: 20px;
}

.table th:last-child,
.table td:last-child {
    padding-right: 20px;
}

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

.table tbody tr:last-child td:first-child {
    border-bottom-left-radius: calc(var(--radius-xl) - 1px);
}

.table tbody tr:last-child td:last-child {
    border-bottom-right-radius: calc(var(--radius-xl) - 1px);
}

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

.table-top td {
    vertical-align: top;
}

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

.table .col-actions {
    width: 1%;
    text-align: right;
    white-space: nowrap;
}

.table .col-check {
    width: 1%;
}

.cell-title {
    font-weight: var(--weight-medium);
    color: var(--color-text);
}

a.cell-title,
.cell-title > a {
    color: var(--color-text);
    font-weight: var(--weight-medium);
    text-decoration: none;
}

a.cell-title:hover,
.cell-title > a:hover {
    color: var(--color-link);
    text-decoration: underline;
}

.cell-sub {
    display: block;
    margin-top: 2px;
    font-size: 12.5px;
    color: var(--color-text-tertiary);
}

.table .row-muted td {
    color: var(--color-text-tertiary);
}

.table .row-muted .cell-title,
.table .row-muted a.cell-title,
.table .row-muted .cell-title > a {
    color: var(--color-text-secondary);
}

/* Spalten, die nur auf breiten Bildschirmen Platz haben (in der mobilen
   Kartenansicht < 768 px werden sie wieder angezeigt) */
@media (min-width: 768px) and (max-width: 1023.98px) {
    .table .col-from-lg {
        display: none;
    }
}

@media (min-width: 768px) and (max-width: 1279.98px) {
    .table .col-from-xl {
        display: none;
    }
}

@media (min-width: 768px) and (max-width: 1599.98px) {
    .table .col-from-2xl {
        display: none;
    }
}

.table-compact th {
    padding-block: 8px;
}

.table-compact td {
    padding-block: 8px;
}

.table .row-actions {
    flex-wrap: nowrap;
}

.table-empty td,
.table td.table-empty {
    padding: 0;
}

.table-empty:hover td {
    background: none;
}

/* Schutz vor horizontalem Seiten-Scroll: unter 1024 px scrollt die Tabelle in
   ihrem Rahmen; darüber setzt js/app.js .is-overflowing nur, wenn sie nicht passt
   (dann ohne haftenden Kopf). */
.table-wrap.is-overflowing {
    overflow-x: auto;
}

.table-wrap.is-overflowing .table th {
    position: static;
}

@media (max-width: 1023.98px) {
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table th {
        position: static;
    }
}

@media (max-width: 767.98px) {
    /* Kartenansicht scrollt nie seitlich – kein Beschneiden (z. B. Trefferflächen) */
    .table-wrap:has(> .table-stack) {
        overflow: visible;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }

    .card-flush .table-wrap:has(> .table-stack) {
        padding: 12px;
    }

    .table-stack,
    .table-stack tbody {
        display: block;
    }

    .table-stack thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    .table-stack tbody {
        display: grid;
        gap: 10px;
    }

    .table-stack tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 16px;
        padding: 14px 16px;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-xl);
        background: var(--color-surface);
        box-shadow: var(--shadow-xs);
    }

    .table-stack td,
    .table-stack td:first-child,
    .table-stack td:last-child,
    .table-stack tbody tr:last-child td {
        display: block;
        min-width: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: none;
        text-align: left;
        white-space: normal;
        overflow-wrap: break-word;
        -webkit-hyphens: auto;
        hyphens: auto;
    }

    .table-stack tbody tr:hover td {
        background: none;
    }

    .table-stack td.num {
        text-align: left;
    }

    .table-stack .badge {
        height: auto;
        min-height: 22px;
        padding-block: 4px;
        line-height: 1.25;
        white-space: normal;
    }

    .table-stack td[data-label]:not([data-label=''])::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 3px;
        font-size: 11.5px;
        font-weight: var(--weight-medium);
        letter-spacing: 0.01em;
        color: var(--color-text-tertiary);
    }

    .table-stack td.cell-full,
    .table-stack td.cell-title,
    .table-stack td.col-actions {
        grid-column: 1 / -1;
    }

    .table-stack td.cell-title {
        font-size: var(--text-md);
    }

    .table-stack td.col-actions,
    .table-stack tbody tr:last-child td.col-actions {
        width: auto;
        padding-top: 12px;
        border-top: 1px solid var(--color-border-subtle);
        text-align: left;
    }

    .table-stack td.col-actions .row-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .table-stack td:empty,
    .table-stack .hide-stacked {
        display: none;
    }

    .table-stack tr.table-empty {
        display: block;
        padding: 0;
    }
}

/* ======================================================================
   Badges / Status-Pills (partials/badge.ejs)
   .badge + Ton: -success | -warning | -danger | -info | -neutral | -brand
   Aliasse aus den Services: -failure (=danger), -unknown (=neutral),
   -pending (=warning), -mobile (=brand). Punkt: .badge-dot
   ====================================================================== */
.badge {
    --badge-bg: var(--neutral-bg);
    --badge-fg: var(--neutral-fg);
    --badge-border: var(--neutral-border);
    --badge-dot: var(--neutral-solid);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 100%;
    height: 22px;
    padding: 0 8px;
    border-radius: var(--radius-full);
    background: var(--badge-bg);
    box-shadow: inset 0 0 0 1px var(--badge-border);
    color: var(--badge-fg);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1;
    letter-spacing: 0;
    white-space: nowrap;
    vertical-align: middle;
}

.badge .icon {
    width: 12px;
    height: 12px;
    margin-left: -2px;
}

.badge-dot::before {
    content: '';
    flex-shrink: 0;
    width: 6px;
    height: 6px;
    margin-left: -1px;
    border-radius: 50%;
    background: var(--badge-dot);
}

.badge-success {
    --badge-bg: var(--success-bg);
    --badge-fg: var(--success-fg);
    --badge-border: var(--success-border);
    --badge-dot: var(--success-solid);
}

.badge-warning,
.badge-pending {
    --badge-bg: var(--warning-bg);
    --badge-fg: var(--warning-fg);
    --badge-border: var(--warning-border);
    --badge-dot: var(--warning-solid);
}

.badge-danger,
.badge-failure,
.badge-error {
    --badge-bg: var(--danger-bg);
    --badge-fg: var(--danger-fg);
    --badge-border: var(--danger-border);
    --badge-dot: var(--danger-solid);
}

.badge-info {
    --badge-bg: var(--info-bg);
    --badge-fg: var(--info-fg);
    --badge-border: var(--info-border);
    --badge-dot: var(--info-solid);
}

.badge-neutral,
.badge-unknown {
    --badge-bg: var(--neutral-bg);
    --badge-fg: var(--neutral-fg);
    --badge-border: var(--neutral-border);
    --badge-dot: var(--neutral-solid);
}

.badge-brand,
.badge-mobile {
    --badge-bg: var(--brand-bg);
    --badge-fg: var(--brand-fg);
    --badge-border: var(--brand-border);
    --badge-dot: var(--brand-solid);
}

.badge-lg {
    height: 26px;
    padding: 0 10px;
    font-size: var(--text-sm);
}

.badge-wrap {
    height: auto;
    min-height: 22px;
    padding-block: 4px;
    line-height: 1.25;
    white-space: normal;
}

/* Schlagwort (z. B. Aussprache-Varianten) */
.tag {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--radius-sm);
    background: var(--gray-100);
    color: var(--gray-700);
    font-size: var(--text-xs);
    line-height: 1;
    white-space: nowrap;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* ======================================================================
   Alerts / Flash (partials/flash.ejs)
   .alert + .alert-success | -error (=danger) | -warning | -info | -neutral
   Optional: .alert-icon (Icon als erstes Kind) + .alert-body/.alert-title
   ====================================================================== */
.alert {
    --alert-bg: var(--info-bg);
    --alert-border: var(--info-border);
    --alert-text: var(--info-text);
    --alert-icon: var(--info-fg);
    position: relative;
    padding: 12px 14px;
    border: 1px solid var(--alert-border);
    border-radius: var(--radius-lg);
    background: var(--alert-bg);
    color: var(--alert-text);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
}

.alert:has(> .alert-icon) {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    align-items: start;
    column-gap: 10px;
}

.alert-icon {
    width: 18px;
    height: 18px;
    margin-top: 1px;
    color: var(--alert-icon);
}

.alert-title {
    display: block;
    font-weight: var(--weight-semibold);
}

.alert-body > * + * {
    margin-top: 4px;
}

.alert-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin-top: 8px;
}

.alert a {
    color: inherit;
    font-weight: var(--weight-medium);
    text-decoration-color: currentColor;
}

.alert ul {
    margin-top: 4px;
}

.alert-success {
    --alert-bg: var(--success-bg);
    --alert-border: var(--success-border);
    --alert-text: var(--success-text);
    --alert-icon: var(--success-fg);
}

.alert-warning {
    --alert-bg: var(--warning-bg);
    --alert-border: var(--warning-border);
    --alert-text: var(--warning-text);
    --alert-icon: var(--warning-fg);
}

.alert-error,
.alert-danger {
    --alert-bg: var(--danger-bg);
    --alert-border: var(--danger-border);
    --alert-text: var(--danger-text);
    --alert-icon: var(--danger-fg);
}

.alert-neutral {
    --alert-bg: var(--gray-50);
    --alert-border: var(--color-border);
    --alert-text: var(--gray-700);
    --alert-icon: var(--gray-500);
}

.flash {
    box-shadow: var(--shadow-xs);
}

/* ======================================================================
   Segmented Control (z. B. Zeitraum-Vorgaben)
   .segmented > a.segmented-item[aria-current="true"]
   ====================================================================== */
.segmented {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    max-width: 100%;
    padding: 3px;
    border: 1px solid var(--gray-150);
    border-radius: var(--radius-lg);
    background: var(--gray-100);
    overflow-x: auto;
    scrollbar-width: none;
}

.segmented::-webkit-scrollbar {
    display: none;
}

.segmented-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    height: 28px;
    padding: 0 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--gray-600);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    transition: background-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard),
        box-shadow var(--duration-fast) var(--ease-standard);
}

.segmented-item:hover {
    color: var(--gray-900);
}

.segmented-item.is-active,
.segmented-item[aria-current='true'],
.segmented-item[aria-current='page'],
.segmented-item[aria-pressed='true'] {
    background: var(--color-surface);
    box-shadow: 0 1px 2px rgb(16 24 40 / 0.1), 0 0 0 1px var(--gray-300);
    color: var(--navy-800);
    font-weight: var(--weight-semibold);
}

.segmented-item:focus-visible {
    outline-offset: -2px;
}

/* ======================================================================
   Filterleiste & Toolbar
   .filter-bar > .filter-field (label + control) … .filter-actions
   .toolbar > .toolbar-group … .toolbar-meta
   ====================================================================== */
.filter-bar {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 0 1 auto;
    min-width: 140px;
}

.filter-field-grow {
    flex: 1 1 220px;
}

.filter-field > label,
.filter-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
}

.filter-field :where(input, select) {
    height: var(--control-h-sm);
    font-size: var(--text-sm);
}

.filter-field :where(select) {
    padding-right: 30px;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.toolbar-meta {
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
    font-variant-numeric: tabular-nums;
}

/* Suchfeld bzw. Auswahl in einer Toolbar über einer Liste (mit .input-icon) */
.toolbar-search {
    flex: 1 1 280px;
    max-width: 420px;
}

.toolbar-select {
    flex: 0 1 240px;
    min-width: 172px;
}

@media (max-width: 639.98px) {
    .filter-bar {
        padding: 12px;
    }

    .filter-field,
    .filter-field-grow {
        flex: 1 1 100%;
        min-width: 0;
    }

    .filter-actions {
        flex: 1 1 100%;
        margin-left: 0;
    }

    .filter-actions .btn {
        flex: 1;
    }

    .toolbar-search {
        flex: 1 1 100%;
        max-width: none;
    }

    .toolbar-select {
        flex: 1 1 0;
        min-width: 0;
    }

    /* Toolbar mit Suchfeld/Auswahl: Zähler in eigener Zeile */
    .toolbar:has(.toolbar-search, .toolbar-select) .toolbar-meta {
        flex: 1 1 100%;
    }
}

/* ======================================================================
   Pagination (partials/pagination.ejs)
   ====================================================================== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
}

.pagination-info {
    color: var(--color-text-tertiary);
    font-variant-numeric: tabular-nums;
}

.pagination-pages {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--gray-700);
    font-weight: var(--weight-medium);
    font-variant-numeric: tabular-nums;
    text-decoration: none;
    transition: background-color var(--duration-fast) var(--ease-standard);
}

.page-link:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.page-link[aria-current='page'] {
    border-color: var(--color-border-strong);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
    color: var(--color-text);
}

.page-link.is-disabled {
    color: var(--gray-400);
    pointer-events: none;
}

.page-gap {
    min-width: 20px;
    text-align: center;
    color: var(--color-text-tertiary);
}

@media (max-width: 639.98px) {
    .pagination {
        justify-content: center;
    }

    .page-num {
        display: none;
    }
}

/* ======================================================================
   Leerzustand (partials/empty_state.ejs)
   ====================================================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 48px 24px;
    text-align: center;
}

.empty-state-icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-bottom: 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    color: var(--gray-500);
}

/* Ton: .empty-state-icon.tone-neutral | -warning | -danger | -info | -success */
.empty-state-icon.tone-neutral { color: var(--color-text-secondary); }
.empty-state-icon.tone-success { border-color: var(--success-border); background: var(--success-bg); color: var(--success-fg); }
.empty-state-icon.tone-warning { border-color: var(--warning-border); background: var(--warning-bg); color: var(--warning-fg); }
.empty-state-icon.tone-danger { border-color: var(--danger-border); background: var(--danger-bg); color: var(--danger-fg); }
.empty-state-icon.tone-info { border-color: var(--info-border); background: var(--info-bg); color: var(--info-fg); }

.empty-state-title {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--color-text);
}

.empty-state-text {
    max-width: 46ch;
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
}

.empty-state-action {
    margin-top: 14px;
}

.empty-state-sm {
    padding: 24px 16px;
}

/* ======================================================================
   Beschreibungslisten
   dl.dl-grid > div > dt + dd   (Kacheln, z. B. Anruf-Metadaten)
   dl.dl       > dt + dd         (zweispaltig, z. B. Details)
   ====================================================================== */
.dl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
    gap: 18px 24px;
}

.dl-grid > div {
    min-width: 0;
}

.dl-grid dt {
    margin-bottom: 4px;
    font-size: 12.5px;
    font-weight: var(--weight-medium);
    color: var(--color-text-tertiary);
}

.dl-grid dd {
    font-size: var(--text-base);
    color: var(--color-text);
    overflow-wrap: anywhere;
}

.dl-grid .dl-wide {
    grid-column: 1 / -1;
}

.dl {
    display: grid;
    /* Beschriftung höchstens 44 % (schmale Seitenspalten), maximal 200 px */
    grid-template-columns: minmax(96px, min(200px, 44%)) minmax(0, 1fr);
}

.dl > dt,
.dl > dd {
    padding: 10px 0;
    border-bottom: 1px solid var(--color-border-subtle);
}

.dl > dt {
    padding-right: 16px;
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
}

.dl > dd {
    font-size: var(--text-base);
    color: var(--color-text);
    overflow-wrap: anywhere;
}

.dl > dt:first-of-type,
.dl > dt:first-of-type + dd {
    padding-top: 0;
}

.dl > dt:last-of-type,
.dl > dd:last-of-type {
    padding-bottom: 0;
    border-bottom: 0;
}

/* Lange Werte (IDs, Listen): Beschriftung über dem Wert, volle Breite */
.dl > dt.dl-stacked {
    grid-column: 1 / -1;
    padding-bottom: 4px;
    border-bottom: 0;
}

.dl > dd.dl-stacked {
    grid-column: 1 / -1;
    padding-top: 0;
}

@media (max-width: 639.98px) {
    .dl {
        grid-template-columns: minmax(0, 1fr);
    }

    .dl > dt {
        padding-bottom: 2px;
        border-bottom: 0;
    }

    .dl > dd {
        padding-top: 0;
    }
}

/* ======================================================================
   Tabs  nav.tabs > a.tab[aria-current="page"] (+ .tab-count)
   ====================================================================== */
.tabs {
    display: flex;
    gap: 20px;
    border-bottom: 1px solid var(--color-border);
    overflow-x: auto;
    scrollbar-width: none;
}

.tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-bottom: -1px;
    padding: 10px 0;
    border-bottom: 2px solid transparent;
    color: var(--color-text-tertiary);
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    white-space: nowrap;
    text-decoration: none;
}

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

.tab.is-active,
.tab[aria-current='page'] {
    border-bottom-color: var(--navy-700);
    color: var(--color-text);
}

.tab:focus-visible {
    outline-offset: -2px;
}

.tab-count {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 6px;
    border-radius: var(--radius-full);
    background: var(--gray-100);
    color: var(--gray-600);
    font-size: var(--text-2xs);
    font-weight: var(--weight-semibold);
}

/* ======================================================================
   Timeline  ol.timeline > li.timeline-item > .timeline-marker + .timeline-content
   ====================================================================== */
.timeline {
    margin: 0;
    padding: 0;
    list-style: none;
}

.timeline-item {
    position: relative;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 12px;
    padding-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    top: 30px;
    bottom: 2px;
    left: 13.5px;
    width: 1px;
    background: var(--color-border);
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-item:last-child::before {
    display: none;
}

.timeline-marker {
    position: relative;
    z-index: var(--z-raised);
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--color-border);
    border-radius: 50%;
    background: var(--color-surface);
    color: var(--gray-500);
}

.timeline-marker.tone-success { border-color: var(--success-border); background: var(--success-bg); color: var(--success-fg); }
.timeline-marker.tone-warning { border-color: var(--warning-border); background: var(--warning-bg); color: var(--warning-fg); }
.timeline-marker.tone-danger { border-color: var(--danger-border); background: var(--danger-bg); color: var(--danger-fg); }
.timeline-marker.tone-info { border-color: var(--info-border); background: var(--info-bg); color: var(--info-fg); }
.timeline-marker.tone-brand { border-color: var(--brand-border); background: var(--brand-bg); color: var(--brand-fg); }

.timeline-content {
    min-width: 0;
    padding-top: 4px;
}

.timeline-title {
    font-weight: var(--weight-medium);
    color: var(--color-text);
}

.timeline-meta {
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
    font-variant-numeric: tabular-nums;
}

.timeline-body {
    margin-top: 6px;
}

/* ======================================================================
   Diff (vorher → nachher)
   dl.diff > dt.diff-label + dd > .diff-before .diff-arrow .diff-after
   ====================================================================== */
.diff {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 6px 14px;
    font-size: var(--text-sm);
}

.diff-label,
.diff > dt {
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.diff > dd {
    min-width: 0;
    overflow-wrap: anywhere;
}

.diff-before,
.diff-after {
    padding: 1px 5px;
    border-radius: var(--radius-xs);
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}

.diff-before {
    background: var(--red-50);
    color: var(--red-800);
    text-decoration: line-through;
    text-decoration-color: rgb(145 32 24 / 0.45);
}

.diff-after {
    background: var(--green-50);
    color: var(--green-800);
}

.diff-arrow {
    padding: 0 4px;
    color: var(--color-text-tertiary);
}

/* Leerer Wert („–“): neutral statt rot/grün */
.diff-before.diff-empty,
.diff-after.diff-empty {
    background: transparent;
    color: var(--color-text-tertiary);
    text-decoration: none;
}

@media (max-width: 639.98px) {
    .diff {
        grid-template-columns: minmax(0, 1fr);
        gap: 2px;
    }

    .diff > dd + dt {
        margin-top: 8px;
    }
}

/* ======================================================================
   Transkript (Chat)
   .transcript > .msg.msg-agent | .msg-user | .msg-system
   .msg > .msg-avatar + .msg-content > .msg-meta + .msg-bubble
   ====================================================================== */
.transcript {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.msg {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: min(780px, 88%);
}

.msg-avatar {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: var(--text-2xs);
    font-weight: var(--weight-semibold);
}

.msg-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.msg-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
}

.msg-role {
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
}

.msg-time {
    font-variant-numeric: tabular-nums;
}

.msg-bubble {
    padding: 10px 14px;
    border: 1px solid var(--gray-150);
    border-radius: 14px;
    background: var(--gray-75);
    color: var(--color-text);
    font-size: var(--text-base);
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.msg-agent .msg-avatar {
    background: linear-gradient(135deg, var(--navy-600), var(--navy-900));
    color: #fff;
}

.msg-agent .msg-bubble {
    border-top-left-radius: 4px;
}

.msg-user {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.msg-user .msg-content {
    align-items: flex-end;
}

.msg-user .msg-avatar {
    background: var(--gray-100);
    box-shadow: inset 0 0 0 1px var(--color-border);
    color: var(--gray-600);
}

.msg-user .msg-bubble {
    border-color: var(--blue-100);
    border-top-right-radius: 4px;
    background: var(--blue-50);
}

.msg-system {
    align-self: center;
    max-width: 100%;
}

.msg-system .msg-bubble {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius-full);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-size: 12.5px;
    line-height: 1.4;
}

.msg-system.is-error .msg-bubble {
    border-color: var(--danger-border);
    background: var(--danger-bg);
    color: var(--danger-fg);
}

.msg-system .msg-bubble .icon,
.msg-system .msg-time {
    flex-shrink: 0;
}

.msg-system .msg-time {
    margin-left: 2px;
    color: var(--color-text-tertiary);
    white-space: nowrap;
}

@media (max-width: 639.98px) {
    .msg {
        max-width: 100%;
    }

    .msg-avatar {
        display: none;
    }

    /* schmale Spalte: Ereignisse brechen um – weicher Radius statt Pille */
    .msg-system .msg-bubble {
        border-radius: var(--radius-lg);
    }
}

/* ======================================================================
   Audio
   ====================================================================== */
audio.audio-player,
.audio-player {
    display: block;
    width: 100%;
    height: 44px;
    border-radius: var(--radius-full);
}

audio.audio-player::-webkit-media-controls-panel {
    background-color: var(--gray-75);
}

/* ======================================================================
   Code, Mono, Tastenkürzel
   ====================================================================== */
.mono {
    font-family: var(--font-mono);
    font-size: 0.92em;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

code {
    padding: 0.1em 0.35em;
    border: 1px solid var(--gray-150);
    border-radius: 5px;
    background: var(--gray-75);
    font-size: 0.88em;
    overflow-wrap: anywhere;
}

.code-block {
    margin: 0;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--gray-50);
    font-size: 12.5px;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre;
}

/* Lange Inhalte (z. B. JSON) umbrechen statt seitlich scrollen */
.code-block-wrap {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

kbd {
    display: inline-block;
    min-width: 20px;
    padding: 1px 5px;
    border: 1px solid var(--color-border-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--color-surface);
    font-size: var(--text-xs);
    text-align: center;
}

/* ======================================================================
   Avatar (Initialen)
   ====================================================================== */
.avatar {
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--navy-100);
    color: var(--navy-800);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    letter-spacing: 0.02em;
    line-height: 1;
    user-select: none;
}

.avatar-sm {
    width: 24px;
    height: 24px;
    font-size: 10px;
}

.avatar-lg {
    width: 40px;
    height: 40px;
    font-size: var(--text-sm);
}

.avatar-brand {
    background: linear-gradient(135deg, var(--navy-600), var(--navy-900));
    color: #fff;
}

/* Neutral: System/Skript als Akteur, inaktive Personen */
.avatar-neutral,
.row-muted .avatar {
    background: var(--gray-100);
    color: var(--gray-600);
}

/* ======================================================================
   Fortschritt  <progress class="progress" max="40" value="12">
   ====================================================================== */
.progress {
    --progress-color: var(--navy-600);
    display: block;
    width: 100%;
    height: 6px;
    border: 0;
    border-radius: var(--radius-full);
    background: var(--gray-100);
    overflow: hidden;
    -webkit-appearance: none;
    appearance: none;
}

.progress::-webkit-progress-bar {
    border-radius: var(--radius-full);
    background: var(--gray-100);
}

.progress::-webkit-progress-value {
    border-radius: var(--radius-full);
    background: var(--progress-color);
}

.progress::-moz-progress-bar {
    border-radius: var(--radius-full);
    background: var(--progress-color);
}

.progress-success { --progress-color: var(--green-500); }
.progress-warning { --progress-color: var(--amber-500); }
.progress-danger { --progress-color: var(--red-500); }

/* ======================================================================
   Aufklappen  details.disclosure > summary (+ Icon .disclosure-chevron)
   ====================================================================== */
.disclosure > summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    list-style: none;
    border-radius: var(--radius-xs);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
}

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

.disclosure > summary:hover {
    color: var(--color-text);
}

.disclosure-chevron {
    transition: transform var(--duration) var(--ease-out);
}

.disclosure[open] > summary .disclosure-chevron {
    transform: rotate(90deg);
}

.disclosure-body {
    margin-top: 8px;
}

.disclosure-warning > summary {
    color: var(--warning-fg);
}

.disclosure-warning > summary:hover {
    color: var(--warning-text);
}

/* ======================================================================
   Touch-Ziele (mobil / grober Zeiger): mindestens 40 px
   Bedienelemente wachsen über --control-h/--control-h-sm (tokens.css).
   Kleine Ziele im Fließtext (Pfad, Namen in Karten, Aufklapper, Chips)
   behalten ihre Optik und bekommen eine unsichtbare Trefferfläche.
   ====================================================================== */
@media (max-width: 767.98px), (pointer: coarse) {
    .segmented-item {
        height: var(--touch-min);
    }

    .page-link {
        min-width: var(--touch-min);
        height: var(--touch-min);
    }

    .tab {
        min-height: var(--touch-min);
    }

    /* Checkbox-/Radio-/Schalter-Zeilen: Beschriftung als ≥ 40 px hohe Trefferfläche */
    .check > label,
    .check > .check-text {
        padding-block: 10px;
        margin-block: -10px;
    }

    .table-stack a.cell-title,
    .table-stack .cell-title > a,
    .disclosure > summary,
    .hit-area {
        position: relative;
    }

    .table-stack a.cell-title::after,
    .table-stack .cell-title > a::after,
    .disclosure > summary::after,
    .hit-area::after {
        content: '';
        position: absolute;
        top: 50%;
        left: -4px;
        right: -4px;
        min-height: var(--touch-min);
        height: 100%;
        transform: translateY(-50%);
    }
}
