/* =========================================================================================
   Termingenerierung (Verwaltung): Team wählen, Vorlagen, Zeitslots, Zeitgesteuert, Slot-Planer, Sperrtage.
   „Wer bucht?“: extern (blau, online und intern) · intern (schiefer) · Kiosk (violett, Sonderfall).
   ========================================================================================= */

:root {
    --tg-extern: #1d4ed8;
    --tg-extern-bg: #e8efff;
    --tg-intern: #364a5e;
    --tg-intern-bg: #eef1f5;
    --tg-kiosk: #6d28d9;
    --tg-kiosk-bg: #f1eafe;
    --tg-missing: #b42318;
    --tg-missing-bg: #fdecea;
}

/* ---- Reiter und „Team wählen“ ----------------------------------------------------------- */
.tg-tabs { margin-top: calc(-1 * var(--space-3)); }

.tg-picker {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: flex-end;
    margin: 0 0 var(--space-5);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--c-line);
    border-radius: var(--radius);
    background: var(--c-surface);
}
.tg-picker .field { margin: 0; min-width: 14rem; }
.tg-picker select { min-width: 14rem; max-width: 100%; }
.tg-picker__state { flex: 1 1 18rem; margin: 0; padding-bottom: 6px; }

.tg-state { display: inline-flex; gap: 6px; align-items: center; color: var(--c-text); font-size: var(--fs-small); }
.tg-state .icon { width: 16px; height: 16px; flex: none; }
.tg-state--missing { color: var(--tg-missing); font-weight: var(--fw-bold); }

.tg-rule {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: baseline;
    margin: 0 0 var(--space-5);
    padding: var(--space-3) var(--space-4);
    border-left: 4px solid var(--tg-extern);
    border-radius: var(--radius);
    background: var(--tg-extern-bg);
    color: var(--c-text-strong);
}
.tg-rule .icon { align-self: center; }

/* ---- Team-Liste --------------------------------------------------------------------------- */
.tg-teams__row--missing th,
.tg-teams__row--missing td { background: var(--tg-missing-bg); }
.tg-teams__row--missing th a { color: var(--tg-missing); }

/* ---- intern / extern ------------------------------------------------------------------------ */
.tg-who {
    display: inline-flex;
    align-items: center;
    padding: 1px 10px;
    border: 1px solid var(--tg-c, var(--c-line-strong));
    border-radius: var(--radius-pill);
    background: var(--tg-c-bg, var(--c-panel));
    color: var(--tg-c, var(--c-text));
    font-size: var(--fs-small);
    font-weight: var(--fw-medium);
    white-space: nowrap;
}
.tg-who--public { --tg-c: var(--tg-extern); --tg-c-bg: var(--tg-extern-bg); }
.tg-who--internal { --tg-c: var(--tg-intern); --tg-c-bg: var(--tg-intern-bg); }
.tg-who--kiosk { --tg-c: var(--tg-kiosk); --tg-c-bg: var(--tg-kiosk-bg); }

/* ---- Vorlage: Tabelle, Ändern, neue Zeilen ----------------------------------------------- */
.tg-template td, .tg-template th { vertical-align: top; }
/* Oben bündig (die Bearbeitung öffnet sich in der Zeile), der Text steht trotzdem auf Höhe der Taste „Ändern“ –
   in jeder Darstellung (Groß · Normal · Kompakt · Extra kompakt). */
.tg-template tbody :is(td, th):not(.table__actions) { padding-top: calc(var(--table-cell-y) + (var(--target-sm) - var(--lh-table) * 1em) / 2); }
.tg-template .num { font-weight: var(--fw-bold); }
.tg-edit > summary { list-style: none; }
.tg-edit > summary::-webkit-details-marker { display: none; }
.tg-edit[open] > summary { margin-bottom: var(--space-2); }
.tg-edit__panel {
    display: grid;
    gap: var(--space-3);
    width: min(34rem, 80vw);
    padding: var(--space-3);
    border: 1px solid var(--c-line-strong);
    border-radius: var(--radius);
    background: var(--c-surface);
    box-shadow: var(--shadow-raised);
    text-align: left;
}
.tg-edit__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

.tg-days { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.tg-days > legend { width: 100%; margin-bottom: 4px; }
.tg-day { position: relative; display: inline-flex; }
.tg-day input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.tg-day span {
    display: inline-grid;
    place-items: center;
    min-width: 44px;
    min-height: 40px;
    padding: 0 10px;
    border: 1px solid var(--c-line-strong);
    border-radius: var(--radius-pill);
    background: var(--c-surface);
    color: var(--c-text);
    font-weight: var(--fw-medium);
}
.tg-day input:checked + span { border-color: var(--tg-extern); background: var(--tg-extern-bg); color: var(--tg-extern); box-shadow: inset 0 0 0 1px var(--tg-extern); }
.tg-day input:focus-visible + span { outline: 3px solid var(--c-focus); outline-offset: 2px; }

.tg-who-choice { display: grid; gap: 4px; margin: 0; padding: 0; border: 0; }

.tg-series { display: flex; flex-wrap: wrap; gap: 6px var(--space-2); align-items: center; }
.tg-series .field__help { width: 100%; margin: 0; }
.tg-series__minutes { width: 5.5rem; }

.tg-copy__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: var(--space-4); }
.tg-copy__grid h3 { margin: 0; font-size: var(--fs-md); }

