/* ═══════════════════════════════════════════════════════════════
   BE:KI Direct – Word-Light-Editor (portiert aus BE:KI Frame)
   Ribbon-Interface, A4-Seitenansicht, Druck- und .docx-Export.
   ═══════════════════════════════════════════════════════════════ */

#word-editor-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: #d0d4d8;
  margin: -28px -28px -48px;
}

.schr-editor-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #dde3ec;
}

.schr-text-erstellen {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #dde3ec;
}
.schr-text-erstellen .form-group { flex: 1; margin-bottom: 0; }
.schr-text-erstellen textarea { resize: vertical; min-height: 40px; }

#result-loading {
  position: absolute;
  inset: 0;
  background: rgba(208,212,216,.88);
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13.5px;
  color: #6b7a8d;
}
#result-loading .spin { animation: we-spin 1s linear infinite; }
@keyframes we-spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════
   RIBBON
   ══════════════════════════════════════════════════════════════ */
#ribbon {
  flex-shrink: 0;
  background: #f4f7fb;
  border-bottom: 2px solid rgba(22,72,166,.4);
  position: relative;
  z-index: 10;
}

#ribbon-tabs {
  display: flex;
  align-items: stretch;
  background: rgba(22,72,166,.68);
  backdrop-filter: blur(8px);
  height: 30px;
}

