/* cin_markdown_editor */
/* markdown-editor.css */
/*
 * Markdown editor (cin_markdown_editor).
 * This file is part of the global extension CSS bundle, so every rule is
 * scoped to .md-* classes. Colours use the CRM tokens (--cin-*) with
 * Bootstrap fallbacks; the document "paper" stays light in both themes,
 * because it previews the printed PDF.
 */

.md-app {
  --md-tree-width: 260px;
  --md-notes-width: 330px;
  --md-surface: var(--cin-surface, var(--bs-body-bg));
  --md-surface-2: var(--cin-bg-secondary, var(--bs-secondary-bg));
  --md-hover: var(--cin-surface-hover, var(--bs-tertiary-bg));
  --md-accent-soft: var(--cin-accent-soft, rgba(var(--bs-primary-rgb), .12));
  --md-border: var(--cin-border, var(--bs-border-color));
  background: var(--cin-background, var(--bs-body-bg));
  position: relative;
}

.md-app .border-bottom,
.md-app .border-end,
.md-app .border-start,
.md-app .border-top {
  border-color: var(--md-border) !important;
}

/* ---------------------------------------------------------------- top bar */

.md-topbar {
  background: var(--md-surface);
  min-height: 3.25rem;
}

.md-topbar.md-no-page .md-page-only {
  display: none !important;
}

.md-title-input {
  max-width: 28rem;
  min-width: 10rem;
  flex: 1 1 14rem;
  font-weight: 600;
  font-size: 1rem;
  border-color: transparent;
  background: transparent;
}

.md-title-input:hover:not([readonly]) {
  border-color: var(--md-border);
}

.md-title-input:focus {
  background: var(--bs-body-bg);
}

.md-page-icon {
  font-size: 1.25rem;
  line-height: 1;
  padding: .15rem .35rem;
}

.md-page-icon:hover {
  background: var(--md-hover);
}

/* ---------------------------------------------------------------- presence */

.md-presence {
  padding-left: 6px;
}

.md-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 30px;
  height: 30px;
  margin-left: -6px;
  border: 2px solid var(--md-surface);
  border-radius: 50%;
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: default;
}

.md-avatar.is-self {
  opacity: .75;
}

.md-avatar.is-typing {
  box-shadow: 0 0 0 2px var(--bs-success);
  animation: md-pulse 1.4s ease-in-out infinite;
}

.md-avatar-sm {
  width: 22px;
  height: 22px;
  margin-left: 0;
  border: 0;
  font-size: .6rem;
}

@keyframes md-pulse {
  50% { box-shadow: 0 0 0 4px rgba(var(--bs-success-rgb), .35); }
}

/* ---------------------------------------------------------------- layout */

.md-body {
  position: relative;
}

.md-tree-pane {
  width: var(--md-tree-width);
  flex: 0 0 var(--md-tree-width);
  background: var(--md-surface);
}

.md-editor-pane {
  flex: 1 1 0;
  background: var(--md-surface);
}

.md-preview-pane {
  flex: 1 1 0;
  position: relative;
  padding: 1.5rem;
  background: var(--md-surface-2);
}

.md-notes-pane {
  width: var(--md-notes-width);
  flex: 0 0 var(--md-notes-width);
  background: var(--md-surface);
}

.md-app[data-view-mode="editor"] .md-preview-pane,
.md-app[data-view-mode="preview"] .md-editor-pane {
  display: none !important;
}

.md-body.md-no-page .md-editor-pane,
.md-body.md-no-page .md-preview-pane,
.md-body.md-no-page .md-notes-pane {
  display: none !important;
}

/* ---------------------------------------------------------------- tree */

.md-tree li {
  position: relative;
}

.md-tree-item {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .4rem .3rem calc(var(--md-depth, 0) * 14px + .2rem);
  border-radius: .4rem;
  cursor: pointer;
  user-select: none;
  font-size: .9rem;
}

.md-tree-item:hover {
  background: var(--md-hover);
}

.md-tree-item.active {
  background: var(--md-accent-soft);
  color: var(--bs-primary);
  font-weight: 600;
}

.md-tree-caret,
.md-tree-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 1.2rem;
  height: 1.2rem;
  padding: 0;
  border: 0;
  border-radius: .25rem;
  background: transparent;
  color: var(--bs-secondary-color);
  font-size: .75rem;
}

