/* ===========================================================================
   OSP-Tabelle v1 — Darstellung (UI-Standard §4, §10; WCAG 2.2 AA)
   Hell/Dunkel über CSS-Variablen. Dunkel gilt bei html.dark oder [data-theme="dark"]
   (gleiche Schalter wie dark-mode.js). Eine App überschreibt nur die Variablen.

   Farbregel (W-2, 22.10.2026): blauer Text auf Weiß = #0070B0; #0080C9 nur für Linien,
   Flächen und große Schrift.
   Größe der App (13 · 14 · 16 px) über --ot-schrift; die Fläche bleibt, die Zeilenhöhe folgt.
   =========================================================================== */

.ot {
  --ot-schrift: 14px;
  --ot-zf: 2.5;                       /* Zeilenhöhe in Schrifthöhen: kompakt */
  --ot-kopfh: 2.2em;
  --ot-filterh: 2.2em;
  --ot-mono: 'Fira Code', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --ot-bg: #FFFFFF;
  --ot-text: #1E293B;
  --ot-gedaempft: #475569;
  --ot-kopf: #EEF2F7;
  --ot-kopf2: #F6F8FB;
  --ot-rand: #CBD5E1;
  --ot-streifen: #F8FAFC;
  --ot-hover: #E6F2FA;
  --ot-feld: #FFFFFF;
  --ot-feldrand: #64748B;
  --ot-link: #0070B0;                 /* Text auf Weiß */
  --ot-linie: #0080C9;                /* nur Linien/Flächen/große Schrift */
  --ot-aktiv-bg: #0070B0;
  --ot-aktiv-text: #FFFFFF;
  --ot-fokus: #0070B0;
  --ot-chip-bg: #E0F2FE;
  --ot-chip-text: #0B4F7A;
  --ot-chip-rand: #0070B0;
  --ot-ok-bg: #DCFCE7;    --ot-ok-text: #14532D;
  --ot-fehler-bg: #FEE4E2; --ot-fehler-text: #912018; --ot-fehler-linie: #B42318;
  --ot-konflikt-bg: #FEF3C7; --ot-konflikt-text: #78350F;

  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  position: relative;
  font-family: 'Open Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: var(--ot-schrift);
  line-height: 1.3;
  color: var(--ot-text);
  background: var(--ot-bg);
}
.ot[data-dichte="komfortabel"] { --ot-zf: 3.8; }

html.dark .ot,
[data-theme="dark"] .ot {
  --ot-bg: #0F172A;
  --ot-text: #E2E8F0;
  --ot-gedaempft: #A9B7CC;
  --ot-kopf: #1E293B;
  --ot-kopf2: #162235;
  --ot-rand: #334155;
  --ot-streifen: #131D33;
  --ot-hover: #1B3350;
  --ot-feld: #0B1220;
  --ot-feldrand: #8A9BB3;
  --ot-link: #6CC4F5;
  --ot-aktiv-bg: #0070B0;
  --ot-aktiv-text: #FFFFFF;
  --ot-fokus: #7DD3FC;
  --ot-chip-bg: #0C3A5C;
  --ot-chip-text: #BAE6FD;
  --ot-chip-rand: #7DD3FC;
  --ot-ok-bg: #052E16;    --ot-ok-text: #BBF7D0;
  --ot-fehler-bg: #450A0A; --ot-fehler-text: #FECACA; --ot-fehler-linie: #F87171;
  --ot-konflikt-bg: #422006; --ot-konflikt-text: #FDE68A;
}

.ot *, .ot *::before, .ot *::after { box-sizing: border-box; }
.ot-nur-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Fokus nie verdeckt: sichtbarer Ring innen, Scroll-Abstände setzt das Skript (scroll-padding) */
.ot :focus-visible { outline: 2px solid var(--ot-fokus); outline-offset: -2px; }
.ot-feld:focus-visible, .ot-suchfeld:focus-visible { outline-offset: 1px; }

