/* TipTap Editor Styles */

/* Editor content area */
.tiptap-editor {
  min-height: 120px;
  cursor: text;
}

.tiptap-editor:focus {
  outline: none;
}

/* Placeholder */
.tiptap-editor p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: #9ca3af;
  pointer-events: none;
  height: 0;
}

.dark .tiptap-editor p.is-editor-empty:first-child::before {
  color: #6b7280;
}

/* Toolbar buttons */
.tiptap-tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  /* Было #6b7280 — на фоне панели это 4.0:1 при норме 4.5 для 12px-подписей
     H1/H2/H3 (axe: color-contrast). Токен темнее и темизируется. */
  color: var(--color-fg-muted);
  transition: all 0.15s;
}

.tiptap-tb-btn:hover {
  background-color: #e5e7eb;
  color: #374151;
}

.dark .tiptap-tb-btn {
  color: #9ca3af;
}

.dark .tiptap-tb-btn:hover {
  background-color: #374151;
  color: #e5e7eb;
}

.tiptap-tb-sep {
  width: 1px;
  height: 20px;
  background-color: #e5e7eb;
  margin: 0 4px;
}

.dark .tiptap-tb-sep {
  background-color: #4b5563;
}

/* Floating selection toolbar (BubbleMenu) — Notion/Linear-style format bar over
   a text selection. BubbleMenu sets positioning inline; this is just the look. */
.tiptap-bubble {
  /* Панель обязана быть ВНЕ потока. Замер в модалке «Новая задача» на 390px:
     элемент имел position: static и НИ ОДНОГО инлайн-стиля от плагина, то есть
     BubbleMenu его не подхватил — и он рендерился как вторая, постоянно
     видимая панель форматирования 330×36 под редактором. Вместе со статической
     панелью это съедало ~200px из 844 на одно только форматирование.
     Плагин, когда забирает элемент себе, выставляет позицию и видимость
     инлайн — инлайн-стиль перебивает это правило, поэтому рабочий сценарий
     всплывающей панели не ломается. */
  position: absolute;
  visibility: hidden;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background-color: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* Плагин выставляет инлайн-стили, когда управляет панелью — тогда показываем. */
.tiptap-bubble[style] { visibility: visible; }

.dark .tiptap-bubble {
  background-color: #1f2937;
  border-color: #374151;
}

/* «Copy as Markdown» toolbar button — brief confirmation flash on success. */
.tiptap-tb-btn--copymd.is-copied {
  color: #16a34a;
  background-color: #dcfce7;
}

.dark .tiptap-tb-btn--copymd.is-copied {
  color: #4ade80;
  background-color: #14532d;
}

/* Task list */
.tiptap-editor ul[data-type="taskList"] {
  list-style: none;
  padding-left: 0;
}

.tiptap-editor ul[data-type="taskList"] li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.tiptap-editor ul[data-type="taskList"] li > label {
  flex-shrink: 0;
  margin-top: 3px;
}

.tiptap-editor ul[data-type="taskList"] li > div {
  flex: 1;
}

/* Table */
.tiptap-editor table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
}

.tiptap-editor th,
.tiptap-editor td {
  border: 1px solid #d1d5db;
  padding: 6px 10px;
  text-align: left;
  min-width: 80px;
}

.dark .tiptap-editor th,
.dark .tiptap-editor td {
  border-color: #4b5563;
}

.tiptap-editor th {
  background-color: #f9fafb;
  font-weight: 600;
}

.dark .tiptap-editor th {
  background-color: #374151;
}

/* Code block */
.tiptap-editor pre {
  background-color: #1f2937;
  color: #e5e7eb;
  border-radius: 6px;
  padding: 12px 16px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.875rem;
}

.tiptap-editor pre code {
  color: inherit;
  background: none;
  padding: 0;
  font-size: inherit;
}

/* Blockquote */
.tiptap-editor blockquote {
  border-left: 3px solid #6366f1;
  padding-left: 1em;
  color: #6b7280;
  margin: 1em 0;
}