/* ---- Satz zur Erzeugung ------------------------------------------------------------------------ */
.tg-sentence { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; line-height: 2.2; }
.tg-sentence__num { width: 5rem; }
.tg-all > summary { cursor: pointer; font-weight: var(--fw-medium); }
.tg-all[open] > summary { margin-bottom: var(--space-3); }

/* ---- Regeln für Buchungen (Satz je Regel, Hinweis darunter) ----------------------------------- */
.tg-booking-rules .tg-sentence { margin: 0; }
.tg-booking-rules .field__help { margin: 0; }
.tg-booking-rules__list { display: grid; gap: 4px; margin: 0; padding-left: var(--space-4); }

.tg-holidays { display: grid; gap: 4px; margin: 0; padding-left: var(--space-4); }

/* ---- Erweitert: Hinweis „wird automatisch gepflegt“ ----------------------------------------- */
/* Fließtext mit Symbol und Link (kein Flex: sonst wird jedes Textstück zu einer eigenen schmalen Spalte) */
.plan-auto-note {
    display: block;
    margin: 0 0 var(--space-4);
    padding: var(--space-2) var(--space-3);
    border-left: 4px solid var(--c-line-strong);
    border-radius: var(--radius);
    background: var(--c-page);
    color: var(--c-text);
    font-size: var(--fs-small);
}

/* ---- Buchung intern: Team wählen bzw. über Kundennummer bestimmen ----------------------------- */
.apt-team { display: grid; gap: var(--space-2); margin: 0 0 var(--space-4); padding: var(--space-3); border: 1px solid var(--c-line); border-radius: var(--radius); background: var(--c-surface); }
.apt-team__label { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; font-weight: var(--fw-medium); }
.apt-team .kb-chip { text-decoration: none; }
.apt-team__number { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; font-size: var(--fs-small); }
.apt-team__number .input { width: 14rem; max-width: 100%; }


/* ---- Zeitslots: Wochenraster (Spalten = Tage, Zeilen = Uhrzeit) ------------------------------- */
.tg-weekbar { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); align-items: center; justify-content: space-between; margin: 0 0 var(--space-3); }
.tg-weeknav { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.tg-weeknav__label { padding: 0 var(--space-1); font-variant-numeric: tabular-nums; }
.tg-daysum { display: flex; flex-wrap: wrap; gap: 2px var(--space-4); margin: 0 0 var(--space-2); padding: 0; list-style: none; font-size: var(--fs-small); }
.tg-legend { display: flex; flex-wrap: wrap; gap: 2px var(--space-4); margin: 0 0 var(--space-3); padding: 0; list-style: none; color: var(--c-muted); font-size: var(--fs-xs); }
.tg-legend li { display: inline-flex; gap: 6px; align-items: center; }
.tg-swatch { display: inline-block; width: 16px; height: 14px; border-left: 4px solid var(--tg-c); border-radius: 3px; background-color: var(--tg-bg); }
.tg-swatch.is-internal, .tg-slot.is-internal > .tg-slot__block {
    background-image: repeating-linear-gradient(135deg, transparent 0 5px, rgb(16 24 40 / 9%) 5px 10px);
}
.tg-slot--frei { --tg-c: var(--c-success); --tg-bg: var(--c-success-bg); }
.tg-slot--teils { --tg-c: var(--c-warning); --tg-bg: var(--c-warning-bg); }
.tg-slot--voll, .tg-slot--zu { --tg-c: var(--c-line-strong); --tg-bg: var(--c-page); }

.tg-week {
    --tg-hour: 64px;
    position: relative;
    display: grid;
    grid-template-columns: 3rem repeat(var(--tg-days, 5), minmax(0, 1fr));
    gap: 0 4px;
    margin: 0 0 var(--space-4);
}
.tg-week__hours { position: relative; margin-top: 46px; height: calc(var(--tg-hours) * var(--tg-hour)); color: var(--c-muted); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.tg-week__hours span { position: absolute; left: 0; transform: translateY(-50%); }
.tg-week__day { min-width: 0; }
.tg-week__label { display: flex; flex-direction: column; justify-content: center; height: 46px; margin: 0; font-size: var(--fs-small); font-weight: var(--fw-medium); line-height: 1.3; text-align: center; }
.tg-week__state { color: var(--c-success-text); font-size: var(--fs-xs); font-weight: var(--fw-regular, 400); }
.tg-week__state.is-preview { color: var(--c-muted); }
.tg-genline { display: flex; gap: var(--space-2); align-items: flex-start; margin: 0 0 var(--space-2); padding: var(--space-2) var(--space-3); border-left: 4px solid var(--c-blue); border-radius: var(--radius); background: var(--c-blue-tint); font-size: var(--fs-small); }
.tg-genline__state { margin: var(--space-1) 0 0; font-size: var(--fs-small); }
.tg-daystate { color: var(--c-success-text); }
.tg-daysum--vorschau .tg-daystate { color: var(--c-muted); }
.tg-slot.is-preview > .tg-slot__block, .tg-swatch.is-preview { border: 1px dashed var(--tg-c); border-left-width: 4px; background-color: var(--c-surface); box-shadow: none; }
.tg-slot.is-scheduled > .tg-slot__block, .tg-swatch.is-scheduled { outline: 2px dotted var(--c-blue); outline-offset: -2px; }
.tg-slot__hint { margin: 0; color: var(--c-muted); }
.tg-week__col {
    position: relative;
    height: calc(var(--tg-hours) * var(--tg-hour));
    border: 1px solid var(--c-line);
    border-radius: var(--radius-sm);
    background: var(--c-surface);
    cursor: copy;
}
.tg-week__day.is-past .tg-week__col { background: var(--c-page); cursor: default; }
.tg-week__line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--c-line); pointer-events: none; }
.tg-week__empty { position: absolute; top: var(--space-3); left: var(--space-2); right: var(--space-2); margin: 0; color: var(--c-muted); font-size: var(--fs-small); text-align: center; pointer-events: none; }

