/* ===========================================================================
   AV-Board — PPS · tabelle.css
   Tabellen-Norm (Plan Editorial 0.30, B-8 / W-4). Nur Tokens aus style.css.
   Wirkt auf Tabellen mit data-sortierbar (js/tabelle.js ergänzt .tab-norm).
   =========================================================================== */

table.tab-norm {
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--tab-font);
}
table.tab-norm th,
table.tab-norm td {
    padding: var(--zelle-py) var(--zelle-px);
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
table.tab-norm tbody tr { min-height: var(--zeile-h, 0); }
table.tab-norm tbody tr:last-child td { border-bottom: 0; }
/* Zebra dezent */
table.tab-norm tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.tab-norm tbody tr:hover td { background: var(--primary-soft); }

/* Kopf: normale Schreibung, Grundschrift halbfett (AP-7, UX-7), Haarlinie darunter, klebt unter dem Akten-Kopf */
table.tab-norm thead th {
    position: sticky;
    top: var(--kopf-versatz, 0px);
    z-index: var(--z-kleber);
    background: var(--paper);
    border-bottom: 1px solid var(--ink);
    font-family: var(--font-body);
    font-size: var(--fs-2);
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    color: var(--muted);
    text-align: left;
    white-space: nowrap;
    user-select: none;
}
table.tab-norm thead th.num,
table.tab-norm thead th.mitte { text-align: center; }
table.tab-norm td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Kopf-Versatz (M-2, PPS-Sonntag AP-3): bis 04.10.2026 nirgends gesetzt — die
   Köpfe klebten bei 0 unter dem App-Kopf und verschwanden. Gesetzt nur dort, wo
   die Seite selbst scrollt; in Scroll-Behältern (Datenspalte des Blattes, Panel,
   Kundenakte-Seitenleisten, schmale Tabellenhüllen) bliebe ein Versatz sonst
   als Lücke stehen und schöbe den Kopf in die Zeilen — dort gilt 0. */
#view { --kopf-versatz: var(--hdr-h, 60px); }
#view .akte-raster { --kopf-versatz: calc(var(--hdr-h, 60px) + var(--kopf-hoehe, 0px)); }
#view .blatt-daten, #view #panel, #view .ka-blick, #view .ka-sprung { --kopf-versatz: 0px; }
/* AP-4 (M-1/M-4): Seit Spaltentypen und Verhältnis je Reiter scrollt die Datenspalte
   ab 1180 px nicht mehr waagrecht (artikel.css) — ihr Tabellenkopf klebt dann unter
   dem Blattkopf wie überall auf der Seite. Darunter (Stapel) bleibt sie Scroll-Behälter. */
@media (min-width: 1180px) {
    #view .akte-raster .blatt-raster > .blatt-daten { --kopf-versatz: calc(var(--hdr-h, 60px) + var(--kopf-hoehe, 0px)); }
}
@media (max-width: 899px) {
    #view .tabelle-scroll, #view .tabelle-rahmen { --kopf-versatz: 0px; }
}

/* Sticky gegen die Seite: Hüllen mit horizontalem Scroll würden den Kopf
   einsperren. Auf breiten Schirmen passt die Tabelle — dort nur beschneiden. */
@media (min-width: 900px) {
    .tabelle-scroll:has(> table.tab-norm),
    .tabelle-rahmen:has(> table.tab-norm) { overflow-x: clip; overflow-y: visible; }
}

/* Sortierbare Köpfe */
table.tab-norm th.tab-sortierbar { cursor: pointer; padding-right: calc(var(--zelle-px) + 12px); }
table.tab-norm th.tab-sortierbar:hover { color: var(--ink); }
table.tab-norm th.tab-sortierbar:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
table.tab-norm th.tab-sortierbar::after {
    content: "↕"; position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    opacity: .0; font-size: var(--fs-1); color: var(--muted);
}
table.tab-norm th.tab-sortierbar:hover::after { opacity: .6; }
table.tab-norm th.tab-sort-auf::after { content: "▲"; opacity: 1; color: var(--primary-strong); }
table.tab-norm th.tab-sort-ab::after { content: "▼"; opacity: 1; color: var(--primary-strong); }

/* Ziehgriff am rechten Rand der Kopfzelle */
table.tab-norm th .tab-griff {
    position: absolute; top: 0; right: -4px; bottom: 0; width: 9px;
    cursor: col-resize; touch-action: none; z-index: var(--z-griff);
}
/* Letzte Spalte: Griff ganz innen — sonst ragt er 4 px über die Tabelle hinaus und jede Tabelle
   meldet scrollWidth > clientWidth (F-G10, Nacharbeit AP-P1). */
table.tab-norm th:last-child .tab-griff { right: 0; }
table.tab-norm th .tab-griff::after {
    content: ""; position: absolute; top: 25%; bottom: 25%; left: 4px; width: 1px;
    background: var(--line);
}
table.tab-norm th .tab-griff:hover::after,
table.tab-norm th .tab-griff.zieht::after { background: var(--primary); width: 2px; left: 3px; }

/* Aktionsknöpfe in Zeilen: erst bei Hover/Fokus, auf Touch immer */
.zeile-aktion { opacity: 1; transition: opacity .12s; } /* FB-062: immer sichtbar (Lauf 10, P-05) */
tr:hover .zeile-aktion,
tr:focus-within .zeile-aktion,
.zeile-aktion:focus-visible { opacity: 1; }
@media (hover: none) { .zeile-aktion { opacity: 1; } }

/* Detailzeilen gehören zur Hauptzeile darüber */
table.tab-norm tr.zeile-detail td { background: var(--surface-2); color: var(--muted); }

/* ⓘ-Hinweis statt Unterzeile */
.info-i {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.3em; height: 1.3em; margin-left: .35em;
    border: 1px solid var(--muted); border-radius: 50%;     /* Rand ≥ 3 : 1 (WCAG 1.4.11): --muted hat 6,1 : 1 auf Papier */
    font: 600 var(--fs-1)/1 var(--font-body); color: var(--muted);
    cursor: help; vertical-align: middle; background: var(--surface);
}
.info-i:hover, .info-i:focus-visible { color: var(--primary-strong); border-color: var(--primary); }
/* Zielfläche ≥ 24 px (WCAG 2.5.8, AP-9): Das Zeichen bleibt klein, ein unsichtbarer Rand macht die Trefferfläche größer. */
.info-i { position: relative; }
.info-i::after { content: ''; position: absolute; inset: -5px; }

/* Arbeitsplan / Prüfplan / Werkzeug-Tabellen (nie sortierbar): nur Dichte-Tokens */
table.schlicht.ap-tabelle th, table.schlicht.ap-tabelle td { padding: var(--zelle-py) var(--zelle-px); }
table.schlicht.ap-tabelle td { font-size: var(--tab-font); line-height: 1.35; }
table.schlicht.ap-tabelle tbody tr:hover .zeile-aktion { opacity: 1; }
/* Arbeitsplan-Griff bleibt greifbar, auch wenn die Knöpfe noch ruhen */
.ap-aktionen.zeile-aktion:focus-within { opacity: 1; }

/* Lernvorschläge: Hinweistext zwei Zeilen, Klick klappt auf */
.lh-text { max-width: 70ch; line-height: 1.4; }
.lh-text.lang { cursor: pointer; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lh-text.lang.offen { display: block; overflow: visible; }
.lh-text.lang:not(.offen)::after { content: " ▾"; color: var(--primary-strong); }

/* ── Baukasten v2 (Lauf 10, P-03) ─────────────────────────────────────────── */

/* In der Datenspalte der Artikelakte scrollt die Tabelle waagrecht statt zu quetschen;
   der klebende Kopf gilt dort innerhalb der Hülle. */
.blatt-daten .tabelle-scroll:has(> table.tab-norm),
.blatt-daten .tabelle-rahmen:has(> table.tab-norm) { overflow-x: auto; }
/* AP-4: ab 1180 px passt die Tabelle in ihre Spalte (Spaltentypen, Verhältnis je Reiter,
   Verdichtung unter 560 px) — kein Scroll-Behälter, damit der Kopf an der Seite klebt. */
@media (min-width: 1180px) {
    .blatt-daten .tabelle-scroll:has(> table.tab-norm),
    .blatt-daten .tabelle-rahmen:has(> table.tab-norm) { overflow-x: clip; overflow-y: visible; }
}

/* Leiste über der Tabelle: ein Zeichenknopf „Tabelle anpassen“ (AP-7), davor Trefferzahl und Hinweis bei
   sortierter Reihenfolge. Volle Deckkraft, Klickziel 28 px. */
.tab2-leiste {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-1) var(--sp-2);
    margin: 0 0 2px; font-size: var(--fs-1); color: var(--muted);
}
.tab2-knopf {
    display: inline-flex; align-items: center; min-height: 24px; border: 0; background: none; padding: 2px var(--sp-1); border-radius: var(--radius-s);
    font: inherit; color: var(--muted); cursor: pointer; list-style: none;
}
.tab2-knopf::-webkit-details-marker { display: none; }
.tab2-knopf:hover, .tab2-knopf:focus-visible { color: var(--primary-strong); background: var(--primary-soft); outline: none; }
.tab2-spalten { position: relative; }
.tab2-zeichen {
    display: inline-flex; align-items: center; justify-content: center; list-style: none; cursor: pointer;
    width: var(--ctl-h-s); height: var(--ctl-h-s); border-radius: var(--radius-s); color: var(--muted);
}
.tab2-zeichen::-webkit-details-marker { display: none; }
.tab2-zeichen:hover, .tab2-spalten[open] > .tab2-zeichen { color: var(--primary-strong); background: var(--primary-soft); }
.tab2-zeichen:focus-visible { color: var(--primary-strong); outline: 2px solid var(--primary); outline-offset: 0; }
.tab2-zurueck { margin-top: var(--sp-1); width: 100%; justify-content: center; }
.tab2-menue {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: var(--z-menue); min-width: 200px; max-height: 320px; overflow-y: auto;
    padding: var(--sp-1) var(--sp-2); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-s, 0 2px 8px rgba(0,0,0,.12)); color: var(--ink);
}
.tab2-wahl { display: flex; align-items: center; gap: var(--sp-1); min-height: 24px; padding: var(--sp-1) 2px; white-space: nowrap; cursor: pointer; }
.tab2-sortiert { color: var(--st-work, var(--accent-dark)); }
.tab2-sortiert[hidden] { display: none; }

