/* Cosmos.Common.AspNetCore.Blazor.RichTextEdit — editor + viewer styles.

   Two consumers:
     1. The Toast UI Editor inside <RichTextEdit> — overrides Toast UI defaults
        so the editor inherits the host application's typography.
     2. The read-only <RichTextView> renderer — mirrors editor typography so the
        view and edit experience are visually identical. */

/* ------------------------------------------------------------------------
   1. Editor — content area inherits host typography
   ------------------------------------------------------------------------ */
.toastui-editor-contents,
.toastui-editor-contents p,
.toastui-editor-contents h1,
.toastui-editor-contents h2,
.toastui-editor-contents h3,
.toastui-editor-contents h4,
.toastui-editor-contents ul,
.toastui-editor-contents ol,
.toastui-editor-contents li,
.toastui-editor-contents blockquote {
  font-family: inherit;
  font-size:   inherit;
  line-height: inherit;
  color:       inherit;
}

.toastui-editor-contents h1 { font-size: 2.00em; }
.toastui-editor-contents h2 { font-size: 1.50em; }
.toastui-editor-contents h3 { font-size: 1.17em; }

.toastui-editor-contents code,
.toastui-editor-contents pre,
.toastui-editor-contents pre code {
  font-family: var(--bs-font-monospace, ui-monospace, "JetBrains Mono",
               Consolas, Menlo, monospace);
  font-size: 0.92em;
}

.toastui-editor-contents img {
  max-width: 100%;
  height: auto;
}

.toastui-editor-md-container .ProseMirror,
.toastui-editor-md-container .CodeMirror {
  font-family: var(--bs-font-monospace, ui-monospace, Consolas, Menlo, monospace);
}

/* Disabled-mode hint. Toast UI 3.x has no first-class disable; we toggle a class
   on the host element and set contenteditable=false on the inner ProseMirror. */
.rich-text-edit-disabled {
  opacity: 0.85;
}
.rich-text-edit-disabled .toastui-editor-toolbar {
  pointer-events: none;
  opacity: 0.5;
}

/* ------------------------------------------------------------------------
   2. RichTextView — read-only renderer used by badges, lists, public views
   ------------------------------------------------------------------------ */
/* SEC-07: stored rich text must not escape its box. `contain: layout paint` makes the
   view the containing block for fixed/absolute descendants and clips painting (incl.
   transforms) to it; `isolation` bounds z-index; `overflow: auto` scrolls wide tables. */
.rich-text-view {
  font-family: inherit;
  font-size:   inherit;
  line-height: inherit;
  color:       inherit;
  contain:     layout paint;
  isolation:   isolate;
  overflow:    auto;
}

.rich-text-view h1 { font-size: 2.00em; }
.rich-text-view h2 { font-size: 1.50em; }
.rich-text-view h3 { font-size: 1.17em; }
.rich-text-view p  { margin: 0 0 0.5rem 0; }
.rich-text-view ul,
.rich-text-view ol { margin: 0 0 0.5rem 1.25rem; padding: 0; }

.rich-text-view code,
.rich-text-view pre,
.rich-text-view pre code {
  font-family: var(--bs-font-monospace, ui-monospace, "JetBrains Mono",
               Consolas, Menlo, monospace);
  font-size: 0.92em;
}

.rich-text-view img { max-width: 100%; height: auto; }

.rich-text-view table { border-collapse: collapse; margin: 0 0 0.5rem 0; }
.rich-text-view table td,
.rich-text-view table th {
  border: 1px solid var(--cosmos-border);
  padding: 0.25rem 0.5rem;
}

/* ---------------------------------------------------------------------------
   3. Editor CHROME -- theme it from the canonical tokens.

   Toast UI ships its own stylesheet from a CDN, which knows nothing about Cosmos
   tokens, so without this block the editor stays a light-mode panel inside a dark
   dialog. Rather than loading Toast UI's own dark theme (a second CDN file, and its
   greys are not ours), the chrome is repainted from the canonical slots so it tracks
   all three themes automatically -- including a fourth, added later.
   --------------------------------------------------------------------------- */

.toastui-editor-defaultUI {
  border: 1px solid var(--cosmos-border) !important;
  border-radius: var(--cosmos-radius-sm) !important;
  background: var(--cosmos-surface) !important;
}

.toastui-editor-defaultUI-toolbar {
  background: var(--cosmos-canvas) !important;
  border-bottom: 1px solid var(--cosmos-border) !important;
}

.toastui-editor-toolbar-divider {
  background-color: var(--cosmos-border-strong) !important;
}

.toastui-editor-main,
.toastui-editor-md-container,
.toastui-editor-ww-container,
.toastui-editor-md-preview {
  background: var(--cosmos-surface) !important;
  color: var(--cosmos-fg) !important;
}

.toastui-editor-md-splitter {
  background-color: var(--cosmos-border) !important;
}

/* Bottom Markdown/WYSIWYG switch */
.toastui-editor-mode-switch {
  background: var(--cosmos-canvas) !important;
  border-top: 1px solid var(--cosmos-border) !important;
}
.toastui-editor-mode-switch .tab-item {
  background: var(--cosmos-canvas) !important;
  border-color: var(--cosmos-border) !important;
  color: var(--cosmos-fg-muted) !important;
}
.toastui-editor-mode-switch .tab-item.active {
  background: var(--cosmos-surface) !important;
  color: var(--cosmos-fg) !important;
}

/* Popups (heading picker, link/table dialogs) */
.toastui-editor-popup,
.toastui-editor-popup-body,
.toastui-editor-context-menu {
  background: var(--cosmos-surface-raised) !important;
  border: 1px solid var(--cosmos-border) !important;
  color: var(--cosmos-fg) !important;
}

.toastui-editor-contents {
  background: var(--cosmos-surface) !important;
}
.toastui-editor-contents table td,
.toastui-editor-contents table th {
  border-color: var(--cosmos-border) !important;
}
.toastui-editor-contents blockquote {
  border-left-color: var(--cosmos-border-strong) !important;
  color: var(--cosmos-fg-muted) !important;
}

/* Toolbar icons are CSS SPRITES, not fonts -- they cannot be recoloured with a token.
   On a dark toolbar the dark glyphs would vanish, so invert them, the same trick the
   DataGrid already uses for its select chevron. Gated on data-bs-theme, which the theme
   boot script derives from the active theme's mode. */
[data-bs-theme="dark"] .toastui-editor-defaultUI-toolbar .toastui-editor-toolbar-icons {
  filter: invert(1) brightness(1.6);
}