/* ── Werkzeugleiste ───────────────────────────────────────────────────────── */
.ot-leiste {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: .4em .5em;
  padding: .25em .5em;
  background: var(--ot-kopf2);
  border-bottom: 1px solid var(--ot-rand);
}
.ot-suche { display: block; flex: 0 1 14em; min-width: 7em; }
.ot-suchfeld, .ot-feld {
  width: 100%; min-height: 28px; height: 28px;
  padding: 0 .55em;
  font: inherit; font-size: .93em;
  color: var(--ot-text); background: var(--ot-feld);
  border: 1px solid var(--ot-feldrand); border-radius: 8px;
}
.ot-suchfeld::placeholder, .ot-feld::placeholder { color: var(--ot-gedaempft); opacity: 1; }
.ot-knopf {
  min-height: 28px; min-width: 28px; padding: 0 .75em;
  font: inherit; font-size: .93em; white-space: nowrap; cursor: pointer;
  color: var(--ot-text); background: var(--ot-feld);
  border: 1px solid var(--ot-feldrand); border-radius: 8px;
}
.ot-knopf:hover:not(:disabled) { background: var(--ot-hover); }
.ot-knopf:disabled { color: var(--ot-gedaempft); cursor: default; opacity: .7; }
.ot-knopf[aria-pressed="true"] { background: var(--ot-aktiv-bg); color: var(--ot-aktiv-text); border-color: var(--ot-aktiv-bg); }
.ot-knopf[aria-pressed="true"]:focus-visible { outline-color: var(--ot-text); outline-offset: 2px; }
.ot-klein { padding: 0; width: 28px; }
.ot-zaehler { font-variant-numeric: tabular-nums; color: var(--ot-gedaempft); white-space: nowrap; padding: 0 .25em; }
.ot-chips { display: flex; flex-wrap: wrap; gap: .3em; }
.ot-chips:empty { display: none; }
.ot-chip {
  min-height: 28px; padding: 0 .7em; font: inherit; font-size: .88em; cursor: pointer;
  color: var(--ot-chip-text); background: var(--ot-chip-bg);
  border: 1px solid var(--ot-chip-rand); border-radius: 999px;
}
.ot-chip:hover { filter: brightness(.96); }
.ot-link {
  padding: 0 .15em; min-height: 24px; font: inherit; cursor: pointer; background: none; border: 0;
  color: var(--ot-link); text-decoration: underline; text-underline-offset: 2px;
}
.ot-chips { flex: 0 1 auto; min-width: 0; }
/* Meldung steht in der Leiste, bricht sie nie um: gekürzt wird nur der Meldungstext (voll im Tooltip und für Screenreader) */
.ot-meldung:empty { display: none; }
.ot-meldung { flex: 1 1 8em; max-width: max-content; min-width: 0; display: flex; align-items: center; gap: .6em; padding: .15em .7em; border-radius: 8px; font-size: .93em; }
.ot-meldung-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ot-meldung .ot-link { flex: 0 0 auto; }
.ot-meldung .ot-zu { min-width: 24px; min-height: 24px; text-decoration: none; font-size: 1.05em; }
.ot-meldung.ot-hinweis { background: var(--ot-kopf); color: var(--ot-text); border: 1px solid var(--ot-rand); }
.ot-meldung.ot-ok { background: var(--ot-ok-bg); color: var(--ot-ok-text); }
.ot-meldung.ot-fehler { background: var(--ot-fehler-bg); color: var(--ot-fehler-text); }
.ot-meldung.ot-konflikt { background: var(--ot-konflikt-bg); color: var(--ot-konflikt-text); }
.ot-meldung .ot-link { color: inherit; }

/* ── Rahmen und Tabelle ───────────────────────────────────────────────────── */
.ot-rahmen {
  flex: 1 1 auto; min-height: 0; max-width: 100%;
  overflow: auto;                       /* rollt in sich — die Seite rollt nie */
  position: relative;
  background: var(--ot-bg);
}
.ot-tabelle {
  border-collapse: separate; border-spacing: 0;
  table-layout: fixed;                  /* Breite setzt das Skript nach Inhalt, nie über 100 % gestreckt */
  max-width: none;
}
.ot-tabelle col { min-width: 0; }

.ot-tabelle th {
  position: sticky; z-index: 3;
  padding: 0; margin: 0;
  background: var(--ot-kopf);
  border-bottom: 1px solid var(--ot-rand);
  text-align: center; font-weight: 600;
  white-space: nowrap;
}
.ot-kopfzeile th { top: 0; height: var(--ot-kopfh); }
.ot-filterzeile th { top: var(--ot-kopfh); height: var(--ot-filterh); padding: .2em .3em; background: var(--ot-kopf2); font-weight: 400; z-index: 3; }
.ot-th.ot-frei { text-align: left; }

.ot-sort {
  display: flex; align-items: center; justify-content: center; gap: .35em;
  width: 100%; height: 100%; min-height: 28px;
  padding: 0 14px 0 .4em;
  font: inherit; font-weight: 600; color: inherit; text-align: inherit;
  background: none; border: 0; cursor: pointer;
}
button.ot-sort:hover { background: var(--ot-hover); }
.ot-th.ot-frei .ot-sort { justify-content: flex-start; padding-left: .6em; }
.ot-ohne { cursor: default; }
.ot-titel { overflow: hidden; text-overflow: clip; white-space: nowrap; }
.ot-pfeil { color: var(--ot-gedaempft); font-size: .85em; flex: 0 0 auto; }
.ot-pfeil.ot-an { color: var(--ot-link); font-size: 1em; }
.ot-stift { font-size: .8em; color: var(--ot-gedaempft); flex: 0 0 auto; }