/* Filter je Spalte (data-filterbar, Plan Abgleich 11201 B-3): zweite Kopfzeile, klebt nicht mit
   (zwei klebende Zeilen auf derselben Höhe lägen übereinander), Felder so breit wie die Spalte. */
.tab2-treffer { font-variant-numeric: tabular-nums; color: var(--ink); }
.tab2-treffer:empty { display: none; }
table.tab-norm thead tr.tab-filter-zeile th {
    position: static; padding-top: 2px; padding-bottom: var(--sp-1); border-bottom: 1px solid var(--line);
    font-family: var(--font-body); font-size: var(--fs-2); letter-spacing: 0; text-transform: none;
    font-weight: 400; color: var(--ink); white-space: nowrap; user-select: auto;
}
.tab-filter-zeile input[type="search"], .tab-filter-zeile input[type="date"] {
    width: 100%; min-width: 0; box-sizing: border-box; min-height: 24px; padding: 2px var(--sp-1); font: inherit;
    color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s);
}
.tab-filter-zeile input:focus-visible { outline: 2px solid var(--primary); outline-offset: 0; }
.tab-filter-datum { display: flex; flex-direction: column; gap: 2px; min-width: 8.5em; }
.tab-filter-wahl { position: relative; }
.tab-filter-wahl > summary { max-width: 14em; overflow: hidden; text-overflow: ellipsis; }
.tab-filter-wahl > summary::after { content: " ▾"; }
.tab-filter-wahl > summary { display: inline-block; min-height: 24px; line-height: 20px; box-sizing: border-box; vertical-align: middle; }
.tab-filter-wahl .tab2-menue { left: 0; right: auto; min-width: 160px; }
.tab-filter-zeile input[type="search"]:not(:placeholder-shown) { border-color: var(--primary); }
/* Gefilterte Zeilengruppen — eigene Klasse, ``hidden`` gehört data-sofort. */
table .tab-gefiltert { display: none !important; }