.tg-slot {
    position: absolute;
    top: var(--top);
    left: calc(2px + var(--lane, 0) * (100% - 4px) / var(--lanes, 1));
    width: calc((100% - 4px) / var(--lanes, 1) - 2px);
    height: var(--height);
    min-height: 18px;
}
.tg-slot__block {
    display: flex;
    flex-wrap: wrap;
    gap: 0 4px;
    align-items: center;
    box-sizing: border-box;
    height: 100%;
    overflow: hidden;
    padding: 1px 6px;
    border-left: 4px solid var(--tg-c);
    border-radius: var(--radius-sm);
    background-color: var(--tg-bg);
    color: var(--c-text-strong);
    font-size: var(--fs-xs);
    line-height: 1.25;
    list-style: none;
    cursor: pointer;
    box-shadow: 0 1px 2px rgb(16 24 40 / 10%);
}
.tg-slot__block::-webkit-details-marker { display: none; }
.tg-slot__block:focus-visible { outline: 3px solid var(--c-focus, #3c57a7); outline-offset: 1px; }
.tg-slot__time { font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }
.tg-slot.is-past { opacity: 0.6; }
.tg-slot.is-past .tg-slot__block { cursor: default; }
.tg-slot[open] { z-index: 5; }
.tg-slot[open] > .tg-slot__block { outline: 2px solid var(--tg-c); }
.tg-slot__panel, .tg-newslot {
    position: absolute;
    top: 0;
    left: calc(100% + 6px);
    z-index: 6;
    box-sizing: border-box;
    width: 17rem;
    padding: var(--space-3);
    border: 1px solid var(--c-line-strong);
    border-radius: var(--radius);
    background: var(--c-surface);
    box-shadow: var(--shadow-pop);
    color: var(--c-text);
    font-size: var(--fs-small);
    cursor: default;
}
.tg-slot__panel { display: grid; gap: var(--space-2); }
.tg-newslot { left: calc(100% + 6px); }
.tg-week__day.opens-left .tg-slot__panel, .tg-week__day.opens-left .tg-newslot { right: calc(100% + 6px); left: auto; }
.tg-slot__title { margin: 0; font-weight: var(--fw-bold); }
.tg-slot__panel .subtle { margin: 0; }
.tg-slot__panel .stack, .tg-newslot.stack { gap: var(--space-2); }

@media (max-width: 640px) {
    .tg-week { display: block; }
    .tg-week__hours, .tg-week__line { display: none; }
    .tg-week__day + .tg-week__day { margin-top: var(--space-3); }
    .tg-week__label { height: auto; margin: 0 0 6px; line-height: 1.4; text-align: left; }
    .tg-week__col { display: flex; flex-direction: column; gap: 6px; height: auto; border: 0; background: none; cursor: default; }
    .tg-week__day.is-past .tg-week__col { background: none; }
    .tg-week__empty { position: static; text-align: left; }
    .tg-slot { position: static; width: auto; height: auto; min-height: 0; }
    .tg-slot__block { padding: 8px 10px; font-size: var(--fs-small); }
    .tg-slot__panel, .tg-newslot, .tg-week__day.opens-left .tg-slot__panel { position: static; width: auto; margin-top: 6px; box-shadow: none; }
    .tg-picker { padding: var(--space-3); }
    .tg-picker .field, .tg-picker select { min-width: 0; width: 100%; }
    .tg-edit__panel { width: calc(100vw - 2 * var(--space-4)); }
}
