/* Flächen und Rückmeldung (D6): Karte, Chip, Badge, Alert, Terminchip, Liste, Tabelle, Dialog/Sheet, Toast, Leerzustand, Skeleton.
   Nur Alias-Tokens (--tp-color-*) und Skalen aus tokens.css. */
@layer components {

    /* Karte */
    .tp-card {
        background: var(--tp-layer-2-bg);
        border: 1px solid var(--tp-layer-2-border);
        border-radius: var(--tp-radius);
        box-shadow: var(--tp-layer-2-shadow);
        color: var(--tp-color-text);
    }
    .tp-card--raised { box-shadow: var(--tp-shadow); }
    .tp-card__header { padding: var(--tp-space-3) var(--tp-space-4); border-bottom: 1px solid var(--tp-color-border); }
    .tp-card__title { margin: 0; font-size: var(--tp-font-size-lg); font-weight: 600; }
    .tp-card__body { padding: var(--tp-space-4); }
    .tp-card__footer { padding: var(--tp-space-3) var(--tp-space-4); border-top: 1px solid var(--tp-color-border); }

    /* Chip */
    .tp-chip {
        display: inline-flex;
        align-items: center;
        gap: var(--tp-space-1);
        padding: var(--tp-space-1) var(--tp-space-3);
        font: inherit;
        font-size: var(--tp-font-size-sm);
        color: var(--tp-color-text-muted);
        background: var(--tp-color-surface);
        border: 1px solid var(--tp-color-border);
        border-radius: var(--tp-radius-pill);
    }
    .tp-chip--action { min-height: var(--tp-touch-min); cursor: pointer; transition: background var(--tp-duration-fast) var(--tp-easing); }
    :where(:root[data-input="mouse"]) .tp-chip--action:hover { background: var(--tp-color-primary-tint); }
    .tp-chip--selected {
        background: var(--tp-color-primary-tint);
        border-color: var(--tp-color-primary);
        color: var(--tp-color-primary-hover);
    }
    .tp-chip:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }

    /* Badge */
    .tp-badge {
        display: inline-block;
        padding: 0 var(--tp-space-2);
        font-size: var(--tp-font-size-sm);
        font-weight: 600;
        line-height: 1.5;
        border-radius: var(--tp-radius-pill);
        background: var(--tp-color-border);
        color: var(--tp-color-text);
    }
    .tp-badge--primary { background: var(--tp-color-primary-tint); color: var(--tp-color-primary-hover); }
    .tp-badge--attention { background: var(--tp-color-attention-tint); color: var(--tp-color-text); }
    .tp-badge--error { background: var(--tp-color-error-tint); color: var(--tp-color-error); }
    .tp-badge--success { background: var(--tp-color-success-tint); color: var(--tp-color-success); }
    .tp-badge--info { background: var(--tp-color-info-tint); color: var(--tp-color-info); }

    /* Alert */
    .tp-alert {
        padding: var(--tp-space-3) var(--tp-space-4);
        border-radius: var(--tp-radius);
        border-left: 4px solid var(--tp-color-info);
        background: var(--tp-color-info-tint);
        color: var(--tp-color-text);
    }
    .tp-alert__title { display: block; margin-bottom: var(--tp-space-1); }
    .tp-alert--success { border-left-color: var(--tp-color-success); background: var(--tp-color-success-tint); }
    .tp-alert--warn { border-left-color: var(--tp-color-attention); background: var(--tp-color-attention-tint); }
    .tp-alert--danger { border-left-color: var(--tp-color-error); background: var(--tp-color-error-tint); }

    /* Terminchip (DV5): zarte Fläche in der Kalenderfarbe, Rand links kräftig, Text in --tp-cal-ink (Kontrast geprüft, siehe components.css).
       Fällig (--attention): Aufmerksamkeitsfarbe. Vergangen (--past): hellere Fläche, schwächerer Rand, Text bleibt lesbar. */
    .tp-entry-chip {
        display: block;
        width: 100%;
        padding: var(--tp-space-2) var(--tp-space-3);
        font: inherit;
        font-size: var(--tp-font-size-sm);
        line-height: 1.35;
        text-align: left;
        border: 0;
        border-left: 4px solid var(--tp-cal-strong);
        border-radius: 4px var(--tp-radius) var(--tp-radius) 4px;
        background: var(--tp-cal-soft);
        color: var(--tp-cal-ink);
    }
    button.tp-entry-chip { cursor: pointer; }
    :where(:root[data-input="mouse"]) button.tp-entry-chip:hover { background: color-mix(in srgb, var(--tp-cal-src) calc(var(--tp-cal-soft-mix) + 8%), var(--tp-color-surface)); }
    button.tp-entry-chip:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }
    .tp-entry-chip--attention {
        border-left-color: var(--tp-color-attention);
        background: var(--tp-color-attention-tint);
        color: var(--tp-color-text);
    }
    .tp-entry-chip--past {
        border-left-color: var(--tp-cal-border);
        background: color-mix(in srgb, var(--tp-cal-soft) 45%, var(--tp-color-surface));
    }
    .tp-entry-chip--past .tp-entry-chip__time { font-weight: 500; }
    .tp-entry-chip__icon { margin-right: var(--tp-space-1); vertical-align: -2px; }
    .tp-entry-chip__time { margin-right: var(--tp-space-1); font-weight: 600; font-variant-numeric: tabular-nums; }

    /* Liste (Tablet-Listenkarte mit Pfeil) */
    .tp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--tp-space-2); }
    .tp-list__item { margin: 0; }
    .tp-list__link {
        display: flex;
        align-items: center;
        gap: var(--tp-space-3);
        width: 100%;
        min-height: var(--tp-touch-min);
        padding: var(--tp-space-3) var(--tp-space-4);
        font: inherit;
        text-align: left;
        text-decoration: none;
        color: var(--tp-color-text);
        background: var(--tp-color-surface);
        border: 1px solid var(--tp-color-border);
        border-radius: var(--tp-radius);
    }
    a.tp-list__link, button.tp-list__link { cursor: pointer; transition: background var(--tp-duration-fast) var(--tp-easing); }
    :where(:root[data-input="mouse"]) a.tp-list__link:hover, :where(:root[data-input="mouse"]) button.tp-list__link:hover { background: var(--tp-color-primary-tint); }
    a.tp-list__link:focus-visible, button.tp-list__link:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }
    .tp-list__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
    .tp-list__title { font-size: var(--tp-font-size); font-weight: 600; }
    .tp-list__subtitle { font-size: var(--tp-font-size-sm); color: var(--tp-color-text-muted); }
    .tp-list__extra { color: var(--tp-color-text-muted); font-size: var(--tp-font-size-sm); }
    .tp-list__arrow { font-size: var(--tp-font-size-xl); line-height: 1; color: var(--tp-color-text-muted); }

    /* Tabelle */
    .tp-table-wrap { overflow-x: auto; }
    .tp-table { width: 100%; border-collapse: collapse; color: var(--tp-color-text); }
    .tp-table__caption { padding: var(--tp-space-2) 0; text-align: left; color: var(--tp-color-text-muted); font-size: var(--tp-font-size-sm); }
    .tp-table th, .tp-table td { padding: var(--tp-space-2) var(--tp-space-3); text-align: left; border-bottom: 1px solid var(--tp-color-border); }
    .tp-table th { font-size: var(--tp-font-size-sm); font-weight: 600; color: var(--tp-color-text-muted); border-bottom-color: var(--tp-color-border-strong); }
    :where(:root[data-input="mouse"]) .tp-table tbody tr:hover { background: var(--tp-color-primary-tint); }

    /* Dialog und Sheet */
    .tp-dialog {
        position: fixed;
        inset: 0;
        z-index: 1050;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: var(--tp-space-4);
        background: rgba(0, 0, 0, 0.45);
    }
    .tp-dialog__panel {
        display: flex;
        flex-direction: column;
        width: min(100%, 32rem);
        max-height: 100%;
        background: var(--tp-layer-3-bg);
        color: var(--tp-color-text);
        border: 1px solid var(--tp-layer-3-border);
        border-radius: var(--tp-radius-lg);
        box-shadow: var(--tp-layer-3-shadow);
        animation: tp-dialog-in var(--tp-duration) var(--tp-easing);
    }
    .tp-dialog__panel:focus { outline: none; }
    .tp-dialog__header { display: flex; align-items: center; gap: var(--tp-space-3); padding: var(--tp-space-4); border-bottom: 1px solid var(--tp-color-border); }
    .tp-dialog__title { flex: 1; margin: 0; font-size: var(--tp-font-size-lg); font-weight: 600; }
    .tp-dialog__close {
        min-width: var(--tp-touch-min);
        min-height: var(--tp-touch-min);
        font-size: var(--tp-font-size-xl);
        line-height: 1;
        color: var(--tp-color-text-muted);
        background: transparent;
        border: 0;
        border-radius: var(--tp-radius);
        cursor: pointer;
    }
    :where(:root[data-input="mouse"]) .tp-dialog__close:hover { background: var(--tp-color-primary-tint); }
    .tp-dialog__close:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }
    .tp-dialog__body { padding: var(--tp-space-4); overflow-y: auto; }
    .tp-dialog__footer { display: flex; justify-content: flex-end; gap: var(--tp-space-2); padding: var(--tp-space-3) var(--tp-space-4); border-top: 1px solid var(--tp-color-border); }

    /* Sheet von unten (DV9): Griff, zwei Rasthoehen (halb, voll), Hoehen in dvh, Ausweichen vor der Tastatur (--tp-kb-inset aus dialog.js). */
    .tp-dialog--sheet { align-items: flex-end; padding: 0; }
    .tp-dialog--sheet .tp-dialog__panel {
        width: 100%;
        height: 55dvh;
        max-height: 100dvh;
        margin-bottom: var(--tp-kb-inset, 0px);
        border-radius: var(--tp-radius-lg) var(--tp-radius-lg) 0 0;
        animation-name: tp-sheet-in;
        transition: height var(--tp-duration) var(--tp-easing), transform var(--tp-duration) var(--tp-easing);
    }
    .tp-dialog--sheet.tp-dialog--full .tp-dialog__panel { height: calc(100dvh - var(--tp-kb-inset, 0px) - max(var(--tp-space-4), env(safe-area-inset-top))); }
    .tp-dialog--sheet.tp-dialog--large.tp-dialog--full .tp-dialog__panel { height: calc(100dvh - var(--tp-kb-inset, 0px)); border-radius: 0; padding-top: env(safe-area-inset-top); }
    .tp-dialog--sheet .tp-dialog__panel.tp-dialog__panel--dragging { transition: none; }
    .tp-dialog--sheet .tp-dialog__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 0; }
    .tp-dialog--sheet .tp-dialog__footer { padding-bottom: calc(var(--tp-space-3) + env(safe-area-inset-bottom)); }
    .tp-dialog__handle { display: flex; justify-content: center; padding-top: var(--tp-space-1); touch-action: none; }
    .tp-dialog__grip {
        width: 4.5rem; min-height: var(--tp-touch-min); padding: 0; border: 0; background: transparent; cursor: grab; touch-action: none;
        display: flex; align-items: center; justify-content: center;
    }
    .tp-dialog__grip::before { content: ""; width: 2.5rem; height: 0.3rem; border-radius: 999px; background: var(--tp-color-border-strong); }
    .tp-dialog__grip:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); border-radius: var(--tp-radius); }
    .tp-dialog--sheet .tp-dialog__header { touch-action: none; padding-top: var(--tp-space-1); }
    /* Hauptknopf klebt unten im Sheet (ueber der Tastatur); der Inhalt scrollt darueber. */
    .tp-dialog--sheet .tp-editor__actions {
        position: sticky; bottom: 0; z-index: 1;
        margin: var(--tp-space-3) calc(-1 * var(--tp-space-4)) 0;
        padding: var(--tp-space-3) var(--tp-space-4) calc(var(--tp-space-3) + env(safe-area-inset-bottom));
        background: var(--tp-layer-3-bg); border-top: 1px solid var(--tp-color-border);
    }
    .tp-dialog--sheet .tp-editor__actions > .tp-btn { flex: 1 1 auto; }
    /* Dialoge, die nie Sheet werden (Rueckfragen), bleiben auf dem Handy trotzdem unten verankert. */
    :where([data-profile="phone"]) .tp-dialog { align-items: flex-end; padding: 0; }
    :where([data-profile="phone"]) .tp-dialog:not(.tp-dialog--sheet) .tp-dialog__panel { width: 100%; max-height: 90dvh; border-radius: var(--tp-radius-lg) var(--tp-radius-lg) 0 0; animation-name: tp-sheet-in; }
    :where(:root[data-input="touch"]) .tp-dialog__close { min-width: 3rem; min-height: 3rem; }
    @keyframes tp-dialog-in { from { opacity: 0; transform: translateY(var(--tp-space-3)); } to { opacity: 1; transform: none; } }
    @keyframes tp-sheet-in { from { transform: translateY(100%); } to { transform: none; } }

    /* Toast */
    .tp-toast {
        display: flex;
        align-items: center;
        gap: var(--tp-space-3);
        max-width: 32rem;
        padding: var(--tp-space-3) var(--tp-space-4);
        color: var(--tp-color-text);
        background: var(--tp-layer-3-bg);
        border: 1px solid var(--tp-layer-3-border);
        border-left: 4px solid var(--tp-color-info);
        border-radius: var(--tp-radius);
        box-shadow: var(--tp-layer-3-shadow);
    }
    .tp-toast__text { flex: 1; }
    .tp-toast__close { min-width: var(--tp-touch-min); min-height: var(--tp-touch-min); font-size: var(--tp-font-size-lg); color: var(--tp-color-text-muted); background: transparent; border: 0; border-radius: var(--tp-radius); cursor: pointer; }
    .tp-toast__action { min-height: var(--tp-touch-min); padding: 0 var(--tp-space-3); font: inherit; font-weight: 600; color: var(--tp-color-primary); background: transparent; border: 0; border-radius: var(--tp-radius); cursor: pointer; }
    :where(:root[data-input="mouse"]) .tp-toast__action:hover { background: var(--tp-color-primary-tint); }
    .tp-toast__action:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }
    .tp-toast__close:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }
    .tp-toast--success { border-left-color: var(--tp-color-success); }
    .tp-toast--warn { border-left-color: var(--tp-color-attention); }
    .tp-toast--danger { border-left-color: var(--tp-color-error); }
    /* Toast-Bereich: unten mittig; am Smartphone über der unteren Navigation (Höhe der Leiste + Sicherheitsrand). */
    .tp-toasts {
        position: fixed; z-index: 1100; left: 50%; bottom: var(--tp-space-4); transform: translateX(-50%);
        display: flex; flex-direction: column; gap: var(--tp-space-2); width: min(32rem, calc(100vw - 2 * var(--tp-space-4)));
        pointer-events: none;
    }
    .tp-toasts .tp-toast { pointer-events: auto; max-width: none; }
    [data-profile="phone"] .tp-toasts { bottom: calc(var(--tp-touch-min) + var(--tp-space-5) + env(safe-area-inset-bottom)); }

    /* Leerzustand */
    .tp-empty { display: flex; flex-direction: column; align-items: center; gap: var(--tp-space-2); padding: var(--tp-space-6) var(--tp-space-4); text-align: center; color: var(--tp-color-text-muted); }
    .tp-empty__symbol { font-size: var(--tp-font-size-hero); line-height: 1; color: var(--tp-color-primary); }
    .tp-empty__title { margin: 0; font-size: var(--tp-font-size-lg); color: var(--tp-color-text); }
    .tp-empty__text { margin: 0; max-width: 28rem; }
    .tp-empty__actions { margin-top: var(--tp-space-3); }

    /* Profilbild (TpAvatar, P3): rund; Initialen in Kalenderfarbe (oder Akzent), Bild füllt den Kreis. Größe über --tp-avatar-size (Tokens sm/md/lg). */
    .tp-avatar {
        --tp-avatar-size: var(--tp-avatar-size-md);
        display: inline-flex; align-items: center; justify-content: center; flex: none; box-sizing: border-box; overflow: hidden; vertical-align: middle;
        width: var(--tp-avatar-size); height: var(--tp-avatar-size); border-radius: var(--tp-radius-pill);
        border: 1px solid var(--tp-color-border); background: var(--tp-color-primary-tint); color: var(--tp-color-primary);
        font-size: calc(var(--tp-avatar-size) * 0.4); font-weight: 700; line-height: 1; letter-spacing: .02em; user-select: none;
    }
    .tp-sender { display: inline-flex; align-items: center; gap: var(--tp-space-2); }
    .tp-avatar--sm { --tp-avatar-size: var(--tp-avatar-size-sm); }
    .tp-avatar--lg { --tp-avatar-size: var(--tp-avatar-size-lg); }
    .tp-avatar--initials[style] { border: 2px solid var(--tp-cal-strong); background: var(--tp-cal-soft); color: var(--tp-cal-ink); }
    .tp-avatar--initials::before { content: attr(data-initials); } /* Initialen aus data-initials: bleiben außerhalb des Zeilentextes (Suche, Hilfstechnik) */
    .tp-avatar__img { width: 100%; height: 100%; object-fit: cover; display: block; }
    .tp-avatar.tp-skeleton { border-color: transparent; border-radius: var(--tp-radius-pill); } /* Ladezustand: Schimmer des Skeletons (steht danach), Kreisform bleibt */
    /* Skeleton */
    .tp-skeleton-group { display: flex; flex-direction: column; gap: var(--tp-space-2); }
    .tp-skeleton {
        border-radius: var(--tp-radius-sm);
        /* Ruhiger Schimmer: langsam und mit geringem Kontrast (Glanz nur ein Viertel Primärtönung über der Grundfläche). */
        --tp-skeleton-base: color-mix(in srgb, var(--tp-color-border) 70%, var(--tp-color-surface));
        --tp-skeleton-shine: color-mix(in srgb, var(--tp-color-primary-tint) 40%, var(--tp-skeleton-base));
        background: linear-gradient(90deg, var(--tp-skeleton-base) 30%, var(--tp-skeleton-shine) 50%, var(--tp-skeleton-base) 70%);
        background-size: 200% 100%;
        animation: tp-skeleton-shimmer var(--tp-motion-ambient) ease-in-out infinite;
    }
    [data-profile="senior"] .tp-skeleton { animation: none; }
    .tp-skeleton--circle { border-radius: var(--tp-radius-pill); }
    .tp-skeleton--card { border-radius: var(--tp-radius-lg); }
    .tp-skeleton-row { display: flex; align-items: center; gap: var(--tp-space-3); }
    .tp-skeleton-row > .tp-skeleton:last-child { flex: 1 1 auto; }
    @keyframes tp-skeleton-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

    @media (prefers-reduced-motion: reduce) {
        .tp-skeleton { animation: none; }
        .tp-dialog__panel { animation: none; transition: none; }
    }

    /* Seiten Kalender und Termine (D10): Seitenkopf, Formular-Raster, Kalenderraster, Detailansicht, Knopf-Schweber. Nur Tokens. */
    .tp-page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--tp-space-3); margin-bottom: var(--tp-space-4); }
    .tp-page-head__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--tp-space-2); }
    .tp-page-title { margin: 0; font-size: var(--tp-font-size-xl); font-weight: 700; }
    .tp-section { margin-bottom: var(--tp-space-5); }
    .tp-section__title { margin: 0 0 var(--tp-space-2); font-size: var(--tp-font-size-lg); font-weight: 600; }
    .tp-muted { color: var(--tp-color-text-muted); font-size: var(--tp-font-size-sm); }
    .tp-prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
    .tp-truncate { max-width: 28rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .tp-plain-list { list-style: none; margin: 0; padding: 0; }
    /* Kalender-Kreis (DV5): zarte Fläche, kräftiger Rand, Anfangsbuchstabe in --tp-cal-ink */
    .tp-caldot {
        display: inline-flex; align-items: center; justify-content: center; flex: none; box-sizing: border-box;
        width: 1.5rem; height: 1.5rem; border-radius: 50%; border: 2px solid var(--tp-cal-strong); background: var(--tp-cal-soft); color: var(--tp-cal-ink);
        font-size: 0.75rem; font-weight: 700; line-height: 1; user-select: none; vertical-align: middle;
    }
    .tp-caldot::before { content: attr(data-letter); } /* Buchstabe aus data-letter: bleibt außerhalb des Zeilentextes (Suche, Hilfstechnik) */
    .tp-caldot--md { width: 2rem; height: 2rem; font-size: 0.9rem; }
    .tp-swatch { display: inline-block; width: 0.8rem; height: 0.8rem; margin-right: var(--tp-space-2); border-radius: 50%; vertical-align: baseline; border: 1px solid var(--tp-color-border-strong); }
    .tp-view-switch { display: flex; flex-wrap: wrap; gap: var(--tp-space-2); margin-bottom: var(--tp-space-4); }
    .tp-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: var(--tp-space-3); }
    .tp-table__actions { display: flex; flex-wrap: wrap; gap: var(--tp-space-2); justify-content: flex-end; }
    .tp-entry-link { padding: 0; min-height: 0; font-weight: 600; color: var(--tp-color-primary-hover); text-align: left; }
    .tp-hint { padding: var(--tp-space-2) var(--tp-space-3); font-size: var(--tp-font-size-sm); color: var(--tp-color-text); background: var(--tp-color-attention-tint); border-left: 4px solid var(--tp-color-attention); border-radius: var(--tp-radius-sm); }
    a.tp-btn { text-decoration: none; }

    /* Editor und Formular-Raster */
    .tp-editor { padding: var(--tp-space-4); margin-bottom: var(--tp-space-4); }
    .tp-editor__title { margin: 0 0 var(--tp-space-3); font-size: var(--tp-font-size-lg); font-weight: 600; }
    .tp-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0 var(--tp-space-4); align-items: start; }
    .tp-span-all { grid-column: 1 / -1; }
    .tp-span-wide { grid-column: span 2; }
    .tp-editor__row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--tp-space-3); }
    .tp-editor__inline { display: flex; gap: var(--tp-space-2); align-items: center; }
    .tp-editor__inline--end { align-items: end; }
    .tp-editor__inline > .tp-field { flex: 1; min-width: 0; margin-bottom: 0; }
    .tp-editor__actions { display: flex; flex-wrap: wrap; gap: var(--tp-space-2); margin-top: var(--tp-space-3); }
    .tp-editor__checks { display: flex; flex-wrap: wrap; gap: var(--tp-space-2) var(--tp-space-4); margin-top: var(--tp-space-3); }
    .tp-fieldset { margin: var(--tp-space-4) 0 0; padding: var(--tp-space-3) var(--tp-space-4); border: 1px solid var(--tp-color-border); border-radius: var(--tp-radius); min-width: 0; }
    .tp-fieldset__legend { float: none; width: auto; margin: 0; padding: 0 var(--tp-space-2); font-size: var(--tp-font-size); font-weight: 600; }
    .tp-input--narrow { width: 6rem; }
    .tp-input--color { width: 4rem; padding: var(--tp-space-1); }
    .tp-notify-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--tp-space-3); margin-bottom: var(--tp-space-2); }
    .tp-step-row { flex: 1; min-width: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0 var(--tp-space-3); align-items: end; }
    .tp-step-row__actions { display: flex; gap: var(--tp-space-1); margin-bottom: var(--tp-space-3); }
    .tp-step-timeline, .tp-preview { margin-top: var(--tp-space-3); }
    .tp-preview { padding: var(--tp-space-3) var(--tp-space-4); background: var(--tp-color-primary-tint); border-left: 4px solid var(--tp-color-primary); border-radius: var(--tp-radius-sm); }

    /* Aufklappbare Abschnitte (TpDisclosure), z. B. im Terminformular */
    .tp-disclosure { margin-top: var(--tp-space-3); border: 1px solid var(--tp-color-border); border-radius: var(--tp-radius); min-width: 0; }
    .tp-disclosure__heading { margin: 0; font-size: inherit; font-weight: inherit; }
    .tp-disclosure__head { display: flex; align-items: center; gap: var(--tp-space-3); width: 100%; min-height: var(--tp-touch-min); padding: var(--tp-space-2) var(--tp-space-4); background: transparent; border: 0; border-radius: var(--tp-radius); color: inherit; font: inherit; text-align: left; cursor: pointer; }
    :where(:root[data-input="mouse"]) .tp-disclosure__head:hover { background: var(--tp-color-primary-tint); }
    .tp-disclosure__title { font-weight: 600; flex: none; }
    .tp-disclosure__summary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tp-color-text-muted); font-size: var(--tp-font-size-sm); }
    .tp-disclosure__head .tp-skeleton-group { flex: 1; }
    .tp-disclosure__chevron { margin-left: auto; display: inline-flex; transition: transform var(--tp-duration-fast); }
    .tp-disclosure--open > .tp-disclosure__heading .tp-disclosure__chevron { transform: rotate(180deg); }
    .tp-disclosure__body { padding: var(--tp-space-1) var(--tp-space-4) var(--tp-space-4); }
    .tp-disclosure__body[hidden] { display: none; }
    @media (prefers-reduced-motion: reduce) { .tp-disclosure__chevron { transition: none; } }

    /* Detailansicht eines Termins als Modal (TpDialog; auf Smartphone und Touch-Tablet als Sheet) */
    .tp-dl { display: grid; grid-template-columns: minmax(6rem, 9rem) minmax(0, 1fr); gap: var(--tp-space-2) var(--tp-space-3); margin: 0; }
    .tp-dl dt { font-size: var(--tp-font-size-sm); font-weight: 600; color: var(--tp-color-text-muted); }
    .tp-dl dd { margin: 0; overflow-wrap: anywhere; }
    .tp-entry-detail__actions { display: flex; flex: 1 1 auto; flex-wrap: wrap; justify-content: flex-end; gap: var(--tp-space-2); }
    .tp-dialog--sheet .tp-dl { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .tp-dialog--sheet .tp-dl dd { margin-bottom: var(--tp-space-3); }

    /* Kalenderraster (Woche/Monat) mit Terminchips */
    .tp-cal__bar { display: flex; align-items: center; gap: var(--tp-space-2); margin-bottom: var(--tp-space-2); }
    .tp-cal__title { margin-left: var(--tp-space-2); }
    .tp-cal__grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--tp-color-border); border: 1px solid var(--tp-color-border); border-radius: var(--tp-radius); overflow: hidden; }
    .tp-cal__head { background: var(--tp-color-background); text-align: center; font-weight: 600; padding: var(--tp-space-1); }
    .tp-cal__cell { background: var(--tp-color-surface); min-height: 5.5rem; padding: var(--tp-space-1); min-width: 0; }
    .tp-cal__grid--week .tp-cal__cell { min-height: 12rem; }
    .tp-cal__cell--today { background: var(--tp-color-attention-tint); }
    .tp-cal__cell--other { background: var(--tp-color-background); color: var(--tp-color-text-muted); }
    .tp-cal__day { font-size: var(--tp-font-size-sm); color: var(--tp-color-text-muted); }
    .tp-cal__items, .tp-cal__cell .tp-sortable { display: flex; flex-direction: column; gap: var(--tp-space-1); min-height: 2rem; }
    .tp-cal__cell .tp-entry-chip { display: flex; align-items: center; min-height: var(--tp-touch-min); padding: 2px var(--tp-space-2); font-size: var(--tp-font-size-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .tp-cal__step { font-size: var(--tp-font-size-sm); color: var(--tp-color-text-muted); padding-left: var(--tp-space-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .tp-cal__cell .tp-draggable { padding: 0; border: 0; background: transparent; }
    .tp-cal__cell .tp-sortable-ghost { outline: 2px dashed var(--tp-color-primary); }
    :where([data-profile="phone"]) .tp-cal__grid { grid-template-columns: minmax(0, 1fr); }
    :where([data-profile="phone"]) .tp-cal__head { display: none; }
    :where([data-profile="phone"]) .tp-cal__cell, :where([data-profile="phone"]) .tp-cal__grid--week .tp-cal__cell { min-height: 0; }

    /* Knopf-Schweber "+" (Smartphone) */
    .tp-fab-wrap { position: sticky; bottom: var(--tp-space-4); display: flex; justify-content: flex-end; margin-top: var(--tp-space-4); pointer-events: none; }
    .tp-fab {
        pointer-events: auto; width: 3.5rem; height: 3.5rem; display: inline-flex; align-items: center; justify-content: center;
        border: 0; border-radius: 50%; background: var(--tp-color-primary); color: var(--tp-color-surface); box-shadow: var(--tp-shadow-lg); cursor: pointer;
    }
    :where(:root[data-input="mouse"]) .tp-fab:hover:not(:disabled) { background: var(--tp-color-primary-hover); }
    .tp-fab:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }
    .tp-fab:disabled { opacity: 0.5; cursor: not-allowed; }

    /* Reiter (TpTabs): eine Zeile, am Smartphone waagerecht scrollbar, aktiver Reiter mit Unterstrich */
    .tp-tabs { display: flex; gap: var(--tp-space-1); overflow-x: auto; overflow-y: hidden; border-bottom: 1px solid var(--tp-color-border-strong); margin-bottom: var(--tp-space-4); scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
    .tp-tab {
        flex: 0 0 auto; min-height: var(--tp-touch-min); padding: 0 var(--tp-space-4); border: 0; border-bottom: 3px solid transparent; margin-bottom: -1px;
        background: transparent; color: var(--tp-color-text-muted); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
    }
    :where(:root[data-input="mouse"]) .tp-tab:hover { color: var(--tp-color-text); background: var(--tp-color-primary-tint); }
    .tp-tab--active { color: var(--tp-color-primary-hover); border-bottom-color: var(--tp-color-primary); }
    .tp-tab:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }
    .tp-tabpanel:focus-visible { outline: none; }
    .tp-detail-list { display: grid; grid-template-columns: max-content 1fr; gap: var(--tp-space-2) var(--tp-space-4); margin: 0 0 var(--tp-space-4); }
    .tp-detail-list dt { color: var(--tp-color-text-muted); font-weight: 600; }
    .tp-detail-list dd { margin: 0; display: flex; align-items: center; gap: var(--tp-space-2); }

    /* Maus-Bedienung (DV7): Vorschau, Tooltip und Kontextmenü liegen als popover="manual" in der obersten Ebene (kein Abschneiden); floating.js setzt left/top. */
    .tp-pop { display: contents; }
    .tp-popover {
        position: fixed; inset: auto; margin: 0; padding: var(--tp-space-2) var(--tp-space-3);
        max-width: min(20rem, calc(100vw - 16px)); overflow: visible; pointer-events: none;
        color: var(--tp-color-text); background: var(--tp-layer-3-bg); border: 1px solid var(--tp-layer-3-border);
        border-radius: var(--tp-radius); box-shadow: var(--tp-layer-3-shadow);
        font-size: var(--tp-font-size-sm); line-height: 1.35;
    }
    .tp-popover--tip { padding: var(--tp-space-1) var(--tp-space-2); border-radius: var(--tp-radius-sm); white-space: nowrap; }
    .tp-preview { display: flex; flex-direction: column; gap: 2px; }
    .tp-preview__title { font-size: var(--tp-font-size); }
    .tp-preview__row { color: var(--tp-color-text-muted); }
    .tp-preview__notes { margin-top: var(--tp-space-1); overflow-wrap: anywhere; }

    .tp-menu-layer { position: fixed; inset: 0; margin: 0; padding: 0; width: auto; height: auto; max-width: none; max-height: none; overflow: visible; background: transparent; border: 0; }
    .tp-menu-layer::backdrop { background: transparent; }
    .tp-menu {
        position: fixed; left: 0; top: 0; min-width: 12rem; max-width: min(24rem, calc(100vw - 16px)); padding: var(--tp-space-1);
        display: flex; flex-direction: column; gap: 1px;
        background: var(--tp-layer-3-bg); border: 1px solid var(--tp-layer-3-border); border-radius: var(--tp-radius); box-shadow: var(--tp-layer-3-shadow);
    }
    .tp-menu:focus-visible { outline: none; }
    .tp-menu__item {
        display: flex; align-items: center; gap: var(--tp-space-2); width: 100%; min-height: 2.25rem; padding: 0 var(--tp-space-3);
        font: inherit; color: var(--tp-color-text); text-align: left; background: transparent; border: 0; border-radius: var(--tp-radius-sm); cursor: pointer;
    }
    .tp-menu__item--active, .tp-menu__item:focus-visible { background: var(--tp-color-primary-tint); outline: none; }
    .tp-menu__item--danger { color: var(--tp-color-error); }
    .tp-menu__item:disabled { color: var(--tp-color-text-muted); cursor: default; }
    .tp-menu__sep { height: 1px; margin: var(--tp-space-1) 0; background: var(--tp-color-border); }

    /* Zeilenaktionen (Bearbeiten, Löschen ...) erscheinen mit der Maus erst beim Überfahren und bei Tastaturfokus; bei Touch bleiben sie sichtbar.
       Unsichtbar heißt hier nur durchsichtig: die Knöpfe bleiben per Tab erreichbar, und :focus-within blendet sie dann ein. */
    :where(:root[data-input="mouse"]) :is(tr, .tp-list__item) :is(.tp-table__actions, .tp-row-actions) { opacity: 0; transition: opacity var(--tp-duration-fast) var(--tp-easing); }
    :where(:root[data-input="mouse"]) :is(tr, .tp-list__item):is(:hover, :focus-within) :is(.tp-table__actions, .tp-row-actions) { opacity: 1; }
    .tp-list__item--has-actions { display: flex; align-items: center; gap: var(--tp-space-2); }
    .tp-list__item--has-actions > .tp-list__link { flex: 1; min-width: 0; }
    .tp-list__actions { display: flex; gap: var(--tp-space-2); }
}