/* ── Spaltentypen (M-1, PPS-Sonntag AP-4) ─────────────────────────────────────
   Gesetzt von tabelle.js (data-typ am Kopf, tab-typ-* an den Zellen). Schmale
   Typen schrumpfen auf ihren Inhalt (width:1% bei auto-layout), Text bekommt den Rest. */
table th[data-typ="nr"], table th[data-typ="badge"], table th[data-typ="aktion"], table th[data-typ="datum"],
table td.tab-typ-nr, table td.tab-typ-badge, table td.tab-typ-aktion, table td.tab-typ-datum {
    width: 1%; white-space: nowrap;
}
table th[data-typ="num"], table td.tab-typ-num {
    width: 1%; white-space: nowrap; font-variant-numeric: tabular-nums;
}
table.tab-norm th[data-typ="num"], table.tab-norm td.tab-typ-num,
table.tab-norm thead th[data-typ="num"].mitte { text-align: right; }
table th[data-typ="id"], table td.tab-typ-id { white-space: nowrap; }
table td.tab-typ-id { font-family: var(--font-code, var(--font-mono)); }
/* In einer Kennungszelle bleibt nur die Kennung selbst ungebrochen — Bedeutung und Hinweise darunter fließen. */
table td.tab-typ-id > :is(div, .bezug-bedeutung, .bezug-kandidaten, .bezug-befund-zeile, .lauf-vermerk, .kombi-zeile) { white-space: normal; font-family: var(--font-body); }
/* Kurzform eines Kopfes (tabKopf kurz) — gezeigt nur in schmalen Spalten (artikel.css). */
.tk-kurz { display: none; }
table th[data-typ="text"], table td.tab-typ-text { min-width: 16ch; }
/* Höchstens zwei Zeilen, danach Ellipse — der volle Text steht im Tooltip der Zelle. */
.tab-zwei {
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
    overflow: hidden; overflow-wrap: anywhere;
}

