/* ============================================================
   css/rich.css – Texteditor (RTE) und gerenderte Inhalte (Rich). Editor und Ansicht teilen sich die Regeln für `.rich`.
   Vorlage: docs/mockups/Texteditor-Mockup.html. Nur Tokens aus design.css (Hervorhebungen --hl-*, Hinweise --info/--warning/--success).
   Alte Einträge: <font face/size> und Inline-font-family/font-size erscheinen in der App-Schrift (nur Anzeige, nichts wird umgeschrieben).
   ============================================================ */

/* ---------- Inhalt (Editor und Ansicht) ---------- */
.rich {
  font-size: var(--fs-md);
  line-height: 1.65;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.rich > *:first-child {
  margin-top: 0;
}
.rich > *:last-child {
  margin-bottom: 0;
}
.rich p {
  margin: 0 0 10px;
}
.rich p.t-small {
  font-size: var(--fs-sm);
  color: var(--ink-2);
}
.rich h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: var(--fs-2xl);
  line-height: 1.2;
  margin: 22px 0 8px;
}
.rich h4 {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin: 18px 0 6px;
}
.rich ul,
.rich ol {
  margin: 0 0 12px;
  padding-left: 24px;
}
.rich li {
  margin: 2px 0;
}
.rich a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.rich s,
.rich strike,
.rich del {
  color: var(--ink-3);
}
.rich mark {
  color: inherit;
  border-radius: var(--r-sm);
  padding: 0 2px;
}
.rich mark.hl-gelb {
  background: var(--hl-gelb);
}
.rich mark.hl-gruen {
  background: var(--hl-gruen);
}
.rich mark.hl-blau {
  background: var(--hl-blau);
}
.rich mark.hl-rosa {
  background: var(--hl-rosa);
}
.rich blockquote {
  margin: 14px 0;
  padding: 2px 0 2px 16px;
  border-left: 3px solid var(--a-person);
  font-family: var(--font-serif);
  font-size: var(--fs-xl);
  font-style: italic;
  color: var(--ink-2);
}
.rich hr {
  border: 0;
  border-top: 1px solid var(--border-strong);
  margin: 20px 0;
}
.rich ul.checklist {
  list-style: none;
  padding-left: 2px;
}
.rich ul.checklist li {
  position: relative;
  padding-left: 30px;
}
.rich ul.checklist li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  width: 17px;
  height: 17px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  cursor: pointer;
}
.rich ul.checklist li[data-checked="true"] {
  color: var(--ink-3);
  text-decoration: line-through;
}
.rich ul.checklist li[data-checked="true"]::before {
  background: var(--primary);
  border-color: var(--primary);
}
.rich ul.checklist li[data-checked="true"]::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 8px;
  width: 7px;
  height: 4px;
  border-left: 2px solid var(--on-primary);
  border-bottom: 2px solid var(--on-primary);
  transform: rotate(-45deg);
}
.rich .callout {
  margin: 14px 0;
  padding: 12px 14px 12px 44px;
  border-radius: var(--r-md);
  position: relative;
}
.rich .callout > *:last-child {
  margin-bottom: 0;
}
.rich .callout::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 14px;
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask: var(--m) center / contain no-repeat;
  mask: var(--m) center / contain no-repeat;
}
.rich .callout[data-type="info"] {
  background: var(--info-tint);
  color: var(--info);
  --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E");
}
.rich .callout[data-type="wichtig"] {
  background: var(--warning-tint);
  color: var(--warning);
  --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4M12 17h.01'/%3E%3C/svg%3E");
}
.rich .callout[data-type="erfolg"] {
  background: var(--success-tint);
  color: var(--success);
  --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E");
}
.rich .callout p {
  color: var(--ink);
}
.rich details.fold {
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 14px;
}
.rich details.fold > summary {
  cursor: pointer;
  font-weight: 600;
  padding: 10px 0;
  list-style: none;
  display: flex;
  gap: 8px;
  align-items: center;
}
.rich details.fold > summary::-webkit-details-marker {
  display: none;
}
.rich details.fold > summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--ink-3);
  border-bottom: 2px solid var(--ink-3);
  transform: rotate(-45deg);
  transition: transform 0.15s;
  margin-right: 4px;
}
.rich details.fold[open] > summary::before {
  transform: rotate(45deg);
}
.rich details.fold[open] {
  padding-bottom: 6px;
}
.rich table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: var(--fs-md);
  table-layout: fixed;
}
.rich th,
.rich td {
  border: 1px solid var(--border-strong);
  padding: 7px 10px;
  vertical-align: top;
  text-align: left;
  overflow-wrap: anywhere;
}
.rich th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: var(--fs-sm);
  color: var(--ink-2);
}
.rich td.num,
.rich th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.rich img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-md);
  display: block;
  margin: var(--s2) 0;
}
.rich figure {
  margin: 14px 0;
}
.rich figcaption {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  margin-top: 6px;
}
.rich .richImgMissing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  color: var(--ink-3);
  font-size: var(--fs-sm);
}
/* alte Einträge: freie Schriften und Größen erscheinen in der App-Schrift */
/* design-audit:ignore-start (inherit: gespeicherte Fremdschriften bewusst überschreiben) */
.rich font {
  font-family: inherit;
  font-size: inherit;
}
.rich [style*="font-family"] {
  font-family: inherit !important;
}
.rich [style*="font-size"] {
  font-size: inherit !important;
}
/* design-audit:ignore-end */
/* Ansicht in Listen-Vorschauen: kompakter, kleinere Überschriften */
.rich.compact {
  font-size: var(--fs-sm);
}
.rich.compact h3,
.rich.compact h4 {
  font-size: var(--fs-md);
  font-family: var(--font-ui);
  font-weight: 600;
  margin: 8px 0 4px;
}