.rtab {
  padding: 0 16px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,.75);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: .02em;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.rtab:hover { background: rgba(255,255,255,.12); color: #fff; }
.rtab.rtab-active {
  background: #f4f7fb;
  color: var(--navy);
  border-radius: 4px 4px 0 0;
  margin-top: 3px;
}

.ribbon-panel {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 8px;
  min-height: 60px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: visible;
}

.rgroup {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 3px;
  padding: 4px 8px 4px;
}
.rgroup-btns { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.rgroup-label { font-size: 9.5px; color: #9ba8bb; text-align: center; width: 100%; letter-spacing: .03em; }

.rsep { width: 1px; background: #dde3ec; align-self: stretch; margin: 4px 2px; flex-shrink: 0; }

.rb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1px;
  min-width: 30px;
  height: 34px;
  padding: 0 6px;
  border: 1.5px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: #1e293b;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background .1s, border-color .1s;
  white-space: nowrap;
  flex-shrink: 0;
}
#ribbon .rb svg { width: 18px; height: 18px; }
.rb:hover { background: #e8eef8; border-color: #c8d4ea; }
.rb.rb-active { background: #dce8f8; border-color: var(--navy); color: var(--navy); }
.rb:disabled { opacity: .4; cursor: not-allowed; }

.rb.rb-large, .rb.rb-action {
  flex-direction: column;
  height: 50px;
  min-width: 50px;
  padding: 4px 7px;
  font-size: 11px;
  gap: 3px;
}
.rb.rb-large span, .rb.rb-action span { font-size: 10.5px; color: #4b5a6e; }
.rb.rb-large:hover span, .rb.rb-action:hover span { color: var(--navy); }
.rb.rb-action.copied { border-color: var(--teal-d); background: #f0faf5; }
#ribbon .rb.rb-large svg, #ribbon .rb.rb-action svg { width: 20px; height: 20px; }

.rs {
  height: 26px;
  border: 1.5px solid #dde3ec;
  border-radius: 4px;
  background: #fff;
  color: #1e293b;
  font-size: 12px;
  cursor: pointer;
  padding: 0 4px;
  font-family: inherit;
  transition: border-color .12s;
}
.rs:hover, .rs:focus { border-color: var(--navy); outline: none; }
.rs-font  { min-width: 96px; max-width: 110px; }
.rs-size  { width: 44px; }
.rs-style { min-width: 110px; }

.rb-color-wrap { display: inline-flex; border: 1.5px solid transparent; border-radius: 4px; overflow: hidden; flex-shrink: 0; }
.rb-color-wrap:hover { border-color: #c8d4ea; background: #e8eef8; }
.rb-color-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 26px; height: 26px; padding: 0 3px; border: none; background: transparent; cursor: pointer; gap: 1px;
}
.rb-color-arrow {
  width: 13px; height: 26px; border: none; border-left: 1px solid #dde3ec;
  background: transparent; font-size: 9px; cursor: pointer; color: #6b7a8d; padding: 0;
}
.rb-color-arrow:hover { background: #dce8f8; }

.rb-dropdown-wrap { position: relative; }
.rb-dropdown {
  position: fixed;
  background: #fff;
  border: 1.5px solid #dde3ec;
  border-radius: 8px;
  padding: 4px 0;
  min-width: 160px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 9200;
}
.rdd-item { padding: 7px 14px; font-size: 12.5px; cursor: pointer; color: #1e293b; transition: background .1s; }
.rdd-item:hover { background: #eef4ff; }
.rdd-item.rb-dd-active { color: var(--navy); font-weight: 600; }

/* ── Lineal ──────────────────────────────────────────────────── */
#ruler { background: #e8ecf0; border-bottom: 1px solid #c8d0dc; padding: 2px 0; flex-shrink: 0; overflow: hidden; }
#ruler-inner {
  width: 210mm; height: 18px; margin: 0 auto; background: #fff;
  border: 1px solid #c8d0dc; border-radius: 2px; position: relative;
  background: linear-gradient(to bottom, #f4f7fb 0%, #fff 100%);
}

/* ── Seitenbereich ───────────────────────────────────────────── */
#editor-page-area {
  flex: 1;
  overflow-y: auto;
  padding: 28px 0 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #d0d4d8;
  transform-origin: top center;
}

#editor-page {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,.22);
  border-radius: 1px;
  padding: 2.5cm;
  box-sizing: border-box;
  flex-shrink: 0;
  transition: padding .2s;
  position: relative;
}

#tiptap-editor {
  outline: none;
  min-height: 200px;
  font-family: Calibri, sans-serif;
  font-size: 12pt;
  line-height: 1.5;
  color: #1e293b;
  caret-color: var(--navy);
  /* NICHT `word-break: break-word`. Das ist die alte Schreibweise für
     `overflow-wrap: anywhere` – und `anywhere` senkt die Mindestbreite
     eines Elements auf ein einzelnes Zeichen. In einer Tabelle heisst
     das: der Browser darf jede Spalte beliebig schmal rechnen und
     trennt dafür mitten im Wort („Uhrzei/t", „Enthaltunge/n").

     `overflow-wrap: break-word` bricht dieselben überlangen Wörter,
     zählt aber bei der Mindestbreite das ganze Wort mit. Die Spalten
     werden dadurch so breit, wie ihre längste Zellenzeile es braucht –
     die Tabelle passt sich an, nicht das Wort. */
  word-break: normal;
  overflow-wrap: break-word;
}
#tiptap-editor:focus { outline: none; }
#tiptap-editor .ProseMirror { outline: none !important; border: none !important; box-shadow: none !important; }
#tiptap-editor ::selection { background-color: rgba(22,72,166,.18); color: inherit; }
#tiptap-editor p { margin: 0 0 0.5em; }
#tiptap-editor h1 { font-size: 2em;   font-weight: 700; margin: .5em 0 .3em; color: var(--navy); }
#tiptap-editor h2 { font-size: 1.5em; font-weight: 700; margin: .4em 0 .25em; color: var(--navy-d); }
#tiptap-editor h3 { font-size: 1.2em; font-weight: 700; margin: .35em 0 .2em; color: #1e293b; }
#tiptap-editor ul, #tiptap-editor ol { padding-left: 1.6em; margin: .3em 0; }
#tiptap-editor li { margin-bottom: .15em; }
#tiptap-editor blockquote { border-left: 3px solid var(--navy); margin: .5em 0; padding: .3em 1em; color: #4b5a6e; font-style: italic; }
#tiptap-editor code { font-family: 'Courier New', monospace; background: #f4f7fb; border: 1px solid #dde3ec; border-radius: 3px; padding: 1px 4px; font-size: .9em; }
#tiptap-editor pre { background: #f4f7fb; border: 1px solid #dde3ec; border-radius: 6px; padding: 12px 16px; overflow-x: auto; }
#tiptap-editor hr { border: none; border-top: 2px solid #dde3ec; margin: 1em 0; }
#tiptap-editor table { border-collapse: collapse; width: 100%; margin: 1em 0; }
#tiptap-editor td, #tiptap-editor th { border: 1px solid #aaa; padding: 6px 10px; min-width: 60px; vertical-align: top; }
#tiptap-editor th { background: #eef4ff; font-weight: 700; }
#tiptap-editor td.selectedCell, #tiptap-editor th.selectedCell { background: rgba(22,72,166,.08); }
#tiptap-editor img { max-width: 100%; height: auto; display: block; margin: 6px 0; cursor: pointer; border-radius: 2px; }
#tiptap-editor img.ProseMirror-selectednode { outline: 2px solid var(--navy); }
#tiptap-editor mark { padding: 0.06em 0.12em; border-radius: 2px; mix-blend-mode: multiply; }

/* ── Überarbeiten-Bereich (KI) ─────────────────────────────────── */
#revision-section { width: 210mm; margin-top: 20px; flex-shrink: 0; margin-bottom: 20px; }
.revision-label { font-size: 12px; font-weight: 600; color: #6b7a8d; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 10px; }
.revision-inner { display: flex; gap: 10px; align-items: flex-end; background: #fff; border: 1.5px solid #dde3ec; border-radius: 12px; padding: 14px 16px; }
.revision-inner textarea { flex: 1; min-height: 44px; max-height: 120px; }

/* ── Statusleiste ──────────────────────────────────────────────── */
#status-bar {
  display: flex;
  align-items: center;
  padding: 4px 16px;
  background: rgba(22,72,166,.68);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
  gap: 8px;
}
.sb-zoom-btn {
  width: 22px; height: 22px; border: 1.5px solid rgba(255,255,255,.3); border-radius: 4px;
  background: rgba(255,255,255,.1); color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.sb-zoom-btn:hover { background: rgba(255,255,255,.2); }
#zoom-label { color: #fff !important; }
#word-count { color: rgba(255,255,255,.65) !important; }

/* ── Find & Replace / Custom-Margin Modals (leichtgewichtig) ───── */
.we-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 9300; display: none; align-items: center; justify-content: center;
}
.we-modal-box {
  background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 380px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
}
.we-modal-box h3 { font-size: 15px; font-weight: 700; color: var(--navy); margin-bottom: 14px; }
.we-modal-box .form-actions { margin-top: 14px; }

/* ── Drucklayout ─────────────────────────────────────────────── */
@media print {
  /* NICHT „alles ausser #page-outlet" ausblenden: das Blatt liegt drei
     Ebenen tief (body > #app > #main > #page-outlet). Eine Regel auf
     `body > *` traf deshalb auch den Vorfahren des Blattes mit – und
     der Ausdruck blieb leer. Ausgeblendet wird stattdessen benannt,
     was nicht aufs Papier gehört. */
  #modal-overlay, #confirm-overlay, #toast-container,
  #sidebar, #topbar, #app-footer, #sidebar-overlay { display: none !important; }

  /* Die Reiter der Sitzungsvorbereitung. Auf dem Schirm sagen sie, wo
     man ist; auf Papier ist das nicht mehr die Frage. */
  .planer-reiter { display: none !important; }

  /* Und die Höhenbegrenzungen. Der Bildschirmaufbau hält alles in einem
     Fenster: `height: 100vh` und `overflow: hidden` auf body, #app und
     #main, dazu der Editorrahmen als Flexspalte. Beim Drucken heisst
     das: was über die erste Seite hinausragt, ist abgeschnitten – und
     genau eine Seite kam aus dem Drucker. Zum Drucken wird daraus
     gewöhnlicher Fließtext, der so lang werden darf, wie er ist. */
  html, body { height: auto !important; overflow: visible !important; }
  #app, #main { display: block !important; height: auto !important; overflow: visible !important;
                margin: 0 !important; padding: 0 !important; }
  #page-outlet { display: block !important; flex: none !important; height: auto !important;
                 padding: 0 !important; margin: 0 !important; overflow: visible !important; }
  #word-editor-wrap { display: block !important; flex: none !important; height: auto !important;
                      overflow: visible !important; background: none !important;
                      position: static !important; margin: 0 !important; }

  #ribbon, #ruler, #revision-section, #result-loading, #status-bar { display: none !important; }
  #editor-page-area { padding: 0 !important; overflow: visible !important; display: block !important; transform: none !important; background: none !important; }
  #editor-page { width: 100% !important; min-height: auto !important; box-shadow: none !important; padding: 2cm !important; border-radius: 0 !important; }

  /* Eine Abstimmungstabelle, die unten zwei Zeilen anfängt und oben auf
     der nächsten Seite weitergeht, ist nicht mehr zu lesen: die
     Spaltentitel stehen eine Seite vorher. Passt sie ganz, rutscht sie
     als Ganzes auf die nächste Seite; ist sie länger als eine Seite,
     bleibt wenigstens jede einzelne Zeile beisammen. */
  #editor-page table, #editor-page tr { break-inside: avoid; page-break-inside: avoid; }
  /* Und eine Überschrift bleibt nicht allein am Seitenfuß zurück. */
  #editor-page h1, #editor-page h2, #editor-page h3 { break-after: avoid; page-break-after: avoid; }
}

@media (max-width: 900px) {
  #editor-page, #revision-section { width: 100%; }
  #ruler-inner { width: 100%; }
  .rs-font { min-width: 80px; }
}

/* ── Gemeinsam schreiben: wer ist im Text? ─────────────────────
   Die Leiste sitzt zwischen Aktionszeile und Ribbon. Sie muss ohne
   Nachdenken lesbar sein: beim Mitschreiben in einer laufenden
   Sitzung schaut niemand zweimal hin. */
.to-leiste {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid #dde3ec;
  font-size: 13px;
}

.to-verbindung { font-weight: 600; }
.to-verbindung.ist-da  { color: #059669; }
.to-verbindung.ist-weg { color: #b45309; }

.to-leute { display: flex; gap: 6px; flex-wrap: wrap; }

/* Der Name in der Farbe, in der auch der Cursor dieser Person im
   Text steht - sonst lässt sich die Markierung niemandem zuordnen. */
.to-person {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--f, #888);
}

/* Mit Bild wird die Kapsel links bündig aufgezogen, damit das Bild
   den Rand berührt und nicht in einem farbigen Kasten schwimmt. */
.to-person.hat-bild { padding-left: 2px; }

.to-person img {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  /* Ein heller Ring, damit ein dunkles Bild nicht in der Farbe der
     Person verschwindet – sie ist zugleich die Farbe des Cursors. */
  box-shadow: 0 0 0 1.5px rgba(255,255,255,.65);
}

.to-abgeschlossen {
  flex-shrink: 0;
  padding: 8px 16px;
  background: #ecfdf5;
  border-bottom: 1px solid #a7f3d0;
  color: #065f46;
  font-size: 13px;
}

/* ── Die Cursor der anderen im Text ────────────────────────────
   Kommt von @tiptap/extension-collaboration-cursor: ein Strich an
   der Schreibstelle, darüber der Name. Der Name steht nur beim
   Darüberfahren dauerhaft, sonst verdeckt er bei fünf Leuten den
   Text, den man gerade schreibt. */
.collaboration-cursor__caret {
  position: relative;
  margin-left: -1px;
  margin-right: -1px;
  border-left: 1px solid #0d0d0d;
  border-right: 1px solid #0d0d0d;
  word-break: normal;
  pointer-events: none;
}

.collaboration-cursor__label {
  position: absolute;
  top: -1.4em;
  left: -1px;
  border-radius: 3px 3px 3px 0;
  padding: 1px 6px;
  font-size: 11px;
  font-style: normal;
  font-weight: 600;
  line-height: normal;
  color: #fff;
  white-space: nowrap;
  user-select: none;
  opacity: 0;
  transition: opacity .15s;
}

.collaboration-cursor__caret:hover .collaboration-cursor__label { opacity: 1; }

/* Beim Tippen kurz aufblenden, damit man sieht, wo jemand arbeitet. */
.collaboration-cursor__caret .collaboration-cursor__label { animation: to-name-zeigen 2.6s ease forwards; }

@keyframes to-name-zeigen {
  0%, 55% { opacity: 1; }
  100%    { opacity: 0; }
}

@media print {
  .to-leiste, .to-abgeschlossen { display: none !important; }
  .collaboration-cursor__caret  { border: none !important; }
  .collaboration-cursor__label  { display: none !important; }
}