/* Ausgeblendete Spalten */
table .tab2-aus, table col.tab2-aus { display: none !important; }

/* Spalten-Option „original“: Quellwert gedämpft neben dem überschriebenen Wert */
.tab2-original {
    margin-left: .45em; color: var(--subtle, var(--muted)); font-size: max(12px, .86em);
    text-decoration: line-through; text-decoration-thickness: 1px;
}

/* Reihenfolge-Tabelle sortiert: Griffe und Verschiebe-Knöpfe ruhen sichtbar (G-16) */
table[data-reihenfolge][data-tab-sortiert] .ap-griff,
table[data-reihenfolge][data-tab-sortiert] [data-reihenfolge-griff],
table[data-reihenfolge][data-tab-sortiert] [onclick*="Verschieben("] { opacity: .3; cursor: not-allowed; }

/* ── Schmal (≤ 560 px): jede Zeile als Karte (AP-UX, U-4 „390 px lesbar“) ─────
   tabelle.js schreibt den Kopftext je Zelle in data-kopf. Unter 560 px Viewport
   steht er links als Beschriftung, der Wert rechts — kein waagrechtes Scrollen
   mehr. Ausgenommen: Reihenfolge-Tabellen (Ziehen braucht die Zeile) und
   Tabellen mit data-karten="nein" und solche mit eigener Kartenliste (data-label,
   Start-Block AP-SO). Der Kopf bleibt für Screenreader im DOM. */
