/* Kalender-Seite (M3a): Steuerung in der Seitenleiste, Tagesansicht. Nur Tokens, keine festen Farben. */
@layer components {

    /* ----- Steuerung (Kalenderauswahl + Ansicht) ----- */
    .tp-calnav { display: flex; flex-direction: column; gap: var(--tp-space-3); min-width: 0; }
    .tp-calnav__views { display: flex; gap: var(--tp-space-1); margin: 0; flex-wrap: nowrap; }
    .tp-calnav__views > * { flex: 1 1 0; min-width: 0; }
    .tp-calnav__calendars { margin: 0; padding: 0; border: 0; min-width: 0; }
    .tp-calnav__checks { display: flex; flex-direction: column; gap: var(--tp-space-1); }

    /* Desktop und senior: Slot unter dem Menü, scrollt intern. */
    .tp-nav__slot {
        flex: 0 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
        padding-top: var(--tp-space-3); border-top: 1px solid var(--tp-color-border);
    }

    /* Tablet und Smartphone: kompakt oben im Inhalt, Kalender als umbrechende Reihe. */
    .tp-shell__topslot { margin-bottom: var(--tp-space-3); padding-bottom: var(--tp-space-3); border-bottom: 1px solid var(--tp-color-border); }
    .tp-shell__topslot .tp-calnav { flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: var(--tp-space-2) var(--tp-space-4); }
    .tp-shell__topslot .tp-calnav__views { flex: 0 0 auto; }
    .tp-shell__topslot .tp-calnav__views > * { flex: 0 0 auto; }
    .tp-shell__topslot .tp-calnav__calendars { flex: 1 1 14rem; }
    .tp-shell__topslot .tp-calnav__checks { flex-direction: row; flex-wrap: wrap; gap: var(--tp-space-1) var(--tp-space-4); max-height: 6.5rem; overflow-y: auto; }
    .tp-shell__topslot .tp-fieldset__legend { margin-bottom: var(--tp-space-1); }
    [data-profile="phone"] .tp-shell__topslot .tp-calnav { flex-direction: column; }
    [data-profile="phone"] .tp-shell__topslot .tp-calnav__views { width: 100%; }
    [data-profile="phone"] .tp-shell__topslot .tp-calnav__views > * { flex: 1 1 0; }

    /* Kalenderauswahl kompakt: kein Außenabstand der Zeilen (kein leerer Bereich unter den Kästchen). */
    .tp-calnav__checks .tp-check { margin-bottom: 0; }
    /* Kästchen in der Farbe des Kalenders (Tokens als Rückfall) */
    .tp-calnav__checks .tp-check__box { border-color: var(--tp-cal-strong); }
    .tp-calnav__checks .tp-check__input:checked ~ .tp-check__box { background: var(--tp-cal-strong); border-color: var(--tp-cal-strong); }
    .tp-calnav__checks .tp-check__label { display: inline-flex; align-items: center; gap: var(--tp-space-2); }
    .tp-calnav__checks .tp-check__label { min-width: 0; }
    .tp-calnav__owner { display: inline-flex; flex: 0 0 auto; }
    .tp-calnav__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    :where(:root[data-input="mouse"]) .tp-calnav__checks .tp-check__row:hover .tp-check__input:not(:disabled) ~ .tp-check__box { border-color: var(--tp-cal-strong); }

    /* ----- Zahl eines Tages als Schaltfläche (Wechsel in die Tagesansicht) ----- */
    .tp-cal__day--link {
        display: inline-flex; align-items: center; justify-content: center; min-width: var(--tp-touch-min); min-height: var(--tp-touch-min); padding: 0 var(--tp-space-1); border: 0; border-radius: var(--tp-radius); background: transparent;
        font: inherit; font-size: var(--tp-font-size-sm); color: var(--tp-color-text-muted); cursor: pointer;
    }
    :where(:root[data-input="mouse"]) .tp-cal__day--link:hover { background: var(--tp-color-primary-tint); color: var(--tp-color-text); }

    /* ----- Tagesansicht ----- */
    .tp-day__title { text-transform: none; }
    .tp-day__empty { padding: var(--tp-space-4) 0; }
    .tp-day__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--tp-space-3); }
    .tp-day__item {
        background: color-mix(in srgb, var(--tp-cal-soft) 55%, var(--tp-layer-2-bg)); border: 1px solid var(--tp-layer-2-border); border-left: 4px solid var(--tp-cal-strong);
        border-radius: var(--tp-radius); box-shadow: var(--tp-layer-2-shadow); padding: var(--tp-space-3) var(--tp-space-4); min-width: 0;
    }
    .tp-day__head {
        display: flex; align-items: baseline; gap: var(--tp-space-3); width: 100%; padding: 0; border: 0; background: transparent;
        font: inherit; font-size: var(--tp-font-size-lg); color: var(--tp-color-text); text-align: left; min-width: 0;
    }
    button.tp-day__head { cursor: pointer; min-height: var(--tp-touch-min); }
    :where(:root[data-input="mouse"]) button.tp-day__head:hover .tp-day__name { text-decoration: underline; }
    .tp-day__time { flex: none; color: var(--tp-cal-ink); font-variant-numeric: tabular-nums; }
    .tp-day__name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
    .tp-day__sound { flex: none; color: var(--tp-color-attention); }
    .tp-day__details { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--tp-space-1) var(--tp-space-3); margin: var(--tp-space-2) 0 0; }
    .tp-day__details dt { color: var(--tp-color-text-muted); font-size: var(--tp-font-size-sm); }
    .tp-day__details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
    .tp-day__step {
        display: flex; flex-wrap: wrap; gap: var(--tp-space-2); padding: var(--tp-space-1) var(--tp-space-3);
        border-left: 2px dotted var(--tp-cal-strong); color: var(--tp-color-text-muted);
    }
    .tp-day__stepline { padding: 0; }
    /* Layoutwechsel nur über das Profil (profile.js), nicht über eigene Breiten; :where() hält die Spezifität wie bei einer Media Query. */
    :where([data-profile="phone"]) .tp-day__details { grid-template-columns: minmax(0, 1fr); }
    :where([data-profile="phone"]) .tp-day__details dt { margin-top: var(--tp-space-1); }

    /* ----- Plus unten im Tag (neuer Termin) ----- */
    .tp-add {
        display: inline-flex; align-items: center; justify-content: center; gap: var(--tp-space-2); padding: var(--tp-space-1) var(--tp-space-2);
        border: 1px dashed var(--tp-color-border-strong); border-radius: var(--tp-radius); background: transparent;
        font: inherit; color: var(--tp-color-text-muted); cursor: pointer;
    }
    :where(:root[data-input="mouse"]) .tp-add:hover { background: var(--tp-color-primary-tint); color: var(--tp-color-text); border-color: var(--tp-color-primary); }
    .tp-add:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }
    .tp-cal__add { display: flex; width: 100%; margin-top: var(--tp-space-1); min-height: max(1.75rem, var(--tp-touch-min)); }
    .tp-day__add { width: 100%; min-height: var(--tp-touch-min); margin-top: var(--tp-space-3); font-size: var(--tp-font-size-lg); }
    [data-profile="phone"] .tp-cal__add, [data-profile="tablet"] .tp-cal__add { min-height: var(--tp-touch-min); }
    /* Wochenansicht, nicht volle Tage: Zelle als Spalte, Plus ohne Rahmen mittig im freien Bereich unter den Terminen. */
    .tp-cal__grid--week .tp-cal__cell { display: flex; flex-direction: column; }
    .tp-cal__grid--week .tp-cal__add--free { flex: 1 1 auto; width: 100%; border: 0; background: transparent; min-height: max(2.5rem, var(--tp-touch-min)); }
    :where(:root[data-input="mouse"]) .tp-cal__grid--week .tp-cal__add--free:hover { border: 0; }
    :where([data-profile="phone"]) .tp-cal__grid--week .tp-cal__add--free { flex: 0 0 auto; }
    /* Monatsansicht wie Woche, nur auf breiten Layouts (Smartphone einspaltig bleibt unverändert). */
    :where(:root:not([data-profile="phone"])) .tp-cal__grid--month .tp-cal__cell { display: flex; flex-direction: column; }
    :where(:root:not([data-profile="phone"])) .tp-cal__grid--month .tp-cal__add--free { flex: 1 1 auto; width: 100%; border: 0; background: transparent; min-height: max(2.5rem, var(--tp-touch-min)); }
    :where(:root[data-input="mouse"]) :where(:root:not([data-profile="phone"])) .tp-cal__grid--month .tp-cal__add--free:hover { border: 0; }

    /* ----- Termin-Formular als großes Modal (EntryEditDialog) ----- */
    .tp-dialog--large:not(.tp-dialog--sheet) { padding: var(--tp-space-3); }
    /* V5: so hoch wie der Inhalt (die Körper-Fläche scrollt erst am Rand) und höchstens 46rem breit. */
    .tp-dialog--large:not(.tp-dialog--sheet) .tp-dialog__panel { width: min(100%, 46rem); height: auto; max-height: 100%; }
    .tp-dialog--large .tp-dialog__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
    .tp-dialog--large .tp-editor { border: 0; box-shadow: none; padding: 0; background: transparent; }
    .tp-entry-dialog__calendar { margin-bottom: var(--tp-space-3); }

    /* ----- Vorlagen (VT5): Name der Vorlage im Editor, Zielliste im Kopier-Dialog, Einleitung im Reiter ----- */
    .tp-entry-template-name { margin-bottom: var(--tp-space-3); }
    .tp-template-targets { display: flex; flex-direction: column; gap: var(--tp-space-1); margin-block: var(--tp-space-2); }
    .tp-editor__intro { margin: 0 0 var(--tp-space-3); }

    /* ----- Smartphone: Kalenderfilter als waagerecht scrollbare Chip-Zeile in den Kalenderfarben ----- */
    .tp-calchips {
        display: flex; gap: var(--tp-space-2); overflow-x: auto; overflow-y: hidden; padding-bottom: var(--tp-space-1);
        scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
    }
    .tp-calchips::-webkit-scrollbar { display: none; }
    /* Runder Chip ohne Namen (Avatar des Besitzers im Kalenderfarben-Ring). Ausgewählt: dicker durchgezogener Ring plus Häkchen-Marke; nicht ausgewählt: dünner gestrichelter Ring, gedämpft. */
    .tp-calchip {
        position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center;
        width: var(--tp-touch-min); height: var(--tp-touch-min); padding: 0; box-sizing: border-box;
        border: 2px dashed var(--tp-cal-border); border-radius: var(--tp-radius-pill); background: transparent;
        font: inherit; cursor: pointer; scroll-snap-align: start;
    }
    .tp-calchip .tp-avatar { pointer-events: none; }
    .tp-calchip[aria-pressed="true"] { border: 3px solid var(--tp-cal-strong); background: var(--tp-cal-soft); }
    .tp-calchip[aria-pressed="true"]::after {
        content: "¹3"; position: absolute; right: -2px; bottom: -2px; width: 1.1rem; height: 1.1rem; border-radius: 50%;
        display: grid; place-items: center; font-size: 0.7rem; font-weight: 700; line-height: 1;
        background: var(--tp-cal-strong); color: var(--tp-color-surface);
    }
    .tp-calchip[aria-pressed="false"] .tp-avatar { opacity: 0.5; }
    .tp-calchip:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }
    [data-profile="phone"] .tp-shell__topslot .tp-calnav { gap: var(--tp-space-2); }
    [data-profile="phone"] .tp-shell__topslot .tp-calnav__views { margin-bottom: 0; }

    /* ----- Wochenstreifen der Tagesansicht (Smartphone): sieben Tage, antippbar, Punkt bei Terminen ----- */
    .tp-weekstrip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--tp-space-1); margin-bottom: var(--tp-space-3); }
    .tp-weekstrip__day {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 3.5rem; padding: var(--tp-space-1) 0;
        border: 1px solid transparent; border-radius: var(--tp-radius); background: transparent; color: var(--tp-color-text-muted); font: inherit; cursor: pointer;
    }
    .tp-weekstrip__dow { font-size: var(--tp-font-size-sm); }
    .tp-weekstrip__num { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--tp-color-text); }
    .tp-weekstrip__dot { width: 0.4rem; height: 0.4rem; border-radius: 50%; background: var(--tp-color-primary); }
    .tp-weekstrip__dot--none { background: transparent; }
    .tp-weekstrip__day--today .tp-weekstrip__num { color: var(--tp-color-attention); }
    .tp-weekstrip__day[aria-pressed="true"] { background: var(--tp-color-primary-tint); border-color: var(--tp-color-primary); }
    .tp-weekstrip__day:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }

    /* ----- Schwebender Plus-Knopf "Neuer Termin" (Smartphone): unten rechts über der unteren Navigation ----- */
    .tp-fab--float {
        position: fixed; right: var(--tp-space-4); z-index: 10; width: 3.5rem; height: 3.5rem;
        bottom: calc(4.5rem + env(safe-area-inset-bottom) + var(--tp-space-3));
    }


    /* ----- Aufgaben abhaken, Serien-Ausnahmen, Ort ----- */
    .tp-taskcheck { display: inline-flex; align-items: center; justify-content: center; flex: none; min-width: var(--tp-touch-min); min-height: var(--tp-touch-min); cursor: pointer; }
    .tp-taskcheck__input { width: 1.35rem; height: 1.35rem; margin: 0; accent-color: var(--tp-color-primary); cursor: pointer; }
    .tp-taskcheck__input:disabled { cursor: progress; }
    .tp-taskcheck--static { cursor: default; color: var(--tp-color-text-muted); }
    .tp-taskcheck--static::before { content: "CB"; }
    .tp-taskcheck--static.tp-taskcheck--done::before { content: "¹3"; color: var(--tp-color-primary); }
    .tp-day__line { display: flex; align-items: center; gap: var(--tp-space-2); min-width: 0; }
    .tp-day__line .tp-day__head { flex: 1 1 auto; width: auto; }
    .tp-day__item--done .tp-day__name, .tp-today__entry--done .tp-today__title, .tp-entry--done .tp-entry-link,
    .tp-entry--done .tp-list__title, .tp-tasklist__item--done .tp-tasklist__name { text-decoration: line-through; color: var(--tp-color-text-muted); }
    .tp-day__item--done, .tp-today__entry--done, .tp-tasklist__item--done { opacity: 0.8; }
    .tp-today__entry { display: flex; align-items: center; gap: var(--tp-space-1); }
    .tp-list__item--withcheck { display: flex; align-items: center; }
    .tp-list__item--withcheck > .tp-list__link { flex: 1 1 auto; min-width: 0; }
    .tp-entry-namecell { display: flex; align-items: center; gap: var(--tp-space-1); }
    .tp-moved-mark {
        flex: none; display: inline-block; padding: 0 var(--tp-space-2); border-radius: 999px; font-size: var(--tp-font-size-sm); font-weight: 600;
        background: var(--tp-color-attention-tint, var(--tp-color-primary-tint)); color: var(--tp-color-text);
    }
    .tp-tasklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--tp-space-1); }
    .tp-tasklist__item { display: flex; align-items: center; gap: var(--tp-space-2); min-width: 0; border-left: 4px solid var(--tp-cal-strong); padding-left: var(--tp-space-1); }
    .tp-tasklist__name { flex: 0 1 auto; min-width: 0; border: 0; background: transparent; color: var(--tp-color-text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; padding: var(--tp-space-2) 0; min-height: var(--tp-touch-min); }
    :where(:root[data-input="mouse"]) .tp-tasklist__name:hover { text-decoration: underline; }
    .tp-tasklist__meta { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .tp-undated-tasks { margin-top: var(--tp-space-4); }
    .tp-detail-exception { display: flex; align-items: center; justify-content: space-between; gap: var(--tp-space-2); flex-wrap: wrap; }

    /* ----- Stundenraster (Tag und Woche, Profil desktop und tablet) ----- */
    .tp-grid { --tp-grid-axis: 3.5rem; min-width: 0; }
    .tp-grid__add { margin-left: auto; }
    .tp-grid__scroller {
        position: relative; overflow: auto; height: clamp(24rem, 70dvh, 62rem); border: 1px solid var(--tp-color-border);
        border-radius: var(--tp-radius); background: var(--tp-color-surface);
    }
    .tp-grid__row { display: grid; grid-template-columns: var(--tp-grid-axis) repeat(var(--tp-grid-days), minmax(0, 1fr)); min-width: 0; }
    .tp-grid--week .tp-grid__row { min-width: 40rem; }
    .tp-grid__top { position: sticky; top: 0; z-index: 4; background: var(--tp-color-surface); border-bottom: 1px solid var(--tp-color-border); }
    .tp-grid__head { display: flex; align-items: center; justify-content: center; gap: var(--tp-space-1); padding: var(--tp-space-1); border-left: 1px solid var(--tp-color-border); font-weight: 600; }
    .tp-grid__head--today .tp-grid__num { background: var(--tp-color-attention); color: var(--tp-color-surface); border-radius: var(--tp-radius-pill); padding: 0 var(--tp-space-2); }
    .tp-grid__headbtn { border: 0; background: transparent; font: inherit; color: inherit; cursor: pointer; min-height: var(--tp-touch-min); border-radius: var(--tp-radius); }
    :where(:root[data-input="mouse"]) .tp-grid__headbtn:hover { background: var(--tp-color-primary-tint); }
    .tp-grid__dow { color: var(--tp-color-text-muted); }
    .tp-grid__num { font-variant-numeric: tabular-nums; }
    .tp-grid__shift { font-size: var(--tp-font-size-sm); color: var(--tp-color-text-muted); border: 1px solid var(--tp-color-border); border-radius: var(--tp-radius-pill); padding: 0 var(--tp-space-1); }
    .tp-grid__corner { padding: var(--tp-space-1); font-size: var(--tp-font-size-sm); color: var(--tp-color-text-muted); }
    .tp-grid__lanes { border-top: 1px solid var(--tp-color-border); }
    .tp-grid__lane { display: flex; flex-direction: column; gap: 2px; padding: 2px; border-left: 1px solid var(--tp-color-border); min-width: 0; }
    .tp-grid__laneitem {
        display: flex; align-items: center; min-width: 0; border-left: 4px solid var(--tp-cal-strong); border-radius: var(--tp-radius-sm);
        background: var(--tp-cal-soft);
    }
    .tp-grid__laneitem--done .tp-grid__lanebtn { text-decoration: line-through; color: var(--tp-color-text-muted); }
    .tp-grid__lanebtn { flex: 1 1 auto; min-width: 0; min-height: var(--tp-touch-min); padding: 2px var(--tp-space-2); border: 0; background: transparent; font: inherit; font-size: var(--tp-font-size-sm); color: var(--tp-cal-ink); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    button.tp-grid__lanebtn { cursor: pointer; }
    .tp-grid__laneitem .tp-taskcheck { min-width: var(--tp-touch-min); min-height: var(--tp-touch-min); }
    .tp-grid__body { position: relative; }
    .tp-grid__axis { position: relative; }
    .tp-grid__hour { position: absolute; right: var(--tp-space-2); transform: translateY(-50%); font-size: var(--tp-font-size-sm); color: var(--tp-color-text-muted); font-variant-numeric: tabular-nums; background: var(--tp-color-surface); padding: 0 2px; }
    .tp-grid__hour:first-child { transform: none; }
    .tp-grid__col {
        position: relative; border-left: 1px solid var(--tp-color-border); min-width: 0;
        background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--tp-hour-px) - 1px), var(--tp-color-border) calc(var(--tp-hour-px) - 1px), var(--tp-color-border) var(--tp-hour-px));
    }
    .tp-grid__col--weekend { background-color: var(--tp-color-weekend); }
    .tp-grid__col--today { background-color: color-mix(in srgb, var(--tp-color-attention) 6%, var(--tp-color-surface)); }
    .tp-grid--day .tp-grid__col--today { background-color: var(--tp-color-surface); }
    .tp-grid__col--free { cursor: cell; }
    .tp-grid__void { position: absolute; left: 0; right: 0; bottom: 0; pointer-events: none; background: repeating-linear-gradient(135deg, var(--tp-color-background) 0, var(--tp-color-background) 4px, var(--tp-color-border) 4px, var(--tp-color-border) 5px); }
    .tp-grid__block {
        position: absolute; box-sizing: border-box; min-height: 1.15rem; overflow: hidden; padding: 1px var(--tp-space-2); cursor: pointer;
        border-left: 4px solid var(--tp-cal-strong); border-radius: var(--tp-radius-sm); font-size: var(--tp-font-size-sm); line-height: 1.25;
        background: var(--tp-cal-soft); color: var(--tp-cal-ink);
        display: flex; flex-wrap: wrap; column-gap: var(--tp-space-1); align-content: flex-start; z-index: 1;
    }
    .tp-grid__block--movable { touch-action: pan-y; }
    .tp-grid__block:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); z-index: 3; }
    .tp-grid__block--dragging { z-index: 5; box-shadow: var(--tp-shadow); opacity: 0.9; transition: none; }
    .tp-grid__block--cont-before { border-top-left-radius: 0; border-top-right-radius: 0; }
    .tp-grid__block--cont-after { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
    .tp-grid--day .tp-grid__block:not(.tp-grid__block--point) { background: color-mix(in srgb, var(--tp-cal-src) var(--tp-cal-block-mix), var(--tp-color-surface)); }
    .tp-grid__block--point { min-height: var(--tp-touch-min); background: transparent; flex-wrap: nowrap; border-left-width: 3px; box-shadow: inset 0 -1px 0 var(--tp-cal-strong); white-space: nowrap; }
    .tp-grid__time { font-variant-numeric: tabular-nums; font-weight: 600; }
    .tp-grid__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .tp-grid__place { flex: 1 0 100%; }
    .tp-grid__resize { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; cursor: ns-resize; }
    .tp-grid__resize::after { content: ""; position: absolute; left: 50%; bottom: 2px; width: 1.5rem; height: 2px; margin-left: -0.75rem; border-radius: 1px; background: var(--tp-cal-strong); opacity: 0.8; }
    :where([data-profile="tablet"]) .tp-grid__resize { height: 14px; }
    .tp-grid__now { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--tp-color-error); z-index: 2; pointer-events: none; }
    .tp-grid__now::before { content: ""; position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--tp-color-error); }
    .tp-grid__nowtime { position: absolute; right: 2px; top: -1.1rem; font-size: var(--tp-font-size-sm); color: var(--tp-color-error); font-variant-numeric: tabular-nums; }
    .tp-grid__switch { display: flex; justify-content: flex-end; margin-bottom: var(--tp-space-2); }

    /* ----- Monat zum Scrollen (KS5, desktop und tablet): Wochenzeilen mit KW-Spalte, fester Kopf, feste Zeilenhöhe ----- */
    .tp-ms {
        --tp-ms-row-h: 7rem; --tp-ms-kw-w: 3rem; --tp-ms-day-head: 1.5rem;
        --tp-ms-tint: color-mix(in srgb, var(--tp-color-surface) 86%, var(--tp-color-primary-tint));
        min-width: 0; overflow: hidden;
        border: 1px solid var(--tp-color-border); border-radius: var(--tp-radius); background: var(--tp-color-surface);
    }
    .tp-ms__scroll { position: relative; overflow-y: auto; overscroll-behavior: contain; height: clamp(24rem, calc(100dvh - 17rem), 64rem); background: var(--tp-color-surface); }
    /* Bis zum ersten Scrollen zur Zielwoche unsichtbar (kein Sprung vor dem Start); ohne Messen bleibt die Skelett-Anzeige sichtbar. */
    .tp-ms__scroll:not([data-ready]) .tp-ms__row { visibility: hidden; }

    .tp-ms__head { position: sticky; top: 0; z-index: 5; background: var(--tp-color-surface); border-bottom: 1px solid var(--tp-color-border-strong); }
    .tp-ms__bar { display: flex; align-items: center; gap: var(--tp-space-2); padding: var(--tp-space-2) var(--tp-space-3); border-bottom: 1px solid var(--tp-color-border); background: var(--tp-color-surface); }
    .tp-ms__title { flex: 1 1 auto; min-width: 0; text-transform: capitalize; }
    .tp-ms__weekdays { display: grid; grid-template-columns: var(--tp-ms-kw-w) minmax(0, 1fr); background: var(--tp-color-background); }
    .tp-ms__kwh { text-align: center; font-size: var(--tp-font-size-sm); color: var(--tp-color-text-muted); padding: var(--tp-space-1) 0; }
    .tp-ms__wd { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
    .tp-ms__wd span { text-align: center; font-weight: 600; font-size: var(--tp-font-size-sm); padding: var(--tp-space-1) 0; }

    .tp-ms__row { display: grid; grid-template-columns: var(--tp-ms-kw-w) minmax(0, 1fr); height: var(--tp-ms-row-h); box-sizing: border-box; border-bottom: 1px solid var(--tp-color-border); background: var(--tp-color-surface); }
    .tp-ms__row--ph { display: block; background: var(--tp-color-background); padding: var(--tp-space-2); }
    .tp-ms__ph { height: 100%; }
    .tp-ms__kw {
        display: flex; align-items: flex-start; justify-content: center; padding-top: var(--tp-space-1); background: var(--tp-color-background);
        border-right: 1px solid var(--tp-color-border); color: var(--tp-color-text-muted); font-size: var(--tp-font-size-sm); font-variant-numeric: tabular-nums;
    }
    .tp-ms__days { position: relative; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); min-width: 0; }

    .tp-ms__day { display: flex; flex-direction: column; min-width: 0; overflow: hidden; padding: 0 var(--tp-space-1); border-right: 1px solid var(--tp-color-border); background: var(--tp-color-surface); }
    .tp-ms__day--tint { background: var(--tp-ms-tint); }
    /* Wochenende nach der Monatstönung, aber vor "heute", Feiertag und Terminen: deren Farben behalten Vorrang */
    .tp-ms__day--weekend { background: var(--tp-color-weekend); }
    .tp-ms__day--today { background: var(--tp-color-attention-tint); }
    .tp-ms__dayhead { display: flex; align-items: center; justify-content: space-between; gap: var(--tp-space-1); flex: none; height: var(--tp-ms-day-head); min-width: 0; }
    .tp-ms__num {
        padding: 0 var(--tp-space-1); border: 0; border-radius: var(--tp-radius-pill); background: transparent; font: inherit; font-size: var(--tp-font-size-sm); font-weight: 600;
        font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--tp-color-text);
    }
    .tp-ms__num--link { cursor: pointer; }
    /* Auf der Wochenende-Tönung trägt die Zahl und "+n weitere" die volle Textfarbe (Grau wäre dort unter AA) */
    .tp-ms__day--weekend .tp-ms__num, .tp-ms__day--weekend .tp-ms__more { color: var(--tp-color-text); }
    .tp-ms__day--today .tp-ms__num { background: var(--tp-color-primary); color: var(--tp-color-surface); padding: 0 var(--tp-space-2); }
    :where(:root[data-input="mouse"]) .tp-ms__num--link:hover { background: var(--tp-color-primary-tint); color: var(--tp-color-text); }
    .tp-ms__num:focus-visible, .tp-ms__add:focus-visible, .tp-ms__more:focus-visible { outline: none; box-shadow: var(--tp-focus-ring); }

    /* Tastatur (KS7): das Raster ist ein Tab-Stopp. Fokus: Innenrand am Raster; die aktive Zelle trägt einen 3-px-Rahmen in der Fokusfarbe (innen, über Ferienstreifen). */
    .tp-ms__scroll:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--tp-color-focus); }
    .tp-ms__scroll:focus .tp-ms__day--active { position: relative; }
    .tp-ms__scroll:focus .tp-ms__day--active::after { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; outline: 3px solid var(--tp-color-focus); outline-offset: -3px; }
    @media (forced-colors: active) { .tp-ms__scroll:focus .tp-ms__day--active::after { outline-color: Highlight; } }

    /* Plus: mit der Maus nur beim Überfahren und bei Fokus sichtbar, bei Touch immer */
    .tp-ms__add {
        display: inline-flex; align-items: center; justify-content: center; flex: none; width: 1.5rem; height: 1.5rem; padding: 0; border: 0; border-radius: var(--tp-radius);
        background: transparent; color: var(--tp-color-text-muted); cursor: pointer;
    }
    :where(:root[data-input="mouse"]) .tp-ms__add { opacity: 0; }
    :where(:root[data-input="mouse"]) .tp-ms__day:is(:hover, :focus-within) .tp-ms__add { opacity: 1; }
    :where(:root[data-input="mouse"]) .tp-ms__add:hover { background: var(--tp-color-primary-tint); color: var(--tp-color-text); }
    /* Touch: kein Plus-Chip; die ganze Zelle ist das Ziel (Tipp öffnet die Tagesansicht), Termine, Zahl und "+n weitere" liegen über der Fläche. */
    .tp-ms__hit { position: absolute; inset: 0; padding: 0; border: 0; background: transparent; cursor: pointer; -webkit-tap-highlight-color: transparent; }
    :where(:root[data-input="touch"]) .tp-ms__day { position: relative; --tp-ms-day-head: 1.375rem; }
    :where(:root[data-input="touch"]) .tp-ms__dayhead, :where(:root[data-input="touch"]) .tp-ms__day .tp-ms__items,
    :where(:root[data-input="touch"]) .tp-ms__day .tp-sortable { position: relative; pointer-events: none; }
    :where(:root[data-input="touch"]) .tp-ms__dayhead > *, :where(:root[data-input="touch"]) .tp-ms__day .tp-ms__items > *,
    :where(:root[data-input="touch"]) .tp-ms__day .tp-sortable > * { pointer-events: auto; }

    .tp-ms__items, .tp-ms__day .tp-sortable { display: flex; flex-direction: column; gap: 2px; min-width: 0; min-height: 0; }
    .tp-ms__day .tp-entry-chip { display: flex; align-items: center; height: 1.4rem; min-height: 0; padding: 0 var(--tp-space-1); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* Mit Maus am Tablet-Profil höhere Chips; bei Touch bleiben sie 1,4rem, damit drei Termine plus "+n weitere" in die feste Zeilenhöhe 7rem passen. */
    :where([data-profile="tablet"]):where(:root[data-input="mouse"]) .tp-ms__day .tp-entry-chip { height: 1.75rem; }
    .tp-ms__day .tp-draggable { padding: 0; border: 0; background: transparent; }
    .tp-ms__day .tp-sortable-ghost { outline: 2px dashed var(--tp-color-primary); }
    .tp-ms__day .tp-cal__step { height: 1.2rem; line-height: 1.2rem; }
    :where(:root[data-input="touch"]) .tp-ms__more { position: relative; line-height: 1rem; }
    .tp-ms__more { flex: none; align-self: flex-start; padding: 0 var(--tp-space-1); border: 0; background: transparent; font: inherit; font-size: 0.72rem; color: var(--tp-color-text-muted); cursor: pointer; }
    :where(:root[data-input="mouse"]) button.tp-ms__more:hover { color: var(--tp-color-text); text-decoration: underline; }

    /* ----- Feiertage und Ferien (KS8): Zelle und Name in der Aufmerksamkeitsfarbe, Ferien als Streifen in der Info-Farbe (Tokens: hell und dunkel) ----- */
    .tp-ms { --tp-ms-strip-h: 1rem; --tp-ms-strip-gap: 2px; }
    :where(:root[data-input="touch"]) .tp-ms { --tp-ms-day-head: 1.375rem; }
    .tp-ms__dayhead { margin-bottom: calc(var(--tp-ms-lanes, 0) * (var(--tp-ms-strip-h) + var(--tp-ms-strip-gap))); }
    .tp-ms__day--holiday { background: var(--tp-color-holiday-tint); }
    .tp-ms__day--holiday:not(.tp-ms__day--today) .tp-ms__num { color: var(--tp-color-holiday); font-weight: 700; }
    .tp-ms__holiday { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.72rem; font-weight: 600; color: var(--tp-color-holiday); }

    .tp-vac { display: grid; grid-template-columns: repeat(var(--tp-vac-cols, 7), minmax(0, 1fr)); grid-auto-rows: var(--tp-ms-strip-h, 1rem); row-gap: var(--tp-ms-strip-gap, 2px); min-width: 0; }
    .tp-ms__days > .tp-vac { position: absolute; inset-inline: 0; top: var(--tp-ms-day-head); z-index: 1; }
    :where(:root[data-input="touch"]) .tp-ms__days > .tp-vac { pointer-events: none; }
    .tp-vac__strip {
        --tp-vac-edge: color-mix(in srgb, var(--tp-color-vacation) 45%, var(--tp-color-vacation-tint));
        display: flex; align-items: center; min-width: 0; overflow: hidden; box-sizing: border-box; padding: 0 var(--tp-space-1);
        background: var(--tp-color-vacation-tint); color: var(--tp-color-vacation); border: 1px solid var(--tp-vac-edge); border-inline-width: 0;
    }
    .tp-vac__strip--start { border-inline-start-width: 1px; border-start-start-radius: var(--tp-radius-sm); border-end-start-radius: var(--tp-radius-sm); margin-inline-start: 2px; }
    .tp-vac__strip--end { border-inline-end-width: 1px; border-start-end-radius: var(--tp-radius-sm); border-end-end-radius: var(--tp-radius-sm); margin-inline-end: 2px; }
    .tp-vac__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.6875rem; font-weight: 600; line-height: 1; }
    .tp-vac__more { align-self: center; justify-self: end; z-index: 1; margin-inline-end: 2px; padding: 0 var(--tp-space-1); border-radius: var(--tp-radius-pill); background: var(--tp-color-vacation); color: var(--tp-color-surface); font-size: 0.6875rem; font-weight: 700; line-height: 1rem; }

    /* Wochenansicht (Stundenraster): Feiertagsname im Tageskopf, Ferienstreifen unter den Tageszahlen. */
    .tp-grid__head { flex-wrap: wrap; }
    .tp-grid__head--holiday { background: var(--tp-color-holiday-tint); }
    .tp-grid__holiday { flex: 1 0 100%; min-width: 0; text-align: center; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; font-size: var(--tp-font-size-sm); font-weight: 600; color: var(--tp-color-holiday); }
    .tp-grid__vacrow { border-top: 1px solid var(--tp-color-border); }
    .tp-grid__vacs { grid-column: 2 / -1; min-width: 0; padding: 2px 0; }

    /* Wochenliste und Smartphone-Raster (EntryCalendar): Name in der Zelle, Ferien als Balken (Monat schmal ohne Text). */
    .tp-cal__cell--holiday { background: var(--tp-color-holiday-tint); }
    .tp-cal__holiday { font-size: var(--tp-font-size-sm); font-weight: 600; color: var(--tp-color-holiday); overflow-wrap: anywhere; }
    .tp-cal__vac { margin-block: 2px; padding: 0 var(--tp-space-1); border-radius: var(--tp-radius-sm); background: var(--tp-color-vacation-tint); color: var(--tp-color-vacation); border: 1px solid color-mix(in srgb, var(--tp-color-vacation) 45%, var(--tp-color-vacation-tint)); font-size: var(--tp-font-size-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .tp-cal__vac--thin { height: 0.25rem; padding: 0; overflow: hidden; font-size: 0; }

    /* Tagesansicht: Hinweiszeilen oben. */
    .tp-hnote { display: flex; flex-direction: column; gap: var(--tp-space-1); margin-bottom: var(--tp-space-3); }
    .tp-hnote__line { margin: 0; padding: var(--tp-space-1) var(--tp-space-3); border-radius: var(--tp-radius); border-inline-start: 4px solid currentColor; }
    .tp-hnote__line--holiday { background: var(--tp-color-holiday-tint); color: var(--tp-color-holiday); }
    .tp-hnote__line--vacation { background: var(--tp-color-vacation-tint); color: var(--tp-color-vacation); }
    .tp-grid > .tp-hnote { margin-bottom: var(--tp-space-2); }
    /* Schalter Feiertage und Schulferien (KS9): Block in der Seitenleiste (Desktop), Chips auf Tablet und Smartphone, Legende per Klick. */
    .tp-hflags--switches { display: flex; flex-direction: column; gap: var(--tp-space-1); }
    .tp-hflags--switches .tp-check { margin-bottom: 0; }
    .tp-hflags__head { display: flex; align-items: center; justify-content: space-between; gap: var(--tp-space-2); }
    .tp-hflags__title { padding: 0; }
    .tp-hflags--chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--tp-space-2); }
    .tp-hflags--chips .tp-chip { min-height: var(--tp-touch-min); display: inline-flex; align-items: center; padding-inline: var(--tp-space-4); border-radius: var(--tp-radius-pill); }
    .tp-hflags--inline { display: contents; }
    .tp-hflags--inline .tp-chip { flex: none; white-space: nowrap; }
    .tp-hflags--inline .tp-iconbtn { flex: none; }
    .tp-hlegend { list-style: none; margin: 0; padding: var(--tp-space-2) var(--tp-space-3); display: flex; flex-wrap: wrap; gap: var(--tp-space-2) var(--tp-space-4); border: 1px solid var(--tp-color-border); border-radius: var(--tp-radius); background: var(--tp-color-surface); font-size: var(--tp-font-size-sm); }
    .tp-hlegend li { display: inline-flex; align-items: center; gap: var(--tp-space-2); }
    .tp-hlegend__swatch { width: 1.25rem; height: 1rem; border-radius: var(--tp-radius-sm); border: 1px solid transparent; flex: none; }
    .tp-hlegend__swatch--holiday { background: var(--tp-color-holiday-tint); border-color: var(--tp-color-holiday); }
    .tp-hlegend__swatch--vacation { background: var(--tp-color-vacation-tint); border-color: color-mix(in srgb, var(--tp-color-vacation) 45%, var(--tp-color-vacation-tint)); }
    .tp-hlegend__swatch--today { width: 1rem; border-radius: var(--tp-radius-pill); background: var(--tp-color-primary); }
    .tp-hflags__empty { margin: 0; font-size: var(--tp-font-size-sm); }
    .tp-shell__topslot .tp-calnav > .tp-hflags, .tp-shell__topslot .tp-calnav > .tp-hlegend, .tp-shell__topslot .tp-calnav > .tp-hflags__empty { flex: 0 0 auto; }

    /* ----- Monat am Smartphone (KS6): gleiches Raster, kompakt. Zeile 4,75rem, KW-Spalte schmal, Termine als Mini-Chips (nur Titel, kein Tipp-Ziel), die ganze Zelle öffnet den Tag.
       Feiertag: nur Zelle und Zahl; Ferien: Streifen 0,25rem ohne Text; Namen stehen im festen Kopf (.tp-ms__note) und in der Tagesansicht. ----- */
    :where([data-profile="phone"]) .tp-ms { --tp-ms-row-h: 4.75rem; --tp-ms-kw-w: 1.75rem; --tp-ms-day-head: 1.25rem; --tp-ms-strip-h: 0.25rem; --tp-ms-strip-gap: 1px; }
    :where([data-profile="phone"]) .tp-ms__scroll { height: clamp(20rem, calc(100dvh - 16rem), 64rem); }
    :where([data-profile="phone"]) .tp-ms__bar { padding: var(--tp-space-1) var(--tp-space-2); }
    :where([data-profile="phone"]) .tp-ms__kwlong, :where([data-profile="phone"]) .tp-ms__morelong { display: none; }
    :where([data-profile="phone"]) .tp-ms__kwh, :where([data-profile="phone"]) .tp-ms__kw { font-size: 0.6875rem; }
    :where([data-profile="phone"]) .tp-ms__day { position: relative; padding: 0 1px; --tp-ms-day-head: 1.25rem; }
    :where([data-profile="phone"]) .tp-ms__num { padding: 0 2px; font-size: 0.6875rem; }
    :where([data-profile="phone"]) .tp-ms__day--today .tp-ms__num { padding: 0 var(--tp-space-1); }
    :where([data-profile="phone"]) .tp-ms__dayhead, :where([data-profile="phone"]) .tp-ms__day .tp-ms__items,
    :where([data-profile="phone"]) .tp-ms__day .tp-sortable, :where([data-profile="phone"]) .tp-ms__more { position: relative; pointer-events: none; }
    :where([data-profile="phone"]) .tp-ms__dayhead > * { pointer-events: auto; }
    :where([data-profile="phone"]) .tp-ms__day .tp-entry-chip {
        height: 1rem; padding: 0 2px; font-size: 0.6875rem; line-height: 1rem; border-left-width: 2px; border-radius: 2px var(--tp-radius-sm) var(--tp-radius-sm) 2px; pointer-events: none;
    }
    :where([data-profile="phone"]) .tp-ms__day .tp-cal__step { display: none; }
    :where([data-profile="phone"]) .tp-ms__more { line-height: 0.875rem; font-size: 0.6875rem; padding: 0 2px; }
    :where([data-profile="phone"]) .tp-ms__days > .tp-vac { pointer-events: none; }
    :where([data-profile="phone"]) .tp-vac__strip { padding: 0; }
    :where([data-profile="phone"]) .tp-vac__more { display: none; }
    .tp-ms__note {
        display: flex; gap: var(--tp-space-2); height: 1.25rem; padding: 0 var(--tp-space-2); overflow: hidden; white-space: nowrap; box-sizing: border-box;
        border-top: 1px solid var(--tp-color-border); background: var(--tp-color-surface); font-size: 0.6875rem; font-weight: 600; line-height: 1.25rem;
    }
    .tp-ms__note-part { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .tp-ms__note-part--holiday { color: var(--tp-color-holiday); }
    .tp-ms__note-part--vacation { color: var(--tp-color-vacation); }
}