.dark .tiptap-editor blockquote {
  border-left-color: #818cf8;
  color: #9ca3af;
}

/* Image */
.tiptap-editor img {
  max-width: 100%;
  border-radius: 6px;
  margin: 1em 0;
}

/* Link */
.tiptap-editor a {
  color: #3b82f6;
  text-decoration: underline;
}

/* Highlight */
.tiptap-editor mark {
  background-color: #fef08a;
  border-radius: 2px;
  padding: 0 2px;
}

.dark .tiptap-editor mark {
  background-color: #854d0e;
  color: #fef08a;
}

/* Horizontal rule */
.tiptap-editor hr {
  border: none;
  border-top: 2px solid #e5e7eb;
  margin: 1.5em 0;
}

.dark .tiptap-editor hr {
  border-top-color: #4b5563;
}

/* Slash command menu */
.tiptap-slash-menu {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
  min-width: 240px;
}

.dark .tiptap-slash-menu {
  background: #1f2937;
  border-color: #374151;
}

.tiptap-slash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
  border: none;
  background: none;
  color: #374151;
  font-size: 14px;
}

.dark .tiptap-slash-item {
  color: #e5e7eb;
}

.tiptap-slash-item:hover,
.tiptap-slash-item.is-selected {
  background-color: #eff6ff;
}

.dark .tiptap-slash-item:hover,
.dark .tiptap-slash-item.is-selected {
  background-color: #1e3a5f;
}

.tiptap-slash-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #f3f4f6;
  font-size: 14px;
  flex-shrink: 0;
}

.dark .tiptap-slash-icon {
  background: #374151;
}

.tiptap-slash-text {
  display: flex;
  flex-direction: column;
}

.tiptap-slash-title {
  font-weight: 500;
}

.tiptap-slash-desc {
  font-size: 12px;
  color: #9ca3af;
}

.dark .tiptap-slash-desc {
  color: #6b7280;
}

/* S-B-59 — video embeds (YouTube/Vimeo). Responsive 16:9; the iframe src host
   is locked in the Embed node (tiptap/extensions/embed.js). */
.tiptap-embed {
  position: relative;
  margin: 1rem 0;
  border-radius: var(--radius-lg, 0.5rem);
  overflow: hidden;
  background: #000;
  aspect-ratio: 16 / 9;
}

.tiptap-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Validation failed → plain link box, never an iframe. */
.tiptap-embed--fallback {
  aspect-ratio: auto;
  background: transparent;
  padding: 0.5rem 0.75rem;
  border: 1px dashed var(--color-border, #d1d5db);
}

.tiptap-embed--fallback a {
  color: var(--color-accent, #2563eb);
  word-break: break-all;
}

.tiptap-editor .tiptap-embed.ProseMirror-selectednode {
  outline: 2px solid var(--color-accent, #2563eb);
  outline-offset: 2px;
}

/* S-B-59 — AI assist dropdown in the bubble toolbar. */
.tiptap-ai {
  position: relative;
  display: inline-flex;
}

.tiptap-ai-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 10000;
  min-width: 11rem;
  padding: 0.25rem;
  border-radius: var(--radius-lg, 0.5rem);
  background: var(--color-bg-elevated, #fff);
  border: 1px solid var(--color-border, #d1d5db);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
  display: flex;
  flex-direction: column;
}

.tiptap-ai-menu[hidden] { display: none; }

.tiptap-ai-menu button {
  text-align: left;
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
  border-radius: 0.375rem;
  color: var(--color-fg, #111827);
  white-space: nowrap;
}

.tiptap-ai-menu button:hover {
  background: var(--color-bg-muted, #f3f4f6);
}

/* Pending state while an AI request is in flight. */
.tiptap-ai-busy .tiptap-tb-btn--ai {
  opacity: 0.5;
  pointer-events: none;
}

.tiptap-ai-busy .tiptap-content {
  opacity: 0.7;
}
