@layer components {

/* stylelint-disable selector-class-pattern -- TipTap/ProseMirror third-party class names */

/* ============================================
   TipTap Rich Text Editor Styles [MC-171]
   ============================================ */

/* --- Editor Container --- */

.tiptap-editor-wrapper {
  --_editor-code-color: var(--color-error-700);
  --_editor-blockquote-bg: var(--color-bg-accent);
  --_editor-selected-cell-bg: color-mix(in srgb, var(--color-primary-100) 50%, transparent);

  position: relative;
}

/* --- Editable Editor Border --- */

.tiptap-editor-wrapper--editable {
  border: 1px solid var(--color-border-secondary);
  border-radius: 8px;
  transition: border-color 0.15s ease;
}

.tiptap-editor-wrapper--editable:focus-within {
  border-color: var(--color-primary-500);
}

/* --- Typography & Base Styles (mirrors .markdown-content) --- */

.tiptap-editor-wrapper .ProseMirror {
  /* Base styles */
  outline: none;
  overflow-wrap: break-word;
  min-block-size: 80px;
  padding: var(--space-3);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--color-text-emphasis);
}

/* When editor is followed by attachment upload, flatten bottom corners */
.comment-form-redesign .tiptap-editor-wrapper--editable {
  border-radius: 8px 8px 0 0;
}

.tiptap-editor-wrapper .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: inline-start;
  color: var(--color-text-muted);
  pointer-events: none;
  block-size: 0;
}

.tiptap-editor-wrapper .ProseMirror h1 {
  font-size: var(--text-2xl);
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0 0 var(--space-4);
  padding-block-end: var(--space-2);
  border-block-end: 1px solid var(--color-border-primary);
  line-height: var(--leading-tight);
}

  .tiptap-editor-wrapper .ProseMirror h1:first-child {
    margin-block-start: 0;
  }

.tiptap-editor-wrapper .ProseMirror h2 {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text-emphasis);
  margin: var(--space-6) 0 var(--space-3);
  line-height: var(--leading-tight);
}

  .tiptap-editor-wrapper .ProseMirror h2:first-child {
    margin-block-start: 0;
  }

.tiptap-editor-wrapper .ProseMirror h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text-emphasis);
  margin: var(--space-5) 0 var(--space-2);
  line-height: var(--leading-snug);
}

.tiptap-editor-wrapper .ProseMirror h4 {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text-emphasis);
  margin: var(--space-4) 0 var(--space-2);
  line-height: var(--leading-snug);
}

  .tiptap-editor-wrapper .ProseMirror h4:first-child {
    margin-block-start: 0;
  }

.tiptap-editor-wrapper .ProseMirror h5,
.tiptap-editor-wrapper .ProseMirror h6 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-strong);
  margin: var(--space-3) 0 var(--space-2);
  line-height: var(--leading-normal);
}

  .tiptap-editor-wrapper .ProseMirror h5:first-child,
  .tiptap-editor-wrapper .ProseMirror h6:first-child {
    margin-block-start: 0;
  }

/* Paragraphs */
  .tiptap-editor-wrapper .ProseMirror p {
    margin: 0 0 var(--space-4);
    line-height: var(--leading-relaxed);
  }

    .tiptap-editor-wrapper .ProseMirror p:last-child {
      margin-block-end: 0;
    }

  /* Lists */
  .tiptap-editor-wrapper .ProseMirror ul,
  .tiptap-editor-wrapper .ProseMirror ol {
    margin: 0 0 var(--space-4);
    padding-inline-start: var(--space-6);
  }

  .tiptap-editor-wrapper .ProseMirror ul {
    list-style-type: disc;
  }

    .tiptap-editor-wrapper .ProseMirror ul ul {
      list-style-type: circle;
    }

      .tiptap-editor-wrapper .ProseMirror ul ul ul {
        list-style-type: square;
      }

  .tiptap-editor-wrapper .ProseMirror ol {
    list-style-type: decimal;
  }

  .tiptap-editor-wrapper .ProseMirror li {
    margin-block-end: var(--space-1);
    line-height: var(--leading-relaxed);

    /* Remove paragraph bottom margin when followed by a nested sublist.
       ProseMirror wraps list item text in <p>, and the :last-child selector
       on p doesn't apply when a <ul>/<ol> sibling follows. */
  }

    .tiptap-editor-wrapper .ProseMirror li:last-child {
      margin-block-end: 0;
    }

    /* stylelint-disable-next-line no-descending-specificity */
    .tiptap-editor-wrapper .ProseMirror li > ul,
    .tiptap-editor-wrapper .ProseMirror li > ol {
      margin-block-start: 0;
      margin-block-end: 0;
    }

    /* stylelint-disable no-descending-specificity -- nested list paragraph spacing */
    .tiptap-editor-wrapper .ProseMirror li > p:has(+ ul),
    .tiptap-editor-wrapper .ProseMirror li > p:has(+ ol) {
    /* stylelint-enable no-descending-specificity */
      margin-block-end: 0;
    }