.ot-griff {
  position: absolute; top: 0; right: 0; bottom: 0; width: 10px; cursor: col-resize; touch-action: none;
}
.ot-griff::after { content: ''; position: absolute; right: 4px; top: 25%; bottom: 25%; width: 2px; background: var(--ot-feldrand); opacity: .55; border-radius: 1px; }
.ot-griff:hover::after, .ot-griff:focus-visible::after { background: var(--ot-linie); opacity: 1; width: 3px; }
.ot-griff:focus-visible { outline-offset: -1px; }

.ot-tabelle td {
  padding: 0;
  height: calc(var(--ot-schrift) * var(--ot-zf));
  background: var(--ot-bg);
  border-bottom: 1px solid var(--ot-rand);
  text-align: center; vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
.ot-ger td { background: var(--ot-streifen); }
.ot-zeile:hover td { background: var(--ot-hover); }
.ot-abstand td { height: auto; padding: 0; border: 0; background: transparent; }
.ot-abstand:hover td { background: transparent; }
td.ot-frei { text-align: left; }

.ot-z { padding: 0 .65em; line-height: 1.2; }
.ot-kuerz {                              /* lange Texte: zwei Zeilen, vollständig im Tooltip */
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  overflow: hidden; overflow-wrap: anywhere;
}
td.ot-ganz { overflow: visible; }
.ot-ganz .ot-z {                         /* NULL-FEHLER: Crimpwerte und Nummern nie kürzen — sie brechen um, nichts wird abgeschnitten */
  white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere;
  font-family: var(--ot-mono); display: block;
}
.ot-th.ot-ganz { overflow: visible; }
.ot-rahmen:focus { outline: none; }
.ot-rahmen:focus-visible { outline: 2px solid var(--ot-fokus); outline-offset: -2px; }
.ot-nichts::before { content: '–'; color: var(--ot-gedaempft); }

/* Erste Spalte steht beim Querscrollen */
.ot-tabelle tr > :first-child { position: sticky; left: 0; z-index: 2; box-shadow: 1px 0 0 var(--ot-rand); }
.ot-tabelle thead tr > :first-child { z-index: 5; }
.ot-tabelle tr.ot-abstand > :first-child { position: static; box-shadow: none; }

/* Bearbeiten in der Zelle */
.ot-bearb .ot-z { cursor: text; }
.ot-bearb:hover .ot-z { text-decoration: underline dotted; text-underline-offset: 3px; }
td.ot-editiert { padding: 2px 3px; }
.ot-eingabe {
  width: 100%; height: 100%; min-height: 24px; padding: 0 .5em;
  font: inherit; text-align: inherit; font-variant-numeric: tabular-nums;
  color: var(--ot-text); background: var(--ot-feld);
  border: 2px solid var(--ot-linie); border-radius: 6px;
}
.ot-ganz .ot-eingabe { font-family: var(--ot-mono); }
.ot-eingabe[readonly] { opacity: .75; }
.ot-eingabe[aria-invalid="true"] { border-color: var(--ot-fehler-linie); }
.ot-eingabe:focus-visible { outline: 2px solid var(--ot-fokus); outline-offset: 1px; }
.ot-tabelle td.ot-gespeichert { background: var(--ot-ok-bg); transition: background-color .6s ease; }
.ot-tabelle td.ot-fehlerzelle { box-shadow: inset 0 0 0 2px var(--ot-fehler-linie); }

.ot-leersatz {
  position: sticky; left: 0; width: 100%;
  padding: 1.6em 1em; text-align: center; color: var(--ot-text);
}

/* ── Spaltenmenü ──────────────────────────────────────────────────────────── */
.ot-menue {
  position: absolute; z-index: 30; top: 3em; right: .5em;
  width: min(34em, calc(100% - 1em)); max-height: calc(100% - 4em); overflow: auto;
  padding: .6em .7em; color: var(--ot-text); background: var(--ot-bg);
  border: 1px solid var(--ot-feldrand); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .25);
}
.ot-menue[hidden] { display: none; }
.ot-menue-kopf { display: flex; align-items: center; justify-content: space-between; gap: .5em; }
.ot-menue-tools { display: flex; gap: .4em; }
.ot-menue-hinweis { margin: .3em 0 .4em; color: var(--ot-gedaempft); font-size: .9em; }
.ot-menue-liste { list-style: none; margin: 0; padding: 0; }
.ot-menue-zeile {
  display: grid; grid-template-columns: 1fr 28px 28px 6.5em; align-items: center; gap: .35em;
  min-height: 32px; border-top: 1px solid var(--ot-rand);
}
.ot-menue-an { display: flex; align-items: center; gap: .5em; min-height: 28px; cursor: pointer; }
.ot-menue-an input { width: 1.15em; height: 1.15em; accent-color: var(--ot-aktiv-bg); }
.ot-menue-breite input { text-align: center; }

@media (prefers-reduced-motion: reduce) { .ot * { transition: none !important; } }
@media (forced-colors: active) {
  .ot-tabelle td, .ot-tabelle th { border-bottom: 1px solid CanvasText; }
  .ot-tabelle td.ot-fehlerzelle { outline: 2px solid Highlight; }
}