@media (max-width: 560px) {
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) {
        display: block; width: 100% !important; min-width: 0 !important; table-layout: auto;
    }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > colgroup { display: none; }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > thead {
        display: block; position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
    }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > :is(tbody, tfoot) { display: block; }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > :is(tbody, tfoot) > tr {
        display: block; padding: var(--sp-1) 0; border-bottom: 1px solid var(--line);
    }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > :is(tbody, tfoot) > tr > td {
        display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3);
        width: auto !important; min-width: 0 !important; max-width: none; padding: 2px var(--sp-1);   /* 4 px: Platz für den Hover-Rand der Wertfelder (margin −3 px) */
        border: 0; background: none; text-align: right; white-space: normal; overflow-wrap: anywhere;
    }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > :is(tbody, tfoot) > tr > td[data-kopf]::before {
        content: attr(data-kopf); flex: 0 0 auto; max-width: 45%; text-align: left;
        color: var(--muted); font-family: var(--font-body); font-size: var(--fs-1); font-weight: 600;
    }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > :is(tbody, tfoot) > tr > td:not([data-kopf]) {
        display: block; text-align: left;
    }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > :is(tbody, tfoot) > tr > td:empty { display: none; }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) .tab-zwei { text-align: right; }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > :is(tbody, tfoot) > tr > td > * { min-width: 0; max-width: 100%; }
    #view table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label])) > :is(tbody, tfoot) > tr > td :is(.badge, .ap-eignung, .wert-feld) { white-space: normal; max-width: 100%; }
    /* Kartenmodus: die Hülle rollt nicht mehr — Rundungsreste (≤ 2 px) werden abgeschnitten, nicht gerollt. */
    #view :is(.tabelle-rahmen, .tabelle-scroll):has(> table[data-typen]:not([data-reihenfolge]):not([data-karten="nein"]):not(:has(td[data-label]))) { overflow-x: clip; }
}

/* Tabellen ohne Baukasten tragen ihre Typen nur zur Beschriftung und Ausrichtung (AP-UX): Die
   Mindestbreite der Textspalten gilt dort nicht — sie hätte schmale Katalogtabellen verbreitert. */
table[data-typen-auto] :is(th[data-typ="text"], td.tab-typ-text) { min-width: 0; }

/* Leere Spalten (U-3, AP-UX): tabelle.js markiert Spalten, die in keiner Zeile einen Wert tragen. */
table th.tab-leer-spalte, table td.tab-leer-spalte { display: none; }

/* ── Opt-ins (AL 06.11.2026, Controller-Befunde 9/10) — wirken nur an Tabellen, die sie tragen ──────────
   .tab-zentriert: Zellen und Köpfe mittig, Freitext (data-typ="text") links.
   data-filter-klapp: Filterzeile erst nach Klick auf „Filter“ (Klasse .tab-filter-offen); der Filter wirkt weiter.
   data-suche: Suchfeld in der Leiste, Zeilen ohne Treffer tragen .tab-gesucht-aus. */
table.tab-zentriert th, table.tab-zentriert td { text-align: center; }
table.tab-zentriert td.num, table.tab-zentriert td.tab-typ-num, table.tab-zentriert th[data-typ="num"] { text-align: center; }
table.tab-zentriert th[data-typ="text"], table.tab-zentriert td.tab-typ-text { text-align: left; }
table[data-filter-klapp]:not(.tab-filter-offen) tr.tab-filter-zeile { display: none; }
table .tab-gesucht-aus { display: none !important; }
.tab2-filterknopf[aria-expanded="true"] { color: var(--primary-strong, var(--primary)); font-weight: 600; }