/* Task Lists */

.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] {
  list-style: none;
  padding-inline-start: 0;
}

  .tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin-block-end: var(--space-1);
  }

    .tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li:last-child {
      margin-block-end: 0;
    }

.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li > label {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  block-size: calc(var(--text-sm) * var(--leading-relaxed));
}

  .tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li > label input[type="checkbox"] {
    appearance: none;
    inline-size: 16px;
    block-size: 16px;
    min-inline-size: 16px;
    border: 1.5px solid var(--color-border-secondary);
    border-radius: 3px;
    background: var(--color-white);
    cursor: pointer;
    position: relative;
  }

    .tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li > label input[type="checkbox"]:checked {
      background: var(--color-primary-500);
      border-color: var(--color-primary-500);
    }

    .tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li > label input[type="checkbox"]:checked::after {
      content: "";
      position: absolute;
      left: 4px;
      inset-block-start: 1px;
      inline-size: 5px;
      block-size: 9px;
      border: solid white;
      border-width: 0 2px 2px 0;
      transform: rotate(45deg);
    }

.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li[data-checked="true"] > div > p {
  text-decoration: line-through;
  color: var(--color-text-muted);
}

.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li > div {
  flex: 1;
  min-inline-size: 0;
}

/* Inline Code */
.tiptap-editor-wrapper .ProseMirror code {
  font-family: var(--font-family-mono);
  font-size: 0.9em;
  background: var(--color-bg-tertiary);
  color: var(--_editor-code-color);
  padding: var(--space-0-5) var(--space-1);
  border-radius: 4px;
  border: 1px solid var(--color-border-primary);
}

/* Code Blocks */
.tiptap-editor-wrapper .ProseMirror pre {
  margin: 0 0 var(--space-4);
  padding: var(--space-4);
  background: var(--color-bg-inverse);
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid var(--color-neutral-700);
}

.tiptap-editor-wrapper .ProseMirror pre code {
  background: none;
  color: inherit;
  padding: 0;
  border: none;
  border-radius: 0;
  font-family: var(--font-family-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  display: block;
  white-space: pre;
}

/* Blockquotes */
.tiptap-editor-wrapper .ProseMirror blockquote {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  /* Physical: paired with physical border-radius shorthand */
  border-left: 4px solid var(--color-primary-400);
  background: var(--_editor-blockquote-bg);
  border-radius: 0 8px 8px 0;
  color: var(--color-text-strong);
}

/* stylelint-disable-next-line no-descending-specificity */
.tiptap-editor-wrapper .ProseMirror blockquote p {
  margin: 0;
}

/* stylelint-disable-next-line no-descending-specificity */
.tiptap-editor-wrapper .ProseMirror blockquote p + p {
  margin-block-start: var(--space-3);
}

/* Links */
.tiptap-editor-wrapper .ProseMirror a {
  color: var(--color-text-accent-bright);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.tiptap-editor-wrapper .ProseMirror a:hover {
  color: var(--color-text-accent);
}

/* Emphasis */
.tiptap-editor-wrapper .ProseMirror strong,
.tiptap-editor-wrapper .ProseMirror b {
  font-weight: 600;
  color: var(--color-text-emphasis);
}

.tiptap-editor-wrapper .ProseMirror del,
.tiptap-editor-wrapper .ProseMirror s {
  text-decoration: line-through;
  color: var(--color-text-tertiary);
}

/* Horizontal Rule */
.tiptap-editor-wrapper .ProseMirror hr {
  margin: var(--space-6) 0;
  border: none;
  border-block-start: 1px solid var(--color-border-primary);
}

/* Tables */
.tiptap-editor-wrapper .ProseMirror table {
  inline-size: 100%;
  margin: 0 0 var(--space-4);
  border-collapse: collapse;
  font-size: var(--text-sm);
  border: 1px solid var(--color-border-primary);
  border-radius: 8px;
  overflow: hidden;
}

.tiptap-editor-wrapper .ProseMirror th {
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  text-align: start;
  color: var(--color-text-emphasis);
  background: var(--color-bg-tertiary);
  border-block-end: 2px solid var(--color-border-primary);
  border-inline-end: 1px solid var(--color-border-primary);
}

.tiptap-editor-wrapper .ProseMirror th:last-child {
  border-inline-end: none;
}

.tiptap-editor-wrapper .ProseMirror td {
  padding: var(--space-3) var(--space-4);
  border-block-end: 1px solid var(--color-border-primary);
  border-inline-end: 1px solid var(--color-border-primary);
  color: var(--color-text-strong);
}

.tiptap-editor-wrapper .ProseMirror td:last-child {
  border-inline-end: none;
}

.tiptap-editor-wrapper .ProseMirror tr:last-child td {
  border-block-end: none;
}

/* Selected table cell */
.tiptap-editor-wrapper .ProseMirror .selectedCell {
  background: var(--_editor-selected-cell-bg);
}

/* --- Bubble Menu --- */

.tiptap-bubble-menu {
  display: none;
  align-items: center;
  gap: 2px;
  padding: var(--space-1);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
}

  /* Show the bubble menu only when TipTap's BubbleMenu extension sets visibility */
  .tiptap-bubble-menu[style*="visibility: visible"] {
    display: flex;
  }

.tiptap-bubble-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: 32px;
  block-size: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background 0.1s ease, color 0.1s ease;
}

.tiptap-bubble-btn:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-emphasis);
}