.md-tree-caret:hover,
.md-tree-add:hover {
  background: var(--md-border);
}

.md-tree-add {
  margin-left: auto;
  visibility: hidden;
  font-size: 1rem;
}

.md-tree-item:hover .md-tree-add {
  visibility: visible;
}

.md-tree-icon {
  flex: none;
  width: 1.3rem;
  text-align: center;
}

.md-tree-title {
  flex: 1 1 auto;
  min-width: 0;
}

.md-dot {
  flex: none;
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  background: var(--bs-warning);
}

.md-drop-inside {
  outline: 2px dashed var(--bs-primary);
  outline-offset: -2px;
}

.md-drop-before {
  box-shadow: inset 0 2px 0 var(--bs-primary);
}

.md-drop-after {
  box-shadow: inset 0 -2px 0 var(--bs-primary);
}

/* ---------------------------------------------------------------- editor */

.md-toolbar {
  background: var(--md-surface);
}

.md-tool {
  border: 0 !important;
  background: transparent;
  color: var(--bs-body-color);
  padding: .25rem .45rem;
}

.md-tool:hover,
.md-tool:focus-visible {
  background: var(--md-hover);
  color: var(--bs-body-color);
}

.md-tool.active {
  background: var(--md-accent-soft);
  color: var(--bs-primary);
}

.md-toolbar.md-disabled > .btn-group:not(.md-keep) {
  opacity: .45;
  pointer-events: none;
}

.md-app .nav-tabs .nav-link.md-has-content::after {
  content: "";
  display: inline-block;
  width: .4rem;
  height: .4rem;
  margin-left: .35rem;
  border-radius: 50%;
  background: var(--bs-success);
  vertical-align: middle;
}

.md-source {
  resize: none;
  padding: 1rem 1.25rem 3rem;
  font-family: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  font-size: .9rem;
  line-height: 1.65;
  font-variant-ligatures: none;
  tab-size: 2;
  background: var(--md-surface);
  box-shadow: none !important;
}

.md-source[readonly] {
  background: var(--md-surface-2);
}

.md-drop-hint {
  position: absolute;
  inset: .75rem;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border: 2px dashed var(--bs-primary);
  border-radius: .75rem;
  background: rgba(var(--bs-primary-rgb), .08);
  color: var(--bs-primary);
  font-weight: 600;
  pointer-events: none;
}

.md-drop-hint.d-none {
  display: none !important;
}

.md-statusbar {
  background: var(--md-surface);
  white-space: nowrap;
}

.md-statusbar > :last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------------------------------------------- pickers */

.md-emoji-menu {
  width: 340px;
  max-width: calc(100vw - 2rem);
}

.md-emoji-tabs .md-emoji-tab {
  flex: 1;
  padding: .2rem 0;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 1.05rem;
}

.md-emoji-tabs .md-emoji-tab.active {
  border-bottom-color: var(--bs-primary);
}

.md-emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
}

.md-emoji {
  height: 36px;
  border: 0;
  border-radius: .35rem;
  background: transparent;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--bs-body-color);
}

.md-emoji:hover {
  background: var(--md-hover);
}

.md-color-menu {
  width: 290px;
}

.md-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}

.md-swatch {
  width: 1.9rem;
  height: 1.9rem;
  border: 1px solid var(--md-border);
  border-radius: .35rem;
  background: #fff;
  font-weight: 700;
}

.md-swatch:hover {
  outline: 2px solid var(--bs-primary);
  outline-offset: 1px;
}

.md-swatch span {
  text-decoration: underline 3px;
  text-underline-offset: 2px;
}

/* ---------------------------------------------------------------- paper */

.md-paper {
  position: relative;
  max-width: 210mm;
  min-height: calc(100% - 1rem);
  margin: 0 auto;
  padding: 16mm 18mm;
  border-radius: .25rem;
  background: #fff;
  color: #1f2328;
  color-scheme: light;
  box-shadow: var(--cin-shadow-md, 0 4px 16px rgba(16, 24, 40, .1));
}

.md-paper-header,
.md-paper-footer {
  position: relative;
  font-size: .8rem;
  color: #444;
}

.md-paper-header {
  margin-bottom: 1.25rem;
  padding-bottom: .6rem;
  border-bottom: 1px dashed #c3cad6;
}

.md-paper-footer {
  margin-top: 1.75rem;
  padding-top: .6rem;
  border-top: 1px dashed #c3cad6;
}

