/* =========================================================================
   editor.css — Gestaltung des WYSIWYG-Editors für Kursinhalte

   Grundsatz: Die Schreibfläche trägt die Klasse "lektion-text" und benutzt
   damit dieselben Regeln wie die ausgelieferte Lektion — Boxen, Tabellen,
   Codeblöcke, Überschriften, Zeilenlänge. Hier steht nur, was dazukommt:
   die Symbolleiste, die kleinen Knöpfe an der Tabelle, die Marken für
   Seitenumbruch und Lösungsblock und ein paar Hilfen beim Bearbeiten.
   Wer eine Lektionsfarbe sucht: Sie steht in style.css und wird nicht
   nachgebaut, sonst laufen Lesen und Bearbeiten auseinander.

   Alle Farben kommen aus den Variablen von style.css, damit der Dunkelmodus
   ohne Zutun mitgeht.
   ========================================================================= */

.wys {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------------- Symbolleiste ---------------- */
/* Sie bleibt beim Blättern oben stehen: Bei einer Lektion von 3000 Wörtern
   möchte niemand zum Fettsetzen erst nach oben scrollen. */

.wys-leiste {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.wys-knopf {
  background: transparent;
  color: var(--sap-dark);
  border: 1px solid transparent;
  border-radius: 6px;
  min-width: 32px;
  height: 30px;
  padding: 0 8px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.wys-knopf svg { display: block; pointer-events: none; }
.wys-knopf:hover { background: var(--surface-hover); border-color: var(--border); }
/* Der aktive Zustand muss auch ohne Farbunterscheidung erkennbar sein —
   deshalb Rahmen UND Hintergrund, nicht nur eine blaue Fläche. */
.wys-knopf.ist-aktiv {
  background: var(--surface-hover);
  border-color: var(--sap-blue);
  color: var(--sap-blue);
}
.wys-knopf:focus-visible {
  outline: 2px solid var(--sap-blue-dark);
  outline-offset: 1px;
}
.wys-knopf:disabled { opacity: 0.4; cursor: not-allowed; }
.wys-knopf:disabled:hover { background: transparent; border-color: transparent; }
.wys-knopf-text { font-size: 12.5px; font-weight: 600; padding: 0 12px; }

.wys-auswahl {
  height: 30px;
  padding: 0 6px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  max-width: 190px;
}
.wys-auswahl:disabled { opacity: 0.5; }

.wys-trenner {
  width: 1px;
  height: 20px;
  margin: 0 5px;
  background: var(--border);
  flex-shrink: 0;
}
.wys-dehnung { flex: 1 1 auto; min-width: 8px; }

/* ---------------- Schreibfläche ---------------- */
/* Die Höchstbreite von .lektion-text bleibt bewusst stehen: Der Editor soll
   genauso aussehen wie die Lektion, also auch dieselbe Zeilenlänge haben.
   Breiter wird nur der Rahmen ringsum, damit die Symbolleiste Platz hat. */

.wys-flaeche {
  margin: 0 auto;
  padding: 26px 28px 60px;
  width: 100%;
  min-height: 520px;
  max-height: 72vh;
  overflow-y: auto;
  outline: none;
  background: var(--surface);
  border-radius: 0 0 var(--radius) var(--radius);
}
.wys-flaeche:focus-visible { box-shadow: inset 0 0 0 2px var(--sap-blue); }

/* .lektion-text setzt max-width auf dem Element selbst; damit der Textspalte
   trotzdem der Rahmen bleibt, wird sie hier innerhalb zentriert. */
.wys-flaeche.lektion-text { max-width: 816px; }

/* Der Block unter dem Cursor bekommt eine feine Marke am linken Rand — sie
   zeigt, worauf sich Absatzart und Boxwahl gerade beziehen. */
.wys-flaeche > * { position: relative; }
.wys-flaeche > *:hover::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 2px;
  bottom: 2px;
  width: 2px;
  border-radius: 2px;
  background: var(--border);
}

/* Der erste Block soll nicht mit einem grossen Aussenabstand beginnen —
   sonst klafft oben ein Loch, das es in der Lektion nicht gibt. */
.wys-flaeche > *:first-child { margin-top: 0; }

/* Leere Absätze wären unsichtbar und damit unauffindbar. */
.wys-flaeche p:empty::after,
.wys-flaeche h1:empty::after,
.wys-flaeche h2:empty::after,
.wys-flaeche h3:empty::after,
.wys-flaeche h4:empty::after {
  content: "\200b";
}

/* Überschrift 2 und 3 kennt der Lektionswandler nicht — er reicht sie als
   Text durch, weil die Kurserzeugung die Dateien vorher daran aufschneidet.
   Im Editor sind sie trotzdem Überschriften, denn so sind sie gemeint. Sie
   übernehmen die Grössen der Kapitel- und Lektionstitel der Lesansicht. */
.wys-flaeche h1 {
  margin: 8px 0 18px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--sap-dark);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--sap-blue);
}
.wys-flaeche h2 {
  margin: 36px 0 14px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--sap-dark);
}