/* Reset <code> styling inside bubble menu buttons so it doesn't inherit editor code styles */
/* stylelint-disable-next-line no-descending-specificity */
.tiptap-bubble-btn code {
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
  font-family: inherit;
  border-radius: 0;
}

.tiptap-bubble-btn--active {
  --_bubble-active-bg: var(--color-bg-accent-hover);
  --_bubble-active-color: var(--color-text-accent);
  --_bubble-active-bg-hover: var(--color-bg-accent-active);

  background: var(--_bubble-active-bg);
  color: var(--_bubble-active-color);
}

.tiptap-bubble-btn--active:hover {
  background: var(--_bubble-active-bg-hover);
}

.tiptap-bubble-btn:focus-visible {
  outline: 2px solid var(--color-primary-400);
  outline-offset: -2px;
}

.tiptap-bubble-divider {
  inline-size: 1px;
  block-size: 20px;
  background: var(--color-bg-subtle);
  margin: 0 2px;
}

/* --- Slash Command Menu --- */

.tiptap-slash-menu {
  position: fixed;
  z-index: 9999;
  min-inline-size: 200px;
  max-block-size: 300px;
  overflow-y: auto;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-secondary) transparent;
}

  .tiptap-slash-menu::-webkit-scrollbar {
    inline-size: 6px;
  }

  .tiptap-slash-menu::-webkit-scrollbar-track {
    background: transparent;
  }

  .tiptap-slash-menu::-webkit-scrollbar-thumb {
    background: var(--color-border-secondary);
    border-radius: 3px;
  }

    .tiptap-slash-menu::-webkit-scrollbar-thumb:hover {
      background: var(--color-border-muted);
    }

.tiptap-slash-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  inline-size: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-strong);
  cursor: pointer;
  font-size: var(--text-sm);
  text-align: start;
  transition: background 0.1s ease;
}

.tiptap-slash-item:hover,
.tiptap-slash-item--active {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

  .tiptap-slash-item:focus-visible {
    outline: 2px solid var(--color-primary-400);
    outline-offset: -2px;
  }

  html[data-theme="dark"] .tiptap-slash-item {
    color: var(--color-neutral-300);
  }

  @media (prefers-color-scheme: dark) {
    html:not([data-theme]) .tiptap-slash-item {
      color: var(--color-neutral-300);
    }
  }

    html[data-theme="dark"] .tiptap-slash-item:hover,
    html[data-theme="dark"] .tiptap-slash-item--active {
      background: var(--color-neutral-700);
      color: var(--color-neutral-100);
    }

    html[data-theme="dark"] .tiptap-slash-item:focus-visible {
      outline-color: var(--color-primary-300);
    }

    @media (prefers-color-scheme: dark) {
      html:not([data-theme]) .tiptap-slash-item:hover,
      html:not([data-theme]) .tiptap-slash-item--active {
        background: var(--color-neutral-700);
        color: var(--color-neutral-100);
      }

      html:not([data-theme]) .tiptap-slash-item:focus-visible {
        outline-color: var(--color-primary-300);
      }
    }

.tiptap-slash-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: 28px;
  block-size: 28px;
  border-radius: 6px;
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
  flex-shrink: 0;
}

.tiptap-slash-label {
  flex: 1;
}

.tiptap-slash-empty {
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

/* --- Description Editor Controls --- */

.description-editor-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-block-start: var(--space-3);
  justify-content: flex-end;
}

.description-status {
  font-size: var(--text-xs);
  margin-inline-start: var(--space-2);
}

.description-status--success {
  color: var(--color-status-success-action);
}

.description-status--error {
  color: var(--color-status-error-action);
}

.description-edit-btn {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-tertiary);
  cursor: pointer;
  font-size: var(--text-xs);
  transition: background 0.15s ease, color 0.15s ease;
}

.description-edit-btn:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-strong);
}