.md-paper-header::before,
.md-paper-footer::before {
  content: attr(data-label);
  position: absolute;
  right: 0;
  padding: 0 .4rem;
  border-radius: .25rem;
  background: #eef2f8;
  color: #6b7686;
  font-size: .6rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.md-paper-header::before {
  bottom: -.55rem;
}

.md-paper-footer::before {
  top: -.55rem;
}

.md-note-float {
  position: absolute;
  z-index: 6;
}

/* ---------------------------------------------------------------- rendered Markdown */

.md-content {
  color: #1f2328;
  font-size: .95rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.md-content > :first-child {
  margin-top: 0 !important;
}

.md-content > :last-child {
  margin-bottom: 0 !important;
}

.md-content h1,
.md-content h2,
.md-content h3,
.md-content h4 {
  margin: 1.4em 0 .5em;
  color: #111827;
  font-weight: 650;
  line-height: 1.25;
}

.md-content h1 {
  padding-bottom: .25em;
  border-bottom: 2px solid #e5e9f0;
  font-size: 1.85em;
}

.md-content h2 {
  padding-bottom: .2em;
  border-bottom: 1px solid #edf0f5;
  font-size: 1.4em;
}

.md-content h3 {
  font-size: 1.18em;
}

.md-content p,
.md-content ul,
.md-content ol,
.md-content table,
.md-content pre,
.md-content blockquote {
  margin: 0 0 .9em;
}

.md-content ul,
.md-content ol {
  padding-left: 1.6em;
}

.md-content li + li {
  margin-top: .2em;
}

.md-content li:has(> input[type="checkbox"]) {
  margin-left: -1.4em;
  list-style: none;
}

.md-content input[type="checkbox"] {
  margin: 0 .45em 0 0;
  vertical-align: -1px;
}

.md-content a {
  color: #1d4ed8;
}

.md-content hr {
  margin: 1.5em 0;
  border: 0;
  border-top: 2px solid #e5e9f0;
  opacity: 1;
}

.md-content img {
  max-width: 100%;
  height: auto;
  border-radius: .25rem;
}

.md-content img.md-missing {
  display: inline-block;
  padding: .4rem .7rem;
  border: 1px dashed #c62828;
  color: #c62828;
  font-size: .8rem;
}

.md-content mark {
  padding: 0 .15em;
  border-radius: .2rem;
  background: #fff59d;
  color: inherit;
}

.md-content code {
  padding: .15em .4em;
  border-radius: .25rem;
  background: #f0f2f6;
  color: #24292f;
  font-size: .86em;
}

.md-content pre {
  padding: .85rem 1rem;
  overflow: auto;
  border: 1px solid #e5e9f0;
  border-radius: .4rem;
  background: #f6f8fa;
  line-height: 1.5;
}

.md-content pre code {
  padding: 0;
  background: none;
  white-space: pre-wrap;
}

.md-content pre code.hljs {
  padding: 0;
  background: none;
}

.md-content blockquote {
  padding: .35em 1em;
  border-left: 4px solid #cfd6e2;
  color: #4b5563;
}

.md-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: .93em;
}

.md-content th,
.md-content td {
  padding: .4rem .65rem;
  border: 1px solid #dfe3ea;
  text-align: left;
  vertical-align: top;
}

.md-content th {
  background: #f3f5f9;
  font-weight: 650;
}

.md-content thead:not(:has(th:not(:empty))) {
  display: none;
}

.md-content .callout {
  padding: .6em 1em;
  border-left-width: 4px;
  border-radius: 0 .4rem .4rem 0;
  color: #1f2328;
}

.md-content .callout > :last-child {
  margin-bottom: 0;
}

.md-content .callout-title {
  margin-bottom: .25em;
  font-weight: 650;
}

.md-content .callout-note { border-color: #1565c0; background: #e8f1fd; }
.md-content .callout-note .callout-title { color: #1565c0; }
.md-content .callout-tip { border-color: #2e7d32; background: #e9f6ea; }
.md-content .callout-tip .callout-title { color: #2e7d32; }
.md-content .callout-important { border-color: #6a1b9a; background: #f4eafa; }
.md-content .callout-important .callout-title { color: #6a1b9a; }
.md-content .callout-warning { border-color: #ef6c00; background: #fff3e2; }
.md-content .callout-warning .callout-title { color: #b45309; }
.md-content .callout-caution { border-color: #c62828; background: #fdecec; }
.md-content .callout-caution .callout-title { color: #c62828; }

.md-content .attachment-link {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .05rem .55rem;
  border: 1px solid #cdd7e6;
  border-radius: .35rem;
  background: #f3f6fb;
  color: #1f3a6b;
  text-decoration: none;
}

.md-content .attachment-link:hover {
  background: #e6edf8;
}

.md-content .cols {
  display: flex;
  gap: 1.25rem;
  margin-bottom: .9em;
}

.md-content .cols > * {
  flex: 1;
  min-width: 0;
}

.md-content .cols > * > :last-child {
  margin-bottom: 0;
}

.md-content .right { text-align: right; }
.md-content .center { text-align: center; }
.md-content .small { font-size: .82em; line-height: 1.45; }

.md-content .letterhead h2 {
  margin: 0 0 .1em;
  padding: 0;
  border: 0;
}

.md-content .sender-line {
  display: inline-block;
  margin-bottom: .6em;
  border-bottom: 1px solid #9aa3b0;
  color: #555;
  font-size: .72em;
}

.md-content .page-break {
  position: relative;
  height: 0;
  margin: 1.6em -18mm;
  border-top: 2px dashed #c3cad6;
}

.md-content .page-break::after {
  content: "Seitenumbruch";
  position: absolute;
  top: -.6rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 .5rem;
  background: #fff;
  color: #8a94a3;
  font-size: .65rem;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.md-content .md-placeholder {
  padding: 0 .3rem;
  border-radius: .25rem;
  background: #e8eefb;
  color: #2563eb;
  font-size: .9em;
  font-weight: 600;
}

.md-content mark.md-note-anchor {
  padding: 0;
  border-bottom: 2px solid #f2b705;
  border-radius: 0;
  background: rgba(255, 213, 79, .35);
  cursor: pointer;
  transition: background-color .2s;
}

.md-content mark.md-note-anchor.is-resolved {
  border-bottom-color: #c8ccd3;
  background: rgba(200, 204, 211, .25);
}

.md-content mark.md-note-anchor.is-hover,
.md-content mark.md-note-anchor.is-flash {
  background: rgba(255, 193, 7, .7);
}

.md-dms-preview {
  max-height: calc(100vh - 22rem);
  overflow: auto;
  padding: .75rem 1rem;
  border-radius: .35rem;
  background: #fff;
  color-scheme: light;
}

.md-version-preview {
  max-height: 60vh;
  overflow: auto;
  background: #fff;
  color-scheme: light;
}

/* ---------------------------------------------------------------- notes */

.md-note-card {
  border-color: var(--md-border);
  transition: box-shadow .2s;
}

.md-note-card.is-resolved {
  opacity: .7;
}

.md-note-card.md-flash {
  box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), .35);
}

.md-note-quote {
  display: block;
  margin-bottom: .5rem;
  padding: .25rem .5rem;
  border: 0;
  border-left: 3px solid #f2b705;
  border-radius: 0 .25rem .25rem 0;
  background: rgba(255, 213, 79, .15);
  color: var(--bs-secondary-color);
  font-size: .8rem;
  font-style: italic;
}

.md-note-text {
  font-size: .875rem;
  white-space: normal;
  word-break: break-word;
}

.md-note-reply {
  margin-left: .6rem;
  padding-left: .6rem;
  border-left: 2px solid var(--md-border);
}

.md-mention {
  color: var(--bs-primary);
  font-weight: 600;
}

.md-mention.is-self {
  padding: 0 .2rem;
  border-radius: .25rem;
  background: var(--md-accent-soft);
}

.md-composer-quote {
  padding: .25rem .5rem;
  border-left: 3px solid #f2b705;
  background: rgba(255, 213, 79, .15);
  font-style: italic;
}

.md-mention-menu {
  top: auto;
  bottom: 100%;
  width: 100%;
  max-height: 260px;
  overflow-y: auto;
}

.md-mentions-menu {
  width: 340px;
}

.md-mentions-list {
  max-height: 360px;
  overflow-y: auto;
}

.md-template-option {
  white-space: normal;
}

/* ---------------------------------------------------------------- visual editor (Tiptap) */

.md-app[data-editor-mode="visual"] .md-preview-pane,
.md-app[data-editor-mode="visual"] .md-view-switch {
  display: none !important;
}

.md-app[data-editor-mode="visual"][data-view-mode="preview"] .md-editor-pane {
  display: flex !important;
}

.md-app[data-editor-mode="visual"] .md-editor-pane {
  border-right: 0 !important;
}

.md-visual-scroll {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 1.5rem;
  background: var(--md-surface-2);
}

.md-visual-scroll.d-none {
  display: none !important;
}

.md-visual-paper {
  min-height: calc(100% - 1rem);
  cursor: text;
}

.md-visual-content {
  min-height: 60vh;
  outline: none;
}

.md-visual-content p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  color: #9aa3b0;
  pointer-events: none;
}

.md-visual-content ul[data-type="taskList"] {
  padding-left: .2em;
  list-style: none;
}

.md-visual-content ul[data-type="taskList"] > li {
  display: flex;
  gap: .5em;
  margin-left: 0;
}

.md-visual-content ul[data-type="taskList"] > li > label {
  flex: none;
  margin-top: .1em;
  user-select: none;
}

.md-visual-content ul[data-type="taskList"] > li > div {
  flex: 1 1 auto;
  min-width: 0;
}

.md-visual-content ul[data-type="taskList"] > li > div > p {
  margin-bottom: .2em;
}

.md-visual-content ul[data-type="taskList"] > li[data-checked="true"] > div {
  color: #6b7686;
  text-decoration: line-through;
}

.md-visual-content blockquote.callout::before {
  content: attr(data-title);
  display: block;
  margin-bottom: .25em;
  font-weight: 650;
}

.md-visual-content .callout-note::before { color: #1565c0; }
.md-visual-content .callout-tip::before { color: #2e7d32; }
.md-visual-content .callout-important::before { color: #6a1b9a; }
.md-visual-content .callout-warning::before { color: #b45309; }
.md-visual-content .callout-caution::before { color: #c62828; }

.md-visual-content table {
  table-layout: fixed;
}

.md-visual-content th > p,
.md-visual-content td > p {
  margin: 0;
}

.md-visual-content li > p {
  margin-bottom: .2em;
}

.md-visual-content td,
.md-visual-content th {
  position: relative;
}

.md-visual-content .selectedCell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(37, 99, 235, .12);
  pointer-events: none;
}

.md-visual-content img.ProseMirror-selectednode,
.md-visual-content .md-html-block.ProseMirror-selectednode,
.md-visual-content .page-break.ProseMirror-selectednode {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.md-visual-content .page-break {
  margin-top: 1.6em;
  margin-bottom: 1.6em;
}

.md-html-block {
  position: relative;
  margin: 0 0 .9em;
  padding: .6rem .75rem;
  border: 1px dashed #c3cad6;
  border-radius: .35rem;
  background: #fbfcfe;
  cursor: default;
}

.md-html-block:hover {
  border-color: #2563eb;
}

.md-html-block > div > :last-child {
  margin-bottom: 0;
}

.md-html-badge {
  position: absolute;
  top: -.7rem;
  right: .5rem;
  padding: 0 .45rem;
  border: 1px solid #c3cad6;
  border-radius: .25rem;
  background: #fff;
  color: #6b7686;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity .15s;
}

.md-html-block:hover .md-html-badge,
.md-html-block.ProseMirror-selectednode .md-html-badge {
  opacity: 1;
}

.md-visual-content .ProseMirror-gapcursor::after {
  border-top-color: #1f2328;
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1399.98px) {
  .md-app {
    --md-tree-width: 220px;
    --md-notes-width: 290px;
  }
}

@media (max-width: 991.98px) {
  .md-tree-pane,
  .md-notes-pane {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 20;
    box-shadow: var(--cin-shadow-lg, 0 12px 40px rgba(16, 24, 40, .22));
  }

  .md-tree-pane {
    left: 0;
  }

  .md-notes-pane {
    right: 0;
    max-width: 100%;
  }

  .md-app[data-view-mode="split"] .md-preview-pane {
    display: none !important;
  }

  .md-preview-pane {
    padding: .75rem;
  }

  .md-paper {
    padding: 1.25rem 1rem;
  }

  .md-content .page-break {
    margin-right: -1rem;
    margin-left: -1rem;
  }

  .md-content .cols {
    flex-direction: column;
  }
}