/* ---------------- Marken: Seitenumbruch und Lösungsblock ---------------- */
/* Das Backend wirft diese Zeilen weg beziehungsweise setzt sie später in ein
   <details> um. Unsichtbar darf das im Editor nicht sein, sonst löscht sie
   jemand aus Versehen oder setzt sie doppelt. */

.wys-marke {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 26px 0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  user-select: none;
  cursor: default;
}
.wys-marke::before,
.wys-marke::after {
  content: "";
  flex: 1;
  height: 0;
  border-top: 2px dashed var(--border);
}
.wys-marke span {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  white-space: nowrap;
}

/* ---------------- Boxen im Bearbeitungszustand ---------------- */

.wys-flaeche .box-label {
  user-select: none;
  cursor: default;
}
/* Ein Boxtyp, den der Wandler nicht kennt: sichtbar machen statt verschlucken. */
.wys-flaeche .box-unbekannt {
  --box-farbe: var(--hot);
  --box-grund: #fdeaea;
}
[data-theme="dark"] .wys-flaeche .box-unbekannt { --box-grund: #331c1c; --box-farbe: #e58080; }

/* ---------------- Codeblöcke ---------------- */
/* In der Lektion steht "white-space: pre"; beim Schreiben darf eine sehr
   lange Zeile trotzdem umbrechen, sonst tippt man aus dem Bild heraus. */

.wys-flaeche pre.codeblock {
  white-space: pre-wrap;
  min-height: 2.6em;
  outline: none;
}
.wys-flaeche pre.codeblock:empty::before {
  content: "Codeblock — Eingabetaste macht eine neue Zeile, Strg+Eingabe verlässt ihn";
  color: var(--text-muted);
  font-style: italic;
}

/* ---------------- Tabellen ---------------- */

/* Die Hülle um eine Tabelle hält deren Knöpfe daneben statt darin: Ein <div>
   innerhalb eines <table> verschiebt der Browser beim ersten Anfassen. */
.wys-flaeche .wys-tabelle { margin: 22px 0; }
.wys-flaeche .wys-tabelle > table { margin-top: 0; }

.wys-flaeche .wys-werkzeuge {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 6px;
  user-select: none;
}
.wys-minik {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
}
.wys-minik:hover { background: var(--surface-hover); color: var(--sap-blue); }
.wys-minik:focus-visible { outline: 2px solid var(--sap-blue-dark); outline-offset: 1px; }

/* Eine Zelle ohne Inhalt ist erlaubt — man muss sie nur treffen können. */
.wys-flaeche table.inhalt td:empty,
.wys-flaeche table.inhalt th:empty { min-width: 40px; }
.wys-flaeche table.inhalt td:focus,
.wys-flaeche table.inhalt th:focus,
.wys-flaeche table.tcode-tabelle td:focus {
  outline: 2px solid var(--sap-blue);
  outline-offset: -2px;
}
/* Die Kopfzeile der TCODE-Tabelle erzeugt der Wandler selbst; sie ist
   gesperrt und soll auch so aussehen. */
.wys-flaeche table.tcode-tabelle thead th { cursor: default; }
.wys-flaeche table.tcode-tabelle td:first-child code {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
}

/* ---------------- Quelltextansicht ---------------- */
/* Der Rettungsanker: Wenn die Umwandlung einmal etwas nicht abbildet, kommt
   man hier an den rohen Text. Bewusst dieselbe Schrift und Grösse wie im
   alten Editorfeld des Admin-Portals. */

.wys-quelltext {
  width: 100%;
  min-height: 520px;
  max-height: 72vh;
  border: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 18px 20px;
  font-family: "Consolas", "Menlo", "DejaVu Sans Mono", monospace;
  font-size: 12.5px;
  line-height: 1.6;
  background: var(--surface-alt);
  color: var(--text);
  resize: vertical;
  tab-size: 2;
  outline: none;
}
.wys-quelltext:focus-visible { box-shadow: inset 0 0 0 2px var(--sap-blue); }

/* ---------------- Dialog "Tabelle einfügen" ---------------- */
/* Kein <dialog>, weil der Editor selbst schon in einem modalen Dialog des
   Admin-Portals stecken kann und zwei Modale sich gegenseitig blockieren. */

.wys-dialog {
  position: absolute;
  z-index: 10;
  margin: 6px 0 0 10px;
  width: 260px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.wys-dialog-titel {
  font-size: 14px;
  font-weight: 700;
  color: var(--sap-dark);
  margin-bottom: 12px;
}
.wys-dialog-feld {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.wys-dialog-feld input {
  width: 100%;
  padding: 6px 8px;
  font: inherit;
  font-weight: 400;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-alt);
  color: var(--text);
}
.wys-dialog-fuss {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.wys-dialog-fuss button {
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: 6px;
}
.wys-dialog-fuss .btn-secondary {
  background: var(--surface);
  color: var(--sap-dark);
  border: 1px solid var(--border);
}

/* ---------------- Schmale Fenster ---------------- */

@media (max-width: 900px) {
  .wys-flaeche { padding: 18px 16px 50px; min-height: 380px; }
  .wys-leiste { gap: 3px; padding: 6px; }
  .wys-trenner { margin: 0 2px; }
  .wys-dehnung { min-width: 0; flex-basis: 100%; height: 0; }
}