/* ---------- Editor ---------- */
.rteBox {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  position: relative;
}
.rteBox:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint);
}
.rteTb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 6px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--r-md) var(--r-md) 0 0;
  position: sticky;
  top: 0;
  z-index: 5;
}
.rteSep {
  width: 1px;
  height: 20px;
  background: var(--border-strong);
  margin: 0 4px;
}
.rteBtn {
  height: 30px;
  min-width: 30px;
  padding: 0 6px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: var(--fs-sm);
  font-weight: 500;
}
.rteBtn:hover {
  background: var(--surface-3);
  color: var(--ink);
}
.rteBtn[aria-pressed="true"] {
  background: var(--primary-tint);
  color: var(--primary);
}
.rteBtn .lc {
  width: 17px;
  height: 17px;
}
.rteBtn .rteChev {
  width: 14px;
  height: 14px;
  opacity: 0.7;
}
.rteBtn.rteStyle {
  min-width: 132px;
  justify-content: space-between;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
}
.rteBtn.rteDanger {
  color: var(--danger);
}
.rteTbar {
  display: none;
  flex-basis: 100%;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.rteTbar.show {
  display: flex;
}
.rteTbar .rteLbl {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  padding: 0 6px 0 4px;
  display: inline-flex;
  gap: 5px;
  align-items: center;
}
.rteEditor {
  min-height: var(--mh, 120px);
  padding: var(--s4);
  overflow-x: auto;
  outline: none;
  border-bottom-left-radius: var(--r-md);
  border-bottom-right-radius: var(--r-md);
}
.rteEditor:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-3);
}
.rteEditor table.active {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.rteEditor td.cur,
.rteEditor th.cur {
  box-shadow: inset 0 0 0 2px var(--primary-tint);
}
.rteEditor.rteDrop {
  background: var(--primary-tint);
}
/* Menüs und Popovers (außerhalb der Dialoge, deshalb fest positioniert) */
.rteMenu {
  position: fixed;
  z-index: 140;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-2);
  padding: 6px;
  min-width: 210px;
  max-width: calc(100vw - 16px);
  display: none;
}
.rteMenu.open {
  display: block;
}
.rteMi {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: left;
  font-size: var(--fs-md);
  color: var(--ink);
}
.rteMi:hover {
  background: var(--surface-2);
}
.rteMi .lc {
  color: var(--ink-3);
}
.rteMi .rteK {
  margin-left: auto;
  font-size: var(--fs-xs);
  color: var(--ink-3);
}
.rteMh {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  font-weight: 500;
  padding: 6px 10px 2px;
}
.rteMdiv {
  height: 1px;
  background: var(--border);
  margin: 5px 4px;
}
.rteSw {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
}
.rteSwb {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  background: var(--c, var(--surface));
}
.rteSwb.none {
  position: relative;
}
.rteSwb.none::after {
  content: "";
  position: absolute;
  inset: 5px 12px;
  background: var(--danger);
  transform: rotate(45deg);
  border-radius: var(--r-sm);
}
.rteGrid {
  display: grid;
  grid-template-columns: repeat(8, 18px);
  gap: 3px;
  padding: 8px;
}
.rteGrid span {
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
}
.rteGrid span.on {
  background: var(--primary-tint);
  border-color: var(--primary);
}
.rteGridLbl {
  padding: 0 8px 6px;
  font-size: var(--fs-sm);
  color: var(--ink-2);
}
.rteLinkPop {
  padding: 8px;
  display: flex;
  gap: 6px;
  min-width: 320px;
}
.rteLinkPop .input {
  height: 32px;
}
@media (max-width: 640px) {
  .rteLinkPop {
    min-width: 0;
    flex-wrap: wrap;
  }
  .rteBtn.rteStyle {
    min-width: 110px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .rich details.fold > summary::before {
    transition: none;
  }
}