.description-save-btn {
  padding: var(--space-1) var(--space-3);
  border: none;
  border-radius: 6px;
  background: var(--color-primary-500);
  color: white;
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 500;
  transition: background 0.15s ease;
}

  .description-save-btn:hover {
    background: var(--color-primary-600);
  }

.description-cancel-btn {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border-primary);
  border-radius: 6px;
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 500;
  transition: background 0.15s ease;
}

.description-cancel-btn:hover {
  background: var(--color-bg-subtle);
}

.tiptap-editor-wrapper .ProseMirror .ProseMirror-gapcursor::after {
  border-block-start: 1px solid var(--color-text-strong);
}

/* --- Inline Images [MC-279] --- */

.tiptap-editor-wrapper .ProseMirror .tiptap-image {
  display: block;
  max-inline-size: 100%;
  block-size: auto;
  margin-block: var(--space-4);
  margin-inline: 0;
  border-radius: var(--radius-md);
}

/* Uploading state: uses alt text as selector because TipTap's Image extension
   does not pass through custom data attributes. If Image is extended to support
   arbitrary attrs, replace with a data-uploading attribute instead. */
.tiptap-editor-wrapper .ProseMirror .tiptap-image[alt="Uploading..."] {
  opacity: 0.5;
  filter: grayscale(0.3);
}

/* --- Drop cursor --- */

.tiptap-editor-wrapper .ProseMirror .ProseMirror-dropcursor {
  color: var(--color-text-link);
}

/* ============================================
   Dark Mode
   ============================================ */

/* Dark mode editor overrides */
html[data-theme="dark"] .tiptap-editor-wrapper {
  --_editor-code-color: var(--color-error-300);
  --_editor-blockquote-bg: color-mix(in srgb, var(--color-primary-900) 30%, transparent);
  --_editor-selected-cell-bg: color-mix(in srgb, var(--color-primary-800) 40%, transparent);
}

/* Dark mode bubble menu */
html[data-theme="dark"] .tiptap-bubble-btn--active {
  --_bubble-active-bg: var(--color-primary-900);
  --_bubble-active-color: var(--color-primary-300);
  --_bubble-active-bg-hover: var(--color-primary-800);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) .tiptap-editor-wrapper {
    --_editor-code-color: var(--color-error-300);
    --_editor-blockquote-bg: color-mix(in srgb, var(--color-primary-900) 30%, transparent);
    --_editor-selected-cell-bg: color-mix(in srgb, var(--color-primary-800) 40%, transparent);
  }

  html:not([data-theme]) .tiptap-bubble-btn--active {
    --_bubble-active-bg: var(--color-primary-900);
    --_bubble-active-color: var(--color-primary-300);
    --_bubble-active-bg-hover: var(--color-primary-800);
  }
}

/* ============================================
   Mention Support [MC-174]
   ============================================ */

/* --- Inline Mention Badge --- */

.tiptap-mention {
  display: inline;
  padding: 0 var(--space-1);
  background: color-mix(in srgb, var(--color-primary-500) 12%, transparent);
  border-radius: var(--radius-full);
  color: var(--color-text-accent-bright);
  font-weight: var(--font-medium);
  text-decoration: none;
}

  html[data-theme="dark"] .tiptap-mention {
    background: color-mix(in srgb, var(--color-primary-500) 20%, transparent);
    color: var(--color-primary-300);
  }

  @media (prefers-color-scheme: dark) {
    html:not([data-theme]) .tiptap-mention {
      background: color-mix(in srgb, var(--color-primary-500) 20%, transparent);
      color: var(--color-primary-300);
    }
  }

/* --- Mention Suggestion Menu --- */

.tiptap-mention-menu {
  position: fixed;
  z-index: 9999;
  min-inline-size: 200px;
  max-inline-size: 320px;
  max-block-size: 280px;
  overflow-y: auto;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-secondary) transparent;
}

  .tiptap-mention-menu::-webkit-scrollbar {
    inline-size: 6px;
  }

  .tiptap-mention-menu::-webkit-scrollbar-track {
    background: transparent;
  }

  .tiptap-mention-menu::-webkit-scrollbar-thumb {
    background: var(--color-border-secondary);
    border-radius: 3px;
  }

    .tiptap-mention-menu::-webkit-scrollbar-thumb:hover {
      background: var(--color-border-muted);
    }

.tiptap-mention-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  inline-size: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-strong);
  cursor: pointer;
  font-size: var(--text-sm);
  text-align: start;
  transition: background 0.1s ease;
}

.tiptap-mention-item:hover,
.tiptap-mention-item--active {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.tiptap-mention-avatar {
  inline-size: 28px;
  block-size: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.tiptap-mention-avatar--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-subtle);
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

.tiptap-mention-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tiptap-mention-empty {
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}


/* stylelint-enable selector-class-pattern */

} /* @layer components */
